Merge pull request #17315 from mwganson/ssclearall
[Spreadsheet] avoid removing user dynamic properties when clearing ce…
This commit is contained in:
@@ -127,40 +127,47 @@ const Cell* PropertySheet::getValueFromAlias(const std::string& alias) const
|
||||
}
|
||||
}
|
||||
|
||||
bool PropertySheet::isValidAlias(const std::string& candidate)
|
||||
bool PropertySheet::isValidCellAddressName(const std::string& candidate)
|
||||
{
|
||||
static const boost::regex gen("^[A-Za-z][_A-Za-z0-9]*$");
|
||||
boost::cmatch cm;
|
||||
|
||||
/* Check if it matches a cell reference */
|
||||
if (boost::regex_match(candidate.c_str(), cm, gen)) {
|
||||
static const boost::regex e("\\${0,1}([A-Z]{1,2})\\${0,1}([0-9]{1,5})");
|
||||
|
||||
if (boost::regex_match(candidate.c_str(), cm, e)) {
|
||||
const boost::sub_match<const char*> colstr = cm[1];
|
||||
const boost::sub_match<const char*> rowstr = cm[2];
|
||||
|
||||
if (App::validRow(rowstr.str()) >= 0 && App::validColumn(colstr.str())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PropertySheet::isValidAlias(const std::string& candidate)
|
||||
{
|
||||
|
||||
/* Check if it is used before */
|
||||
if (getValueFromAlias(candidate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* check if it would be a valid cell address name, e.g. "A2" or "C3" */
|
||||
if (isValidCellAddressName(candidate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check to make sure it doesn't clash with a reserved name */
|
||||
if (ExpressionParser::isTokenAUnit(candidate)
|
||||
|| ExpressionParser::isTokenAConstant(candidate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check to make sure it doesn't match a cell reference */
|
||||
if (boost::regex_match(candidate.c_str(), cm, gen)) {
|
||||
static const boost::regex e("\\${0,1}([A-Z]{1,2})\\${0,1}([0-9]{1,5})");
|
||||
|
||||
if (boost::regex_match(candidate.c_str(), cm, e)) {
|
||||
const boost::sub_match<const char*> colstr = cm[1];
|
||||
const boost::sub_match<const char*> rowstr = cm[2];
|
||||
|
||||
// A valid cell address?
|
||||
if (App::validRow(rowstr.str()) >= 0 && App::validColumn(colstr.str())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
@@ -124,6 +124,9 @@ public:
|
||||
|
||||
bool isValidAlias(const std::string& candidate);
|
||||
|
||||
// checks whether candidate is of form A1, C4, etc.
|
||||
bool isValidCellAddressName(const std::string& candidate);
|
||||
|
||||
std::vector<App::CellAddress> getUsedCells() const;
|
||||
|
||||
std::tuple<App::CellAddress, App::CellAddress> getUsedRange() const;
|
||||
|
||||
@@ -108,7 +108,11 @@ Sheet::~Sheet()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cells in the sheet.
|
||||
* Clear all cells in the sheet. These are implemented as dynamic
|
||||
* properties, for example "A1" is added as a dynamic property. Since
|
||||
* now users may add dyanamic properties, we need to try to avoid
|
||||
* removing those, too, so we check whether the dynamic property name
|
||||
* is a valid cell address name before removing it.
|
||||
*/
|
||||
|
||||
void Sheet::clearAll()
|
||||
@@ -118,7 +122,9 @@ void Sheet::clearAll()
|
||||
std::vector<std::string> propNames = props.getDynamicPropertyNames();
|
||||
|
||||
for (const auto& propName : propNames) {
|
||||
this->removeDynamicProperty(propName.c_str());
|
||||
if (cells.isValidCellAddressName(propName.c_str())) {
|
||||
this->removeDynamicProperty(propName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
propAddress.clear();
|
||||
|
||||
Reference in New Issue
Block a user