provide ExportTemplate::Reset functionality

work/spdx
Michail Vourlakos 4 years ago
parent c57a69ae05
commit f020400aec

@ -66,6 +66,20 @@ Applet &Applet::operator=(Applet &&rhs)
return (*this); 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 bool Applet::isInstalled() const
{ {
return isValid() && id != name; return isValid() && id != name;

@ -44,12 +44,14 @@ public:
QString description; QString description;
QString icon; QString icon;
bool isInstalled() const;
bool isValid() const;
//! Operators //! Operators
Applet &operator=(const Applet &rhs); Applet &operator=(const Applet &rhs);
Applet &operator=(Applet &&rhs); Applet &operator=(Applet &&rhs);
bool operator==(const Applet &rhs) const;
bool isInstalled() const; bool operator!=(const Applet &rhs) const;
bool isValid() const;
}; };
typedef GenericTable<Applet> AppletsTable; typedef GenericTable<Applet> AppletsTable;

@ -86,6 +86,11 @@ int Applets::row(const QString &id)
return -1; return -1;
} }
bool Applets::inDefaultValues() const
{
return c_applets == o_applets;
}
void Applets::initDefaults() void Applets::initDefaults()
{ {
for(int i=0; i<c_applets.rowCount(); ++i) { for(int i=0; i<c_applets.rowCount(); ++i) {
@ -99,6 +104,8 @@ void Applets::clear()
beginRemoveRows(QModelIndex(), 0, c_applets.rowCount() - 1); beginRemoveRows(QModelIndex(), 0, c_applets.rowCount() - 1);
c_applets.clear(); c_applets.clear();
endRemoveRows(); endRemoveRows();
emit appletsDataChanged();
} }
} }
@ -108,7 +115,9 @@ void Applets::reset()
QVector<int> roles; QVector<int> roles;
roles << Qt::CheckStateRole; roles << Qt::CheckStateRole;
emit dataChanged(index(0, NAMECOLUMN), index(c_applets.rowCount()-1, NAMECOLUMN), roles); emit dataChanged(index(0, NAMECOLUMN), index(c_applets.rowCount()-1, NAMECOLUMN), roles);
emit appletsDataChanged();
} }
void Applets::setData(const Latte::Data::AppletsTable &applets) void Applets::setData(const Latte::Data::AppletsTable &applets)
@ -121,6 +130,8 @@ void Applets::setData(const Latte::Data::AppletsTable &applets)
initDefaults(); initDefaults();
o_applets = c_applets; o_applets = c_applets;
endInsertRows(); endInsertRows();
emit appletsDataChanged();
} }
} }
@ -129,12 +140,19 @@ void Applets::selectAll()
QVector<int> roles; QVector<int> roles;
roles << Qt::CheckStateRole; roles << Qt::CheckStateRole;
bool changed{false};
for(int i=0; i<c_applets.rowCount(); ++i) { for(int i=0; i<c_applets.rowCount(); ++i) {
if (!c_applets[i].isSelected) { if (!c_applets[i].isSelected) {
c_applets[i].isSelected = true; c_applets[i].isSelected = true;
emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles); emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles);
changed = true;
} }
} }
if (changed) {
emit appletsDataChanged();
}
} }
void Applets::deselectAll() void Applets::deselectAll()
@ -142,16 +160,25 @@ void Applets::deselectAll()
QVector<int> roles; QVector<int> roles;
roles << Qt::CheckStateRole; roles << Qt::CheckStateRole;
bool changed{false};
for(int i=0; i<c_applets.rowCount(); ++i) { for(int i=0; i<c_applets.rowCount(); ++i) {
if (c_applets[i].isSelected) { if (c_applets[i].isSelected) {
c_applets[i].isSelected = false; c_applets[i].isSelected = false;
emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles); emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles);
changed = true;
} }
} }
if (changed) {
emit appletsDataChanged();
}
} }
void Applets::setSelected(const Latte::Data::AppletsTable &applets) void Applets::setSelected(const Latte::Data::AppletsTable &applets)
{ {
bool changed{false};
for(int i=0; i<applets.rowCount(); ++i) { for(int i=0; i<applets.rowCount(); ++i) {
int pos = c_applets.indexOf(applets[i].id); int pos = c_applets.indexOf(applets[i].id);
@ -161,8 +188,13 @@ void Applets::setSelected(const Latte::Data::AppletsTable &applets)
c_applets[pos].isSelected = applets[i].isSelected; c_applets[pos].isSelected = applets[i].isSelected;
emit dataChanged(index(pos, NAMECOLUMN), index(pos, NAMECOLUMN), roles); emit dataChanged(index(pos, NAMECOLUMN), index(pos, NAMECOLUMN), roles);
changed = true;
} }
} }
if (changed) {
emit appletsDataChanged();
}
} }
Qt::ItemFlags Applets::flags(const QModelIndex &index) const Qt::ItemFlags Applets::flags(const QModelIndex &index) const
@ -216,6 +248,7 @@ bool Applets::setData(const QModelIndex &index, const QVariant &value, int role)
case NAMECOLUMN: case NAMECOLUMN:
if (role == Qt::CheckStateRole) { if (role == Qt::CheckStateRole) {
c_applets[row].isSelected = (value.toInt() > 0 ? true : false); c_applets[row].isSelected = (value.toInt() > 0 ? true : false);
emit appletsDataChanged();
return true; return true;
} }
break; break;

