VariableMenuHeaderWidget.cpp
43 lines
| 1.2 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r289 | #include "Variable/VariableMenuHeaderWidget.h" | ||
r1420 | #include "Variable/Variable2.h" | |||
Alexandre Leroux
|
r289 | |||
#include <ui_VariableMenuHeaderWidget.h> | ||||
Q_LOGGING_CATEGORY(LOG_VariableMenuHeaderWidget, "VariableMenuHeaderWidget") | ||||
VariableMenuHeaderWidget::VariableMenuHeaderWidget( | ||||
r1420 | const QVector<std::shared_ptr<Variable2>>& variables, QWidget* parent) | |||
: QWidget { parent }, ui { new Ui::VariableMenuHeaderWidget } | ||||
Alexandre Leroux
|
r289 | { | ||
ui->setupUi(this); | ||||
// Generates label according to the state of the variables. The label contains : | ||||
// - the variable name if there is only one variable in the list | ||||
// - 'x variables' where x is the number of variables otherwise | ||||
const auto nbVariables = variables.size(); | ||||
r1420 | if (nbVariables == 1) | |||
{ | ||||
if (auto variable = variables.first()) | ||||
{ | ||||
Alexandre Leroux
|
r289 | ui->label->setText(variable->name()); | ||
} | ||||
r1420 | else | |||
{ | ||||
Alexandre Leroux
|
r289 | qCCritical(LOG_VariableMenuHeaderWidget()) | ||
<< tr("Can't get the name of the variable : variable is null"); | ||||
} | ||||
} | ||||
r1420 | else if (nbVariables > 1) | |||
{ | ||||
Alexandre Leroux
|
r289 | ui->label->setText(tr("%1 variables").arg(nbVariables)); | ||
} | ||||
r1420 | else | |||
{ | ||||
Alexandre Leroux
|
r289 | ui->label->setText(tr("No variable")); | ||
} | ||||
} | ||||
VariableMenuHeaderWidget::~VariableMenuHeaderWidget() noexcept | ||||
{ | ||||
delete ui; | ||||
} | ||||