File indexing completed on 2024-05-19 15:46:03

0001 /*
0002     SPDX-FileCopyrightText: 2019 Daniel Mensinger <daniel@mensinger-ka.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QJsonValue>
0010 #include <QWidget>
0011 #include <memory>
0012 
0013 class MesonOptionBaseView;
0014 class MesonRewriterOptionContainer;
0015 using MesonOptViewPtr = std::shared_ptr<MesonOptionBaseView>;
0016 using MesonOptContainerPtr = std::shared_ptr<MesonRewriterOptionContainer>;
0017 
0018 namespace Ui
0019 {
0020 class MesonRewriterInputBase;
0021 class MesonRewriterOptionContainer;
0022 }
0023 
0024 class QLineEdit;
0025 
0026 class MesonKWARGSInfo;
0027 class MesonKWARGSModify;
0028 
0029 class MesonRewriterInputBase : public QWidget
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     enum Type { STRING };
0035 
0036 public:
0037     explicit MesonRewriterInputBase(const QString& name, const QString& kwarg, QWidget* parent);
0038     virtual ~MesonRewriterInputBase();
0039 
0040     int nameWidth();
0041     void setMinNameWidth(int width);
0042     bool isEnabled() const;
0043     bool hasChanged() const;
0044 
0045     virtual Type type() const = 0;
0046 
0047     void resetFromAction(MesonKWARGSInfo* action);
0048     void writeToAction(MesonKWARGSModify* action);
0049 
0050 protected:
0051     void setInputWidget(QWidget* input);
0052 
0053     virtual bool hasValueChanged() const = 0;
0054     virtual void doReset() = 0;
0055     virtual QWidget* inputWidget() = 0;
0056     virtual void resetValue(const QJsonValue& val) = 0;
0057     virtual QJsonValue value() = 0;
0058 
0059 public Q_SLOTS:
0060     void reset();
0061     void remove();
0062     void add();
0063     void updateUi();
0064 
0065 Q_SIGNALS:
0066     void configChanged();
0067 
0068 private:
0069     Ui::MesonRewriterInputBase* m_ui = nullptr;
0070     QString m_name;
0071     QString m_kwarg;
0072     bool m_enabled = false;
0073     bool m_default_enabled = false;
0074 };
0075 
0076 class MesonRewriterInputString : public MesonRewriterInputBase
0077 {
0078     Q_OBJECT
0079 
0080 public:
0081     explicit MesonRewriterInputString(const QString& name, const QString& kwarg, QWidget* parent);
0082     virtual ~MesonRewriterInputString();
0083 
0084     MesonRewriterInputBase::Type type() const override;
0085 
0086 protected:
0087     void doReset() override;
0088     QWidget* inputWidget() override;
0089     bool hasValueChanged() const override;
0090     void resetValue(const QJsonValue& val) override;
0091     QJsonValue value() override;
0092 
0093 private:
0094     QString m_initialValue;
0095     QLineEdit* m_lineEdit = nullptr;
0096 };
0097 
0098 class MesonRewriterOptionContainer : public QWidget
0099 {
0100     Q_OBJECT
0101 
0102 public:
0103     MesonRewriterOptionContainer(MesonOptViewPtr optView, QWidget* parent);
0104 
0105     bool shouldDelete() const;
0106     bool hasChanged() const;
0107     MesonOptViewPtr view();
0108 
0109 public Q_SLOTS:
0110     void deleteMe();
0111 
0112 Q_SIGNALS:
0113     void configChanged();
0114 
0115 private:
0116     Ui::MesonRewriterOptionContainer* m_ui = nullptr;
0117     MesonOptViewPtr m_optView = nullptr;
0118 
0119     bool m_markedForDeletion = false;
0120 };