diff --git a/demo/demo.qml b/demo/demo.qml index c734a7d..fbaefe4 100644 --- a/demo/demo.qml +++ b/demo/demo.qml @@ -107,6 +107,7 @@ ApplicationWindow { anchors.fill: parent TextField { id: processFilterInput + focus: true width: parent.width placeholderText: "Filter processes" onTextChanged: { @@ -122,14 +123,14 @@ ApplicationWindow { model: processes sortIndicatorVisible: true alternatingRowColors: true - TableViewColumn { - title: "pid" - role: "pid" - } TableViewColumn { title: "name" role: "name" } + TableViewColumn { + title: "pid" + role: "pid" + } TableViewColumn { title: "cpu" role: "cpu" @@ -140,29 +141,19 @@ ApplicationWindow { var role = getColumn(processView.sortIndicatorColumn).role; model.sortByRole(role, processView.sortIndicatorOrder); } - Component.onCompleted: { - var r = processView.rootIndex; - var a = processes.index(0, 0, r); - var b = processes.index(1, 0, r); - processView.expand(processView.rootIndex); - processView.expand(a); - processView.expand(b); - processes.rowsInserted.connect(function (index) { - processView.expand(processView.rootIndex); - processView.expand(index); - }); + Timer { + interval: 100; running: true; repeat: true + onTriggered: { + var root = processView.rootIndex; + var systemd = processes.index(1, 0, root); + if (processes.data(systemd) === "systemd") { + processView.expand(systemd); + running = false; + } + } } } } -/* - view->connect(&models->sortedProcesses, &QAbstractItemModel::rowsInserted, - view, [view](const QModelIndex& index) { - if (!index.isValid()) { - view->expandAll(); - } - }); - } -*/ } Tab { id: chartTab diff --git a/demo/src/SortedModel.cpp b/demo/src/SortedModel.cpp index 6d51da9..d3da45e 100644 --- a/demo/src/SortedModel.cpp +++ b/demo/src/SortedModel.cpp @@ -1 +1,17 @@ +#include "SortedModel.h" + +bool SortedModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + if (QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) { + return true; + } + + QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent); + for (int i = 0 ; i < sourceModel()->rowCount(source_index); ++i) { + if (filterAcceptsRow(i, source_index)) return true; + } + + return false; +} + #include "SortedModel.moc" diff --git a/demo/src/SortedModel.h b/demo/src/SortedModel.h index 5157aa0..7e9e571 100644 --- a/demo/src/SortedModel.h +++ b/demo/src/SortedModel.h @@ -8,6 +8,10 @@ class SortedModel : public QSortFilterProxyModel { Q_OBJECT public: SortedModel() :QSortFilterProxyModel() {} + bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const; + Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { + return QSortFilterProxyModel::data(index, role); + } public slots: void sortByRole(const QString& role, Qt::SortOrder order) { QHashIterator i(roleNames());