Commit 6387588d authored by Daniel Mensinger's avatar Daniel Mensinger
Browse files

meson: some mintro / rewriter refactoring

parent 40ee1e27
......@@ -275,6 +275,33 @@ void MesonOptionString::setValue(QString val)
m_value = val;
}
// Set value from string
void MesonOptionArray::setFromString(QString value)
{
setValue({ value });
}
void MesonOptionBool::setFromString(QString value)
{
setValue(value.toLower() == QStringLiteral("true"));
}
void MesonOptionCombo::setFromString(QString value)
{
setValue(value);
}
void MesonOptionInteger::setFromString(QString value)
{
setValue(value.toInt());
}
void MesonOptionString::setFromString(QString value)
{
setValue(value);
}
// Base option functions
MesonOptionBase::~MesonOptionBase() {}
......@@ -393,7 +420,7 @@ MesonOptionPtr MesonOptionBase::fromJSON(const QJsonObject& obj)
int MesonOptions::numChanged() const
{
int sum = 0;
for(auto i : m_options) {
for (auto i : m_options) {
if (i && i->isUpdated()) {
++sum;
}
......@@ -401,13 +428,12 @@ int MesonOptions::numChanged() const
return sum;
}
QStringList MesonOptions::getMesonArgs() const
{
QStringList result;
result.reserve(m_options.size());
for(auto i : m_options) {
for (auto i : m_options) {
if (i && i->isUpdated()) {
result << i->mesonArg();
}
......
......@@ -49,6 +49,7 @@ public:
virtual Type type() const = 0;
virtual QString value() const = 0;
virtual QString initialValue() const = 0;
virtual void setFromString(QString value) = 0;
virtual void reset() = 0;
QString name() const;
......@@ -74,6 +75,7 @@ public:
MesonOptionBase::Type type() const override;
QString value() const override;
QString initialValue() const override;
void setFromString(QString value) override;
void reset() override;
QStringList rawValue() const;
......@@ -92,6 +94,7 @@ public:
MesonOptionBase::Type type() const override;
QString value() const override;
QString initialValue() const override;
void setFromString(QString value) override;
void reset() override;
bool rawValue() const;
......@@ -110,6 +113,7 @@ public:
MesonOptionBase::Type type() const override;
QString value() const override;
QString initialValue() const override;
void setFromString(QString value) override;
void reset() override;
QString rawValue() const;
......@@ -130,6 +134,7 @@ public:
MesonOptionBase::Type type() const override;
QString value() const override;
QString initialValue() const override;
void setFromString(QString value) override;
void reset() override;
int rawValue() const;
......@@ -148,6 +153,7 @@ public:
MesonOptionBase::Type type() const override;
QString value() const override;
QString initialValue() const override;
void setFromString(QString value) override;
void reset() override;
QString rawValue() const;
......
......@@ -131,6 +131,30 @@ void MesonOptionBaseView::setChanged(bool changed)
emit configChanged();
}
std::shared_ptr<MesonOptionBaseView> MesonOptionBaseView::fromOption(MesonOptionPtr option, QWidget* parent)
{
std::shared_ptr<MesonOptionBaseView> opt = nullptr;
switch (option->type()) {
case MesonOptionBase::ARRAY:
opt = make_shared<MesonOptionArrayView>(option, parent);
break;
case MesonOptionBase::BOOLEAN:
opt = make_shared<MesonOptionBoolView>(option, parent);
break;
case MesonOptionBase::COMBO:
opt = make_shared<MesonOptionComboView>(option, parent);
break;
case MesonOptionBase::INTEGER:
opt = make_shared<MesonOptionIntegerView>(option, parent);
break;
case MesonOptionBase::STRING:
opt = make_shared<MesonOptionStringView>(option, parent);
break;
}
return opt;
}
// Derived class constructors
MesonOptionArrayView::MesonOptionArrayView(MesonOptionPtr option, QWidget* parent)
......
......@@ -50,6 +50,8 @@ public:
void setInputWidget(QWidget* input);
static std::shared_ptr<MesonOptionBaseView> fromOption(MesonOptionPtr option, QWidget* parent);
protected:
void setChanged(bool changed);
......
......@@ -84,24 +84,7 @@ KJob* MesonOptionsView::repopulate(MesonIntrospectJob* introJob)
}
for (auto i : m_options->options()) {
OPT_VIEW_PTR opt = nullptr;
switch (i->type()) {
case MesonOptionBase::ARRAY:
opt = make_shared<MesonOptionArrayView>(i, m_ui->tabWidget);
break;
case MesonOptionBase::BOOLEAN:
opt = make_shared<MesonOptionBoolView>(i, m_ui->tabWidget);
break;
case MesonOptionBase::COMBO:
opt = make_shared<MesonOptionComboView>(i, m_ui->tabWidget);
break;
case MesonOptionBase::INTEGER:
opt = make_shared<MesonOptionIntegerView>(i, m_ui->tabWidget);
break;
case MesonOptionBase::STRING:
opt = make_shared<MesonOptionStringView>(i, m_ui->tabWidget);
break;
}
OPT_VIEW_PTR opt = MesonOptionBaseView::fromOption(i, m_ui->tabWidget);
if (!opt) {
qCWarning(KDEV_Meson) << "Unhandled option type " << i->type();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment