From 46e638e7d0efac6a688542c190721924f0a6a507 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 2 May 2021 00:59:34 +0300 Subject: [PATCH] viewsdialog:error/warnings indicators --- .../viewsdialog/delegates/namedelegate.cpp | 25 +++++++-- app/settings/viewsdialog/viewscontroller.cpp | 52 ++++++++++++++++++- app/settings/viewsdialog/viewsmodel.cpp | 33 ++++++++++++ app/settings/viewsdialog/viewsmodel.h | 5 ++ 4 files changed, 108 insertions(+), 7 deletions(-) diff --git a/app/settings/viewsdialog/delegates/namedelegate.cpp b/app/settings/viewsdialog/delegates/namedelegate.cpp index 794f86abf..de4689e41 100644 --- a/app/settings/viewsdialog/delegates/namedelegate.cpp +++ b/app/settings/viewsdialog/delegates/namedelegate.cpp @@ -56,6 +56,9 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, bool isMoveOrigin = index.data(Model::Views::ISMOVEORIGINROLE).toBool(); bool isChanged = (index.data(Model::Views::ISCHANGEDROLE).toBool() || index.data(Model::Views::HASCHANGEDVIEWROLE).toBool()); + bool hasErrors = index.data(Model::Views::ERRORSROLE).toBool(); + bool hasWarnings = index.data(Model::Views::WARNINGSROLE).toBool(); + Latte::Data::Screen screen = index.data(Model::Views::SCREENROLE).value(); Latte::Data::View view = index.data(Model::Views::VIEWROLE).value(); @@ -79,21 +82,33 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, } // draw changes indicator - QRect availableTextRect = Latte::remainedFromChangesIndicator(option); + QRect remainedrect = Latte::remainedFromChangesIndicator(option); Latte::drawChangesIndicatorBackground(painter, option); if (isChanged) { Latte::drawChangesIndicator(painter, option); } + myOptions.rect = remainedrect; + + // draw errors/warnings + if (hasErrors || hasWarnings) { + remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight); + Latte::drawIconBackground(painter, myOptions, Qt::AlignRight); + if (hasErrors) { + Latte::drawIcon(painter, myOptions, "data-error", Qt::AlignRight); + } else if (hasWarnings) { + Latte::drawIcon(painter, myOptions, "data-warning", Qt::AlignRight); + } + myOptions.rect = remainedrect; + } - myOptions.rect = availableTextRect; - + // draw screen icon int maxiconsize = -1; //disabled - availableTextRect = Latte::remainedFromScreenDrawing(myOptions, maxiconsize); + remainedrect = Latte::remainedFromScreenDrawing(myOptions, maxiconsize); Latte::drawScreenBackground(painter, option.widget->style(), myOptions, maxiconsize); QRect availableScreenRect = Latte::drawScreen(painter, myOptions, screen.geometry, maxiconsize, textopacity); Latte::drawView(painter, myOptions, view, availableScreenRect, textopacity); - myOptions.rect = availableTextRect; + myOptions.rect = remainedrect; Latte::drawFormattedText(painter, myOptions, textopacity); } diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp index ad2432153..a6d1ed69a 100644 --- a/app/settings/viewsdialog/viewscontroller.cpp +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -500,10 +500,13 @@ void Views::messagesForErrorsWarnings(const Latte::CentralLayout *centralLayout) Data::Layout currentdata = centralLayout->data(); - //! show warnings + m_model->clearErrorsAndWarnings(); + + //! warnings if (currentdata.warnings > 0) { Data::WarningsList warnings = centralLayout->warnings(); + // show warnings for (int i=0; i< warnings.count(); ++i) { if (warnings[i].id == Data::Warning::ORPHANEDSUBCONTAINMENT) { messageForWarningOrphanedSubContainments(warnings[i]); @@ -511,12 +514,35 @@ void Views::messagesForErrorsWarnings(const Latte::CentralLayout *centralLayout) messageForWarningAppletAndContainmentWithSameId(warnings[i]); } } + + // count warnings per view + for (int i=0; icurrentData(cid); + if (!view.isValid()) { + //! one step back from subcontainment to view in order to find the influenced view id + cid = m_model->viewForSubContainment(cid); + view = m_model->currentData(cid); + } + + if (view.isValid()) { + view.warnings++; + m_model->updateCurrentView(cid, view); + } + } + } } - //! show errors + //! errors if (currentdata.errors > 0) { Data::ErrorsList errors = centralLayout->errors(); + // show errors for (int i=0; i< errors.count(); ++i) { if (errors[i].id == Data::Error::APPLETSWITHSAMEID) { messageForErrorAppletsWithSameId(errors[i]); @@ -524,6 +550,28 @@ void Views::messagesForErrorsWarnings(const Latte::CentralLayout *centralLayout) messageForErrorOrphanedParentAppletOfSubContainment(errors[i]); } } + + // count errors per view + for (int i=0; icurrentData(cid); + if (!view.isValid()) { + //! one step back from subcontainment to view in order to find the influenced view id + cid = m_model->viewForSubContainment(cid); + view = m_model->currentData(cid); + } + + if (view.isValid()) { + view.errors++; + m_model->updateCurrentView(cid, view); + } + } + } } } diff --git a/app/settings/viewsdialog/viewsmodel.cpp b/app/settings/viewsdialog/viewsmodel.cpp index 7b64832a1..d6249d578 100644 --- a/app/settings/viewsdialog/viewsmodel.cpp +++ b/app/settings/viewsdialog/viewsmodel.cpp @@ -382,6 +382,17 @@ bool Views::isVertical(const Plasma::Types::Location &location) const return (location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge); } +QString Views::viewForSubContainment(const QString &sid) +{ + for(int i=0; i roles; + roles << Qt::DisplayRole; + roles << Qt::UserRole; + roles << ERRORSROLE; + roles << WARNINGSROLE; + + emit dataChanged(this->index(0, IDCOLUMN), this->index(m_viewsTable.rowCount()-1, SUBCONTAINMENTSCOLUMN), roles); +} + void Views::populateScreens() { s_screens.clear(); @@ -490,6 +517,8 @@ void Views::updateCurrentView(QString currentViewId, Latte::Data::View &view) roles << ISACTIVEROLE; roles << HASCHANGEDVIEWROLE; roles << ISMOVEORIGINROLE; + roles << ERRORSROLE; + roles << WARNINGSROLE; emit dataChanged(this->index(currentrow, IDCOLUMN), this->index(currentrow, SUBCONTAINMENTSCOLUMN), roles); } @@ -767,6 +796,10 @@ QVariant Views::data(const QModelIndex &index, int role) const return viewVariant; } else if (role == ISMOVEORIGINROLE) { return m_viewsTable[row].isMoveOrigin; + } else if (role == ERRORSROLE) { + return m_viewsTable[row].errors; + } else if (role == WARNINGSROLE) { + return m_viewsTable[row].warnings; } if (role == Qt::TextAlignmentRole && column != NAMECOLUMN){ diff --git a/app/settings/viewsdialog/viewsmodel.h b/app/settings/viewsdialog/viewsmodel.h index 6b8314477..561628b33 100644 --- a/app/settings/viewsdialog/viewsmodel.h +++ b/app/settings/viewsdialog/viewsmodel.h @@ -65,6 +65,8 @@ public: SCREENROLE, VIEWROLE, ISMOVEORIGINROLE, + ERRORSROLE, + WARNINGSROLE, SORTINGROLE }; @@ -101,6 +103,8 @@ public: int rowForId(const QString &id) const; + QString viewForSubContainment(const QString &sid); + const Latte::Data::View &at(const int &row); const Latte::Data::View currentData(const QString &id); const Latte::Data::View originalData(const QString &id); @@ -111,6 +115,7 @@ public: void setOriginalData(Latte::Data::ViewsTable &data); void setOriginalView(QString currentViewId, Latte::Data::View &view); void updateCurrentView(QString currentViewId, Latte::Data::View &view); + void clearErrorsAndWarnings(); void updateActiveStatesBasedOn(const CentralLayout *layout);