2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_qselectdialog.h"
|
|
|
|
#include "ui_lc_qselectdialog.h"
|
|
|
|
#include "lc_application.h"
|
2016-08-01 05:44:15 +02:00
|
|
|
#include "lc_model.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "piece.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include "group.h"
|
|
|
|
|
2018-04-17 03:29:42 +02:00
|
|
|
lcQSelectDialog::lcQSelectDialog(QWidget* Parent, lcModel* Model)
|
2016-08-01 05:44:15 +02:00
|
|
|
: QDialog(Parent), ui(new Ui::lcQSelectDialog)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2018-04-17 03:29:42 +02:00
|
|
|
AddChildren(ui->treeWidget->invisibleRootItem(), nullptr, Model);
|
2014-11-29 03:55:58 +01:00
|
|
|
ui->treeWidget->expandAll();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*, int)));
|
|
|
|
}
|
|
|
|
|
|
|
|
lcQSelectDialog::~lcQSelectDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQSelectDialog::accept()
|
|
|
|
{
|
2024-05-26 22:01:34 +02:00
|
|
|
mObjects.clear();
|
2014-11-29 03:55:58 +01:00
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> Items;
|
|
|
|
Items.append(ui->treeWidget->invisibleRootItem());
|
|
|
|
|
|
|
|
while (!Items.isEmpty())
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* Item = Items[0];
|
|
|
|
Items.removeFirst();
|
|
|
|
|
|
|
|
if (!Item->childCount())
|
|
|
|
{
|
|
|
|
if (Item->checkState(0) == Qt::Checked)
|
|
|
|
{
|
|
|
|
lcObject* Object = (lcObject*)Item->data(0, IndexRole).value<uintptr_t>();
|
2024-05-26 22:01:34 +02:00
|
|
|
mObjects.emplace_back(Object);
|
2014-11-29 03:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
|
|
|
|
Items.append(Item->child(ChildIdx));
|
|
|
|
}
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQSelectDialog::on_selectAll_clicked()
|
|
|
|
{
|
|
|
|
ui->treeWidget->blockSignals(true);
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QList<QTreeWidgetItem*> Items;
|
|
|
|
Items.append(ui->treeWidget->invisibleRootItem());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
while (!Items.isEmpty())
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* Item = Items[0];
|
|
|
|
Items.removeFirst();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Item->childCount())
|
|
|
|
Item->setCheckState(0, Qt::Checked);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
|
|
|
|
Items.append(Item->child(ChildIdx));
|
|
|
|
}
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
ui->treeWidget->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
void lcQSelectDialog::on_selectNone_clicked()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
ui->treeWidget->blockSignals(true);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QList<QTreeWidgetItem*> Items;
|
|
|
|
Items.append(ui->treeWidget->invisibleRootItem());
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
while (!Items.isEmpty())
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* Item = Items[0];
|
|
|
|
Items.removeFirst();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Item->childCount())
|
|
|
|
Item->setCheckState(0, Qt::Unchecked);
|
2013-08-09 06:57:18 +02:00
|
|
|
else
|
2014-11-29 03:55:58 +01:00
|
|
|
{
|
|
|
|
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
|
|
|
|
Items.append(Item->child(ChildIdx));
|
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->treeWidget->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
void lcQSelectDialog::on_selectInvert_clicked()
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
ui->treeWidget->blockSignals(true);
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> Items;
|
|
|
|
Items.append(ui->treeWidget->invisibleRootItem());
|
|
|
|
|
|
|
|
while (!Items.isEmpty())
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* Item = Items[0];
|
|
|
|
Items.removeFirst();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Item->childCount())
|
|
|
|
Item->setCheckState(0, Item->checkState(0) == Qt::Checked ? Qt::Unchecked : Qt::Checked);
|
2013-08-09 06:57:18 +02:00
|
|
|
else
|
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
|
|
|
|
Items.append(Item->child(ChildIdx));
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-29 03:55:58 +01:00
|
|
|
|
|
|
|
ui->treeWidget->blockSignals(false);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
void lcQSelectDialog::itemChanged(QTreeWidgetItem *item, int column)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2016-02-17 00:11:52 +01:00
|
|
|
Q_UNUSED(column);
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* ParentItem = item->parent();
|
|
|
|
|
|
|
|
if (!ParentItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Qt::CheckState State = item->checkState(0);
|
|
|
|
|
|
|
|
for (;;)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* ParentParentItem = ParentItem->parent();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (ParentParentItem)
|
|
|
|
ParentItem = ParentParentItem;
|
2013-08-09 06:57:18 +02:00
|
|
|
else
|
2014-11-29 03:55:58 +01:00
|
|
|
break;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
ui->treeWidget->blockSignals(true);
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> Items;
|
|
|
|
Items.append(ParentItem);
|
|
|
|
|
|
|
|
while (!Items.isEmpty())
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* Item = Items[0];
|
|
|
|
Items.removeFirst();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Item->childCount())
|
|
|
|
Item->setCheckState(0, State);
|
2013-08-09 06:57:18 +02:00
|
|
|
else
|
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int ChildIdx = 0; ChildIdx < Item->childCount(); ChildIdx++)
|
|
|
|
Items.append(Item->child(ChildIdx));
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-29 03:55:58 +01:00
|
|
|
|
|
|
|
ui->treeWidget->blockSignals(false);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 03:29:42 +02:00
|
|
|
void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup, lcModel* Model)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
const lcArray<lcGroup*>& Groups = Model->GetGroups();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-03-29 01:59:58 +01:00
|
|
|
for (lcGroup* Group : Groups)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
if (Group->mGroup != ParentGroup)
|
2013-08-09 06:57:18 +02:00
|
|
|
continue;
|
|
|
|
|
2015-10-21 17:03:45 +02:00
|
|
|
QTreeWidgetItem* GroupItem = new QTreeWidgetItem(ParentItem, QStringList(Group->mName));
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2018-04-17 03:29:42 +02:00
|
|
|
AddChildren(GroupItem, Group, Model);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
const lcArray<lcPiece*>& Pieces = Model->GetPieces();
|
|
|
|
lcStep currentStep = Model->GetCurrentStep();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-03-29 01:59:58 +01:00
|
|
|
for (lcPiece* Piece : Pieces)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
if (Piece->GetGroup() != ParentGroup || !Piece->IsVisible(currentStep))
|
2013-08-09 06:57:18 +02:00
|
|
|
continue;
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem* PieceItem = new QTreeWidgetItem(ParentItem, QStringList(Piece->GetName()));
|
2020-02-24 23:31:08 +01:00
|
|
|
PieceItem->setData(0, IndexRole, QVariant::fromValue<uintptr_t>((uintptr_t)Piece));
|
2014-11-29 03:55:58 +01:00
|
|
|
PieceItem->setCheckState(0, Piece->IsSelected() ? Qt::Checked : Qt::Unchecked);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!ParentGroup)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
const lcArray<lcCamera*>& Cameras = Model->GetCameras();
|
2014-05-27 00:58:08 +02:00
|
|
|
|
2019-03-29 01:59:58 +01:00
|
|
|
for (lcCamera* Camera : Cameras)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Camera->IsVisible())
|
2013-08-09 06:57:18 +02:00
|
|
|
continue;
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem *cameraItem = new QTreeWidgetItem(ParentItem, QStringList(Camera->GetName()));
|
2020-02-24 23:31:08 +01:00
|
|
|
cameraItem->setData(0, IndexRole, QVariant::fromValue<uintptr_t>((uintptr_t)Camera));
|
2014-11-29 03:55:58 +01:00
|
|
|
cameraItem->setCheckState(0, Camera->IsSelected() ? Qt::Checked : Qt::Unchecked);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 08:32:39 +01:00
|
|
|
const lcArray<lcLight*>& Lights = Model->GetLights();
|
2014-05-27 00:58:08 +02:00
|
|
|
|
2019-03-29 01:59:58 +01:00
|
|
|
for (lcLight* Light : Lights)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
if (!Light->IsVisible())
|
2013-08-09 06:57:18 +02:00
|
|
|
continue;
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
QTreeWidgetItem *lightItem = new QTreeWidgetItem(ParentItem, QStringList(Light->GetName()));
|
2020-02-24 23:31:08 +01:00
|
|
|
lightItem->setData(0, IndexRole, QVariant::fromValue<uintptr_t>((uintptr_t)Light));
|
2014-11-29 03:55:58 +01:00
|
|
|
lightItem->setCheckState(0, Light->IsSelected() ? Qt::Checked : Qt::Unchecked);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|