diff --git a/example/example.qrc b/example/example.qrc index 0dd5438b..04ccb1c6 100644 --- a/example/example.qrc +++ b/example/example.qrc @@ -186,5 +186,6 @@ qml/window/PageWindow.qml qml/page/T_StaggeredView.qml qml/viewmodel/SettingsViewModel.qml + qml/viewmodel/TextBoxViewModel.qml diff --git a/example/qml-Qt6/page/T_TextBox.qml b/example/qml-Qt6/page/T_TextBox.qml index 768fb481..0d25a7ac 100644 --- a/example/qml-Qt6/page/T_TextBox.qml +++ b/example/qml-Qt6/page/T_TextBox.qml @@ -4,12 +4,19 @@ import QtQuick.Layouts import QtQuick.Window import FluentUI import "qrc:///example/qml/component" +import "qrc:///example/qml/viewmodel" FluScrollablePage{ - - launchMode: FluPageType.SingleInstance - title:"TextBox" + + TextBoxViewModel{ + id:viewModel + } + + Component.onDestruction: { + console.debug("T_TextBox页面销毁了") + } + FluArea{ Layout.fillWidth: true height: 68 @@ -20,6 +27,10 @@ FluScrollablePage{ placeholderText: "单行输入框" disabled:text_box_switch.checked cleanEnabled: true + text:viewModel.text1 + onTextChanged: { + viewModel.text1 = text + } anchors{ verticalCenter: parent.verticalCenter left: parent.left @@ -84,6 +95,10 @@ FluScrollablePage{ FluMultilineTextBox{ id:multiine_textbox placeholderText: "多行输入框" + text:viewModel.text2 + onTextChanged: { + viewModel.text2 = text + } disabled:text_box_multi_switch.checked anchors{ verticalCenter: parent.verticalCenter diff --git a/example/qml-Qt6/viewmodel/SettingsViewModel.qml b/example/qml-Qt6/viewmodel/SettingsViewModel.qml index 04524e54..c409d8c1 100644 --- a/example/qml-Qt6/viewmodel/SettingsViewModel.qml +++ b/example/qml-Qt6/viewmodel/SettingsViewModel.qml @@ -1,6 +1,5 @@ import QtQuick import FluentUI -import "qrc:///example/qml/component" FluViewModel{ diff --git a/example/qml-Qt6/viewmodel/TextBoxViewModel.qml b/example/qml-Qt6/viewmodel/TextBoxViewModel.qml new file mode 100644 index 00000000..e06ae30f --- /dev/null +++ b/example/qml-Qt6/viewmodel/TextBoxViewModel.qml @@ -0,0 +1,8 @@ +import QtQuick +import FluentUI + +FluViewModel { + objectName: "TextBoxView" + property string text1 + property string text2 +} diff --git a/example/qml/page/T_TextBox.qml b/example/qml/page/T_TextBox.qml index 4e8bdc09..86475a82 100644 --- a/example/qml/page/T_TextBox.qml +++ b/example/qml/page/T_TextBox.qml @@ -4,13 +4,21 @@ import QtQuick.Layouts 1.15 import QtQuick.Window 2.15 import FluentUI 1.0 import "qrc:///example/qml/component" +import "qrc:///example/qml/viewmodel" import "../component" +import "../viewmodel" FluScrollablePage{ - - launchMode: FluPageType.SingleInstance - title:"TextBox" + + TextBoxViewModel{ + id:viewModel + } + + Component.onDestruction: { + console.debug("T_TextBox页面销毁了") + } + FluArea{ Layout.fillWidth: true height: 68 @@ -21,6 +29,10 @@ FluScrollablePage{ placeholderText: "单行输入框" disabled:text_box_switch.checked cleanEnabled: true + text:viewModel.text1 + onTextChanged: { + viewModel.text1 = text + } anchors{ verticalCenter: parent.verticalCenter left: parent.left @@ -85,6 +97,10 @@ FluScrollablePage{ FluMultilineTextBox{ id:multiine_textbox placeholderText: "多行输入框" + text:viewModel.text2 + onTextChanged: { + viewModel.text2 = text + } disabled:text_box_multi_switch.checked anchors{ verticalCenter: parent.verticalCenter diff --git a/example/qml/viewmodel/SettingsViewModel.qml b/example/qml/viewmodel/SettingsViewModel.qml index 75fc5ae7..cf27b4f2 100644 --- a/example/qml/viewmodel/SettingsViewModel.qml +++ b/example/qml/viewmodel/SettingsViewModel.qml @@ -1,6 +1,5 @@ import QtQuick 2.15 import FluentUI 1.0 -import "qrc:///example/qml/component" FluViewModel{ diff --git a/example/qml/viewmodel/TextBoxViewModel.qml b/example/qml/viewmodel/TextBoxViewModel.qml new file mode 100644 index 00000000..4dbaa97e --- /dev/null +++ b/example/qml/viewmodel/TextBoxViewModel.qml @@ -0,0 +1,8 @@ +import QtQuick 2.15 +import FluentUI 1.0 + +FluViewModel { + objectName: "TextBoxView" + property string text1 + property string text2 +} diff --git a/src/Def.h b/src/Def.h index 3784b679..7981ede7 100644 --- a/src/Def.h +++ b/src/Def.h @@ -17,16 +17,9 @@ QML_NAMED_ELEMENT(FluViewModelType) namespace FluHttpType { Q_NAMESPACE enum CacheMode { - /** 不使用缓存 */ NoCache = 0x0000, - - /** 请求网络失败后,读取缓存 */ RequestFailedReadCache = 0x0001, - - /** 如果缓存不存在才请求网络,否则使用缓存 */ IfNoneCacheRequest = 0x0002, - - /** 先使用缓存,不管是否存在,仍然请求网络 */ FirstCacheThenRequest = 0x0004, }; Q_ENUM_NS(CacheMode) diff --git a/src/FluApp.h b/src/FluApp.h index e383baa4..cfb5cb54 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -18,28 +18,12 @@ class FluApp : public QObject { Q_OBJECT - /** - * @brief initialRoute 初始路由 - */ Q_PROPERTY_AUTO(QString,initialRoute); - - /** - * @brief routes 路由表 - */ Q_PROPERTY_AUTO(QJsonObject,routes); - - /** - * @brief http拦截器 - */ Q_PROPERTY_AUTO(FluHttpInterceptor*,httpInterceptor); - QML_NAMED_ELEMENT(FluApp) QML_SINGLETON private: - /** - * @brief FluApp 将默认构造函数设置为私有,则qml创建单例就会走create工厂方法创建单例 - * @param parent - */ explicit FluApp(QObject *parent = nullptr); public: ~FluApp(); @@ -48,50 +32,16 @@ public: return getInstance(); } static FluApp *getInstance(); - /** - * @brief run - */ Q_INVOKABLE void run(); - - /** - * @brief navigate - * @param route - * @param argument - * @param fluRegister - */ Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr); - - /** - * @brief init - * @param window - */ Q_INVOKABLE void init(QQuickWindow *window); - - /** - * @brief awesomelist - * @param keyword - * @return - */ Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = ""); - - /** - * @brief closeApp - */ Q_INVOKABLE void closeApp(); - Q_INVOKABLE void deleteWindow(QQuickWindow* window); - public: - /** - * @brief wnds - */ QMap wnds; - private: static FluApp* m_instance; - /** - * @brief appWindow - */ QWindow *appWindow; }; diff --git a/src/FluHttp.cpp b/src/FluHttp.cpp index 9e1a1ed2..22ab5545 100644 --- a/src/FluHttp.cpp +++ b/src/FluHttp.cpp @@ -82,7 +82,9 @@ void FluHttp::cancel(){ } } -void FluHttp::post(HttpRequest* request,HttpCallable* callable){ +void FluHttp::post(HttpRequest* r,HttpCallable* c){ + auto request = QPointer(r); + auto callable = QPointer(c); request->method("post"); auto requestMap = request->toMap(); auto httpId = request->httpId(); @@ -143,7 +145,9 @@ void FluHttp::post(HttpRequest* request,HttpCallable* callable){ }); } -void FluHttp::postString(HttpRequest* request,HttpCallable* callable){ +void FluHttp::postString(HttpRequest* r,HttpCallable* c){ + auto request = QPointer(r); + auto callable = QPointer(c); request->method("postString"); auto requestMap = request->toMap(); auto httpId = request->httpId(); @@ -196,7 +200,9 @@ void FluHttp::postString(HttpRequest* request,HttpCallable* callable){ }); } -void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){ +void FluHttp::postJson(HttpRequest* r,HttpCallable* c){ + auto request = QPointer(r); + auto callable = QPointer(c); request->method("postJson"); auto requestMap = request->toMap(); auto httpId = request->httpId(); @@ -248,7 +254,9 @@ void FluHttp::postJson(HttpRequest* request,HttpCallable* callable){ }); } -void FluHttp::get(HttpRequest* request,HttpCallable* callable){ +void FluHttp::get(HttpRequest* r,HttpCallable* c){ + auto request = QPointer(r); + auto callable = QPointer(c); request->method("get"); auto requestMap = request->toMap(); auto httpId = request->httpId(); @@ -299,7 +307,9 @@ void FluHttp::get(HttpRequest* request,HttpCallable* callable){ }); } -void FluHttp::download(HttpRequest* request,HttpCallable* callable){ +void FluHttp::download(HttpRequest* r,HttpCallable* c){ + auto request = QPointer(r); + auto callable = QPointer(c); request->method("download"); auto requestMap = request->toMap(); auto httpId = request->httpId(); @@ -535,11 +545,11 @@ void FluHttp::onStart(QPointer callable){ } } -void FluHttp::onFinish(QPointer callable,HttpRequest* request){ +void FluHttp::onFinish(QPointer callable,QPointer request){ if(callable){ Q_EMIT callable->finish(); } - if(request->parent()->inherits("FluHttp")){ + if(request&&request->parent()->inherits("FluHttp")){ request->deleteLater(); } } diff --git a/src/FluHttp.h b/src/FluHttp.h index 5d9c1863..81b0a082 100644 --- a/src/FluHttp.h +++ b/src/FluHttp.h @@ -53,7 +53,7 @@ private: bool cacheExists(const QString& httpId); QString getCacheFilePath(const QString& httpId); void onStart(QPointer callable); - void onFinish(QPointer callable,HttpRequest* request); + void onFinish(QPointer callable,QPointer request); void onError(QPointer callable,int status,QString errorString,QString result); void onSuccess(QPointer callable,QString result); void onCache(QPointer callable,QString result); diff --git a/src/FluRegister.h b/src/FluRegister.h index a1628d26..51e91c35 100644 --- a/src/FluRegister.h +++ b/src/FluRegister.h @@ -17,25 +17,9 @@ class FluRegister : public QObject Q_PROPERTY_AUTO(QString,path); public: explicit FluRegister(QObject *parent = nullptr); - - /** - * @brief launch 窗口跳转 - * @param argument 跳转携带参数 - */ Q_INVOKABLE void launch(const QJsonObject& argument = {}); - - /** - * @brief onResult 将结果数据回传到上一个窗口 - * @param data 结果数据 - */ Q_INVOKABLE void onResult(const QJsonObject& data = {}); - - /** - * @brief result 收到结果数据的信号 - * @param data 结果数据 - */ Q_SIGNAL void result(const QJsonObject& data); - }; #endif // FLUREGISTER_H diff --git a/src/FluTheme.h b/src/FluTheme.h index ad0b4116..a7a40df0 100644 --- a/src/FluTheme.h +++ b/src/FluTheme.h @@ -12,31 +12,11 @@ class FluTheme : public QObject { Q_OBJECT - /** - * @brief dark 改变窗口夜间样式,只读属性,可以通过darkMode切换 - */ Q_PROPERTY(bool dark READ dark NOTIFY darkChanged) - - /** - * @brief primaryColor 主题颜色 - */ Q_PROPERTY_AUTO(FluColorSet*,primaryColor) - - /** - * @brief darkMode 夜间模式,支持System=0、Light=1、Dark=2 - */ Q_PROPERTY_AUTO(int,darkMode); - - /** - * @brief nativeText 本地渲染文本 - */ Q_PROPERTY_AUTO(bool,nativeText); - - /** - * @brief 是否开启动画效果 - */ Q_PROPERTY_AUTO(bool,enableAnimation); - QML_NAMED_ELEMENT(FluTheme) QML_SINGLETON private: diff --git a/src/FluTools.h b/src/FluTools.h index fcaac58d..e5e18d46 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -25,172 +25,56 @@ public: } static FluTools *getInstance(); - /** - * @brief qtMajor Qt Major版本 - * @return - */ Q_INVOKABLE int qtMajor(); - /** - * @brief qtMajor Qt Minor版本 - * @return - */ Q_INVOKABLE int qtMinor(); - /** - * @brief isMacos 是否是Macos系统 - * @return - */ Q_INVOKABLE bool isMacos(); - /** - * @brief isLinux 是否是Linux系统 - * @return - */ Q_INVOKABLE bool isLinux(); - /** - * @brief isWin 是否是Windows系统 - * @return - */ Q_INVOKABLE bool isWin(); - /** - * @brief clipText 将字符串添加到剪切板 - * @param text - */ Q_INVOKABLE void clipText(const QString& text); - /** - * @brief uuid 获取uuid - * @return - */ Q_INVOKABLE QString uuid(); - /** - * @brief readFile 读取文件内容 - * @param fileName - * @return - */ Q_INVOKABLE QString readFile(const QString& fileName); - /** - * @brief setQuitOnLastWindowClosed 设置关闭最后一个窗口是否退出程序 - * @param val - */ Q_INVOKABLE void setQuitOnLastWindowClosed(bool val); - /** - * @brief setOverrideCursor 设置全局鼠标样式 - * @param shape - */ Q_INVOKABLE void setOverrideCursor(Qt::CursorShape shape); - /** - * @brief restoreOverrideCursor 还原全局鼠标样式 - */ Q_INVOKABLE void restoreOverrideCursor(); - /** - * @brief html2PlantText 将html转换成纯文本 - * @param html - */ Q_INVOKABLE QString html2PlantText(const QString& html); - /** - * @brief toLocalPath 获取文件路径,可以去掉windows系统下的file:///,macos下的file:// - * @param url - * @return 返回文件路径 - */ Q_INVOKABLE QString toLocalPath(const QUrl& url); - /** - * @brief deleteItem 销毁Item对象 - * @param p - */ Q_INVOKABLE void deleteItem(QObject *p); - /** - * @brief getFileNameByUrl - * @param url - * @return - */ Q_INVOKABLE QString getFileNameByUrl(const QUrl& url); - /** - * @brief getVirtualGeometry - * @return - */ Q_INVOKABLE QRect getVirtualGeometry(); - /** - * @brief getApplicationDirPath - * @return - */ Q_INVOKABLE QString getApplicationDirPath(); - /** - * @brief getUrlByFilePath - * @param path - * @return - */ Q_INVOKABLE QUrl getUrlByFilePath(const QString& path); - /** - * @brief colorAlpha - * @param color - * @param alpha - * @return - */ Q_INVOKABLE QColor colorAlpha(const QColor&,qreal alpha); - /** - * @brief md5 - * @param text - * @return - */ Q_INVOKABLE QString md5(QString text); - /** - * @brief sha256 - * @param text - * @return - */ Q_INVOKABLE QString sha256(QString text); - /** - * @brief toBase64 - * @param text - * @return - */ Q_INVOKABLE QString toBase64(QString text); - /** - * @brief fromBase64 - * @param text - * @return - */ Q_INVOKABLE QString fromBase64(QString text); - - /** - * @brief removeDir - * @param dirPath - * @return - */ Q_INVOKABLE bool removeDir(QString dirPath); - /** - * @brief removeFile - * @param filePath - * @return - */ Q_INVOKABLE bool removeFile(QString filePath); - /** - * @brief showFileInFolder - * @param path - */ Q_INVOKABLE void showFileInFolder(QString path); }; diff --git a/src/FluViewModel.cpp b/src/FluViewModel.cpp index 9d57d172..11bf3292 100644 --- a/src/FluViewModel.cpp +++ b/src/FluViewModel.cpp @@ -21,7 +21,6 @@ Model::Model(QObject *parent) Model::~Model() { - qDebug()<<"Model delete~"; } ViewModelManager::ViewModelManager(QObject *parent) @@ -68,7 +67,6 @@ PropertyObserver::PropertyObserver(QString name,QObject* model,QObject *parent) } PropertyObserver::~PropertyObserver(){ - qDebug()<<"PropertyObserver delete~"; } void PropertyObserver::_propertyChange(){ diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index fd5235df..898b1159 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -163,6 +163,7 @@ void FluentUI::registerTypes(const char *uri){ qmlRegisterUncreatableMetaObject(FluNavigationViewType::staticMetaObject, uri,major,minor,"FluNavigationViewType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluTimelineType::staticMetaObject, uri,major,minor,"FluTimelineType", "Access to enums & flags only"); qmlRegisterUncreatableMetaObject(FluScreenshotType::staticMetaObject, uri,major,minor,"FluScreenshotType", "Access to enums & flags only"); + qmlRegisterUncreatableMetaObject(FluViewModelType::staticMetaObject, uri,major,minor,"FluViewModelType", "Access to enums & flags only"); qmlRegisterModule(uri,major,minor); } diff --git a/src/Qt5/imports/FluentUI/plugins.qmltypes b/src/Qt5/imports/FluentUI/plugins.qmltypes index 503c40b5..82f9a7b7 100644 --- a/src/Qt5/imports/FluentUI/plugins.qmltypes +++ b/src/Qt5/imports/FluentUI/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:/QtProjects/build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release/src' +// 'qmlplugindump -nonrelocatable FluentUI 1.0 D:\QtProjects\build-FluentUI-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\src' Module { dependencies: ["QtQuick 2.0"] @@ -290,6 +290,28 @@ Module { } } } + Component { + name: "FluViewModel" + prototype: "QObject" + exports: ["FluentUI/FluViewModel 1.0"] + exportMetaObjectRevisions: [0] + Property { name: "scope"; type: "int" } + Property { name: "target"; type: "QObject"; isPointer: true } + Signal { name: "initData" } + } + Component { + name: "FluViewModelType" + exports: ["FluentUI/FluViewModelType 1.0"] + isCreatable: false + exportMetaObjectRevisions: [0] + Enum { + name: "Scope" + values: { + "Window": 0, + "Application": 1 + } + } + } Component { name: "FluWatermark" defaultProperty: "data" @@ -2624,8 +2646,8 @@ Module { Property { name: "topPadding"; type: "int" } Property { name: "navWidth"; type: "int" } Property { name: "pageMode"; type: "int" } - Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_45"; isPointer: true } - Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_45"; isPointer: true } + Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_48"; isPointer: true } + Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_48"; isPointer: true } Signal { name: "logoClicked" } Method { name: "collapseAll"; type: "QVariant" } Method { @@ -2801,14 +2823,19 @@ Module { } } Component { - prototype: "QQuickItem" + prototype: "QQuickPage" name: "FluentUI/FluPivot 1.0" exports: ["FluentUI/FluPivot 1.0"] exportMetaObjectRevisions: [0] isComposite: true defaultProperty: "content" - Property { name: "normalColor"; type: "QColor" } - Property { name: "hoverColor"; type: "QColor" } + Property { name: "textNormalColor"; type: "QColor" } + Property { name: "textHoverColor"; type: "QColor" } + Property { name: "textSize"; type: "int" } + Property { name: "textBold"; type: "bool" } + Property { name: "textSpacing"; type: "int" } + Property { name: "headerSpacing"; type: "int" } + Property { name: "headerHeight"; type: "int" } Property { name: "content"; type: "QObject"; isList: true; isReadonly: true } Property { name: "currentIndex"; type: "int" } }