From 152a3cf7b604f876e5b7f2ff1c96a7da189d33e1 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 16 Apr 2018 18:29:42 -0700 Subject: [PATCH] Fixed edit/find/select dialogs not working while editing a submodel. --- common/lc_mainwindow.cpp | 8 +++++++- common/lc_mainwindow.h | 8 ++++++++ common/lc_model.cpp | 4 ++-- qt/lc_qeditgroupsdialog.cpp | 8 ++++---- qt/lc_qeditgroupsdialog.h | 4 ++-- qt/lc_qfinddialog.cpp | 34 ++++++++++++++++------------------ qt/lc_qfinddialog.h | 4 ++-- qt/lc_qselectdialog.cpp | 10 ++++------ qt/lc_qselectdialog.h | 4 ++-- 9 files changed, 47 insertions(+), 37 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index e3913f5a..1200be62 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -1083,7 +1083,7 @@ void lcMainWindow::ShowSearchDialog() mSearchOptions.Info = ((lcPiece*)Focus)->mPieceInfo; } - lcQFindDialog Dialog(this, &mSearchOptions); + lcQFindDialog Dialog(this, &mSearchOptions, GetActiveModel()); if (Dialog.exec() == QDialog::Accepted) Model->FindPiece(true, true); } @@ -2307,6 +2307,12 @@ void lcMainWindow::SetModelFromSelection() } } +lcModel* lcMainWindow::GetActiveModel() const +{ + View* ActiveView = GetActiveView(); + return ActiveView ? ActiveView->GetActiveModel() : nullptr; +} + void lcMainWindow::HandleCommand(lcCommandId CommandId) { View* ActiveView = GetActiveView(); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 08bb8b2a..60c6dcab 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -192,6 +192,14 @@ public: return CurrentTab ? CurrentTab->GetActiveView() : nullptr; } + lcModel* GetActiveModel() const; + + lcModel* GetCurrentTabModel() const + { + lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget(); + return CurrentTab ? CurrentTab->GetModel() : nullptr; + } + const lcArray* GetViewsForModel(lcModel* Model) const { lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index b4543f80..5ea1759e 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1868,7 +1868,7 @@ void lcModel::ShowEditGroupsDialog() GroupParents[Group] = Group->mGroup; } - lcQEditGroupsDialog Dialog(gMainWindow, PieceParents, GroupParents); + lcQEditGroupsDialog Dialog(gMainWindow, PieceParents, GroupParents, this); if (Dialog.exec() != QDialog::Accepted) return; @@ -4165,7 +4165,7 @@ void lcModel::ShowSelectByNameDialog() return; } - lcQSelectDialog Dialog(gMainWindow); + lcQSelectDialog Dialog(gMainWindow, this); if (Dialog.exec() != QDialog::Accepted) return; diff --git a/qt/lc_qeditgroupsdialog.cpp b/qt/lc_qeditgroupsdialog.cpp index 9601f264..e7ec3fdc 100644 --- a/qt/lc_qeditgroupsdialog.cpp +++ b/qt/lc_qeditgroupsdialog.cpp @@ -2,16 +2,16 @@ #include "lc_qeditgroupsdialog.h" #include "ui_lc_qeditgroupsdialog.h" #include "lc_application.h" -#include "project.h" #include "lc_model.h" #include "piece.h" #include "group.h" #include "lc_basewindow.h" -lcQEditGroupsDialog::lcQEditGroupsDialog(QWidget* Parent, const QMap& PieceParents, const QMap& GroupParents) +lcQEditGroupsDialog::lcQEditGroupsDialog(QWidget* Parent, const QMap& PieceParents, const QMap& GroupParents, lcModel* Model) : QDialog(Parent), mPieceParents(PieceParents), mGroupParents(GroupParents) { mLastItemClicked = nullptr; + mModel = Model; ui = new Ui::lcQEditGroupsDialog; ui->setupUi(this); @@ -40,7 +40,7 @@ void lcQEditGroupsDialog::accept() void lcQEditGroupsDialog::reject() { for (int GroupIdx = 0; GroupIdx < mNewGroups.size(); GroupIdx++) - lcGetActiveModel()->RemoveGroup(mNewGroups[GroupIdx]); + mModel->RemoveGroup(mNewGroups[GroupIdx]); QDialog::reject(); } @@ -57,7 +57,7 @@ void lcQEditGroupsDialog::on_newGroup_clicked() lcGroup* ParentGroup = (lcGroup*)CurrentItem->data(0, GroupRole).value(); - lcGroup* NewGroup = lcGetActiveModel()->AddGroup(tr("Group #"), ParentGroup); + lcGroup* NewGroup = mModel->AddGroup(tr("Group #"), ParentGroup); mGroupParents[NewGroup] = ParentGroup; mNewGroups.append(NewGroup); diff --git a/qt/lc_qeditgroupsdialog.h b/qt/lc_qeditgroupsdialog.h index ba5cbdb6..c527ac99 100644 --- a/qt/lc_qeditgroupsdialog.h +++ b/qt/lc_qeditgroupsdialog.h @@ -11,7 +11,7 @@ class lcQEditGroupsDialog : public QDialog Q_OBJECT public: - lcQEditGroupsDialog(QWidget* Parent, const QMap& PieceParents, const QMap& GroupParents); + lcQEditGroupsDialog(QWidget* Parent, const QMap& PieceParents, const QMap& GroupParents, lcModel* Model); ~lcQEditGroupsDialog(); QMap mPieceParents; @@ -40,8 +40,8 @@ private: void timerEvent(QTimerEvent* Event); + lcModel* mModel; QTreeWidgetItem* mLastItemClicked; bool mEditableDoubleClicked; QBasicTimer mClickTimer; }; - diff --git a/qt/lc_qfinddialog.cpp b/qt/lc_qfinddialog.cpp index 5df30b9f..6edd3966 100644 --- a/qt/lc_qfinddialog.cpp +++ b/qt/lc_qfinddialog.cpp @@ -3,13 +3,11 @@ #include "ui_lc_qfinddialog.h" #include "lc_mainwindow.h" #include "pieceinf.h" -#include "project.h" #include "lc_colors.h" #include "lc_model.h" -lcQFindDialog::lcQFindDialog(QWidget *parent, void *data) : - QDialog(parent), - ui(new Ui::lcQFindDialog) +lcQFindDialog::lcQFindDialog(QWidget* Parent, lcSearchOptions* SearchOptions, lcModel* Model) + : QDialog(Parent), ui(new Ui::lcQFindDialog) { ui->setupUi(this); @@ -18,20 +16,20 @@ lcQFindDialog::lcQFindDialog(QWidget *parent, void *data) : parts->setMinimumContentsLength(1); lcPartsList PartsList; - lcGetActiveModel()->GetPartsList(gDefaultColor, false, PartsList); + Model->GetPartsList(gDefaultColor, false, PartsList); for (const auto& PartIt : PartsList) parts->addItem(PartIt.first->m_strDescription, qVariantFromValue((void*)PartIt.first)); parts->model()->sort(0); - options = (lcSearchOptions*)data; + mSearchOptions = SearchOptions; - ui->findColor->setChecked(options->MatchColor); - ui->color->setCurrentColor(options->ColorIndex); - ui->findID->setChecked(options->MatchInfo); - parts->setCurrentIndex(parts->findData(qVariantFromValue((void*)options->Info))); - ui->findName->setChecked(options->MatchName); - ui->name->setText(options->Name); + ui->findColor->setChecked(mSearchOptions->MatchColor); + ui->color->setCurrentColor(mSearchOptions->ColorIndex); + ui->findID->setChecked(mSearchOptions->MatchInfo); + parts->setCurrentIndex(parts->findData(qVariantFromValue((void*)mSearchOptions->Info))); + ui->findName->setChecked(mSearchOptions->MatchName); + ui->name->setText(mSearchOptions->Name); } lcQFindDialog::~lcQFindDialog() @@ -41,13 +39,13 @@ lcQFindDialog::~lcQFindDialog() void lcQFindDialog::accept() { - options->MatchColor = ui->findColor->isChecked(); - options->ColorIndex = ui->color->currentColor(); - options->MatchInfo= ui->findID->isChecked(); - options->Info = (PieceInfo*)ui->ID->itemData(ui->ID->currentIndex()).value(); - options->MatchName = ui->findName->isChecked(); + mSearchOptions->MatchColor = ui->findColor->isChecked(); + mSearchOptions->ColorIndex = ui->color->currentColor(); + mSearchOptions->MatchInfo= ui->findID->isChecked(); + mSearchOptions->Info = (PieceInfo*)ui->ID->itemData(ui->ID->currentIndex()).value(); + mSearchOptions->MatchName = ui->findName->isChecked(); QString name = ui->name->text(); - strcpy(options->Name, name.toLocal8Bit().data()); + strcpy(mSearchOptions->Name, name.toLocal8Bit().data()); QDialog::accept(); } diff --git a/qt/lc_qfinddialog.h b/qt/lc_qfinddialog.h index 6ef269c2..fb8ae95c 100644 --- a/qt/lc_qfinddialog.h +++ b/qt/lc_qfinddialog.h @@ -12,10 +12,10 @@ class lcQFindDialog : public QDialog Q_OBJECT public: - explicit lcQFindDialog(QWidget *parent, void *data); + lcQFindDialog(QWidget* Parent, lcSearchOptions* SearchOptions, lcModel* Model); ~lcQFindDialog(); - lcSearchOptions *options; + lcSearchOptions* mSearchOptions; public slots: void accept(); diff --git a/qt/lc_qselectdialog.cpp b/qt/lc_qselectdialog.cpp index a070cc95..8e4edbac 100644 --- a/qt/lc_qselectdialog.cpp +++ b/qt/lc_qselectdialog.cpp @@ -2,19 +2,18 @@ #include "lc_qselectdialog.h" #include "ui_lc_qselectdialog.h" #include "lc_application.h" -#include "project.h" #include "lc_model.h" #include "piece.h" #include "camera.h" #include "light.h" #include "group.h" -lcQSelectDialog::lcQSelectDialog(QWidget* Parent) +lcQSelectDialog::lcQSelectDialog(QWidget* Parent, lcModel* Model) : QDialog(Parent), ui(new Ui::lcQSelectDialog) { ui->setupUi(this); - AddChildren(ui->treeWidget->invisibleRootItem(), nullptr); + AddChildren(ui->treeWidget->invisibleRootItem(), nullptr, Model); ui->treeWidget->expandAll(); connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*, int))); @@ -170,9 +169,8 @@ void lcQSelectDialog::itemChanged(QTreeWidgetItem *item, int column) ui->treeWidget->blockSignals(false); } -void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup) +void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup, lcModel* Model) { - lcModel* Model = lcGetActiveModel(); const lcArray& Groups = Model->GetGroups(); for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++) @@ -184,7 +182,7 @@ void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGr QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->mName)); - AddChildren(GroupItem, Group); + AddChildren(GroupItem, Group, Model); } const lcArray& Pieces = Model->GetPieces(); diff --git a/qt/lc_qselectdialog.h b/qt/lc_qselectdialog.h index c398f898..6890b265 100644 --- a/qt/lc_qselectdialog.h +++ b/qt/lc_qselectdialog.h @@ -12,7 +12,7 @@ class lcQSelectDialog : public QDialog Q_OBJECT public: - lcQSelectDialog(QWidget* Parent); + lcQSelectDialog(QWidget* Parent, lcModel* Model); ~lcQSelectDialog(); lcArray mObjects; @@ -32,6 +32,6 @@ public slots: private: Ui::lcQSelectDialog *ui; - void AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup); + void AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup, lcModel* Model); };