viewsdialog:add properly new temporary views

work/spdx
Michail Vourlakos 4 years ago
parent 5dde3fdfc5
commit 23fe87e736

@ -23,8 +23,6 @@
namespace Latte {
namespace Data {
const char *TEMPIDPREFIX = "temp:";
View::View()
: Generic()
{
@ -189,17 +187,6 @@ bool View::hasSubContainment(const QString &subId) const
return subcontainments.containsId(subId);
}
QString View::tempId() const
{
if (isCreated()) {
return id;
}
QString tid = id;
tid.remove(0, QString(TEMPIDPREFIX).count());
return tid;
}
View::State View::state() const
{
return m_state;

@ -66,8 +66,6 @@ public:
bool hasLayoutOrigin() const;
bool hasSubContainment(const QString &subId) const;
QString tempId() const;
View::State state() const;
void setState(View::State state, QString file = QString(), QString view = QString());

@ -25,6 +25,8 @@
namespace Latte {
namespace Data {
const char *TEMPIDPREFIX = "temp:";
ViewsTable::ViewsTable()
: GenericTable<View>()
{
@ -71,6 +73,25 @@ bool ViewsTable::operator!=(const ViewsTable &rhs) const
return !(*this == rhs);
}
void ViewsTable::appendTemporaryView(const Data::View &view)
{
int maxTempId = 0;
for(int i=0; i<rowCount(); ++i) {
if ((*this)[i].id.startsWith(TEMPIDPREFIX)) {
QString tid = (*this)[i].id;
tid.remove(0, QString(TEMPIDPREFIX).count());
if (tid.toInt() > maxTempId) {
maxTempId = tid.toInt();
}
}
}
Data::View newview = view;
newview.id = QString(TEMPIDPREFIX + QString::number(maxTempId+1));
m_list << newview;
}
void ViewsTable::print()
{
qDebug().noquote() << "Views initialized : " + (isInitialized ? QString("true") : QString("false"));
@ -81,6 +102,5 @@ void ViewsTable::print()
}
}
}
}

@ -43,6 +43,8 @@ public:
void print();
void appendTemporaryView(const Data::View &view);
//! Operators
ViewsTable &operator=(const ViewsTable &rhs);
ViewsTable &operator=(ViewsTable &&rhs);

@ -124,6 +124,11 @@ bool Views::hasSelectedView() const
return (selectedRow >= 0);
}
void Views::appendViewFromViewTemplate(const Data::View &view)
{
m_model->appendTemporaryView(view);
}
void Views::selectRow(const QString &id)
{
// m_view->selectRow(rowForId(id));

@ -70,6 +70,8 @@ public:
// const Latte::Data::Layout selectedViewCurrentData() const;
// const Latte::Data::Layout selectedViewOriginalData() const;
void appendViewFromViewTemplate(const Data::View &view);
void selectRow(const QString &id);
//! actions

@ -29,10 +29,12 @@
#include "../settingsdialog/delegates/layoutcmbitemdelegate.h"
#include "../../data/layoutstable.h"
#include "../../data/genericbasictable.h"
#include "../../data/viewstable.h"
#include "../../lattecorona.h"
#include "../../layout/abstractlayout.h"
#include "../../layout/centrallayout.h"
#include "../../layouts/manager.h"
#include "../../layouts/storage.h"
#include "../../layouts/synchronizer.h"
#include "../../templates/templatesmanager.h"
#include "../../tools/commontools.h"
@ -214,6 +216,14 @@ void ViewsHandler::save()
void ViewsHandler::newView(const QString &templateId)
{
qDebug() << "new view from template :: " << templateId;
Data::ViewsTable views = Latte::Layouts::Storage::self()->views(templateId);
if (views.rowCount() > 0) {
Data::View viewfromtemplate = views[0];
viewfromtemplate.setState(Data::View::OriginFromViewTemplate, templateId);
m_viewsController->appendViewFromViewTemplate(views[0]);
}
}
void ViewsHandler::onCurrentLayoutIndexChanged(int row)

@ -131,18 +131,12 @@ void Views::resetData()
setOriginalData(o_viewsTable);
}
void Views::appendView(const Latte::Data::View &view)
void Views::appendTemporaryView(const Latte::Data::View &view)
{
//int newRow = m_layoutsTable.sortedPosForName(layout.name);
Data::View newview = view;
if (!newview.isCreated()) {
}
beginInsertRows(QModelIndex(), m_viewsTable.rowCount(), m_viewsTable.rowCount());
m_viewsTable << view;
m_viewsTable.appendTemporaryView(view);
endInsertRows();
emit rowsInserted();

@ -77,7 +77,7 @@ public:
//! all original data will become also current
void resetData();
void appendView(const Latte::Data::View &view);
void appendTemporaryView(const Latte::Data::View &view);
void removeView(const QString &id);
int rowCount() const;

Loading…
Cancel
Save