Fix "uncategorized" not showing in main page
This commit is contained in:
parent
5667089f1f
commit
ebc27de7ba
@ -106,34 +106,35 @@ void InterfacesModel::syncInterfaces()
|
||||
if (!m_deviceManager) {
|
||||
return;
|
||||
}
|
||||
QStringList baseList;
|
||||
QList<DeviceClass*> deviceClasses;
|
||||
if (m_onlyConfiguredDevices) {
|
||||
for (int i = 0; i < m_deviceManager->devices()->rowCount(); i++) {
|
||||
DeviceClass *dc = m_deviceManager->deviceClasses()->getDeviceClass(m_deviceManager->devices()->get(i)->deviceClassId());
|
||||
baseList << dc->interfaces();
|
||||
deviceClasses << m_deviceManager->deviceClasses()->getDeviceClass(m_deviceManager->devices()->get(i)->deviceClassId());
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < m_deviceManager->deviceClasses()->rowCount(); i++) {
|
||||
DeviceClass *dc = m_deviceManager->deviceClasses()->get(i);
|
||||
baseList << dc->interfaces();
|
||||
deviceClasses << m_deviceManager->deviceClasses()->get(i);
|
||||
}
|
||||
}
|
||||
baseList.removeDuplicates();
|
||||
|
||||
QStringList interfacesInSource;
|
||||
bool isInShownIfaces = false;
|
||||
foreach (const QString &interface, baseList) {
|
||||
if (!m_shownInterfaces.contains(interface)) {
|
||||
continue;
|
||||
}
|
||||
foreach (DeviceClass *dc, deviceClasses) {
|
||||
// qDebug() << "device" <<dc->name() << "has interfaces" << dc->interfaces();
|
||||
|
||||
if (!interfacesInSource.contains(interface)) {
|
||||
interfacesInSource.append(interface);
|
||||
bool isInShownIfaces = false;
|
||||
foreach (const QString &interface, dc->interfaces()) {
|
||||
if (!m_shownInterfaces.isEmpty() && !m_shownInterfaces.contains(interface)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!interfacesInSource.contains(interface)) {
|
||||
interfacesInSource.append(interface);
|
||||
}
|
||||
isInShownIfaces = true;
|
||||
}
|
||||
if (m_showUncategorized && !isInShownIfaces && !interfacesInSource.contains("uncategorized")) {
|
||||
interfacesInSource.append("uncategorized");
|
||||
}
|
||||
isInShownIfaces = true;
|
||||
}
|
||||
if (!isInShownIfaces && !interfacesInSource.contains("uncategorized")) {
|
||||
interfacesInSource.append("uncategorized");
|
||||
}
|
||||
QStringList interfacesToAdd = interfacesInSource;
|
||||
QStringList interfacesToRemove;
|
||||
@ -182,6 +183,7 @@ void InterfacesSortModel::setInterfacesModel(InterfacesModel *interfacesModel)
|
||||
if (m_interfacesModel != interfacesModel) {
|
||||
m_interfacesModel = interfacesModel;
|
||||
setSourceModel(interfacesModel);
|
||||
connect(interfacesModel, &InterfacesModel::countChanged, this, &InterfacesSortModel::countChanged);
|
||||
setSortRole(Devices::RoleName);
|
||||
sort(0);
|
||||
emit interfacesModelChanged();
|
||||
@ -201,3 +203,8 @@ bool InterfacesSortModel::lessThan(const QModelIndex &left, const QModelIndex &r
|
||||
}
|
||||
return m_interfacesModel->shownInterfaces().indexOf(leftName.toString()) < m_interfacesModel->shownInterfaces().indexOf(rightName.toString());
|
||||
}
|
||||
|
||||
QString InterfacesSortModel::get(int index) const
|
||||
{
|
||||
return m_interfacesModel->get(mapToSource(this->index(index, 0)).row());
|
||||
}
|
||||
|
||||
@ -67,6 +67,7 @@ private:
|
||||
class InterfacesSortModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||
Q_PROPERTY(InterfacesModel* interfacesModel READ interfacesModel WRITE setInterfacesModel NOTIFY interfacesModelChanged)
|
||||
|
||||
public:
|
||||
@ -77,7 +78,10 @@ public:
|
||||
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
|
||||
|
||||
Q_INVOKABLE QString get(int index) const;
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
void interfacesModelChanged();
|
||||
|
||||
private:
|
||||
|
||||
@ -111,6 +111,7 @@ Page {
|
||||
interfacesModel: InterfacesModel {
|
||||
deviceManager: engine.deviceManager
|
||||
shownInterfaces: app.supportedInterfaces
|
||||
showUncategorized: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -144,20 +144,22 @@ Page {
|
||||
id: typeFilterComboBox
|
||||
Layout.fillWidth: true
|
||||
textRole: "displayName"
|
||||
InterfacesModel {
|
||||
id: interfacesModel
|
||||
deviceManager: engine.deviceManager
|
||||
shownInterfaces: app.supportedInterfaces
|
||||
onlyConfiguredDevices: false
|
||||
showUncategorized: false
|
||||
InterfacesSortModel {
|
||||
id: interfacesSortModel
|
||||
interfacesModel: InterfacesModel {
|
||||
deviceManager: engine.deviceManager
|
||||
shownInterfaces: app.supportedInterfaces
|
||||
onlyConfiguredDevices: false
|
||||
showUncategorized: false
|
||||
}
|
||||
}
|
||||
model: ListModel {
|
||||
id: typeFilterModel
|
||||
ListElement { interfaceName: ""; displayName: qsTr("All") }
|
||||
|
||||
Component.onCompleted: {
|
||||
for (var i = 0; i < interfacesModel.count; i++) {
|
||||
append({interfaceName: interfacesModel.get(i), displayName: app.interfaceToString(interfacesModel.get(i))});
|
||||
for (var i = 0; i < interfacesSortModel.count; i++) {
|
||||
append({interfaceName: interfacesSortModel.get(i), displayName: app.interfaceToString(interfacesSortModel.get(i))});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,10 +19,6 @@ Item {
|
||||
readonly property int minTileHeight: 240
|
||||
readonly property int tilesPerRow: root.width / minTileWidth
|
||||
|
||||
model: InterfacesModel {
|
||||
id: interfacesModel
|
||||
deviceManager: engine.deviceManager
|
||||
}
|
||||
cellWidth: width / tilesPerRow
|
||||
cellHeight: cellWidth
|
||||
delegate: DevicesPageDelegate {
|
||||
|
||||
Reference in New Issue
Block a user