25 #include <QModelIndex>
27 #include <QStringList>
28 #include <QTableWidgetItem>
29 #include <QHeaderView>
32 #include "../controller/Controller.h"
33 #include "../controller/AddToGroupOperation.h"
34 #include "../controller/CreateGroupOperation.h"
35 #include "../controller/SelectOperation.h"
36 #include "../controller/RemoveFromGroupOperation.h"
37 #include "../controller/DeleteGroupOperation.h"
38 #include "../scene3D/SceneObject.h"
41 #include <MemoryX/gui-plugins/SceneEditor/ui_GroupExplorerWidget.h>
48 groupEditorDialog(groupEditorDialog)
51 ui->newGroupButton->setIcon(QIcon(QString::fromStdString(
":/icons/edit-add.ico")));
54 std::shared_ptr<gui::ShortcutController> shortcutController =
control->getShortcutController();
55 QPointer<QAction> addToNewGroup(
new OverrideAction(
"Group Explorer: Add Selection to new group",
this));
56 this->addAction(addToNewGroup);
57 shortcutController->registerAction(addToNewGroup->text(), addToNewGroup);
62 connect(ui->newGroupButton, SIGNAL(clicked()),
this, SLOT(addSelectionToNewGroup()));
63 connect(addToNewGroup, SIGNAL(triggered()),
this, SLOT(addSelectionToNewGroup()));
66 connect(ui->groupsTableWidget, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(customContextMenuRequested(QPoint)));
69 connect(ui->groupsTableWidget, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(triggerOpenGroupEditor(QModelIndex)));
70 connect(
this, SIGNAL(
groupNameClicked()),
this, SLOT(openGroupEditorDialog()));
76 connect(ui->groupsTableWidget, SIGNAL(itemClicked(QTableWidgetItem*)),
this, SLOT(triggerOperation(QTableWidgetItem*)));
89 void gui::GroupExplorerWidget::customContextMenuRequested(
const QPoint& position)
91 currentItem = ui->groupsTableWidget->itemAt(position);
92 QModelIndex
index = ui->groupsTableWidget->indexAt(position);
97 QMenu* menu =
new QMenu(
this);
98 menu->addAction(tr(
"Add selection to group"),
this, SLOT(addSelectionToGroup()));
99 menu->addAction(tr(
"Add group to selection"),
this, SLOT(addGroupToSelection()));
100 menu->addAction(tr(
"Remove group"),
this, SLOT(groupRemoveClicked()));
101 menu->addAction(tr(
"Show in Group Editor..."),
this, SLOT(openGroupEditorDialog()));
102 menu->popup(ui->groupsTableWidget->viewport()->mapToGlobal(position));
107 void gui::GroupExplorerWidget::addSelectionToGroup()
109 if (currentItem != NULL)
111 std::string groupName = currentItem->text().toStdString();
112 createAddToGroupOperations(groupName);
117 void gui::GroupExplorerWidget::addGroupToSelection()
119 if (currentItem != NULL)
121 std::string groupName = currentItem->text().toStdString();
122 std::vector<scene3D::SceneObjectPtr> objectsInGroup;
126 objectsInGroup =
controller->getScene()->getGroupManager()->getGroupById(groupName)->getAllObjects();
127 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
130 for (std::size_t i = 0; i < objectsInGroup.size(); ++i)
134 objectsInGroup[i]->getObjectId()));
135 operations->push_back(operation);
143 void gui::GroupExplorerWidget::groupRemoveClicked()
145 if (currentItem != NULL)
149 std::string groupName = currentItem->text().toStdString();
151 if (!
controller->getScene()->getGroupManager()->getGroupById(groupName))
156 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
163 object->getObjectId()));
164 operations->push_back(operation);
170 operations->push_back(operation);
176 void gui::GroupExplorerWidget::triggerOperation(QTableWidgetItem* item)
178 ui->groupsTableWidget->setCurrentItem(item);
179 currentItem = ui->groupsTableWidget->item(ui->groupsTableWidget->currentRow(), 0);
181 if (currentItem != NULL)
184 if (item->column() == 1)
186 emit addToGroupClicked();
189 else if (item->column() == 2)
191 emit addToSelectionClicked();
196 void gui::GroupExplorerWidget::triggerOpenGroupEditor(QModelIndex
index)
198 if (
index.column() == 0)
200 emit groupNameClicked();
204 void gui::GroupExplorerWidget::createAddToGroupOperations(std::string groupName)
206 std::vector<scene3D::SceneObjectPtr> selectedObjects;
210 selectedObjects =
controller->getScene()->getSelectionManager()->getAllSelected();
211 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
214 for (std::size_t i = 0; i < selectedObjects.size(); ++i)
218 groupName, selectedObjects[i]->getObjectId()));
219 operations->push_back(operation);
226 void gui::GroupExplorerWidget::openGroupEditorDialog()
228 if (groupEditorDialog)
230 groupEditorDialog->setCurrentGroup(currentItem->text());
231 groupEditorDialog->exec();
235 void gui::GroupExplorerWidget::listAllGroups()
237 ui->groupsTableWidget->clear();
239 std::vector<scene3D::SceneGroupPtr> allGroups;
243 allGroups =
controller->getScene()->getGroupManager()->getAllGroups();
246 ui->groupsTableWidget->setColumnCount(3);
247 ui->groupsTableWidget->setRowCount(allGroups.size());
251 for (std::size_t i = 0; i < allGroups.size(); ++i)
254 QString groupName = QString::fromStdString(group->getGroupId());
255 QTableWidgetItem* item =
new QTableWidgetItem(groupName);
256 QTableWidgetItem* addIcon =
new QTableWidgetItem(QIcon(QString::fromStdString(
":/icons/edit-add.ico")),
"");
257 QTableWidgetItem* selectIcon =
new QTableWidgetItem(QIcon(QString::fromStdString(
":/images/Select.png")),
"");
258 addIcon->setToolTip(tr(
"Add selection to group"));
259 selectIcon->setToolTip(tr(
"Add group to selection"));
260 ui->groupsTableWidget->setItem(
index, 0, item);
261 ui->groupsTableWidget->setItem(
index, 1, addIcon);
262 ui->groupsTableWidget->setItem(
index, 2, selectIcon);
267 QHeaderView* headerView = ui->groupsTableWidget->horizontalHeader();
268 headerView->setResizeMode(headerView->logicalIndexAt(0, 0), QHeaderView::Stretch);
269 headerView->setResizeMode(headerView->logicalIndexAt(1, 0), QHeaderView::Fixed);
270 headerView->setResizeMode(headerView->logicalIndexAt(2, 0), QHeaderView::Fixed);
271 headerView->resizeSection(1, 20);
272 headerView->resizeSection(2, 20);
275 void gui::GroupExplorerWidget::addSelectionToNewGroup()
285 while (
controller->getScene()->getGroupManager()->getGroupById(tr(
"New Group ").toStdString() +
std::to_string(nameIndex)) != NULL);
287 std::string groupName = tr(
"New Group ").toStdString() +
std::to_string(nameIndex);
290 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
294 operations->push_back(operation);
297 createAddToGroupOperations(groupName);
303 ui->retranslateUi(
this);