1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-11 13:18:13 +03:00

provide ExportTemplate::Reset functionality

This commit is contained in:
Michail Vourlakos 2021-02-10 20:05:13 +02:00
parent c57a69ae05
commit f020400aec
7 changed files with 80 additions and 20 deletions

View File

@ -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;

View File

@ -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<Applet> AppletsTable;

View File

@ -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<c_applets.rowCount(); ++i) {
@ -99,6 +104,8 @@ void Applets::clear()
beginRemoveRows(QModelIndex(), 0, c_applets.rowCount() - 1);
c_applets.clear();
endRemoveRows();
emit appletsDataChanged();
}
}
@ -108,7 +115,9 @@ void Applets::reset()
QVector<int> 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<int> roles;
roles << Qt::CheckStateRole;
bool changed{false};
for(int i=0; i<c_applets.rowCount(); ++i) {
if (!c_applets[i].isSelected) {
c_applets[i].isSelected = true;
emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles);
changed = true;
}
}
if (changed) {
emit appletsDataChanged();
}
}
void Applets::deselectAll()
@ -142,16 +160,25 @@ void Applets::deselectAll()
QVector<int> roles;
roles << Qt::CheckStateRole;
bool changed{false};
for(int i=0; i<c_applets.rowCount(); ++i) {
if (c_applets[i].isSelected) {
c_applets[i].isSelected = false;
emit dataChanged(index(i, NAMECOLUMN), index(i, NAMECOLUMN), roles);
changed = true;
}
}
if (changed) {
emit appletsDataChanged();
}
}
void Applets::setSelected(const Latte::Data::AppletsTable &applets)
{
bool changed{false};
for(int i=0; i<applets.rowCount(); ++i) {
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;
emit dataChanged(index(pos, NAMECOLUMN), index(pos, NAMECOLUMN), roles);
changed = true;
}
}
if (changed) {
emit appletsDataChanged();
}
}
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:
if (role == Qt::CheckStateRole) {
c_applets[row].isSelected = (value.toInt() > 0 ? true : false);
emit appletsDataChanged();
return true;
}
break;

View File

@ -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();

View File

@ -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;

View File

@ -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};

View File

@ -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();