From 08db015daf7095c14e607d992cc32e5d58276cda Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 17 Nov 2015 15:27:57 +0100 Subject: [PATCH] un-comment a function that shounldn't be commented. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 30 +++++++++++++--- .../Polyhedron_demo_group_plugin.cpp | 34 +++++++++++++++++-- .../Polyhedron/Polyhedron_demo_group_plugin.h | 25 ++++++++++---- Polyhedron/demo/Polyhedron/Scene.cpp | 2 +- 4 files changed, 75 insertions(+), 16 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 1e8295d2c12..483d47e5f47 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -1135,10 +1135,24 @@ void MainWindow::showSceneContextMenu(const QPoint& p) { int index = -1; if(sender == sceneView) { - QModelIndex modelIndex = sceneView->indexAt(p); - if(!modelIndex.isValid()) return; + QModelIndex modelIndex = sceneView->indexAt(p); + if(!modelIndex.isValid()) + { + const char* prop_name = "Menu modified by MainWindow."; - index = proxyModel->mapToSource(modelIndex).row(); + QMenu* menu = ui->menuFile; + if(menu) { + bool menuChanged = menu->property(prop_name).toBool(); + if(!menuChanged) { + menu->setProperty(prop_name, true); + } + } + if(menu) + menu->exec(sender->mapToGlobal(p)); + return; + } + else + index = proxyModel->mapToSource(modelIndex).row(); } else { index = scene->mainSelectionIndex(); @@ -1552,17 +1566,23 @@ void MainWindow::on_actionRecenterScene_triggered() void MainWindow::recurseExpand(QModelIndex index) { - if(index.child(0,0).isValid()) - recurseExpand(index.child(0,0)); + //qDebug()<index(index.row(),0,index.sibling(row+1, column)); Scene_group_item* group = qobject_cast(scene->item(scene->getIdFromModelIndex(id))); + if(group && group->isExpanded()) { + // qDebug()<name(); sceneView->setExpanded(index, true); } + else if (group && !group->isExpanded()){ + sceneView->setExpanded(index, false); + } if( index.sibling(index.row()+1,0).isValid()) recurseExpand(index.sibling(index.row()+1,0)); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.cpp index aa6b0d85760..b21178da2ed 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.cpp @@ -1,7 +1,7 @@ #include "Polyhedron_demo_group_plugin.h" #include "Polyhedron_demo_group_plugin.moc" #include "Scene.h" - +#include /**************** * Group Plugin * ****************/ @@ -15,8 +15,36 @@ void Polyhedron_demo_group_plugin::init(QMainWindow* mainWindow, messages = m; //creates and link the actions actionAddToGroup= new QAction("Add new group", mw); + if(actionAddToGroup) { - connect(actionAddToGroup, SIGNAL(triggered()), - this, SLOT(add_group())); + connect(actionAddToGroup, SIGNAL(triggered()), + this, SLOT(add_group())); + } + + QMenu* menuFile = mw->findChild("menuFile"); + if ( NULL != menuFile ) + { + QList menuFileActions = menuFile->actions(); + + // Look for action just after "Load..." action + QAction* actionAfterLoad = NULL; + for ( QList::iterator it_action = menuFileActions.begin(), + end = menuFileActions.end() ; it_action != end ; ++ it_action ) //Q_FOREACH( QAction* action, menuFileActions) + { + if ( NULL != *it_action && (*it_action)->text().contains("Load") ) + { + ++it_action; + if ( it_action != end && NULL != *it_action ) + { + actionAfterLoad = *it_action; + } + } + } + + // Insert "Load implicit function" action + if ( NULL != actionAfterLoad ) + { + menuFile->insertAction(actionAfterLoad,actionAddToGroup); + } } } diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.h b/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.h index 1fd18927303..6feb8e22ca4 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.h +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_group_plugin.h @@ -28,22 +28,33 @@ public : { return true; } - QList actions() const { - return QList() << actionAddToGroup; - } + Scene* trueScene; public Q_SLOTS: void add_group() { + //Find the indices of the selected items + QList indices; + QList blacklist; + Q_FOREACH(int id, scene->selectionIndices()){ + Scene_group_item* group = + qobject_cast(trueScene->item(id)); + if(group) + Q_FOREACH(Scene_item *item, group->getChildren()) + blacklist<item_id(item); + + if(!indices.contains(id) && !blacklist.contains(id)) + indices<selectionIndices().isEmpty()) + if(indices.isEmpty()) all_in_one = false; // new group to create Scene_group_item * group = new Scene_group_item("new group"); //group containing the selected item Scene_group_item * existing_group = 0; //for each selected item - Q_FOREACH(int id, trueScene->selectionIndices()){ + Q_FOREACH(int id, indices){ //if the selected item is in a group if(trueScene->item(id)->has_group!=0){ //for each group @@ -72,7 +83,7 @@ public Q_SLOTS: //If all the selected items are in the same group, we put them in a sub_group of this group if(all_in_one) { - Q_FOREACH(int id, trueScene->selectionIndices()) + Q_FOREACH(int id, indices) trueScene->changeGroup(trueScene->item(id),group); trueScene->changeGroup(group, existing_group); scene->addItem(group); @@ -81,7 +92,7 @@ public Q_SLOTS: //else wer create a new group else { - Q_FOREACH(int id, trueScene->selectionIndices()) + Q_FOREACH(int id, indices) trueScene->changeGroup(trueScene->item(id),group); scene->addItem(group); trueScene->group_added(); diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 27c877abe07..9107596c7dc 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -690,7 +690,7 @@ bool Scene::dropMimeData(const QMimeData */*data*/, break; } } - //if the drop item is not a group_item or if it already con, then the drop action must be ignored + //if the drop item is not a group_item or if it already contains the item, then the drop action must be ignored if(!group ||one_contained) { //unless the drop zone is empty, which means the item should be removed from all groups.