diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3059431..60cffd9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,6 +69,7 @@ set(SOURCE_FILES
src/settings/settings.cpp src/settings/settings.h
src/uiconfig/color-helper.cpp src/uiconfig/color-helper.h
src/ukui-menu-application.cpp src/ukui-menu-application.h
+ src/model/model-manager.cpp src/model/model-manager.h
)
# qrc文件
diff --git a/qml/UkuiMenuUI.qml b/qml/UkuiMenuUI.qml
index 87057bd..73096b2 100644
--- a/qml/UkuiMenuUI.qml
+++ b/qml/UkuiMenuUI.qml
@@ -10,6 +10,26 @@ Item {
height: 480
}
+ ListView {
+ x: 200
+ width: 200
+ height: 480
+ clip: true
+
+ model: modelManager.getAppModel()
+ delegate: Rectangle {
+ width: ListView.view.width;
+ height: 40;
+ color: "lightblue"
+ Text {
+ anchors.fill: parent;
+ horizontalAlignment: Qt.AlignHCenter;
+ verticalAlignment: Qt.AlignVCenter;
+ text: model.name
+ }
+ }
+ }
+
AppControls2.AppTest {
x: 400
width: 200
diff --git a/src/model/model-manager.cpp b/src/model/model-manager.cpp
new file mode 100644
index 0000000..1756f4f
--- /dev/null
+++ b/src/model/model-manager.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2022, KylinSoft Co., Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "model-manager.h"
+#include "model.h"
+
+namespace UkuiMenu {
+
+void ModelManager::registerMetaTypes()
+{
+ qRegisterMetaType("AppModel*");
+}
+
+ModelManager::ModelManager(QObject *parent) : QObject(parent)
+{
+ appModel = new AppModel(this);
+}
+
+AppModel *ModelManager::getAppModel()
+{
+ if (appModel) {
+ return appModel;
+ }
+ return nullptr;
+}
+
+} // UkuiMenu
diff --git a/src/model/model-manager.h b/src/model/model-manager.h
new file mode 100644
index 0000000..6f80aa4
--- /dev/null
+++ b/src/model/model-manager.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022, KylinSoft Co., Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifndef UKUI_MENU_MODEL_MANAGER_H
+#define UKUI_MENU_MODEL_MANAGER_H
+
+#include
+
+namespace UkuiMenu {
+
+class AppModel;
+
+class ModelManager : public QObject
+{
+ Q_OBJECT
+public:
+ static void registerMetaTypes();
+ explicit ModelManager(QObject *parent = nullptr);
+ ~ModelManager() override = default;
+
+ Q_INVOKABLE AppModel *getAppModel();
+
+private:
+ AppModel *appModel{nullptr};
+};
+
+} // UkuiMenu
+
+#endif //UKUI_MENU_MODEL_MANAGER_H
diff --git a/src/model/model.cpp b/src/model/model.cpp
index 009d524..ff167b8 100644
--- a/src/model/model.cpp
+++ b/src/model/model.cpp
@@ -21,10 +21,34 @@
#include
#include
#include
-//#include
-
-#include
namespace UkuiMenu {
+AppModel::AppModel(QObject *parent) : QAbstractListModel(parent)
+{
+
+}
+
+int AppModel::rowCount(const QModelIndex &parent) const
+{
+ return 30;
+}
+
+QVariant AppModel::data(const QModelIndex &index, int role) const
+{
+ return QString("test data = %1.").arg(index.row());
+}
+
+QHash AppModel::roleNames() const
+{
+ QHash names;
+ names.insert(0, "name");
+ return names;
+}
+
+QList AppModel::folderApps(const QString &folderName)
+{
+ return {};
+}
+
} // UkuiMenu
diff --git a/src/model/model.h b/src/model/model.h
index 57fed7a..5611be5 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -19,14 +19,24 @@
#ifndef UKUI_MENU_MODEL_H
#define UKUI_MENU_MODEL_H
+#include
#include
+#include "commons.h"
+
namespace UkuiMenu {
-class Model
+class AppModel : public QAbstractListModel
{
+ Q_OBJECT
public:
- Model() = default;
+ explicit AppModel(QObject *parent = nullptr);
+
+ int rowCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ QHash roleNames() const override;
+
+ Q_INVOKABLE QList folderApps(const QString &folderName);
};
} // UkuiMenu
diff --git a/src/ukui-menu-application.cpp b/src/ukui-menu-application.cpp
index 9f487d4..75691de 100644
--- a/src/ukui-menu-application.cpp
+++ b/src/ukui-menu-application.cpp
@@ -19,6 +19,7 @@
#include "ukui-menu-application.h"
#include "settings.h"
#include "commons.h"
+#include "model-manager.h"
#include
#include
@@ -45,7 +46,7 @@ void UkuiMenuApplication::registerQmlTypes()
const char *uri = "org.ukui.menu.core";
int versionMajor = 1, versionMinor = 0;
CommonsModule::defineCommonsMod(uri, versionMajor, versionMinor);
-
+ ModelManager::registerMetaTypes();
}
void UkuiMenuApplication::initQmlEngine()
@@ -56,6 +57,7 @@ void UkuiMenuApplication::initQmlEngine()
m_applicationEngine->addImportPath("qrc:/qml");
m_applicationEngine->rootContext()->setContextProperty("menuSetting", MenuSetting::instance());
+ m_applicationEngine->rootContext()->setContextProperty("modelManager", new ModelManager(this));
QObject::connect(m_applicationEngine, &QQmlApplicationEngine::objectCreated,
this, [url](QObject *obj, const QUrl &objUrl) {