mirror of https://github.com/CGAL/cgal
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.
This commit is contained in:
parent
7497f15a75
commit
d36a447d70
|
|
@ -1,8 +1,10 @@
|
|||
#undef NDEBUG
|
||||
//#define CGAL_SUPERLU_ENABLED
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#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_polyhedron_selection_item*>(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<Scene_polyhedron_selection_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<Scene_polyhedron_selection_item>();
|
||||
if(!selection_item) { return; }
|
||||
|
||||
if(selection_item->selected_facets.empty()) {
|
||||
|
|
@ -119,8 +113,6 @@ private:
|
|||
};
|
||||
typedef boost::function_output_iterator<Nop_functor> Nop_out;
|
||||
|
||||
QMainWindow* mw;
|
||||
Scene_interface* scene;
|
||||
Messages_interface* messages;
|
||||
QAction* actionFairing;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<QAction*> actions() const { return QList<QAction*>() << actionHoleFilling; }
|
||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m);
|
||||
|
||||
template<class SceneType>
|
||||
SceneType* get_selected_item() {
|
||||
int item_id = scene->mainSelectionIndex();
|
||||
SceneType* scene_item = qobject_cast<SceneType*>(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<SceneType*>(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_functor> 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()));
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QtDebug>
|
||||
#include <QVector>
|
||||
#include <QSet>
|
||||
#include <QDockWidget>
|
||||
|
||||
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<QDockWidget*> dockWidgets = mw->findChildren<QDockWidget*>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<QAction*> actions() const;
|
||||
|
||||
// To get a selected item with the type of SceneType
|
||||
template<class SceneType>
|
||||
SceneType* get_selected_item() const {
|
||||
int item_id = scene->mainSelectionIndex();
|
||||
SceneType* scene_item = qobject_cast<SceneType*>(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<SceneType*>(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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <QAction>
|
||||
|
|
@ -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<QAction*> actions() const { return QList<QAction*>() << 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<class SceneType>
|
||||
SceneType* get_selected_item() {
|
||||
int item_id = scene->mainSelectionIndex();
|
||||
SceneType* scene_item = qobject_cast<SceneType*>(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<SceneType*>(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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue