##// END OF EJS Templates
Creates a method (slot) in VisualizationWidget to add the plot menu to a variable menu
Alexandre Leroux -
r231:5b41c2a03db2
parent child
Show More
@@ -1,53 +1,53
1 1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10 10
11 class QMenu;
11 12 class Variable;
12 13 class VisualizationTabWidget;
13 14
14 15 namespace Ui {
15 16 class VisualizationWidget;
16 17 } // namespace Ui
17 18
18 19 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 20 Q_OBJECT
20 21
21 22 public:
22 23 explicit VisualizationWidget(QWidget *parent = 0);
23 24 virtual ~VisualizationWidget();
24 25
25 26 /// Add a zone widget
26 27 virtual void addTab(VisualizationTabWidget *tabWidget);
27 28
28 29 /// Create a tab using a Variable
29 30 VisualizationTabWidget *createTab();
30 31
31 32 /// Remove a tab
32 33 void removeTab(VisualizationTabWidget *tab);
33 34
34 35 // IVisualizationWidget interface
35 36 void accept(IVisualizationWidgetVisitor *visitor) override;
36 37 bool canDrop(const Variable &variable) const override;
37 38 void close() override;
38 39 QString name() const override;
39 40
40 41 public slots:
41 42 /**
42 * Displays a variable in a new graph of a new zone of the current tab
43 * @param variable the variable to display
44 * @todo this is a temporary method that will be replaced by own actions for each type of
45 * visualization widget
43 * Attaches to a menu the menu relating to the visualization of a variable
44 * @param menu the parent menu of the generated menu
45 * @param variable the variable for which to generate the menu
46 46 */
47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
47 void attachVariableMenu(QMenu *menu, std::shared_ptr<Variable> variable) noexcept;
48 48
49 49 private:
50 50 Ui::VisualizationWidget *ui;
51 51 };
52 52
53 53 #endif // VISUALIZATIONWIDGET_H
@@ -1,136 +1,131
1 1 #include "Visualization/VisualizationWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphWidget.h"
4 4 #include "Visualization/VisualizationTabWidget.h"
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/operations/GenerateVariableMenuOperation.h"
6 7 #include "Visualization/qcustomplot.h"
7 8
8 9 #include "ui_VisualizationWidget.h"
9 10
10 11 #include <QToolButton>
11 12
12 13 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13 14
14 15 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 16 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 17 {
17 18 ui->setupUi(this);
18 19
19 20 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 21 addTabViewButton->setText(tr("Add View"));
21 22 addTabViewButton->setCursor(Qt::ArrowCursor);
22 23 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23 24
24 25 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25 26
26 27 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 28 auto width = enable ? tabViewCornerWidget->width() : 0;
28 29 auto height = enable ? tabViewCornerWidget->height() : 0;
29 30 tabViewCornerWidget->setMinimumHeight(height);
30 31 tabViewCornerWidget->setMinimumWidth(width);
31 32 ui->tabWidget->setMinimumHeight(height);
32 33 ui->tabWidget->setMinimumWidth(width);
33 34 };
34 35
35 36 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 37 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
37 38 ui->tabWidget};
38 39 auto index = ui->tabWidget->addTab(widget, widget->name());
39 40 if (ui->tabWidget->count() > 0) {
40 41 enableMinimumCornerWidgetSize(false);
41 42 }
42 43 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
43 44 };
44 45
45 46 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 47 if (ui->tabWidget->count() == 1) {
47 48 enableMinimumCornerWidgetSize(true);
48 49 }
49 50
50 51 ui->tabWidget->removeTab(index);
51 52 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
52 53
53 54 };
54 55
55 56 ui->tabWidget->setTabsClosable(true);
56 57
57 58 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 59 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59 60
60 61 // Adds default tab
61 62 addTabView();
62 63 }
63 64
64 65 VisualizationWidget::~VisualizationWidget()
65 66 {
66 67 delete ui;
67 68 }
68 69
69 70 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 71 {
71 72 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
72 73 // lambda function (in the constructor)
73 74 }
74 75
75 76 VisualizationTabWidget *VisualizationWidget::createTab()
76 77 {
77 78 }
78 79
79 80 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 81 {
81 82 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
82 83 // lambda function (in the constructor)
83 84 }
84 85
85 86 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 87 {
87 88 if (visitor) {
88 89 visitor->visitEnter(this);
89 90
90 91 // Apply visitor for tab children
91 92 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 93 // Widgets different from tabs are not visited (no action)
93 94 if (auto visualizationTabWidget
94 95 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
95 96 visualizationTabWidget->accept(visitor);
96 97 }
97 98 }
98 99
99 100 visitor->visitLeave(this);
100 101 }
101 102 else {
102 103 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
103 104 }
104 105 }
105 106
106 107 bool VisualizationWidget::canDrop(const Variable &variable) const
107 108 {
108 109 // The main widget can never accomodate a variable
109 110 Q_UNUSED(variable);
110 111 return false;
111 112 }
112 113
113 114 void VisualizationWidget::close()
114 115 {
115 116 // The main view cannot be directly closed.
116 117 return;
117 118 }
118 119
119 120 QString VisualizationWidget::name() const
120 121 {
121 122 return QStringLiteral("MainView");
122 123 }
123 124
124 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
125 void VisualizationWidget::attachVariableMenu(QMenu *menu,
126 std::shared_ptr<Variable> variable) noexcept
125 127 {
126 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
127 if (!currentTab->createZone(variable)) {
128 qCCritical(LOG_VisualizationWidget())
129 << tr("Can't display the variable : can't create a new zone in the current tab");
130 }
131 }
132 else {
133 qCCritical(LOG_VisualizationWidget())
134 << tr("Can't display the variable : there is no current tab");
135 }
128 // Generates the actions that make it possible to visualize the variable
129 auto generateVariableMenuOperation = GenerateVariableMenuOperation{menu, variable};
130 accept(&generateVariableMenuOperation);
136 131 }
General Comments 0
You need to be logged in to leave comments. Login now