Commit fbd66cdc authored by Nate Graham's avatar Nate Graham 💤
Browse files

Show and hide the inactive device buttons based on new count property

The old code was incorrect, calling `rowCount` as though it was a
property, but it was instead a function, so it didn't update as
expected.

This commit adds a `count` property that notifies of changes as expected
to the abstract model as well as the filter model. Now the "Show
inactive devices" buttons should be properly hidden by people whose
audio setup has no hidden devices.
parent 9ad93307
......@@ -646,7 +646,7 @@ Item {
icon.name: "view-visible"
// Only show if there actually are any inactive devices
visible: (paSourceModel.rowCount != paSourceFilterModel.rowCount) || (paSinkModel.rowCount != paSinkFilterModel.rowCount)
visible: (paSourceModel.count != paSourceFilterModel.count) || (paSinkModel.count != paSinkFilterModel.count)
checkable: true
......
......@@ -112,7 +112,7 @@ ScrollView {
icon.name: "view-visible"
// Only show if there actually are any inactive devices
visible: (paSourceModel.rowCount != paSourceFilterModel.rowCount) || (paSinkModel.rowCount != paSinkFilterModel.rowCount)
visible: (paSourceModel.count != paSourceFilterModel.count) || (paSinkModel.count != paSinkFilterModel.count)
}
}
}
......
......@@ -48,6 +48,7 @@ AbstractModel::AbstractModel(const MapBaseQObject *map, QObject *parent)
connect(m_map, &MapBaseQObject::added, this, [this](int index) {
onDataAdded(index);
endInsertRows();
Q_EMIT countChanged();
});
connect(m_map, &MapBaseQObject::aboutToBeRemoved, this, [this](int index) {
beginRemoveRows(QModelIndex(), index, index);
......@@ -55,6 +56,7 @@ AbstractModel::AbstractModel(const MapBaseQObject *map, QObject *parent)
connect(m_map, &MapBaseQObject::removed, this, [this](int index) {
Q_UNUSED(index);
endRemoveRows();
Q_EMIT countChanged();
});
}
......
......@@ -37,6 +37,8 @@ public:
enum ItemRole {
PulseObjectRole = Qt::UserRole + 1
};
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_ENUM(ItemRole)
~AbstractModel() override;
......@@ -47,6 +49,9 @@ public:
Q_INVOKABLE int role(const QByteArray &roleName) const;
Q_SIGNALS:
void countChanged();
protected:
AbstractModel(const MapBaseQObject *map, QObject *parent);
void initRoleNames(const QMetaObject &qobjectMetaObject);
......
......@@ -6,6 +6,14 @@ PlasmaCore.SortFilterModel {
property var filters: []
property bool filterOutInactiveDevices: false
// Not readonly because we have to assign to it below, even though you
// really shouldn't change it from outside of this model
property int count: rowCount()
onRowsInserted: count = rowCount()
onRowsRemoved: count = rowCount()
onModelReset: count = rowCount()
filterCallback: function(source_row, value) {
var idx = sourceModel.index(source_row, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment