[plasma/drkonqi] src/coredump/gui: Tweak UI for coredump-gui
Tobias Fella <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f8a1d8246328ca8ef6e4460542d4c72404122407 by Tobias Fella.
Committed on 28/07/2026 at 08:35.
Pushed by tfella into branch 'master'.
Tweak UI for coredump-gui
- Show both the coredump list and details page at the same time
- Highlight the active coredump in the list
M +6 -0 src/coredump/gui/DetailsLoader.cpp
M +3 -0 src/coredump/gui/Patient.h
M +26 -3 src/coredump/gui/PatientModel.cpp
M +15 -2 src/coredump/gui/PatientModel.h
M +5 -0 src/coredump/gui/qml/DetailsPage.qml
M +7 -2 src/coredump/gui/qml/ListPage.qml
M +28 -1 src/coredump/gui/qml/Main.qml
https://invent.kde.org/plasma/drkonqi/-/commit/f8a1d8246328ca8ef6e4460542d4c72404122407
diff --git a/src/coredump/gui/DetailsLoader.cpp b/src/coredump/gui/DetailsLoader.cpp
index 29c3941d3..7db239d33 100644
--- a/src/coredump/gui/DetailsLoader.cpp
+++ b/src/coredump/gui/DetailsLoader.cpp
@@ -7,12 +7,18 @@
void DetailsLoader::setPatient(Patient *patient)
{
+ if (patient == m_patient) {
+ return;
+ }
+
m_patient = patient;
+
if (m_patient) {
load();
} else {
m_LoaderProcess = nullptr;
}
+ Q_EMIT patientChanged();
}
void DetailsLoader::load()
diff --git a/src/coredump/gui/Patient.h b/src/coredump/gui/Patient.h
index d0af867c2..3e050ac06 100644
--- a/src/coredump/gui/Patient.h
+++ b/src/coredump/gui/Patient.h
@@ -10,11 +10,14 @@
#include <KOSRelease>
#include <automaticcoredumpexcavator.h>
+#include <qqmlintegration.h>
class Coredump;
class Patient : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("Get from PatientModel")
QString m_origCoreFilename;
QFileInfo m_coreFileInfo;
diff --git a/src/coredump/gui/PatientModel.cpp b/src/coredump/gui/PatientModel.cpp
index 9325f3124..97ef785fe 100644
--- a/src/coredump/gui/PatientModel.cpp
+++ b/src/coredump/gui/PatientModel.cpp
@@ -34,7 +34,7 @@ QVariant PatientModel::data(const QModelIndex &index, int role) const
if (!hasIndex(index.row(), index.column())) {
return {};
}
- QObject *obj = m_objects.at(index.row());
+ const auto obj = m_objects.at(index.row());
switch ((ItemRole)role) {
case ObjectRole:
return QVariant::fromValue(obj);
@@ -69,12 +69,12 @@ int PatientModel::role(const QByteArray &roleName) const
return m_roles.key(roleName, -1);
}
-void PatientModel::addObject(std::unique_ptr<QObject> patient)
+void PatientModel::addObject(std::unique_ptr<Patient> patient)
{
const int index = m_objects.size();
beginInsertRows(QModelIndex(), index, index);
- QObject *object = patient.release();
+ auto object = patient.release();
object->setParent(this);
m_objects.append(object);
@@ -158,4 +158,27 @@ void PatientModel::setReady(bool ready)
Q_EMIT readyChanged();
}
+int PatientModel::currentIndex() const
+{
+ return m_currentIndex;
+}
+
+void PatientModel::setCurrentIndex(int index)
+{
+ if (m_currentIndex == index) {
+ return;
+ }
+
+ m_currentIndex = index;
+ Q_EMIT currentIndexChanged();
+}
+
+Patient *PatientModel::currentPatient() const
+{
+ if (m_currentIndex == -1 || m_currentIndex >= m_objects.count()) {
+ return nullptr;
+ }
+ return m_objects[m_currentIndex];
+}
+
#include "moc_PatientModel.cpp"
diff --git a/src/coredump/gui/PatientModel.h b/src/coredump/gui/PatientModel.h
index 874f589b6..2088640f4 100644
--- a/src/coredump/gui/PatientModel.h
+++ b/src/coredump/gui/PatientModel.h
@@ -5,6 +5,8 @@
#include <memory>
+#include "Patient.h"
+
#include <QAbstractListModel>
#include <QQmlEngine>
@@ -14,6 +16,9 @@ class PatientModel : public QAbstractListModel
QML_ELEMENT
QML_SINGLETON
+ Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
+ Q_PROPERTY(Patient *currentPatient READ currentPatient NOTIFY currentIndexChanged)
+
public:
enum ItemRole {
IndexRole = Qt::UserRole + 1,
@@ -40,13 +45,19 @@ public:
[[nodiscard]] int role(const QByteArray &roleName) const;
// Takes ownership.
- void addObject(std::unique_ptr<QObject> patient);
+ void addObject(std::unique_ptr<Patient> patient);
Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
bool ready() const;
void setReady(bool ready);
Q_SIGNAL void readyChanged();
+ [[nodiscard]] int currentIndex() const;
+ void setCurrentIndex(int index);
+ Q_SIGNAL void currentIndexChanged();
+
+ [[nodiscard]] Patient *currentPatient() const;
+
private Q_SLOTS:
void propertyChanged();
@@ -56,7 +67,9 @@ private:
[[nodiscard]] QMetaMethod propertyChangedMetaMethod() const;
explicit PatientModel(QObject *parent = nullptr);
- QList<QObject *> m_objects;
+ int m_currentIndex = -1;
+
+ QList<Patient *> m_objects;
QHash<int, QByteArray> m_roles;
QHash<int, QByteArray> m_objectProperties;
QHash<int, int> m_signalIndexToProperties;
diff --git a/src/coredump/gui/qml/DetailsPage.qml b/src/coredump/gui/qml/DetailsPage.qml
index 83192308e..f886b25c2 100644
--- a/src/coredump/gui/qml/DetailsPage.qml
+++ b/src/coredump/gui/qml/DetailsPage.qml
@@ -17,6 +17,11 @@ Kirigami.ScrollablePage {
property string text
property string errorText
+ onPatientChanged: {
+ page.text = "";
+ page.errorText = "";
+ }
+
title: i18nc("@title", "Details")
horizontalScrollBarPolicy: Qt.ScrollBarAsNeeded
diff --git a/src/coredump/gui/qml/ListPage.qml b/src/coredump/gui/qml/ListPage.qml
index 245e852d0..de34f53ad 100644
--- a/src/coredump/gui/qml/ListPage.qml
+++ b/src/coredump/gui/qml/ListPage.qml
@@ -55,15 +55,20 @@ Kirigami.ScrollablePage {
delegate: QQC2.ItemDelegate {
id: delegate
+ required property int modelIndex
+ required property DrKonqi.Patient modelObject
+
text: modelObject.appName
icon.name: modelObject.iconName
+ highlighted: modelIndex === DrKonqi.PatientModel.currentIndex
+
width: ListView.view.width
- onClicked: pageStack.push(Qt.resolvedUrl("DetailsPage.qml"), {patient: modelObject})
+ onClicked: DrKonqi.PatientModel.currentIndex = modelIndex
contentItem: Kirigami.IconTitleSubtitle {
title: delegate.text
- subtitle: modelObject.dateTime
+ subtitle: delegate.modelObject.dateTime
icon: icon.fromControlsIcon(delegate.icon)
}
}
diff --git a/src/coredump/gui/qml/Main.qml b/src/coredump/gui/qml/Main.qml
index 19c839f7f..46b27f369 100644
--- a/src/coredump/gui/qml/Main.qml
+++ b/src/coredump/gui/qml/Main.qml
@@ -6,6 +6,7 @@ import QtQuick.Layouts
import org.kde.config as KConfig
import org.kde.kirigami as Kirigami
+import org.kde.drkonqi.coredump.gui
Kirigami.ApplicationWindow {
id: root
@@ -20,6 +21,32 @@ Kirigami.ApplicationWindow {
configGroupName: "MainWindow"
}
+ readonly property Item applicationStates : Item {
+ states: [
+ State {
+ when: PatientModel.currentIndex === -1
+ PropertyChanges {
+ root.pageStack.items: [listPage]
+ }
+ },
+ State {
+ when: PatientModel.currentIndex !== -1
+ PropertyChanges {
+ root.pageStack.items: [listPage, detailsPage]
+ }
+ }
+ ]
+ }
+
+ readonly property ListPage listPage : ListPage {
+ parent: root.applicationStates
+ }
+
+ readonly property DetailsPage detailsPage : DetailsPage {
+ parent: root.applicationStates
+
+ patient: PatientModel.currentPatient
+ }
+
pageStack.initialPage: ListPage {}
- pageStack.defaultColumnWidth: root.width // show single page
}