Fixed edit/find/select dialogs not working while editing a submodel.

This commit is contained in:
Leonardo Zide 2018-04-16 18:29:42 -07:00
parent aaa33d55e5
commit 152a3cf7b6
9 changed files with 47 additions and 37 deletions

View file

@ -1083,7 +1083,7 @@ void lcMainWindow::ShowSearchDialog()
mSearchOptions.Info = ((lcPiece*)Focus)->mPieceInfo; mSearchOptions.Info = ((lcPiece*)Focus)->mPieceInfo;
} }
lcQFindDialog Dialog(this, &mSearchOptions); lcQFindDialog Dialog(this, &mSearchOptions, GetActiveModel());
if (Dialog.exec() == QDialog::Accepted) if (Dialog.exec() == QDialog::Accepted)
Model->FindPiece(true, true); 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) void lcMainWindow::HandleCommand(lcCommandId CommandId)
{ {
View* ActiveView = GetActiveView(); View* ActiveView = GetActiveView();

View file

@ -192,6 +192,14 @@ public:
return CurrentTab ? CurrentTab->GetActiveView() : nullptr; return CurrentTab ? CurrentTab->GetActiveView() : nullptr;
} }
lcModel* GetActiveModel() const;
lcModel* GetCurrentTabModel() const
{
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget();
return CurrentTab ? CurrentTab->GetModel() : nullptr;
}
const lcArray<View*>* GetViewsForModel(lcModel* Model) const const lcArray<View*>* GetViewsForModel(lcModel* Model) const
{ {
lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model); lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model);

View file

@ -1868,7 +1868,7 @@ void lcModel::ShowEditGroupsDialog()
GroupParents[Group] = Group->mGroup; GroupParents[Group] = Group->mGroup;
} }
lcQEditGroupsDialog Dialog(gMainWindow, PieceParents, GroupParents); lcQEditGroupsDialog Dialog(gMainWindow, PieceParents, GroupParents, this);
if (Dialog.exec() != QDialog::Accepted) if (Dialog.exec() != QDialog::Accepted)
return; return;
@ -4165,7 +4165,7 @@ void lcModel::ShowSelectByNameDialog()
return; return;
} }
lcQSelectDialog Dialog(gMainWindow); lcQSelectDialog Dialog(gMainWindow, this);
if (Dialog.exec() != QDialog::Accepted) if (Dialog.exec() != QDialog::Accepted)
return; return;

View file

@ -2,16 +2,16 @@
#include "lc_qeditgroupsdialog.h" #include "lc_qeditgroupsdialog.h"
#include "ui_lc_qeditgroupsdialog.h" #include "ui_lc_qeditgroupsdialog.h"
#include "lc_application.h" #include "lc_application.h"
#include "project.h"
#include "lc_model.h" #include "lc_model.h"
#include "piece.h" #include "piece.h"
#include "group.h" #include "group.h"
#include "lc_basewindow.h" #include "lc_basewindow.h"
lcQEditGroupsDialog::lcQEditGroupsDialog(QWidget* Parent, const QMap<lcPiece*, lcGroup*>& PieceParents, const QMap<lcGroup*, lcGroup*>& GroupParents) lcQEditGroupsDialog::lcQEditGroupsDialog(QWidget* Parent, const QMap<lcPiece*, lcGroup*>& PieceParents, const QMap<lcGroup*, lcGroup*>& GroupParents, lcModel* Model)
: QDialog(Parent), mPieceParents(PieceParents), mGroupParents(GroupParents) : QDialog(Parent), mPieceParents(PieceParents), mGroupParents(GroupParents)
{ {
mLastItemClicked = nullptr; mLastItemClicked = nullptr;
mModel = Model;
ui = new Ui::lcQEditGroupsDialog; ui = new Ui::lcQEditGroupsDialog;
ui->setupUi(this); ui->setupUi(this);
@ -40,7 +40,7 @@ void lcQEditGroupsDialog::accept()
void lcQEditGroupsDialog::reject() void lcQEditGroupsDialog::reject()
{ {
for (int GroupIdx = 0; GroupIdx < mNewGroups.size(); GroupIdx++) for (int GroupIdx = 0; GroupIdx < mNewGroups.size(); GroupIdx++)
lcGetActiveModel()->RemoveGroup(mNewGroups[GroupIdx]); mModel->RemoveGroup(mNewGroups[GroupIdx]);
QDialog::reject(); QDialog::reject();
} }
@ -57,7 +57,7 @@ void lcQEditGroupsDialog::on_newGroup_clicked()
lcGroup* ParentGroup = (lcGroup*)CurrentItem->data(0, GroupRole).value<uintptr_t>(); lcGroup* ParentGroup = (lcGroup*)CurrentItem->data(0, GroupRole).value<uintptr_t>();
lcGroup* NewGroup = lcGetActiveModel()->AddGroup(tr("Group #"), ParentGroup); lcGroup* NewGroup = mModel->AddGroup(tr("Group #"), ParentGroup);
mGroupParents[NewGroup] = ParentGroup; mGroupParents[NewGroup] = ParentGroup;
mNewGroups.append(NewGroup); mNewGroups.append(NewGroup);

View file

@ -11,7 +11,7 @@ class lcQEditGroupsDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
lcQEditGroupsDialog(QWidget* Parent, const QMap<lcPiece*, lcGroup*>& PieceParents, const QMap<lcGroup*, lcGroup*>& GroupParents); lcQEditGroupsDialog(QWidget* Parent, const QMap<lcPiece*, lcGroup*>& PieceParents, const QMap<lcGroup*, lcGroup*>& GroupParents, lcModel* Model);
~lcQEditGroupsDialog(); ~lcQEditGroupsDialog();
QMap<lcPiece*, lcGroup*> mPieceParents; QMap<lcPiece*, lcGroup*> mPieceParents;
@ -40,8 +40,8 @@ private:
void timerEvent(QTimerEvent* Event); void timerEvent(QTimerEvent* Event);
lcModel* mModel;
QTreeWidgetItem* mLastItemClicked; QTreeWidgetItem* mLastItemClicked;
bool mEditableDoubleClicked; bool mEditableDoubleClicked;
QBasicTimer mClickTimer; QBasicTimer mClickTimer;
}; };

View file

@ -3,13 +3,11 @@
#include "ui_lc_qfinddialog.h" #include "ui_lc_qfinddialog.h"
#include "lc_mainwindow.h" #include "lc_mainwindow.h"
#include "pieceinf.h" #include "pieceinf.h"
#include "project.h"
#include "lc_colors.h" #include "lc_colors.h"
#include "lc_model.h" #include "lc_model.h"
lcQFindDialog::lcQFindDialog(QWidget *parent, void *data) : lcQFindDialog::lcQFindDialog(QWidget* Parent, lcSearchOptions* SearchOptions, lcModel* Model)
QDialog(parent), : QDialog(Parent), ui(new Ui::lcQFindDialog)
ui(new Ui::lcQFindDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -18,20 +16,20 @@ lcQFindDialog::lcQFindDialog(QWidget *parent, void *data) :
parts->setMinimumContentsLength(1); parts->setMinimumContentsLength(1);
lcPartsList PartsList; lcPartsList PartsList;
lcGetActiveModel()->GetPartsList(gDefaultColor, false, PartsList); Model->GetPartsList(gDefaultColor, false, PartsList);
for (const auto& PartIt : PartsList) for (const auto& PartIt : PartsList)
parts->addItem(PartIt.first->m_strDescription, qVariantFromValue((void*)PartIt.first)); parts->addItem(PartIt.first->m_strDescription, qVariantFromValue((void*)PartIt.first));
parts->model()->sort(0); parts->model()->sort(0);
options = (lcSearchOptions*)data; mSearchOptions = SearchOptions;
ui->findColor->setChecked(options->MatchColor); ui->findColor->setChecked(mSearchOptions->MatchColor);
ui->color->setCurrentColor(options->ColorIndex); ui->color->setCurrentColor(mSearchOptions->ColorIndex);
ui->findID->setChecked(options->MatchInfo); ui->findID->setChecked(mSearchOptions->MatchInfo);
parts->setCurrentIndex(parts->findData(qVariantFromValue((void*)options->Info))); parts->setCurrentIndex(parts->findData(qVariantFromValue((void*)mSearchOptions->Info)));
ui->findName->setChecked(options->MatchName); ui->findName->setChecked(mSearchOptions->MatchName);
ui->name->setText(options->Name); ui->name->setText(mSearchOptions->Name);
} }
lcQFindDialog::~lcQFindDialog() lcQFindDialog::~lcQFindDialog()
@ -41,13 +39,13 @@ lcQFindDialog::~lcQFindDialog()
void lcQFindDialog::accept() void lcQFindDialog::accept()
{ {
options->MatchColor = ui->findColor->isChecked(); mSearchOptions->MatchColor = ui->findColor->isChecked();
options->ColorIndex = ui->color->currentColor(); mSearchOptions->ColorIndex = ui->color->currentColor();
options->MatchInfo= ui->findID->isChecked(); mSearchOptions->MatchInfo= ui->findID->isChecked();
options->Info = (PieceInfo*)ui->ID->itemData(ui->ID->currentIndex()).value<void*>(); mSearchOptions->Info = (PieceInfo*)ui->ID->itemData(ui->ID->currentIndex()).value<void*>();
options->MatchName = ui->findName->isChecked(); mSearchOptions->MatchName = ui->findName->isChecked();
QString name = ui->name->text(); QString name = ui->name->text();
strcpy(options->Name, name.toLocal8Bit().data()); strcpy(mSearchOptions->Name, name.toLocal8Bit().data());
QDialog::accept(); QDialog::accept();
} }

View file

@ -12,10 +12,10 @@ class lcQFindDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit lcQFindDialog(QWidget *parent, void *data); lcQFindDialog(QWidget* Parent, lcSearchOptions* SearchOptions, lcModel* Model);
~lcQFindDialog(); ~lcQFindDialog();
lcSearchOptions *options; lcSearchOptions* mSearchOptions;
public slots: public slots:
void accept(); void accept();

View file

@ -2,19 +2,18 @@
#include "lc_qselectdialog.h" #include "lc_qselectdialog.h"
#include "ui_lc_qselectdialog.h" #include "ui_lc_qselectdialog.h"
#include "lc_application.h" #include "lc_application.h"
#include "project.h"
#include "lc_model.h" #include "lc_model.h"
#include "piece.h" #include "piece.h"
#include "camera.h" #include "camera.h"
#include "light.h" #include "light.h"
#include "group.h" #include "group.h"
lcQSelectDialog::lcQSelectDialog(QWidget* Parent) lcQSelectDialog::lcQSelectDialog(QWidget* Parent, lcModel* Model)
: QDialog(Parent), ui(new Ui::lcQSelectDialog) : QDialog(Parent), ui(new Ui::lcQSelectDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
AddChildren(ui->treeWidget->invisibleRootItem(), nullptr); AddChildren(ui->treeWidget->invisibleRootItem(), nullptr, Model);
ui->treeWidget->expandAll(); ui->treeWidget->expandAll();
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*, int))); 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); 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<lcGroup*>& Groups = Model->GetGroups(); const lcArray<lcGroup*>& Groups = Model->GetGroups();
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++) 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)); QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->mName));
AddChildren(GroupItem, Group); AddChildren(GroupItem, Group, Model);
} }
const lcArray<lcPiece*>& Pieces = Model->GetPieces(); const lcArray<lcPiece*>& Pieces = Model->GetPieces();

View file

@ -12,7 +12,7 @@ class lcQSelectDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
lcQSelectDialog(QWidget* Parent); lcQSelectDialog(QWidget* Parent, lcModel* Model);
~lcQSelectDialog(); ~lcQSelectDialog();
lcArray<lcObject*> mObjects; lcArray<lcObject*> mObjects;
@ -32,6 +32,6 @@ public slots:
private: private:
Ui::lcQSelectDialog *ui; Ui::lcQSelectDialog *ui;
void AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup); void AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup, lcModel* Model);
}; };