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

viewsdialog:update model data for newly added views

This commit is contained in:
Michail Vourlakos 2021-04-17 19:32:40 +03:00
parent 1fac17d6ba
commit 4d76005325
7 changed files with 94 additions and 25 deletions

View File

@ -38,8 +38,8 @@ View::View(View &&o)
edge(o.edge),
alignment(o.alignment),
m_state(o.m_state),
originFile(o.originFile),
originView(o.originView),
m_originFile(o.m_originFile),
m_originView(o.m_originView),
subcontainments(o.subcontainments)
{
}
@ -54,8 +54,8 @@ View::View(const View &o)
edge(o.edge),
alignment(o.alignment),
m_state(o.m_state),
originFile(o.originFile),
originView(o.originView),
m_originFile(o.m_originFile),
m_originView(o.m_originView),
subcontainments(o.subcontainments)
{
}
@ -72,8 +72,8 @@ View &View::operator=(const View &rhs)
edge = rhs.edge;
alignment = rhs.alignment;
m_state = rhs.m_state;
originFile = rhs.originFile;
originView = rhs.originView;
m_originFile = rhs.m_originFile;
m_originView = rhs.m_originView;
subcontainments = rhs.subcontainments;
return (*this);
@ -91,8 +91,8 @@ View &View::operator=(View &&rhs)
edge = rhs.edge;
alignment = rhs.alignment;
m_state = rhs.m_state;
originFile = rhs.originFile;
originView = rhs.originView;
m_originFile = rhs.m_originFile;
m_originView = rhs.m_originView;
subcontainments = rhs.subcontainments;
return (*this);
@ -110,8 +110,8 @@ bool View::operator==(const View &rhs) const
&& (edge == rhs.edge)
&& (alignment == rhs.alignment)
&& (m_state == rhs.m_state)
&& (originFile == rhs.originFile)
&& (originView == rhs.originView)
&& (m_originFile == rhs.m_originFile)
&& (m_originView == rhs.m_originView)
&& (subcontainments == rhs.subcontainments);
}
@ -202,6 +202,16 @@ bool View::hasSubContainment(const QString &subId) const
return subcontainments.containsId(subId);
}
QString View::originFile() const
{
return m_originFile;
}
QString View::originView() const
{
return m_originView;
}
View::State View::state() const
{
return m_state;
@ -210,11 +220,9 @@ View::State View::state() const
void View::setState(View::State state, QString file, QString view)
{
m_state = state;
originFile = file;
originView = view;
m_originFile = file;
m_originView = view;
}
}
}

View File

@ -70,6 +70,9 @@ public:
bool isHorizontal() const;
bool isVertical() const;
QString originFile() const;
QString originView() const;
View::State state() const;
void setState(View::State state, QString file = QString(), QString view = QString());
@ -84,8 +87,8 @@ protected:
View::State m_state{IsInvalid};
//! Origin Data
QString originFile;
QString originView;
QString m_originFile;
QString m_originView;
};
}

View File

@ -1550,15 +1550,16 @@ void GenericLayout::duplicateView(Plasma::Containment *containment)
emit viewEdgeChanged();
}
void GenericLayout::newView(const QString &templateFile, const Latte::Data::View &nextViewData)
Data::View GenericLayout::newView(const QString &templateFile, const Latte::Data::View &nextViewData)
{
if (nextViewData.state() == Data::View::IsInvalid) {
return;
return Data::View();
}
Data::View result = Layouts::Storage::self()->newView(this, templateFile, nextViewData);
emit viewEdgeChanged();
return result;
}
void GenericLayout::updateView(const Latte::Data::View &viewData)

View File

@ -125,7 +125,7 @@ public:
void recreateView(Plasma::Containment *containment, bool delayed = true);
bool latteViewExists(Plasma::Containment *containment);
void newView(const QString &templateFile, const Latte::Data::View &nextViewData);
Data::View newView(const QString &templateFile, const Latte::Data::View &nextViewData);
void removeView(const Latte::Data::View &viewData);
void updateView(const Latte::Data::View &viewData);

View File

