Spreadsheet: improve range binding feature (#6995)

* Spreadsheet: improve range binding feature
This commit is contained in:
Zheng Lei
2022-06-09 01:19:41 +08:00
committed by GitHub
parent 920e8e0469
commit 5864e17d9d
6 changed files with 170 additions and 82 deletions

View File

@@ -249,28 +249,9 @@ void SheetTableView::cellProperties()
std::vector<Range> SheetTableView::selectedRanges() const
{
QModelIndexList list = selectionModel()->selectedIndexes();
std::vector<Range> result;
// Insert selected cells into set. This variable should ideally be a hash_set
// but that is not part of standard stl.
std::set<std::pair<int, int> > cells;
for (QModelIndexList::const_iterator it = list.begin(); it != list.end(); ++it)
cells.insert(std::make_pair<int,int>((*it).row(), (*it).column()));
// Create rectangular cells from the unordered collection of selected cells
std::map<std::pair<int, int>, std::pair<int, int> > rectangles;
createRectangles(cells, rectangles);
std::map<std::pair<int, int>, std::pair<int, int> >::const_iterator i = rectangles.begin();
for (; i != rectangles.end(); ++i) {
std::pair<int, int> ul = (*i).first;
std::pair<int, int> size = (*i).second;
result.emplace_back(ul.first, ul.second,
ul.first + size.first - 1, ul.second + size.second - 1);
}
for (const auto &sel : selectionModel()->selection())
result.emplace_back(sel.top(), sel.left(), sel.bottom(), sel.right());
return result;
}