@ -57,6 +57,7 @@ public:
~Applets(); ~Applets();
bool hasChangedData() const; bool hasChangedData() const;
bool inDefaultValues() const;
int rowCount() const; int rowCount() const;
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
@ -76,6 +77,9 @@ public:
void reset(); void reset();
void selectAll(); void selectAll();
signals:
void appletsDataChanged();
private: private:
void initDefaults(); void initDefaults();

@ -34,28 +34,19 @@ ExportTemplateDialog::ExportTemplateDialog(QWidget *parent, const QString &layou
: GenericDialog(parent), : GenericDialog(parent),
m_ui(new Ui::ExportTemplateDialog) m_ui(new Ui::ExportTemplateDialog)
{ {
setAttribute(Qt::WA_DeleteOnClose, true); init();
//! first we need to setup the ui
m_ui->setupUi(this);
initExtractButton(i18n("Export your selected layout as template")); initExtractButton(i18n("Export your selected layout as template"));
initButtons();
//! we must create handlers after creating/adjusting the ui //! we must create handlers after creating/adjusting the ui
m_handler = new Handler::ExportTemplateHandler(this, layoutName, layoutId); m_handler = new Handler::ExportTemplateHandler(this, layoutName, layoutId);
connect(m_handler, &Handler::ExportTemplateHandler::dataChanged, this, &ExportTemplateDialog::onDataChanged);
} }
ExportTemplateDialog::ExportTemplateDialog(Latte::View *view) ExportTemplateDialog::ExportTemplateDialog(Latte::View *view)
: GenericDialog(nullptr), : GenericDialog(nullptr),
m_ui(new Ui::ExportTemplateDialog) m_ui(new Ui::ExportTemplateDialog)
{ {
setAttribute(Qt::WA_DeleteOnClose, true); init();
//! first we need to setup the ui
m_ui->setupUi(this);
initExtractButton(i18n("Export your selected view as template")); initExtractButton(i18n("Export your selected view as template"));
initButtons();
//! we must create handlers after creating/adjusting the ui //! we must create handlers after creating/adjusting the ui
m_handler = new Handler::ExportTemplateHandler(this, view); m_handler = new Handler::ExportTemplateHandler(this, view);
} }
@ -69,8 +60,17 @@ Ui::ExportTemplateDialog *ExportTemplateDialog::ui() const
return m_ui; 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() void ExportTemplateDialog::initButtons()
{ {
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
this, &ExportTemplateDialog::onCancel); this, &ExportTemplateDialog::onCancel);
} }
@ -87,6 +87,11 @@ void ExportTemplateDialog::initExtractButton(const QString &tooltip)
connect(extractBtn, &QPushButton::clicked, this, &ExportTemplateDialog::onCancel); connect(extractBtn, &QPushButton::clicked, this, &ExportTemplateDialog::onCancel);
} }
void ExportTemplateDialog::onDataChanged()
{
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(!m_handler->inDefaultValues());
}
void ExportTemplateDialog::accept() void ExportTemplateDialog::accept()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;

@ -67,11 +67,15 @@ protected:
private slots: private slots:
void onCancel(); void onCancel();
void onDataChanged();
void onReset(); void onReset();
void initButtons(); void initButtons();
void initExtractButton(const QString &tooltip); void initExtractButton(const QString &tooltip);
private:
void init();
private: private:
bool m_isExportingLayout{false}; bool m_isExportingLayout{false};
bool m_isExportingView{false}; bool m_isExportingView{false};

@ -59,16 +59,14 @@ ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *paren
ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, Latte::View *view) ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, Latte::View *view)
: ExportTemplateHandler(parentDialog) : ExportTemplateHandler(parentDialog)
{ {
init();
} }
ExportTemplateHandler::~ExportTemplateHandler() ExportTemplateHandler::~ExportTemplateHandler()
{ {
} }
void ExportTemplateHandler::init() void ExportTemplateHandler::init()
{ {
m_ui->appletsTable->horizontalHeader()->setStretchLastSection(true); m_ui->appletsTable->horizontalHeader()->setStretchLastSection(true);
m_ui->appletsTable->horizontalHeader()->setSectionsClickable(false); 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)); m_ui->appletsTable->setItemDelegateForColumn(Model::Applets::NAMECOLUMN, new Settings::Applets::Delegate::NormalCheckBox(this));
//! Applets Model //! Applets Model
connect(m_appletsModel, &Settings::Model::Applets::appletsDataChanged, this, &ExportTemplateHandler::dataChanged);
m_appletsProxyModel = new QSortFilterProxyModel(this); m_appletsProxyModel = new QSortFilterProxyModel(this);
m_appletsProxyModel->setSourceModel(m_appletsModel); m_appletsProxyModel->setSourceModel(m_appletsModel);
m_appletsProxyModel->setSortRole(Model::Applets::SORTINGROLE); m_appletsProxyModel->setSortRole(Model::Applets::SORTINGROLE);
@ -128,10 +127,9 @@ bool ExportTemplateHandler::hasChangedData() const
bool ExportTemplateHandler::inDefaultValues() const bool ExportTemplateHandler::inDefaultValues() const
{ {
return !hasChangedData(); return m_appletsModel->inDefaultValues();
} }
void ExportTemplateHandler::reset() void ExportTemplateHandler::reset()
{ {
m_appletsModel->reset(); m_appletsModel->reset();

Loading…
Cancel
Save