diff --git a/app/data/appletdata.cpp b/app/data/appletdata.cpp index 27aaaa0ac..0da9df83b 100644 --- a/app/data/appletdata.cpp +++ b/app/data/appletdata.cpp @@ -66,6 +66,20 @@ Applet &Applet::operator=(Applet &&rhs) return (*this); } +bool Applet::operator==(const Applet &rhs) const +{ + return (id == rhs.id) + && (name == rhs.name) + && (description == rhs.description) + && (icon == rhs.icon) + && (isSelected == rhs.isSelected); +} + +bool Applet::operator!=(const Applet &rhs) const +{ + return !(*this == rhs); +} + bool Applet::isInstalled() const { return isValid() && id != name; diff --git a/app/data/appletdata.h b/app/data/appletdata.h index b7ba12b8c..ede46962b 100644 --- a/app/data/appletdata.h +++ b/app/data/appletdata.h @@ -44,12 +44,14 @@ public: QString description; QString icon; + bool isInstalled() const; + bool isValid() const; + //! Operators Applet &operator=(const Applet &rhs); Applet &operator=(Applet &&rhs); - - bool isInstalled() const; - bool isValid() const; + bool operator==(const Applet &rhs) const; + bool operator!=(const Applet &rhs) const; }; typedef GenericTable AppletsTable; diff --git a/app/settings/exporttemplatedialog/appletsmodel.cpp b/app/settings/exporttemplatedialog/appletsmodel.cpp index dc98bddff..d8c3227e6 100644 --- a/app/settings/exporttemplatedialog/appletsmodel.cpp +++ b/app/settings/exporttemplatedialog/appletsmodel.cpp @@ -86,6 +86,11 @@ int Applets::row(const QString &id) return -1; } +bool Applets::inDefaultValues() const +{ + return c_applets == o_applets; +} + void Applets::initDefaults() { for(int i=0; i roles; roles << Qt::CheckStateRole; + emit dataChanged(index(0, NAMECOLUMN), index(c_applets.rowCount()-1, NAMECOLUMN), roles); + emit appletsDataChanged(); } void Applets::setData(const Latte::Data::AppletsTable &applets) @@ -121,6 +130,8 @@ void Applets::setData(const Latte::Data::AppletsTable &applets) initDefaults(); o_applets = c_applets; endInsertRows(); + + emit appletsDataChanged(); } } @@ -129,12 +140,19 @@ void Applets::selectAll() QVector roles; roles << Qt::CheckStateRole; + bool changed{false}; + for(int i=0; i roles; roles << Qt::CheckStateRole; + bool changed{false}; + for(int i=0; i 0 ? true : false); + emit appletsDataChanged(); return true; } break; diff --git a/app/settings/exporttemplatedialog/appletsmodel.h b/app/settings/exporttemplatedialog/appletsmodel.h index 386f15f68..b433d1c86 100644 --- a/app/settings/exporttemplatedialog/appletsmodel.h +++ b/app/settings/exporttemplatedialog/appletsmodel.h @@ -57,6 +57,7 @@ public: ~Applets(); bool hasChangedData() const; + bool inDefaultValues() const; int rowCount() const; int rowCount(const QModelIndex &parent) const override; @@ -76,6 +77,9 @@ public: void reset(); void selectAll(); +signals: + void appletsDataChanged(); + private: void initDefaults(); diff --git a/app/settings/exporttemplatedialog/exporttemplatedialog.cpp b/app/settings/exporttemplatedialog/exporttemplatedialog.cpp index e15e96881..2af0fa639 100644 --- a/app/settings/exporttemplatedialog/exporttemplatedialog.cpp +++ b/app/settings/exporttemplatedialog/exporttemplatedialog.cpp @@ -34,28 +34,19 @@ ExportTemplateDialog::ExportTemplateDialog(QWidget *parent, const QString &layou : GenericDialog(parent), m_ui(new Ui::ExportTemplateDialog) { - setAttribute(Qt::WA_DeleteOnClose, true); - - //! first we need to setup the ui - m_ui->setupUi(this); + init(); initExtractButton(i18n("Export your selected layout as template")); - initButtons(); - //! we must create handlers after creating/adjusting the ui m_handler = new Handler::ExportTemplateHandler(this, layoutName, layoutId); + connect(m_handler, &Handler::ExportTemplateHandler::dataChanged, this, &ExportTemplateDialog::onDataChanged); } ExportTemplateDialog::ExportTemplateDialog(Latte::View *view) : GenericDialog(nullptr), m_ui(new Ui::ExportTemplateDialog) { - setAttribute(Qt::WA_DeleteOnClose, true); - - //! first we need to setup the ui - m_ui->setupUi(this); + init(); initExtractButton(i18n("Export your selected view as template")); - initButtons(); - //! we must create handlers after creating/adjusting the ui m_handler = new Handler::ExportTemplateHandler(this, view); } @@ -69,8 +60,17 @@ Ui::ExportTemplateDialog *ExportTemplateDialog::ui() const return m_ui; } +void ExportTemplateDialog::init() +{ + setAttribute(Qt::WA_DeleteOnClose, true); + //! first we need to setup the ui + m_ui->setupUi(this); + initButtons(); +} + void ExportTemplateDialog::initButtons() { + m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ExportTemplateDialog::onCancel); } @@ -87,6 +87,11 @@ void ExportTemplateDialog::initExtractButton(const QString &tooltip) connect(extractBtn, &QPushButton::clicked, this, &ExportTemplateDialog::onCancel); } +void ExportTemplateDialog::onDataChanged() +{ + m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(!m_handler->inDefaultValues()); +} + void ExportTemplateDialog::accept() { qDebug() << Q_FUNC_INFO; diff --git a/app/settings/exporttemplatedialog/exporttemplatedialog.h b/app/settings/exporttemplatedialog/exporttemplatedialog.h index b8763da1f..725f70501 100644 --- a/app/settings/exporttemplatedialog/exporttemplatedialog.h +++ b/app/settings/exporttemplatedialog/exporttemplatedialog.h @@ -67,11 +67,15 @@ protected: private slots: void onCancel(); + void onDataChanged(); void onReset(); void initButtons(); void initExtractButton(const QString &tooltip); +private: + void init(); + private: bool m_isExportingLayout{false}; bool m_isExportingView{false}; diff --git a/app/settings/exporttemplatedialog/exporttemplatehandler.cpp b/app/settings/exporttemplatedialog/exporttemplatehandler.cpp index eff5a0e28..25bd8339d 100644 --- a/app/settings/exporttemplatedialog/exporttemplatehandler.cpp +++ b/app/settings/exporttemplatedialog/exporttemplatehandler.cpp @@ -59,16 +59,14 @@ ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *paren ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, Latte::View *view) : ExportTemplateHandler(parentDialog) { - init(); } ExportTemplateHandler::~ExportTemplateHandler() { } - void ExportTemplateHandler::init() -{ +{ m_ui->appletsTable->horizontalHeader()->setStretchLastSection(true); m_ui->appletsTable->horizontalHeader()->setSectionsClickable(false); @@ -77,6 +75,7 @@ void ExportTemplateHandler::init() m_ui->appletsTable->setItemDelegateForColumn(Model::Applets::NAMECOLUMN, new Settings::Applets::Delegate::NormalCheckBox(this)); //! Applets Model + connect(m_appletsModel, &Settings::Model::Applets::appletsDataChanged, this, &ExportTemplateHandler::dataChanged); m_appletsProxyModel = new QSortFilterProxyModel(this); m_appletsProxyModel->setSourceModel(m_appletsModel); m_appletsProxyModel->setSortRole(Model::Applets::SORTINGROLE); @@ -128,10 +127,9 @@ bool ExportTemplateHandler::hasChangedData() const bool ExportTemplateHandler::inDefaultValues() const { - return !hasChangedData(); + return m_appletsModel->inDefaultValues(); } - void ExportTemplateHandler::reset() { m_appletsModel->reset();