##// END OF EJS Templates
Creates a widget that will be the header of the menu in variable widget...
Alexandre Leroux -
r289:7ca994d5565d
parent child
Show More
@@ -0,0 +1,37
1 #ifndef SCIQLOP_VARIABLEMENUHEADERWIDGET_H
2 #define SCIQLOP_VARIABLEMENUHEADERWIDGET_H
3
4 #include <QLoggingCategory>
5 #include <QWidget>
6
7 #include <memory>
8
9 namespace Ui {
10 class VariableMenuHeaderWidget;
11 } // Ui
12
13 class Variable;
14
15 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget)
16
17 /**
18 * @brief The VariableMenuHeaderWidget class represents the widget used as a header of a menu in the
19 * variable inspector
20 * @sa VariableInspectorWidget
21 */
22 class VariableMenuHeaderWidget : public QWidget {
23 public:
24 /**
25 * Ctor
26 * @param variables the list of variables used to generate the header
27 * @param parent the parent widget
28 */
29 explicit VariableMenuHeaderWidget(const QVector<std::shared_ptr<Variable> > &variables,
30 QWidget *parent = 0);
31 virtual ~VariableMenuHeaderWidget() noexcept;
32
33 private:
34 Ui::VariableMenuHeaderWidget *ui;
35 };
36
37 #endif // SCIQLOP_VARIABLEMENUHEADERWIDGET_H
@@ -0,0 +1,38
1 #include "Variable/VariableMenuHeaderWidget.h"
2 #include "Variable/Variable.h"
3
4 #include <ui_VariableMenuHeaderWidget.h>
5
6 Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget")
7
8 VariableMenuHeaderWidget::VariableMenuHeaderWidget(
9 const QVector<std::shared_ptr<Variable> > &variables, QWidget *parent)
10 : QWidget{parent}, ui{new Ui::VariableMenuHeaderWidget}
11 {
12 ui->setupUi(this);
13
14 // Generates label according to the state of the variables. The label contains :
15 // - the variable name if there is only one variable in the list
16 // - 'x variables' where x is the number of variables otherwise
17 const auto nbVariables = variables.size();
18 if (nbVariables == 1) {
19 if (auto variable = variables.first()) {
20 ui->label->setText(variable->name());
21 }
22 else {
23 qCCritical(LOG_VariableMenuHeaderWidget())
24 << tr("Can't get the name of the variable : variable is null");
25 }
26 }
27 else if (nbVariables > 1) {
28 ui->label->setText(tr("%1 variables").arg(nbVariables));
29 }
30 else {
31 ui->label->setText(tr("No variable"));
32 }
33 }
34
35 VariableMenuHeaderWidget::~VariableMenuHeaderWidget() noexcept
36 {
37 delete ui;
38 }
@@ -0,0 +1,31
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>VariableMenuHeaderWidget</class>
4 <widget class="QWidget" name="VariableMenuHeaderWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>110</width>
10 <height>34</height>
11 </rect>
12 </property>
13 <layout class="QGridLayout" name="gridLayout">
14 <item row="0" column="0">
15 <widget class="QLabel" name="label">
16 <property name="styleSheet">
17 <string notr="true">background-color: rgba(127, 127, 127, 127);</string>
18 </property>
19 <property name="text">
20 <string>TextLabel</string>
21 </property>
22 <property name="alignment">
23 <set>Qt::AlignCenter</set>
24 </property>
25 </widget>
26 </item>
27 </layout>
28 </widget>
29 <resources/>
30 <connections/>
31 </ui>
General Comments 0
You need to be logged in to leave comments. Login now