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"
|
|
|
|
#include "project.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"
|
|
|
|
|
2016-08-01 05:44:15 +02:00
|
|
|
lcQSelectDialog::lcQSelectDialog(QWidget* Parent)
|
|
|
|
: QDialog(Parent), ui(new Ui::lcQSelectDialog)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-04-14 02:26:40 +02:00
|
|
|
AddChildren(ui->treeWidget->invisibleRootItem(), nullptr);
|
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()
|
|
|
|
{
|
2016-08-01 05:44:15 +02:00
|
|
|
mObjects.RemoveAll();
|
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>();
|
2016-08-01 05:44:15 +02:00
|
|
|
mObjects.Add(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
|
|
|
}
|
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
void lcQSelectDialog::AddChildren(QTreeWidgetItem* ParentItem, lcGroup* ParentGroup)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-12-08 08:32:39 +01:00
|
|
|
lcModel* Model = lcGetActiveModel();
|
|
|
|
const lcArray<lcGroup*>& Groups = Model->GetGroups();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
lcGroup* Group = Groups[GroupIdx];
|
2014-05-25 03:45:19 +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
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
AddChildren(GroupItem, Group);
|
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
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
lcPiece* Piece = Pieces[PieceIdx];
|
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()));
|
|
|
|
PieceItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
|
|
|
|
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
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
lcCamera* Camera = Cameras[CameraIdx];
|
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()));
|
|
|
|
cameraItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Camera));
|
|
|
|
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
|
|
|
|
2014-11-29 03:55:58 +01:00
|
|
|
for (int LightIdx = 0; LightIdx < Lights.GetSize(); LightIdx++)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-11-29 03:55:58 +01:00
|
|
|
lcLight* Light = Lights[LightIdx];
|
2014-04-10 05:07:41 +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()));
|
|
|
|
lightItem->setData(0, IndexRole, qVariantFromValue<uintptr_t>((uintptr_t)Light));
|
|
|
|
lightItem->setCheckState(0, Light->IsSelected() ? Qt::Checked : Qt::Unchecked);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|