diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 45dff4255..239b150ad 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -99,9 +99,9 @@ void DialogHistory::cellClicked(int row, int column) item = ui->tableWidget->item(row, 0); cursorRow = row; item->setIcon(QIcon("://icon/32x32/put_after.png")); - quint32 id = qvariant_cast(item->data(Qt::UserRole)); + const quint32 id = qvariant_cast(item->data(Qt::UserRole)); doc->blockSignals(true); - doc->setCursor(id); + row == ui->tableWidget->rowCount()-1 ? doc->setCursor(0) : doc->setCursor(id); doc->blockSignals(false); } else @@ -185,7 +185,7 @@ void DialogHistory::FillTable() ui->tableWidget->setRowCount(count);//Real row count if (count>0) { - cursorRow = currentRow; + cursorRow = CursorRow(); QTableWidgetItem *item = ui->tableWidget->item(cursorRow, 0); SCASSERT(item != nullptr); item->setIcon(QIcon("://icon/32x32/put_after.png")); @@ -492,3 +492,24 @@ void DialogHistory::RetranslateUi() cursorRow = currentRow; cellClicked(cursorRow, 0); } + +//--------------------------------------------------------------------------------------------------------------------- +int DialogHistory::CursorRow() const +{ + const quint32 cursor = doc->getCursor(); + if (cursor == 0) + { + return ui->tableWidget->rowCount()-1; + } + + for (int i = 0; i < ui->tableWidget->rowCount(); ++i) + { + QTableWidgetItem *item = ui->tableWidget->item(i, 0); + const quint32 id = qvariant_cast(item->data(Qt::UserRole)); + if (cursor == id) + { + return i; + } + } + return ui->tableWidget->rowCount()-1; +} diff --git a/src/app/valentina/dialogs/dialoghistory.h b/src/app/valentina/dialogs/dialoghistory.h index e306f8ebf..fbe5bba14 100644 --- a/src/app/valentina/dialogs/dialoghistory.h +++ b/src/app/valentina/dialogs/dialoghistory.h @@ -91,6 +91,7 @@ private: QString PointName(quint32 pointId); quint32 AttrUInt(const QDomElement &domElement, const QString &name); void RetranslateUi(); + int CursorRow() const; }; #endif // DIALOGHISTORY_H diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index b3368ce36..ff76c450a 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -570,10 +570,10 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); - connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); - connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool, &DialogTool::SelectedObject); - connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); - connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); + connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool.data(), &DialogTool::ChosenObject); + connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool.data(), &DialogTool::SelectedObject); + connect(dialogTool.data(), &DialogTool::DialogClosed, this, closeDialogSlot); + connect(dialogTool.data(), &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); ui->view->itemClicked(nullptr); } else @@ -629,11 +629,11 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); - connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); - connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool, &DialogTool::SelectedObject); - connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); - connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot); - connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); + connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool.data(), &DialogTool::ChosenObject); + connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool.data(), &DialogTool::SelectedObject); + connect(dialogTool.data(), &DialogTool::DialogClosed, this, closeDialogSlot); + connect(dialogTool.data(), &DialogTool::DialogApplied, this, applyDialogSlot); + connect(dialogTool.data(), &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); connect(ui->view, &VMainGraphicsView::MouseRelease, this, &MainWindow::ClickEndVisualization); ui->view->itemClicked(nullptr); } @@ -653,7 +653,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur template void MainWindow::ClosedDialog(int result) { - SCASSERT(dialogTool != nullptr); + SCASSERT(not dialogTool.isNull()); if (result == QDialog::Accepted) { VMainGraphicsScene *scene = qobject_cast(currentScene); @@ -673,7 +673,7 @@ void MainWindow::ClosedDialog(int result) template void MainWindow::ClosedDialogWithApply(int result) { - SCASSERT(dialogTool != nullptr); + SCASSERT(not dialogTool.isNull()); if (result == QDialog::Accepted) { // Only create tool if not already created with apply @@ -691,7 +691,7 @@ void MainWindow::ClosedDialogWithApply(int result) vtool->FullUpdateFromGuiApply(); } } - SCASSERT(dialogTool != nullptr); + SCASSERT(not dialogTool.isNull()); QGraphicsItem *tool = dynamic_cast(dialogTool->GetAssociatedTool()); ui->view->itemClicked(tool); if (dialogTool->GetAssociatedTool() != nullptr) @@ -700,6 +700,15 @@ void MainWindow::ClosedDialogWithApply(int result) vtool->DialogLinkDestroy(); } ArrowTool(); + // If insert not to the end of file call lite parse + if (doc->getCursor() > 0) + { + doc->LiteParseTree(Document::LiteParse); + if (dialogHistory) + { + dialogHistory->UpdateHistory(); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -709,7 +718,7 @@ void MainWindow::ClosedDialogWithApply(int result) template void MainWindow::ApplyDialog() { - SCASSERT(dialogTool != nullptr); + SCASSERT(not dialogTool.isNull()); // Only create tool if not already created with apply if (dialogTool->GetAssociatedTool() == nullptr) @@ -1834,7 +1843,6 @@ void MainWindow::CancelTool() qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; - dialogTool = nullptr; qCDebug(vMainWindow, "Dialog closed."); currentScene->setFocus(Qt::OtherFocusReason); @@ -3090,8 +3098,8 @@ void MainWindow::ActionHistory(bool checked) { dialogHistory = new DialogHistory(pattern, doc, this); dialogHistory->setWindowFlags(Qt::Window); - connect(this, &MainWindow::RefreshHistory, dialogHistory, &DialogHistory::UpdateHistory); - connect(dialogHistory, &DialogHistory::DialogClosed, this, &MainWindow::ClosedActionHistory); + connect(this, &MainWindow::RefreshHistory, dialogHistory.data(), &DialogHistory::UpdateHistory); + connect(dialogHistory.data(), &DialogHistory::DialogClosed, this, &MainWindow::ClosedActionHistory); dialogHistory->show(); } else @@ -4254,7 +4262,7 @@ void MainWindow::ChangePP(int index, bool zoomBestFit) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::EndVisualization(bool click) { - if (dialogTool != nullptr) + if (not dialogTool.isNull()) { dialogTool->ShowDialog(click); } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 88d59c8de..10d5d5a4c 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -242,9 +242,9 @@ private: bool patternReadOnly; - DialogIncrements *dialogTable; - DialogTool *dialogTool; - DialogHistory *dialogHistory; + DialogIncrements *dialogTable; + QPointer dialogTool; + QPointer dialogHistory; /** @brief comboBoxDraws comboc who show name of pattern peaces. */ QComboBox *comboBoxDraws; diff --git a/src/libs/vtools/undocommands/addtocalc.cpp b/src/libs/vtools/undocommands/addtocalc.cpp index 04d3aa966..4e5ab15a5 100644 --- a/src/libs/vtools/undocommands/addtocalc.cpp +++ b/src/libs/vtools/undocommands/addtocalc.cpp @@ -49,7 +49,6 @@ void AddToCalc::undo() qCDebug(vUndo, "Undo."); doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change - doc->setCursor(cursor); QDomElement calcElement; if (doc->GetActivNodeElement(VAbstractPattern::TagCalculation, calcElement)) @@ -74,10 +73,6 @@ void AddToCalc::undo() qCDebug(vUndo, "Can't find tag Calculation."); return; } - if (cursor > 0) - { - doc->setCursor(0); - } emit NeedFullParsing(); VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo @@ -104,7 +99,6 @@ void AddToCalc::redo() if (refElement.isElement()) { calcElement.insertAfter(xml, refElement); - doc->setCursor(0); } else {