@ -220,9 +220,23 @@ void Views::save()
Latte::CentralLayout *centralActive = m_handler->isSelectedLayoutOriginal() ? m_handler->corona()->layoutsManager()->synchronizer()->centralLayout(originallayout.name) : nullptr;
Latte::CentralLayout *central = centralActive ? centralActive : new Latte::CentralLayout(this, currentlayout.id);
//! update altered views
//! views in model
Latte::Data::ViewsTable originalViews = m_model->originalViewsData();
Latte::Data::ViewsTable currentViews = m_model->currentViewsData();
Latte::Data::ViewsTable alteredViews = m_model->alteredViews();
Latte::Data::ViewsTable newViews = m_model->newViews();
QHash<QString, Data::View> newviewsresponses;
//! add new views
for(int i=0; i<newViews.rowCount(); ++i){
if (newViews[i].state() == Data::View::OriginFromViewTemplate) {
Data::View addedview = central->newView(newViews[i].originFile(), newViews[i]);
newviewsresponses[newViews[i].id] = addedview;
}
}
//! update altered views
for (int i=0; i<alteredViews.rowCount(); ++i) {
if (alteredViews[i].state() == Data::View::IsCreated) {
qDebug() << "org.kde.latte updating altered view :: " << alteredViews[i];
@ -231,18 +245,24 @@ void Views::save()
}
//! remove deprecated views
Latte::Data::ViewsTable originalViews = m_model->originalViewsData();
Latte::Data::ViewsTable currentViews = m_model->currentViewsData();
Latte::Data::ViewsTable removedViews = originalViews.subtracted(currentViews);
for (int i=0; i<removedViews.rowCount(); ++i) {
central->removeView(removedViews[i]);
}
if (removedViews.rowCount() > 0) {
if ((removedViews.rowCount() > 0) || (newViews.rowCount() > 0)) {
m_handler->corona()->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles();
}
//! update model for newly added views
for (const auto vid: newviewsresponses.keys()) {
m_model->setOriginalView(vid, newviewsresponses[vid]);
}
//! update all table with latest data
currentViews = m_model->currentViewsData();
//! update model original data
m_model->setOriginalData(currentViews);
}

View File

@ -244,6 +244,21 @@ Latte::Data::ViewsTable Views::alteredViews() const
return views;
}
Latte::Data::ViewsTable Views::newViews() const
{
Latte::Data::ViewsTable views;
for(int i=0; i<rowCount(); ++i) {
QString currentId = m_viewsTable[i].id;
if (!o_viewsTable.containsId(currentId)) {
views << m_viewsTable[i];
}
}
return views;
}
void Views::populateScreens()
{
s_screens.clear();
@ -259,6 +274,26 @@ void Views::populateScreens()
}
}
void Views::setOriginalView(QString currentViewId, Latte::Data::View &view)
{
if (!m_viewsTable.containsId(currentViewId)) {
return;
}
int currentrow = m_viewsTable.indexOf(currentViewId);
o_viewsTable << view;
m_viewsTable[currentrow] = view;
QVector<int> roles;
roles << Qt::DisplayRole;
roles << Qt::UserRole;
roles << ISCHANGEDROLE;
roles << ISACTIVEROLE;
roles << HASCHANGEDVIEWROLE;
emit dataChanged(this->index(currentrow, IDCOLUMN), this->index(currentrow, SUBCONTAINMENTSCOLUMN), roles);
}
void Views::setOriginalData(Latte::Data::ViewsTable &data)
{
clear();
@ -367,7 +402,7 @@ bool Views::setData(const QModelIndex &index, const QVariant &value, int role)
//! specific roles to each independent cell
switch (column) {
case NAMECOLUMN:
if (role == Qt::UserRole || role == Qt::EditRole ) {
if (role == Qt::UserRole || role == Qt::EditRole) {
if (m_viewsTable[row].name == value.toString()) {
return false;
}

View File

@ -106,8 +106,10 @@ public:
const Latte::Data::ViewsTable &originalViewsData();
void setOriginalData(Latte::Data::ViewsTable &data);
void setOriginalView(QString currentViewId, Latte::Data::View &view);
Latte::Data::ViewsTable alteredViews() const;
Latte::Data::ViewsTable newViews() const;
signals:
void rowsInserted();