Verified Commit d4ffa0f8 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/kicker: add section model

This will be used to show all sections in "All Applications".
parent 370976d7
Pipeline #184338 passed with stage
in 7 minutes and 51 seconds
......@@ -138,6 +138,11 @@ AbstractModel *AbstractModel::rootModel()
return rootModel;
}
QVariantList AbstractModel::sections() const
{
return {};
}
void AbstractModel::entryChanged(AbstractEntry *entry)
{
Q_UNUSED(entry)
......
......@@ -21,6 +21,11 @@ class AbstractModel : public QAbstractListModel
Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
Q_PROPERTY(AbstractModel *favoritesModel READ favoritesModel WRITE setFavoritesModel NOTIFY favoritesModelChanged)
/**
* @return all sections in the model
*/
Q_PROPERTY(QVariantList sections READ sections NOTIFY sectionsChanged)
public:
explicit AbstractModel(QObject *parent = nullptr);
~AbstractModel() override;
......@@ -51,6 +56,8 @@ public:
virtual void setFavoritesModel(AbstractModel *model);
AbstractModel *rootModel();
virtual QVariantList sections() const;
virtual void entryChanged(AbstractEntry *entry);
Q_SIGNALS:
......@@ -59,6 +66,7 @@ Q_SIGNALS:
void separatorCountChanged() const;
void iconSizeChanged() const;
void favoritesModelChanged() const;
void sectionsChanged() const;
protected:
AbstractModel *m_favoritesModel = nullptr;
......
......@@ -77,6 +77,7 @@ AppsModel::AppsModel(const QList<AbstractEntry *> &entryList, bool deleteEntries
}
sortEntries();
refreshSectionList();
}
AppsModel::~AppsModel()
......@@ -443,6 +444,11 @@ QStringList AppsModel::hiddenEntries() const
return m_hiddenEntries;
}
QVariantList AppsModel::sections() const
{
return m_sectionList;
}
void AppsModel::refresh()
{
if (!m_complete) {
......@@ -599,6 +605,38 @@ void AppsModel::refreshInternal()
m_entryList = groups;
}
}
refreshSectionList();
}
void AppsModel::refreshSectionList()
{
m_sectionList.clear();
if (m_entryList.empty()) {
Q_EMIT sectionsChanged();
return;
}
// Insert one item so no need to check empty in the loop
m_sectionList.append(QVariantMap{
{QStringLiteral("section"), m_entryList.at(0)->group().toUpper()},
{QStringLiteral("firstIndex"), 0},
});
for (int i = 1; i < m_entryList.size(); i++) {
const QString sectionName = m_entryList.at(i)->group().toUpper();
if (m_sectionList.constLast().toMap()[QStringLiteral("section")].toString() == sectionName) {
continue;
}
m_sectionList.append(QVariantMap{
{QStringLiteral("section"), sectionName},
{QStringLiteral("firstIndex"), i},
});
}
Q_EMIT sectionsChanged();
}
void AppsModel::processServiceGroup(KServiceGroup::Ptr group)
......
......@@ -88,6 +88,8 @@ public:
QStringList hiddenEntries() const;
QVariantList sections() const override;
void entryChanged(AbstractEntry *entry) override;
void classBegin() override;
......@@ -128,9 +130,12 @@ protected:
private:
void processServiceGroup(KServiceGroup::Ptr group);
void sortEntries();
void refreshSectionList();
bool m_autoPopulate;
QVariantList m_sectionList;
QString m_description;
QString m_entryPath;
bool m_staticEntryList;
......
Supports Markdown
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