1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*
SPDX-FileCopyrightText: 2019 Daniel Mensinger <daniel@mensinger-ka.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QJsonValue>
#include <QWidget>
#include <memory>
class MesonOptionBaseView;
class MesonRewriterOptionContainer;
using MesonOptViewPtr = std::shared_ptr<MesonOptionBaseView>;
using MesonOptContainerPtr = std::shared_ptr<MesonRewriterOptionContainer>;
namespace Ui
{
class MesonRewriterInputBase;
class MesonRewriterOptionContainer;
}
class QLineEdit;
class MesonKWARGSInfo;
class MesonKWARGSModify;
class MesonRewriterInputBase : public QWidget
{
Q_OBJECT
public:
enum Type { STRING };
public:
explicit MesonRewriterInputBase(const QString& name, const QString& kwarg, QWidget* parent);
virtual ~MesonRewriterInputBase();
int nameWidth();
void setMinNameWidth(int width);
bool isEnabled() const;
bool hasChanged() const;
virtual Type type() const = 0;
void resetFromAction(MesonKWARGSInfo* action);
void writeToAction(MesonKWARGSModify* action);
protected:
void setInputWidget(QWidget* input);
virtual bool hasValueChanged() const = 0;
virtual void doReset() = 0;
virtual QWidget* inputWidget() = 0;
virtual void resetValue(const QJsonValue& val) = 0;
virtual QJsonValue value() = 0;
public Q_SLOTS:
void reset();
void remove();
void add();
void updateUi();
Q_SIGNALS:
void configChanged();
private:
Ui::MesonRewriterInputBase* m_ui = nullptr;
QString m_name;
QString m_kwarg;
bool m_enabled = false;
bool m_default_enabled = false;
};
class MesonRewriterInputString : public MesonRewriterInputBase
{
Q_OBJECT
public:
explicit MesonRewriterInputString(const QString& name, const QString& kwarg, QWidget* parent);
virtual ~MesonRewriterInputString();
MesonRewriterInputBase::Type type() const override;
protected:
void doReset() override;
QWidget* inputWidget() override;
bool hasValueChanged() const override;
void resetValue(const QJsonValue& val) override;
QJsonValue value() override;
private:
QString m_initialValue;
QLineEdit* m_lineEdit = nullptr;
};
class MesonRewriterOptionContainer : public QWidget
{
Q_OBJECT
public:
MesonRewriterOptionContainer(MesonOptViewPtr optView, QWidget* parent);
bool shouldDelete() const;
bool hasChanged() const;
MesonOptViewPtr view();
public Q_SLOTS:
void deleteMe();
Q_SIGNALS:
void configChanged();
private:
Ui::MesonRewriterOptionContainer* m_ui = nullptr;
MesonOptViewPtr m_optView = nullptr;
bool m_markedForDeletion = false;
};
|