# HG changeset patch # User Santeri Piippo # Date 1520022233 -7200 # Node ID 3fea6bc1519bfcf5dba5ba7f95c2fc91ee343023 # Parent db1d4917626f63465fa097cf6c0f5af27c49f126 removed LDDocument::clearSelection and replaced it with a MainWindow implementation diff -r db1d4917626f -r 3fea6bc1519b src/editmodes/selectMode.cpp --- a/src/editmodes/selectMode.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/editmodes/selectMode.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -129,7 +129,6 @@ if (ev->buttons() & Qt::LeftButton) { - currentDocument()->clearSelection(); QModelIndex index = renderer()->pick(ev->x(), ev->y()); if (index.isValid()) diff -r db1d4917626f -r 3fea6bc1519b src/lddocument.cpp --- a/src/lddocument.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/lddocument.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -457,21 +457,6 @@ // ============================================================================= // -void LDDocument::clearSelection() -{ - for (LDObject* object : m_selection.toList()) - removeFromSelection(object); -} - -// ============================================================================= -// -const QSet& LDDocument::getSelection() const -{ - return m_selection; -} - -// ============================================================================= -// bool LDDocument::swapObjects (LDObject* one, LDObject* other) { if (Model::swapObjects(one, other)) diff -r db1d4917626f -r 3fea6bc1519b src/lddocument.h --- a/src/lddocument.h Thu Mar 01 11:59:54 2018 +0200 +++ b/src/lddocument.h Fri Mar 02 22:23:53 2018 +0200 @@ -50,12 +50,10 @@ void addToHistory (AbstractHistoryEntry* entry); void addToSelection (LDObject* obj); void clearHistory(); - void clearSelection(); void close(); QString defaultName() const; QString fullPath(); QString getDisplayName(); - const QSet& getSelection() const; bool hasUnsavedChanges() const; EditHistory* history() const; void initializeCachedData(); diff -r db1d4917626f -r 3fea6bc1519b src/mainwindow.cpp --- a/src/mainwindow.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/mainwindow.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -1099,6 +1099,11 @@ return m_mathFunctions; } +void MainWindow::clearSelection() +{ + m_selections[m_currentDocument]->clear(); +} + // --------------------------------------------------------------------------------------------------------------------- // ColorToolbarItem::ColorToolbarItem (LDColor color, QToolButton* toolButton) : diff -r db1d4917626f -r 3fea6bc1519b src/mainwindow.h --- a/src/mainwindow.h Thu Mar 01 11:59:54 2018 +0200 +++ b/src/mainwindow.h Fri Mar 02 22:23:53 2018 +0200 @@ -67,6 +67,7 @@ void addMessage (QString msg); void applyToActions (std::function function); void changeDocument (LDDocument* f); + void clearSelection(); void closeInitialDocument(); Configuration* config(); void createBlankDocument(); diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/basictoolset.cpp --- a/src/toolsets/basictoolset.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -71,7 +71,7 @@ { const QString clipboardText = qApp->clipboard()->text(); int idx = m_window->suggestInsertPoint(); - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); int count = 0; for (QString line : clipboardText.split("\n")) @@ -179,7 +179,7 @@ if (dlg->exec() == QDialog::Rejected) return; - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); for (QString line : QString (inputbox->toPlainText()).split ("\n")) { diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/extprogramtoolset.cpp --- a/src/toolsets/extprogramtoolset.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/extprogramtoolset.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -322,7 +322,7 @@ m_window->deleteByColor (color); // Insert the new objects - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); for (LDObject* object : model.objects()) { diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/filetoolset.cpp --- a/src/toolsets/filetoolset.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/filetoolset.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -119,7 +119,7 @@ Model model {m_documents}; m_documents->loadFileContents(&file, model, nullptr, nullptr); - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); for (LDObject* object : model.objects()) { diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/toolset.cpp --- a/src/toolsets/toolset.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/toolset.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -40,3 +40,8 @@ tools << new ViewToolset (parent); return tools; } + +MainWindow* Toolset::mainWindow() const +{ + return qobject_cast(this->parent()); +} diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/toolset.h --- a/src/toolsets/toolset.h Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/toolset.h Fri Mar 02 22:23:53 2018 +0200 @@ -30,4 +30,7 @@ Toolset (MainWindow* parent); static QVector createToolsets (MainWindow* parent); + +protected: + MainWindow* mainWindow() const; }; diff -r db1d4917626f -r 3fea6bc1519b src/toolsets/viewtoolset.cpp --- a/src/toolsets/viewtoolset.cpp Thu Mar 01 11:59:54 2018 +0200 +++ b/src/toolsets/viewtoolset.cpp Fri Mar 02 22:23:53 2018 +0200 @@ -51,7 +51,7 @@ colors << obj->color(); } - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); for (LDObject* obj : currentDocument()->objects()) { @@ -76,7 +76,7 @@ subfilenames << static_cast (obj)->fileInfo()->name(); } - currentDocument()->clearSelection(); + mainWindow()->clearSelection(); for (LDObject* obj : currentDocument()->objects()) { @@ -236,17 +236,30 @@ void ViewToolset::jumpTo() { bool ok; - int defaultValue = (countof(selectedObjects()) == 1) ? (*selectedObjects().begin())->lineNumber() : 0; - int index = QInputDialog::getInt (nullptr, "Go to line", "Go to line:", defaultValue, 1, currentDocument()->size(), 1, &ok); + int defaultValue = 0; + + if (countof(selectedObjects()) == 1) + defaultValue = (*selectedObjects().begin())->lineNumber(); + + int row = QInputDialog::getInt( + nullptr, /* parent */ + tr("Go to line"), /* title */ + tr("Go to line:"), /* caption */ + defaultValue, /* default value */ + 1, /* minimum value */ + currentDocument()->size(), /* maximum value */ + 1, /* step value */ + &ok /* success pointer */ + ); if (ok) { - LDObject *object = currentDocument()->getObject(index - 1); + QModelIndex object = currentDocument()->index(row - 1); - if (object) + if (object.isValid() and object.row() < currentDocument()->size()) { - currentDocument()->clearSelection(); - currentDocument()->addToSelection(object); + mainWindow()->clearSelection(); + currentDocument()->addToSelection(currentDocument()->lookup(object)); } } }