##// END OF EJS Templates
Adds scrollbar to tabs
Alexandre Leroux -
r307:a48a71ab1c8a
parent child
Show More
@@ -1,50 +1,53
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <Common/spimpl.h>
6 #include <Common/spimpl.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QWidget>
9 #include <QWidget>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
12
12
13 class Variable;
13 class Variable;
14 class VisualizationZoneWidget;
14 class VisualizationZoneWidget;
15
15
16 namespace Ui {
16 namespace Ui {
17 class VisualizationTabWidget;
17 class VisualizationTabWidget;
18 } // namespace Ui
18 } // namespace Ui
19
19
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
21 Q_OBJECT
21 Q_OBJECT
22
22
23 public:
23 public:
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
25 virtual ~VisualizationTabWidget();
25 virtual ~VisualizationTabWidget();
26
26
27 /// Add a zone widget
27 /// Add a zone widget
28 void addZone(VisualizationZoneWidget *zoneWidget);
28 void addZone(VisualizationZoneWidget *zoneWidget);
29
29
30 /**
30 /**
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
32 * zone.
32 * zone.
33 * @param variable the variable for which to create the zone
33 * @param variable the variable for which to create the zone
34 * @return the pointer to the created zone
34 * @return the pointer to the created zone
35 */
35 */
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
37
37
38 // IVisualizationWidget interface
38 // IVisualizationWidget interface
39 void accept(IVisualizationWidgetVisitor *visitor) override;
39 void accept(IVisualizationWidgetVisitor *visitor) override;
40 bool canDrop(const Variable &variable) const override;
40 bool canDrop(const Variable &variable) const override;
41 QString name() const override;
41 QString name() const override;
42
42
43 private:
43 private:
44 /// @return the layout of tab in which zones are added
45 QLayout &tabLayout() const noexcept;
46
44 Ui::VisualizationTabWidget *ui;
47 Ui::VisualizationTabWidget *ui;
45
48
46 class VisualizationTabWidgetPrivate;
49 class VisualizationTabWidgetPrivate;
47 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
50 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
48 };
51 };
49
52
50 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
53 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,98 +1,104
1 #include "Visualization/VisualizationTabWidget.h"
1 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationTabWidget.h"
3 #include "ui_VisualizationTabWidget.h"
4
4
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6
6
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8
8
9 namespace {
9 namespace {
10
10
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
12 /// the tab
12 /// the tab
13 QString defaultZoneName(const QLayout &layout)
13 QString defaultZoneName(const QLayout &layout)
14 {
14 {
15 auto count = 0;
15 auto count = 0;
16 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
18 count++;
18 count++;
19 }
19 }
20 }
20 }
21
21
22 return QObject::tr("Zone %1").arg(count + 1);
22 return QObject::tr("Zone %1").arg(count + 1);
23 }
23 }
24
24
25 } // namespace
25 } // namespace
26
26
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
29
29
30 QString m_Name;
30 QString m_Name;
31 };
31 };
32
32
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
34 : QWidget{parent},
34 : QWidget{parent},
35 ui{new Ui::VisualizationTabWidget},
35 ui{new Ui::VisualizationTabWidget},
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
37 {
37 {
38 ui->setupUi(this);
38 ui->setupUi(this);
39
39
40 // Widget is deleted when closed
40 // Widget is deleted when closed
41 setAttribute(Qt::WA_DeleteOnClose);
41 setAttribute(Qt::WA_DeleteOnClose);
42 }
42 }
43
43
44 VisualizationTabWidget::~VisualizationTabWidget()
44 VisualizationTabWidget::~VisualizationTabWidget()
45 {
45 {
46 delete ui;
46 delete ui;
47 }
47 }
48
48
49 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
49 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
50 {
50 {
51 this->layout()->addWidget(zoneWidget);
51 tabLayout().addWidget(zoneWidget);
52 }
52 }
53
53
54 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
54 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
55 {
55 {
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this};
57 this->addZone(zoneWidget);
57 this->addZone(zoneWidget);
58
58
59 // Creates a new graph into the zone
59 // Creates a new graph into the zone
60 zoneWidget->createGraph(variable);
60 zoneWidget->createGraph(variable);
61
61
62 return zoneWidget;
62 return zoneWidget;
63 }
63 }
64
64
65 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
65 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
66 {
66 {
67 if (visitor) {
67 if (visitor) {
68 visitor->visitEnter(this);
68 visitor->visitEnter(this);
69
69
70 // Apply visitor to zone children
70 // Apply visitor to zone children
71 for (auto i = 0; i < layout()->count(); ++i) {
71 auto &layout = tabLayout();
72 if (auto item = layout()->itemAt(i)) {
72 for (auto i = 0; i < layout.count(); ++i) {
73 if (auto item = layout.itemAt(i)) {
73 // Widgets different from zones are not visited (no action)
74 // Widgets different from zones are not visited (no action)
74 if (auto visualizationZoneWidget
75 if (auto visualizationZoneWidget
75 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 visualizationZoneWidget->accept(visitor);
77 visualizationZoneWidget->accept(visitor);
77 }
78 }
78 }
79 }
79 }
80 }
80
81
81 visitor->visitLeave(this);
82 visitor->visitLeave(this);
82 }
83 }
83 else {
84 else {
84 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
85 }
86 }
86 }
87 }
87
88
88 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 {
90 {
90 // A tab can always accomodate a variable
91 // A tab can always accomodate a variable
91 Q_UNUSED(variable);
92 Q_UNUSED(variable);
92 return true;
93 return true;
93 }
94 }
94
95
95 QString VisualizationTabWidget::name() const
96 QString VisualizationTabWidget::name() const
96 {
97 {
97 return impl->m_Name;
98 return impl->m_Name;
98 }
99 }
100
101 QLayout &VisualizationTabWidget::tabLayout() const noexcept
102 {
103 return *ui->scrollAreaWidgetContents->layout();
104 }
@@ -1,97 +1,105
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationZoneWidget.h"
3 #include "ui_VisualizationZoneWidget.h"
4
4
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6
6
7 #include <SqpApplication.h>
7 #include <SqpApplication.h>
8
8
9 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
9 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
10
10
11 namespace {
11 namespace {
12
12
13 /// Minimum height for graph added in zones (in pixels)
14 const auto GRAPH_MINIMUM_HEIGHT = 300;
15
13 /// Generates a default name for a new graph, according to the number of graphs already displayed in
16 /// Generates a default name for a new graph, according to the number of graphs already displayed in
14 /// the zone
17 /// the zone
15 QString defaultGraphName(const QLayout &layout)
18 QString defaultGraphName(const QLayout &layout)
16 {
19 {
17 auto count = 0;
20 auto count = 0;
18 for (auto i = 0; i < layout.count(); ++i) {
21 for (auto i = 0; i < layout.count(); ++i) {
19 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
22 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
20 count++;
23 count++;
21 }
24 }
22 }
25 }
23
26
24 return QObject::tr("Graph %1").arg(count + 1);
27 return QObject::tr("Graph %1").arg(count + 1);
25 }
28 }
26
29
27 } // namespace
30 } // namespace
28
31
29 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
32 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
30 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
33 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
31 {
34 {
32 ui->setupUi(this);
35 ui->setupUi(this);
33
36
34 ui->zoneNameLabel->setText(name);
37 ui->zoneNameLabel->setText(name);
35
38
36 // 'Close' options : widget is deleted when closed
39 // 'Close' options : widget is deleted when closed
37 setAttribute(Qt::WA_DeleteOnClose);
40 setAttribute(Qt::WA_DeleteOnClose);
38 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
41 connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close);
39 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
42 ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
40 }
43 }
41
44
42 VisualizationZoneWidget::~VisualizationZoneWidget()
45 VisualizationZoneWidget::~VisualizationZoneWidget()
43 {
46 {
44 delete ui;
47 delete ui;
45 }
48 }
46
49
47 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
50 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
48 {
51 {
49 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
52 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
50 }
53 }
51
54
52 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
55 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
53 {
56 {
54 auto graphWidget = new VisualizationGraphWidget{
57 auto graphWidget = new VisualizationGraphWidget{
55 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
58 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
59
60 // Set graph properties
61 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
62 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
63
56 this->addGraph(graphWidget);
64 this->addGraph(graphWidget);
57
65
58 graphWidget->addVariable(variable);
66 graphWidget->addVariable(variable);
59
67
60 return graphWidget;
68 return graphWidget;
61 }
69 }
62
70
63 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
71 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
64 {
72 {
65 if (visitor) {
73 if (visitor) {
66 visitor->visitEnter(this);
74 visitor->visitEnter(this);
67
75
68 // Apply visitor to graph children
76 // Apply visitor to graph children
69 auto layout = ui->visualizationZoneFrame->layout();
77 auto layout = ui->visualizationZoneFrame->layout();
70 for (auto i = 0; i < layout->count(); ++i) {
78 for (auto i = 0; i < layout->count(); ++i) {
71 if (auto item = layout->itemAt(i)) {
79 if (auto item = layout->itemAt(i)) {
72 // Widgets different from graphs are not visited (no action)
80 // Widgets different from graphs are not visited (no action)
73 if (auto visualizationGraphWidget
81 if (auto visualizationGraphWidget
74 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
82 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
75 visualizationGraphWidget->accept(visitor);
83 visualizationGraphWidget->accept(visitor);
76 }
84 }
77 }
85 }
78 }
86 }
79
87
80 visitor->visitLeave(this);
88 visitor->visitLeave(this);
81 }
89 }
82 else {
90 else {
83 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
91 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
84 }
92 }
85 }
93 }
86
94
87 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
95 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
88 {
96 {
89 // A tab can always accomodate a variable
97 // A tab can always accomodate a variable
90 Q_UNUSED(variable);
98 Q_UNUSED(variable);
91 return true;
99 return true;
92 }
100 }
93
101
94 QString VisualizationZoneWidget::name() const
102 QString VisualizationZoneWidget::name() const
95 {
103 {
96 return ui->zoneNameLabel->text();
104 return ui->zoneNameLabel->text();
97 }
105 }
@@ -1,20 +1,60
1 <?xml version="1.0" encoding="UTF-8"?>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
2 <ui version="4.0">
3 <class>VisualizationTabWidget</class>
3 <class>VisualizationTabWidget</class>
4 <widget class="QWidget" name="VisualizationTabWidget">
4 <widget class="QWidget" name="VisualizationTabWidget">
5 <property name="geometry">
5 <property name="geometry">
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>400</width>
9 <width>400</width>
10 <height>300</height>
10 <height>300</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
14 <string>Form</string>
14 <string>Form</string>
15 </property>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout"/>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <property name="leftMargin">
18 <number>0</number>
19 </property>
20 <property name="topMargin">
21 <number>0</number>
22 </property>
23 <property name="rightMargin">
24 <number>0</number>
25 </property>
26 <property name="bottomMargin">
27 <number>0</number>
28 </property>
29 <item>
30 <widget class="QScrollArea" name="scrollArea">
31 <property name="styleSheet">
32 <string notr="true">background-color: transparent;</string>
33 </property>
34 <property name="frameShape">
35 <enum>QFrame::NoFrame</enum>
36 </property>
37 <property name="frameShadow">
38 <enum>QFrame::Sunken</enum>
39 </property>
40 <property name="widgetResizable">
41 <bool>true</bool>
42 </property>
43 <widget class="QWidget" name="scrollAreaWidgetContents">
44 <property name="geometry">
45 <rect>
46 <x>0</x>
47 <y>0</y>
48 <width>400</width>
49 <height>300</height>
50 </rect>
51 </property>
52 <layout class="QVBoxLayout" name="verticalLayout_3"/>
53 </widget>
54 </widget>
55 </item>
56 </layout>
17 </widget>
57 </widget>
18 <resources/>
58 <resources/>
19 <connections/>
59 <connections/>
20 </ui>
60 </ui>
General Comments 0
You need to be logged in to leave comments. Login now