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;
}
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();

View file

@ -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<View*>* GetViewsForModel(lcModel* Model) const
{
lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model);

View file

@ -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;

View file

@ -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<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)
{
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<uintptr_t>();
lcGroup* NewGroup = lcGetActiveModel()->AddGroup(tr("Group #"), ParentGroup);
lcGroup* NewGroup = mModel->AddGroup(tr("Group #"), ParentGroup);
mGroupParents[NewGroup] = ParentGroup;
mNewGroups.append(NewGroup);

View file

@ -11,7 +11,7 @@ class lcQEditGroupsDialog : public QDialog
Q_OBJECT
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();
QMap<lcPiece*, lcGroup*> mPieceParents;
@ -40,8 +40,8 @@ private:
void timerEvent(QTimerEvent* Event);
lcModel* mModel;
QTreeWidgetItem* mLastItemClicked;
bool mEditableDoubleClicked;
QBasicTimer mClickTimer;
};

View file

@ -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<void*>();
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<void*>();
mSearchOptions->MatchName = ui->findName->isChecked();
QString name = ui->name->text();
strcpy(options->Name, name.toLocal8Bit().data());
strcpy(mSearchOptions->Name, name.toLocal8Bit().data());
QDialog::accept();
}

View file

@ -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();

View file

@ -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<lcGroup*>& 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<lcPiece*>& Pieces = Model->GetPieces();

View file

@ -12,7 +12,7 @@ class lcQSelectDialog : public QDialog
Q_OBJECT
public:
lcQSelectDialog(QWidget* Parent);
lcQSelectDialog(QWidget* Parent, lcModel* Model);
~lcQSelectDialog();
lcArray<lcObject*> 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);
};