Spreadsheet: fix range checking (#6997)
* App: add option to normalize a Range - To make sure the range starts from top left and ends with bottom right corner. - Default is to not normalize on construction for backward compatibility. - fix range checking in range binding
This commit is contained in:
@@ -830,9 +830,10 @@ Sheet::getCellBinding(Range &range,
|
||||
ExpressionPtr *pEnd,
|
||||
App::ObjectIdentifier *pTarget) const
|
||||
{
|
||||
range.normalize();
|
||||
do {
|
||||
CellAddress addr = *range;
|
||||
for(auto &r : boundRanges) {
|
||||
for(const auto &r : boundRanges) {
|
||||
if(addr.row()>=r.from().row()
|
||||
&& addr.row()<=r.to().row()
|
||||
&& addr.col()>=r.from().col()
|
||||
@@ -885,20 +886,20 @@ void Sheet::updateBindings()
|
||||
std::set<Range> newRangeSet;
|
||||
std::set<Range> rangeSet;
|
||||
boundRanges.clear();
|
||||
for(auto &v : ExpressionEngine.getExpressions()) {
|
||||
for(const auto &v : ExpressionEngine.getExpressions()) {
|
||||
CellAddress from,to;
|
||||
if(!cells.isBindingPath(v.first,&from,&to))
|
||||
continue;
|
||||
App::Range range(from,to);
|
||||
App::Range range(from,to,true);
|
||||
if(!oldRangeSet.erase(range))
|
||||
newRangeSet.insert(range);
|
||||
rangeSet.insert(range);
|
||||
}
|
||||
boundRanges.reserve(rangeSet.size());
|
||||
boundRanges.insert(boundRanges.end(),rangeSet.begin(),rangeSet.end());
|
||||
for(auto &range : oldRangeSet)
|
||||
for(const auto &range : oldRangeSet)
|
||||
rangeUpdated(range);
|
||||
for(auto &range : newRangeSet)
|
||||
for(const auto &range : newRangeSet)
|
||||
rangeUpdated(range);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,8 +188,8 @@ void DlgBindSheet::accept()
|
||||
else {
|
||||
checkAddress(toEnd, toCellEnd, true);
|
||||
if (toCellStart.isValid()) {
|
||||
App::Range fromRange(fromCellStart, fromCellEnd);
|
||||
App::Range toRange(toCellStart, toCellEnd);
|
||||
App::Range fromRange(fromCellStart, fromCellEnd, true);
|
||||
App::Range toRange(toCellStart, toCellEnd, true);
|
||||
if (fromRange.size() != toRange.size()) {
|
||||
auto res = QMessageBox::warning(this, tr("Bind cells"),
|
||||
tr("Source and target cell count mismatch. Partial binding may still work.\n\n"
|
||||
|
||||
Reference in New Issue
Block a user