From d36a447d701e085884d3b0f01fd18dde15ee0c2d Mon Sep 17 00:00:00 2001 From: iyaz Date: Fri, 23 Aug 2013 16:25:37 +0300 Subject: [PATCH] when multiple dock widgets are visible, they were covering each other - solved by adding a function into plugin-helper. Also get_selected_item function is added. --- .../Polyhedron_demo_fairing_plugin.cpp | 24 +++++--------- .../Polyhedron_demo_hole_filling_plugin.cpp | 33 +++++-------------- .../Polyhedron_demo_plugin_helper.cpp | 19 +++++++++++ .../Polyhedron_demo_plugin_helper.h | 22 +++++++++++++ .../Polyhedron_demo_selection_plugin.cpp | 30 ++++------------- 5 files changed, 63 insertions(+), 65 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_fairing_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_fairing_plugin.cpp index 1c24883b384..a0be64f16ab 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_fairing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_fairing_plugin.cpp @@ -1,8 +1,10 @@ +#undef NDEBUG +//#define CGAL_SUPERLU_ENABLED #include #include "Messages_interface.h" #include "Scene_polyhedron_selection_item.h" -#include "Polyhedron_demo_plugin_interface.h" +#include "Polyhedron_demo_plugin_helper.h" #include "ui_Fairing_widget.h" #include "Polyhedron_type.h" @@ -26,7 +28,7 @@ class Polyhedron_demo_fairing_plugin : public QObject, - public Polyhedron_demo_plugin_interface + public Polyhedron_demo_plugin_helper { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) @@ -49,28 +51,20 @@ public: dock_widget->setVisible(false); ui_widget.setupUi(dock_widget); - mw->addDockWidget(Qt::LeftDockWidgetArea, dock_widget); + add_dock_widget(dock_widget); connect(ui_widget.Fair_button, SIGNAL(clicked()), this, SLOT(on_Fair_button_clicked())); connect(ui_widget.Refine_button, SIGNAL(clicked()), this, SLOT(on_Refine_button_clicked())); } - Scene_polyhedron_selection_item* get_selected_item() { - int item_id = scene->mainSelectionIndex(); - Scene_polyhedron_selection_item* selection_item = qobject_cast(scene->item(item_id)); - if(!selection_item) { - print_message("Error: there is no selected polyhedron selection item!"); - return NULL; - } - return selection_item; - } public slots: void fairing_action() { dock_widget->show(); + dock_widget->raise(); } void on_Fair_button_clicked() { - Scene_polyhedron_selection_item* selection_item = get_selected_item(); + Scene_polyhedron_selection_item* selection_item = get_selected_item(); if(!selection_item) { return; } if(selection_item->selected_vertices.empty()) { @@ -92,7 +86,7 @@ public slots: } void on_Refine_button_clicked() { - Scene_polyhedron_selection_item* selection_item = get_selected_item(); + Scene_polyhedron_selection_item* selection_item = get_selected_item(); if(!selection_item) { return; } if(selection_item->selected_facets.empty()) { @@ -119,8 +113,6 @@ private: }; typedef boost::function_output_iterator Nop_out; - QMainWindow* mw; - Scene_interface* scene; Messages_interface* messages; QAction* actionFairing; diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp index fba23227f43..20c817223c6 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp @@ -8,7 +8,7 @@ #include "Scene_polylines_item.h" #include "Scene.h" -#include "Polyhedron_demo_plugin_interface.h" +#include "Polyhedron_demo_plugin_helper.h" #include "ui_Hole_filling_widget.h" #include "Polyhedron_type.h" @@ -264,7 +264,7 @@ public slots: class Polyhedron_demo_hole_filling_plugin : public QObject, - public Polyhedron_demo_plugin_interface + public Polyhedron_demo_plugin_helper { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) @@ -275,24 +275,6 @@ public: QList actions() const { return QList() << actionHoleFilling; } void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m); - template - SceneType* get_selected_item() { - int item_id = scene->mainSelectionIndex(); - SceneType* scene_item = qobject_cast(scene->item(item_id)); - if(!scene_item) { - // no selected SceneType, if there is only one in list use it, otherwise error - int counter = 0; - for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end && counter < 2; ++i) { - if(SceneType* tmp = qobject_cast(scene->item(i))) { - scene_item = tmp; - counter++; - } - } - if(counter != 1) { return NULL; } - } - return scene_item; - } - Scene_polylines_collection* get_polylines_collection(Scene_polyhedron_item* poly_item) { // did not use a map to assoc Scene_polyhedron_item with Scene_polylines_collection to prevent crowded code for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end; ++i) { @@ -304,7 +286,10 @@ public: } public slots: - void hole_filling_action() { dock_widget->show(); } + void hole_filling_action() { + dock_widget->show(); + dock_widget->raise(); + } void on_Fill_all_holes_button(); void on_Visualize_holes_button(); void on_Fill_selected_holes_button(); @@ -328,8 +313,6 @@ private: }; typedef boost::function_output_iterator Nop_out; - QMainWindow* mw; - Scene_interface* scene; Messages_interface* messages; QAction* actionHoleFilling; @@ -385,8 +368,8 @@ void Polyhedron_demo_hole_filling_plugin::init(QMainWindow* mainWindow, ui_widget.Accept_button->setVisible(false); ui_widget.Reject_button->setVisible(false); - mw->addDockWidget(Qt::LeftDockWidgetArea, dock_widget); - + add_dock_widget(dock_widget); + connect(ui_widget.Visualize_holes_button, SIGNAL(clicked()), this, SLOT(on_Visualize_holes_button())); connect(ui_widget.Fill_selected_holes_button, SIGNAL(clicked()), this, SLOT(on_Fill_selected_holes_button())); connect(ui_widget.Fill_all_holes_button, SIGNAL(clicked()), this, SLOT(on_Fill_all_holes_button())); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp index aab8bb028bb..4655d6a1533 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp @@ -6,6 +6,7 @@ #include #include #include +#include QAction* Polyhedron_demo_plugin_helper:: @@ -107,3 +108,21 @@ void Polyhedron_demo_plugin_helper::autoConnectActions() action->objectName().toUtf8().data()); } // end foreach action of actions() } + +void Polyhedron_demo_plugin_helper::add_dock_widget(QDockWidget* dock_widget) +{ + mw->addDockWidget(Qt::LeftDockWidgetArea, dock_widget); + + QList dockWidgets = mw->findChildren(); + int counter = 0; + foreach(QDockWidget* dock, dockWidgets) { + if( mw->dockWidgetArea(dock) != Qt::LeftDockWidgetArea || + dock == dock_widget ) + { continue; } + + if(++counter > 1) { + mw->tabifyDockWidget(dock, dock_widget); + return; + } + } +} diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.h b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.h index d9611a8e55d..03090d5106b 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.h +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.h @@ -11,6 +11,7 @@ class QAction; struct QMetaObject; class QMainWindow; class Scene_interface; +class QDockWidget; #include "Polyhedron_demo_plugin_interface.h" @@ -28,6 +29,27 @@ public: virtual QStringList actionsNames() const; virtual QList actions() const; + // To get a selected item with the type of SceneType + template + SceneType* get_selected_item() const { + int item_id = scene->mainSelectionIndex(); + SceneType* scene_item = qobject_cast(scene->item(item_id)); + if(!scene_item) { + // no selected SceneType - if there is only one in list return it, otherwise NULL + int counter = 0; + for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end && counter < 2; ++i) { + if(SceneType* tmp = qobject_cast(scene->item(i))) { + scene_item = tmp; + counter++; + } + } + if(counter != 1) { return NULL; } + } + return scene_item; + } + + void add_dock_widget(QDockWidget* dock); + // Auto-connect actions to slots. Called by init(). void autoConnectActions(); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp index 9f64d8e6d45..3f0f6277090 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp @@ -6,7 +6,7 @@ #include "Scene_points_with_normal_item.h" #include "Scene_interface.h" -#include "Polyhedron_demo_plugin_interface.h" +#include "Polyhedron_demo_plugin_helper.h" #include "ui_Selection_widget.h" #include @@ -17,7 +17,7 @@ class Polyhedron_demo_selection_plugin : public QObject, - public Polyhedron_demo_plugin_interface + public Polyhedron_demo_plugin_helper { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) @@ -29,10 +29,11 @@ public: } void print_message(QString message) { messages->information(message); } QList actions() const { return QList() << actionSelection; } - void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m){ + void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m) { mw = mainWindow; scene = scene_interface; messages = m; + actionSelection = new QAction(tr("Selection"), mw); connect(actionSelection, SIGNAL(triggered()), this, SLOT(selection_action())); @@ -40,7 +41,7 @@ public: dock_widget->setVisible(false); ui_widget.setupUi(dock_widget); - mw->addDockWidget(Qt::LeftDockWidgetArea, dock_widget); + add_dock_widget(dock_widget); connect(ui_widget.Select_all_button, SIGNAL(clicked()), this, SLOT(on_Select_all_button_clicked())); connect(ui_widget.Clear_button, SIGNAL(clicked()), this, SLOT(on_Clear_button_clicked())); @@ -62,27 +63,10 @@ public: } } - template - SceneType* get_selected_item() { - int item_id = scene->mainSelectionIndex(); - SceneType* scene_item = qobject_cast(scene->item(item_id)); - if(!scene_item) { - // no selected SceneType, if there is only one in list use it, otherwise error - int counter = 0; - for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end && counter < 2; ++i) { - if(SceneType* tmp = qobject_cast(scene->item(i))) { - scene_item = tmp; - counter++; - } - } - if(counter != 1) { return NULL; } - } - return scene_item; - } - public slots: void selection_action() { dock_widget->show(); + dock_widget->raise(); } // Select all void on_Select_all_button_clicked() { @@ -279,8 +263,6 @@ public slots: } private: - QMainWindow* mw; - Scene_interface* scene; Messages_interface* messages; QAction* actionSelection;