un-comment a function that shounldn't be commented.

This commit is contained in:
Maxime Gimeno 2015-11-17 15:27:57 +01:00
parent 62489af1b1
commit 08db015daf
4 changed files with 75 additions and 16 deletions

View File

@ -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;
int row = index.row();
int column = index.column();
if(index.child(0,0).isValid())
recurseExpand(index.child(0,0));
QModelIndex id = scene->index(index.row(),0,index.sibling(row+1, column));
Scene_group_item* group =
qobject_cast<Scene_group_item*>(scene->item(scene->getIdFromModelIndex(id)));
if(group && group->isExpanded())
{
// qDebug()<<group->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));

View File

@ -1,7 +1,7 @@
#include "Polyhedron_demo_group_plugin.h"
#include "Polyhedron_demo_group_plugin.moc"
#include "Scene.h"
#include <QMenu>
/****************
* 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<QMenu*>("menuFile");
if ( NULL != menuFile )
{
QList<QAction*> menuFileActions = menuFile->actions();
// Look for action just after "Load..." action
QAction* actionAfterLoad = NULL;
for ( QList<QAction*>::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);
}
}
}

View File

@ -28,22 +28,33 @@ public :
{
return true;
}
QList<QAction*> actions() const {
return QList<QAction*>() << actionAddToGroup;
}
Scene* trueScene;
public Q_SLOTS:
void add_group() {
//Find the indices of the selected items
QList<int> indices;
QList<int> blacklist;
Q_FOREACH(int id, scene->selectionIndices()){
Scene_group_item* group =
qobject_cast<Scene_group_item*>(trueScene->item(id));
if(group)
Q_FOREACH(Scene_item *item, group->getChildren())
blacklist<<trueScene->item_id(item);
if(!indices.contains(id) && !blacklist.contains(id))
indices<<id;
}
//checks if all the selected items are in the same group
bool all_in_one = true;
if(trueScene->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();

View File

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