Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ AppsModel::AppsModel(QObject *parent)
if (AppMgr::instance()->isValid()) {
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
const auto appItem = this->appItem(id);
const auto appItem = this->itemFromDesktopId(id);
if (!appItem) {
qWarning() << "Not existing item in AppsModel for the desktopId" << id;
return;
Expand All @@ -98,27 +98,6 @@ AppsModel::AppsModel(QObject *parent)
connect(m_tmUpdateCache, &QTimer::timeout, this, &AppsModel::updateModelData);
}

QList<AppItem *> AppsModel::appItems() const
{
QList<AppItem *> items;
for (int i = 0; i < rowCount(); i++) {
if (auto appItem = dynamic_cast<AppItem*>(item(i))) {
items.append(appItem);
}
}

return items;
}

AppItem *AppsModel::appItem(const QString &desktopId) const
{
const auto items = appItems();
auto iter = std::find_if(items.begin(), items.end(), [desktopId](AppItem *item) {
return item->freedesktopId() == desktopId;
});
return iter != items.end() ? *iter : nullptr;
}

void AppsModel::appendRows(const QList<AppItem *> items)
{
// TODO: preformance improvement?
Expand All @@ -127,7 +106,7 @@ void AppsModel::appendRows(const QList<AppItem *> items)
}
}

AppItem *AppsModel::itemFromDesktopId(const QString freedesktopId)
AppItem *AppsModel::itemFromDesktopId(const QString freedesktopId) const
{
QModelIndexList indexes = match(index(0, 0, QModelIndex()),
AppItem::DesktopIdRole, freedesktopId, 1, Qt::MatchExactly);
Expand Down
5 changes: 1 addition & 4 deletions src/models/appsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ class AppsModel : public QStandardItemModel

void appendRows(const QList<AppItem *> items);

AppItem * itemFromDesktopId(const QString freedesktopId);
AppItem * itemFromDesktopId(const QString freedesktopId) const;
[[nodiscard("might need to free them")]] const QList<AppItem *> addItems(const QList<AppItem *> &items);
[[nodiscard("might need to free them")]] const QList<AppItem *> updateItems(const QList<AppItem *> &items);

// QAbstractItemModel interface
QVariant data(const QModelIndex &index, int role) const override;

AppItem *appItem(const QString &desktopId) const;
private slots:
void updateModelData();

Expand All @@ -62,7 +60,6 @@ private slots:

QList<AppItem *> allAppInfosShouldBeShown() const;
void cleanUpInvalidApps(const QList<AppItem *> knownExistedApps);
QList<AppItem *> appItems() const;

Dtk::Core::DConfig * m_dconfig;
QStringList m_excludedAppIdList;
Expand Down