[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [apper/qt5] /: Do the sorting on the main model to get rid of the proxy
From: Daniel Nicoletti <dantti12 () gmail ! com>
Date: 2015-05-06 18:34:54
Message-ID: E1Yq49m-0004tN-Ry () scm ! kde ! org
[Download RAW message or body]
Git commit 9d895663048d480cebde88ca71fa8577fe3a02cb by Daniel Nicoletti.
Committed on 06/05/2015 at 17:24.
Pushed by dantti into branch 'qt5'.
Do the sorting on the main model to get rid of the proxy
which slows things down, and implement show packages in a nicer way
M +2 -0 Apper/application.qrc
M +13 -40 Apper/qml/Installed.qml
A +27 -0 Apper/qml/SoftwareDetails.qml [License: UNKNOWN] *
A +45 -0 Apper/qml/SoftwareListView.qml [License: UNKNOWN] *
M +65 -48 Apper/qml/UpdateDelegate.qml
M +49 -9 libapper/PackageModel.cpp
M +9 -1 libapper/PackageModel.h
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/apper/9d895663048d480cebde88ca71fa8577fe3a02cb
diff --git a/Apper/application.qrc b/Apper/application.qrc
index 9e7b820..76a3a78 100644
--- a/Apper/application.qrc
+++ b/Apper/application.qrc
@@ -9,5 +9,7 @@
<file>qml/BackendDetails.qml</file>
<file>qml/History.qml</file>
<file>qml/Search.qml</file>
+ <file>qml/SoftwareDetails.qml</file>
+ <file>qml/SoftwareListView.qml</file>
</qresource>
</RCC>
diff --git a/Apper/qml/Installed.qml b/Apper/qml/Installed.qml
index 978226a..a0e924c 100644
--- a/Apper/qml/Installed.qml
+++ b/Apper/qml/Installed.qml
@@ -4,49 +4,22 @@ import QtQuick.Layouts 1.0
import Apper 1.0
-ScrollView {
- id: root
-
- ListView {
- id: installedView
- width: root.viewport.width
-
- property int versionCol: 100
-
- Component {
- id: sectionHeading
- Rectangle {
- width: ListView.view.width
- height: childrenRect.height
- color: "lightsteelblue"
-
- Text {
- text: section === "f" ? qsTr("Applications") : qsTr("System \
Packages")
- font.bold: true
- font.pixelSize: 20
- }
- }
- }
-
- model: ApplicationSortFilterModel {
- id: sortModel
- sourcePkgModel: PackageModel {
- id: pkgModel
- onCountChanged: sortModel.sortNow()
+Item {
+
+ ScrollView {
+ id: root
+ anchors.fill: parent
+
+ SoftwareListView {
+ id: view
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.leftMargin: (root.viewport.width % cellWidth) / 2
+ onWidthChanged: {
+ console.debug((width % cellWidth))
}
- applicationsOnly: false
}
- delegate: UpdateDelegate {
- width: ListView.view.width
- }
-
- section.property: "roleIsPkg"
- section.criteria: ViewSection.FirstCharacter
- section.delegate: sectionHeading
}
- Component.onCompleted: {
- pkgModel.getInstalled()
- }
}
diff --git a/Apper/qml/SoftwareDetails.qml b/Apper/qml/SoftwareDetails.qml
new file mode 100644
index 0000000..a4e13e2
--- /dev/null
+++ b/Apper/qml/SoftwareDetails.qml
@@ -0,0 +1,27 @@
+import QtQuick 2.1
+import QtQuick.Controls 1.3
+import QtQuick.Layouts 1.0
+
+Item {
+ id: name
+
+ property string iconName
+
+ ScrollView {
+ GridLayout {
+ Item {
+ Layout.rowSpan: 3
+ id: iconImage
+ height: nameLabel.height + versionLabel.height * 2
+ width: height
+
+ Image {
+ anchors.fill: parent
+ fillMode: Image.PreserveAspectFit
+ source: iconName.length ? iconName : \
"image://icon/applications-other" + asynchronous: true
+ }
+ }
+ }
+ }
+}
diff --git a/Apper/qml/SoftwareListView.qml b/Apper/qml/SoftwareListView.qml
new file mode 100644
index 0000000..fcb110b
--- /dev/null
+++ b/Apper/qml/SoftwareListView.qml
@@ -0,0 +1,45 @@
+import QtQuick 2.1
+import QtQuick.Controls 1.3
+import QtQuick.Layouts 1.0
+
+import Apper 1.0
+
+GridView {
+ id: softwareListView
+
+ focus: true
+
+// property real gridCenter: height * 0.5 - cellWidth / 2
+ property bool showPackages: false
+
+ SystemPalette { id: sysPalette }
+
+ Component {
+ id: sectionHeading
+ Item {
+ visible: pkgModel.packageCount
+ width: softwareListView.width
+ height: childrenRect.height + 5
+
+ CheckBox {
+ text: qsTr("Show %1 more system \
packages").arg(pkgModel.packageCount) + onCheckedChanged: \
pkgModel.showPackages = checked + }
+ }
+ }
+
+ model: PackageModel {
+ id: pkgModel
+ }
+
+ delegate: UpdateDelegate {
+ }
+
+ cellHeight: 50
+ cellWidth: 200
+
+ footer: sectionHeading
+ Component.onCompleted: {
+ pkgModel.getInstalled()
+ }
+}
diff --git a/Apper/qml/UpdateDelegate.qml b/Apper/qml/UpdateDelegate.qml
index eb49ab6..92a71e1 100644
--- a/Apper/qml/UpdateDelegate.qml
+++ b/Apper/qml/UpdateDelegate.qml
@@ -4,100 +4,117 @@ import QtQuick.Layouts 1.0
Item {
id: root
- height: contentGrid.height + 20
- width: ListView.view.width
+ height: contentGrid.height + contentGrid.rowSpacing * 2
+ width: contentGrid.width + contentGrid.rowSpacing * 2
- property int maxColSize: root.width - iconImage.width - actionBt.width - 40
+ property bool isCurrent: GridView.isCurrentItem
GridLayout {
id: contentGrid
anchors.centerIn: parent
- width: parent.width - 20
- columns: 4
+ width: actionBt.width * 3 + iconImage.width * 4 + 4 * rowSpacing
+ columns: 3
Item {
Layout.rowSpan: 3
id: iconImage
- height: nameLabel.height + versionLabel.height * 2
+ height: nameLabel.height + versionLabel.height + repoLabel.height + \
contentGrid.rowSpacing * 2 width: height
Image {
anchors.fill: parent
fillMode: Image.PreserveAspectFit
+ cache: true
source: roleIcon.length ? roleIcon : \
"image://icon/applications-other" asynchronous: true
+ Rectangle {
+ anchors.fill: parent
+ color: "blue"
+ z:-1
+ }
}
}
Label {
Layout.columnSpan: 2
+ Layout.fillWidth: true
id: nameLabel
elide: Text.ElideRight
- font.pointSize: versionLabel.font.pointSize * 1.3
- text: roleName
- }
-
- Button {
- id: actionBt
- Layout.rowSpan: 3
- Layout.alignment: Qt.AlignVCenter
- text: qsTr("Remove")
+ textFormat: Text.StyledText
+ maximumLineCount: 1
+ color: isCurrent ? sysPalette.highlightedText : sysPalette.text
+ text: "<b>" + roleName + "</b> " + roleSummary
}
Label {
- Layout.preferredWidth: width
- width: installedView.versionCol
+ Layout.fillWidth: true
id: versionLabel
elide: Text.ElideRight
- text: roleArch === "all" ? roleVersion : roleVersion + " / " + roleArch
+ maximumLineCount: 1
+ color: isCurrent ? sysPalette.highlightedText : sysPalette.text
+ text: roleVersion + " / " + roleArch
}
- Label {
- Layout.fillWidth: true
- Layout.fillHeight: true
+ Item {
Layout.rowSpan: 2
- elide: Text.ElideRight
- text: roleSummary
- wrapMode: Text.WordWrap
+ Layout.fillHeight: true
+ Layout.alignment: Qt.AlignBottom
+ id: actionBt
+// text: qsTr("Remove")
}
- Item {}
+// Button {
+// Layout.rowSpan: 2
+// Layout.alignment: Qt.AlignBottom
+// id: actionBt
+// text: qsTr("Remove")
+// }
Label {
- Layout.preferredWidth: width
- width: installedView.versionCol
+ Layout.fillWidth: true
id: repoLabel
elide: Text.ElideRight
+ color: isCurrent ? sysPalette.highlightedText : sysPalette.text
text: roleRepo
}
- Component.onCompleted: {
- var width = Math.max(versionLabel.implicitWidth, \
repoLabel.implicitWidth)
- if (width > installedView.versionCol) {
- if (width > maxColSize) {
- installedView.versionCol = maxColSize
- } else {
- installedView.versionCol = width
- }
- }
+// Item {
+// Layout.columnSpan: contentGrid.columns
+// Layout.fillHeight: true
+//// Layout.alignment: Qt.AlignBottom
+//// id: actionBt
+//// text: qsTr("Remove")
+// }
+ }
+
+ Component.onCompleted: {
+ if (index > 1) {
+ return
+ }
+
+ if (contentGrid.height > softwareListView.cellHeight) {
+ softwareListView.cellHeight = contentGrid.height + \
contentGrid.rowSpacing * 4 + }
+
+ if (contentGrid.width > softwareListView.cellWidth) {
+ softwareListView.cellWidth = contentGrid.width + contentGrid.rowSpacing \
* 6 }
}
- SystemPalette { id: sysPalette }
Rectangle {
z: -1
anchors.centerIn: parent
- height: parent.height - 5
- width: parent.width - 10
- color: root.ListView.isCurrentItem ? sysPalette.highlight : \
sysPalette.alternateBase
-
- MouseArea {
- z: 1
- anchors.fill: parent
- onClicked: {
- console.debug(index)
- root.ListView.currentIndex = index
- }
+ height: parent.height - contentGrid.rowSpacing
+ width: parent.width - contentGrid.rowSpacing
+ color: isCurrent ? sysPalette.highlight : "transparent"
+ }
+
+ MouseArea {
+ z: 1
+ anchors.fill: contentGrid
+ onClicked: {
+ console.debug(index)
+ softwareListView.currentIndex = index
}
}
}
diff --git a/libapper/PackageModel.cpp b/libapper/PackageModel.cpp
index a70f75e..d03c318 100644
--- a/libapper/PackageModel.cpp
+++ b/libapper/PackageModel.cpp
@@ -142,9 +142,7 @@ void PackageModel::addPackage(Transaction::Info info, const \
QString &packageID, iPackage.displayName = app.name();
}
- if (!app.description().isEmpty()) {
- iPackage.summary = app.description();
- } else if (!app.summary().isEmpty()) {
+ if (!app.summary().isEmpty()) {
iPackage.summary = app.summary();
} else {
iPackage.summary = summary;
@@ -162,7 +160,7 @@ void PackageModel::addPackage(Transaction::Info info, const \
QString &packageID, if (selected) {
checkPackage(iPackage, false);
}
- m_packages.append(iPackage);
+ m_packages.insert(m_applicationCount++, iPackage);
}
}
@@ -183,7 +181,7 @@ void PackageModel::addPackage(Transaction::Info info, const \
QString &packageID, checkPackage(iPackage, false);
}
m_packages.append(iPackage);
-
+ ++m_packageCount;
}
}
@@ -222,7 +220,7 @@ QVariant PackageModel::data(const QModelIndex &index, int role) \
const return QVariant();
}
- const InternalPackage &package = m_packages[index.row()];
+ const InternalPackage &package = m_packages.at(index.row());
switch (role) {
case IconRole:
@@ -272,7 +270,7 @@ void PackageModel::removePackage(const QString &packageID)
if (iPackage.packageID == packageID &&
iPackage.info != Transaction::InfoUntrusted) {
beginRemoveRows(QModelIndex(), i, i);
- m_packages.remove(i);
+ m_packages.removeAt(i);
endRemoveRows();
// since we removed one entry we don't
@@ -289,6 +287,8 @@ void PackageModel::clear()
beginRemoveRows(QModelIndex(), 0, m_packages.size());
m_finished = false;
m_packages.clear();
+ m_packageCount = 0;
+ m_applicationCount = 0;
m_fetchSizesTransaction = 0;
m_fetchInstalledVersionsTransaction = 0;
@@ -344,6 +344,15 @@ void PackageModel::uncheckAvailablePackages()
}
}
+bool appsFirst(const PackageModel::InternalPackage &p1, const \
PackageModel::InternalPackage &p2) +{
+ if (p1.isPackage != p2.isPackage) {
+ return p2.isPackage;
+ }
+
+ return QString::compare(p1.displayName, p2.displayName, Qt::CaseInsensitive) < \
0; +}
+
void PackageModel::finished()
{
qDebug() << Q_FUNC_INFO << sender();
@@ -356,8 +365,15 @@ void PackageModel::finished()
// trans->disconnect(this, SLOT(finished()));
}
+ qSort(m_packages.begin(), m_packages.end(), appsFirst);
+
// The whole structure is about to change
- beginInsertRows(QModelIndex(), 0, m_packages.size() - 1);
+ if (m_showSystemPackages) {
+ beginInsertRows(QModelIndex(), 0, m_packages.size() - 1);
+ } else {
+ beginInsertRows(QModelIndex(), 0, m_applicationCount - 1);
+ }
+
m_finished = true;
endInsertRows();
@@ -730,7 +746,31 @@ bool PackageModel::allSelected() const
void PackageModel::setCheckable(bool checkable)
{
- m_checkable = checkable;
+ if (m_checkable != checkable) {
+ m_checkable = checkable;
+ emit changed(checkable);
+ }
+}
+
+void PackageModel::setShowPackages(bool show)
+{
+ if (m_showSystemPackages != show) {
+ m_showSystemPackages = show;
+
+
+ // The whole structure is about to change
+ if (m_showSystemPackages) {
+ beginInsertRows(QModelIndex(), m_applicationCount, m_packages.size() - \
1); + endInsertRows();
+ } else {
+ beginRemoveRows(QModelIndex(), m_applicationCount, m_packages.size() - \
1); + endRemoveRows();
+ }
+ emit rowCountChanged();
+
+
+ emit showPackagesChanged(show);
+ }
}
#include "PackageModel.moc"
diff --git a/libapper/PackageModel.h b/libapper/PackageModel.h
index 36c7d42..e5eed55 100644
--- a/libapper/PackageModel.h
+++ b/libapper/PackageModel.h
@@ -36,7 +36,10 @@ class PackageModel : public QAbstractItemModel
{
Q_OBJECT
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY changed)
+ Q_PROPERTY(bool showPackages MEMBER m_showSystemPackages WRITE setShowPackages \
NOTIFY showPackagesChanged) Q_PROPERTY(int count READ rowCount NOTIFY \
rowCountChanged) + Q_PROPERTY(int packageCount MEMBER m_packageCount NOTIFY \
rowCountChanged) + Q_PROPERTY(int applicationCount MEMBER m_applicationCount \
NOTIFY rowCountChanged) public:
enum {
SortRole = Qt::UserRole,
@@ -91,6 +94,7 @@ public:
bool checkable() const;
void setCheckable(bool checkable);
+ void setShowPackages(bool show);
QModelIndex index(int row, int column, const QModelIndex &parent = \
QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const;
@@ -129,6 +133,7 @@ public slots:
signals:
void changed(bool value);
+ void showPackagesChanged(bool value);
void packageUnchecked(const QString &packageID);
void rowCountChanged();
@@ -139,7 +144,10 @@ private:
bool m_finished = true;
bool m_checkable;
QPixmap m_installedEmblem;
- QVector<InternalPackage> m_packages;
+ bool m_showSystemPackages = false;
+ QList<InternalPackage> m_packages;
+ int m_packageCount = 0;
+ int m_applicationCount = 0;
QHash<QString, InternalPackage> m_checkedPackages;
PackageKit::Transaction *m_getUpdatesTransaction = 0;
PackageKit::Transaction *m_fetchSizesTransaction;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic