viewsdialog:error/warnings indicators

work/spdx
Michail Vourlakos 4 years ago
parent 1fbf7b8719
commit 46e638e7d0

@ -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::Screen>();
Latte::Data::View view = index.data(Model::Views::VIEWROLE).value<Latte::Data::View>();
@ -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);
}

@ -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; i<warnings.count(); ++i) {
for (int j=0; j<warnings[i].information.rowCount(); ++j) {
if (!warnings[i].information[j].containment.isValid()) {
continue;
}
QString cid = warnings[i].information[j].containment.storageId;
Data::View view = m_model->currentData(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; i<errors.count(); ++i) {
for (int j=0; j<errors[i].information.rowCount(); ++j) {
if (!errors[i].information[j].containment.isValid()) {
continue;
}
QString cid = errors[i].information[j].containment.storageId;
Data::View view = m_model->currentData(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);
}
}
}
}
}

@ -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<m_viewsTable.rowCount(); ++i) {
if (m_viewsTable[i].hasSubContainment(sid)) {
return m_viewsTable[i].id;
}
}
return QString();
}
void Views::updateActiveStatesBasedOn(const CentralLayout *layout)
{
if (!layout) {
@ -459,6 +470,22 @@ Latte::Data::ViewsTable Views::newViews() const
return views;
}
void Views::clearErrorsAndWarnings()
{
for(int i=0; i<m_viewsTable.rowCount(); ++i) {
m_viewsTable[i].errors = 0;
m_viewsTable[i].warnings = 0;
}
QVector<int> 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){

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

Loading…
Cancel
Save