Fri, 02 Mar 2018 22:23:53 +0200
removed LDDocument::clearSelection and replaced it with a MainWindow implementation
--- 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())
--- 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<LDObject*>& LDDocument::getSelection() const -{ - return m_selection; -} - -// ============================================================================= -// bool LDDocument::swapObjects (LDObject* one, LDObject* other) { if (Model::swapObjects(one, other))
--- 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<LDObject*>& getSelection() const; bool hasUnsavedChanges() const; EditHistory* history() const; void initializeCachedData();
--- 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) :
--- 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<void(QAction*)> function); void changeDocument (LDDocument* f); + void clearSelection(); void closeInitialDocument(); Configuration* config(); void createBlankDocument();
--- 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")) {
--- 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()) {
--- 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()) {
--- 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<MainWindow*>(this->parent()); +}
--- 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<Toolset*> createToolsets (MainWindow* parent); + +protected: + MainWindow* mainWindow() const; };
--- 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<LDSubfileReference*> (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)); } } }