Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Settings] Allow use list of plugins in landscape mode
  • Loading branch information
neochapay committed Jan 28, 2019
1 parent e53f7d9 commit f86bc87
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 209 deletions.
6 changes: 2 additions & 4 deletions glacier-settings.pro
Expand Up @@ -7,13 +7,11 @@ LIBS += -lglacierapp
SOURCES += \
src/main.cpp \
src/models/settingsmodel.cpp \
src/models/imagesmodel.cpp \
src/models/settingsproxymodel.cpp
src/models/imagesmodel.cpp

HEADERS += \
src/models/settingsmodel.h \
src/models/imagesmodel.h \
src/models/settingsproxymodel.h
src/models/imagesmodel.h

QT += qml quick

Expand Down
101 changes: 73 additions & 28 deletions qml/glacier-settings.qml
Expand Up @@ -32,11 +32,9 @@ import "components"
ApplicationWindow{
id: main

SettingsProxyModel{
SettingsModel{
id: settingsModel
model: SettingsModel{
path: "/usr/share/glacier-settings/plugins/"
}
path: "/usr/share/glacier-settings/plugins/"
}

SettingsService{
Expand All @@ -59,37 +57,84 @@ ApplicationWindow{
height: parent.height-tools.height
width: parent.width

contentHeight: quickSettings.height+view.height
contentHeight: content.height

QuickSettings{
id: quickSettings
anchors{
top: parent.top
topMargin: size.dp(20)
}
}

ListView {
id: view
Column {
id: content
width: parent.width
height: view.contentHeight
spacing: size.dp(20)

anchors{
top: quickSettings.bottom
topMargin: size.dp(20)
QuickSettings{
id: quickSettings
}

clip: true
model: settingsModel
delegate: ListViewItemWithActions {
label: title
icon: "/usr/share/glacier-settings/qml/plugins/"+path+"/"+path+".svg"
onClicked:{
console.log(Qt.createComponent(Qt.resolvedUrl("plugins/"+path+"/"+path+".qml")).errorString())
pageStack.push(Qt.resolvedUrl("plugins/"+path+"/"+path+".qml"))
Repeater {
id: view

model: settingsModel
delegate: Rectangle {
id: settingsListDelegate
height: sectionHeading.height+flow.height
width: mainArea.width
color: Theme.backgroundColor

Rectangle {
id: sectionHeading
width: parent.width
height: Theme.itemHeightMedium
color: Theme.backgroundColor

Text {
id: sectionText
text: title
font.capitalization: Font.AllUppercase
font.pixelSize: Theme.fontSizeSmall
color: Theme.textColor
anchors{
left: parent.left
leftMargin: Theme.itemSpacingSmall
verticalCenter: parent.verticalCenter
}
}

Rectangle{
id: line
height: size.ratio(1)
color: Theme.textColor
width: content.width-sectionText.width-Theme.itemHeightExtraSmall
anchors{
left: sectionText.right
leftMargin: Theme.itemSpacingSmall
verticalCenter: sectionText.verticalCenter
}
}
}

Flow{
id: flow
width: parent.width
anchors.top: sectionHeading.bottom
Repeater{
id: list
width: parent.width
height: isUiLandscape ?
Theme.itemHeightMedium*Math.ceil(items.length/2) :
Theme.itemHeightMedium*items.length
model: items

delegate: ListViewItemWithActions {
height: Theme.itemHeightMedium
width: isUiLandscape ? parent.width/2 : parent.width
label: modelData.title
icon: "/usr/share/glacier-settings/qml/plugins/"+modelData.path+"/"+modelData.path+".svg"
onClicked:{
pageStack.push(Qt.resolvedUrl("plugins/"+modelData.path+"/"+modelData.path+".qml"))
}
}
}
}
}
}
section.property: "category"
}
}
}
Expand Down
96 changes: 39 additions & 57 deletions src/models/settingsmodel.cpp
Expand Up @@ -25,7 +25,7 @@
#include <QJsonObject>

/*
* Orgeding categoty DRAFT
* Orgeding category DRAFT
*
* Settings part:
* Personalization
Expand All @@ -42,20 +42,20 @@
* Other
*/


const QStringList SettingsModel::defaultCategories = {
tr("Other")
, tr("Info")
, tr("Development")
, tr("Network")
, tr("Personalization")
"Personalization",
"Network",
"Development",
"Info",
"Other"
};

SettingsModel::SettingsModel(QObject *parent) :
QAbstractListModel(parent)
{
m_roleNames << "title";
m_roleNames << "category";
m_roleNames << "path";
m_roleNames << "items";

for (const QString &role : m_roleNames) {
hash.insert(Qt::UserRole+hash.count() ,role.toLatin1());
Expand Down Expand Up @@ -97,8 +97,6 @@ int SettingsModel::compareCategories(QString leftCategory, QString rightCategory

void SettingsModel::init()
{
settingsList.clear();

QDir pluginsPath = QDir(m_pluginsDir);
qDebug() << "Start scan plugins dir " << pluginsPath.absolutePath();
pluginsPath.setNameFilters(QStringList("*.json"));
Expand Down Expand Up @@ -128,7 +126,7 @@ bool SettingsModel::loadConfig(QString configFileName)
QJsonDocument config = QJsonDocument::fromJson(pluginConfig.readAll());
QJsonObject configObject = config.object();

foreach (QString role, configObject.keys()) {
for (QString role : configObject.keys()) {
if (!m_roleNames.contains(role)) {
m_roleNames << role;
hash.insert(Qt::UserRole+hash.count() ,role.toLatin1());
Expand All @@ -137,7 +135,7 @@ bool SettingsModel::loadConfig(QString configFileName)

if(configObject.contains("title") && configObject.contains("category") && configObject.contains("path"))
{
addItem(configObject);
m_pluginsData.append(configObject);
return true;
}
else
Expand All @@ -146,18 +144,33 @@ bool SettingsModel::loadConfig(QString configFileName)
}
}

void SettingsModel::addItem(QJsonObject item)
QVariant SettingsModel::pluginsInCategory(QString category) const
{
QVariantList pluginsInCat;

int count = settingsList.size();
insertRows(count,1,item);
for (const QJsonValue &item : m_pluginsData) {
if(item.toObject().value("category").toString() == category) {
pluginsInCat.append(item.toObject().toVariantMap());
}
}
return pluginsInCat;
}


int SettingsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return settingsList.count();
return defaultCategories.count();
}


QVariantMap SettingsModel::get(int idx) const
{
QString title = defaultCategories.at(idx);

return QVariantMap{
{"title", title },
{"items", pluginsInCategory(title)}
};
}

QVariant SettingsModel::data(const QModelIndex &index, int role) const
Expand All @@ -166,60 +179,29 @@ QVariant SettingsModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();

if (index.row() >= settingsList.size())
if (index.row() >= defaultCategories.count())
return QVariant();

QJsonObject item = settingsList.at(index.row());
QVariant item = defaultCategories.at(index.row());

if(role == Qt::UserRole)
{
return item.value("title").toString();
return item;
}
else if(role == Qt::UserRole+1)
{
return item.value("category").toString();
}
else if(role == Qt::UserRole+2)
{
return item.value("path").toString();
return pluginsInCategory(item.toString()) ;
}
return QVariant();
}

QJsonObject SettingsModel::data(const QModelIndex &index) const
QVariantMap SettingsModel::data(const QModelIndex &index) const
{
if (!index.isValid())
return QJsonObject();
return QVariantMap();

if (index.row() >= settingsList.size())
return QJsonObject();
if (index.row() >= defaultCategories.size())
return QVariantMap();

return settingsList.at(index.row());
}

bool SettingsModel::insertRows(int position, int rows, QJsonObject &item, const QModelIndex &parent)
{
Q_UNUSED(parent);
beginInsertRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) {
settingsList.insert(position, item);
}
endInsertRows();
return true;
}

bool SettingsModel::removeRows(int position, int rows, const QModelIndex &index)
{
Q_UNUSED(index);
beginRemoveRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) {
settingsList.removeAt(position);
}
endRemoveRows();
return true;
}

void SettingsModel::remove(int idx)
{
this->removeRows(idx,1);
return get(index.row());
}
15 changes: 6 additions & 9 deletions src/models/settingsmodel.h
Expand Up @@ -22,6 +22,7 @@
#include <QObject>
#include <QAbstractListModel>
#include <QJsonObject>
#include <QJsonArray>

class SettingsModel : public QAbstractListModel
{
Expand All @@ -34,14 +35,9 @@ class SettingsModel : public QAbstractListModel

int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QJsonObject data(const QModelIndex &index) const;
QVariantMap data(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const {return hash;}

bool insertRows(int position, int rows, QJsonObject &item, const QModelIndex &index = QModelIndex());
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());

QList<QJsonObject> settingsList;

QString path(){return m_pluginsDir;}
void setPath(QString path);

Expand All @@ -53,14 +49,15 @@ class SettingsModel : public QAbstractListModel
void pathChanged();

public slots:
void addItem(QJsonObject item);
QJsonObject get(int idx){return settingsList[idx];}
void remove(int idx);
QVariantMap get(int idx) const;

private:
QHash<int,QByteArray> hash;
QString m_pluginsDir;
QStringList m_roleNames;
QJsonArray m_pluginsData; //plugins list

QVariant pluginsInCategory(QString category) const;
bool loadConfig(QString configFileName);
};

Expand Down

0 comments on commit f86bc87

Please sign in to comment.