From 0f02e5114337368c7467eed95366b478f0d794ba Mon Sep 17 00:00:00 2001 From: jared Date: Sat, 7 Nov 2020 22:56:31 +0800 Subject: [PATCH] update model --- .gitignore | 4 +- .../TaoCommon/TaoModel/TaoListModelBase.hpp | 2 +- .../TaoQuickShow/Contents/General/Tables.qml | 73 +++++++++++++++++-- examples/TaoQuickShow/Image.qrc | 1 + .../Src/DeviceAdd/DeviceAddModel.cpp | 48 ------------ .../DeviceAddItem.cpp | 0 .../DeviceAddItem.h | 0 .../Src/DeviceAddTable/DeviceAddModel.cpp | 70 ++++++++++++++++++ .../DeviceAddModel.h | 2 + examples/TaoQuickShow/Src/main.cpp | 4 +- examples/TaoQuickShow/TaoQuickShow.pri | 8 +- .../TaoQuick/Qml/CusScroll/CusScrollBar.qml | 1 + .../TaoQuick/Qml/CusTable/CusTableView.qml | 4 +- 13 files changed, 152 insertions(+), 65 deletions(-) delete mode 100644 examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.cpp rename examples/TaoQuickShow/Src/{DeviceAdd => DeviceAddTable}/DeviceAddItem.cpp (100%) rename examples/TaoQuickShow/Src/{DeviceAdd => DeviceAddTable}/DeviceAddItem.h (100%) create mode 100644 examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp rename examples/TaoQuickShow/Src/{DeviceAdd => DeviceAddTable}/DeviceAddModel.h (92%) diff --git a/.gitignore b/.gitignore index 54b5795..7a665b9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ bin *.VC.* *.stash *.cbt -debug \ No newline at end of file +debug +*.ipch +*qmlcache.qrc \ No newline at end of file diff --git a/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp b/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp index d0cdb1d..5246d96 100644 --- a/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp +++ b/3rdparty/TaoCommon/TaoModel/TaoListModelBase.hpp @@ -24,7 +24,7 @@ public: //[begin] add data void append(const QList &datas); - void prepend(T obj); + void prepend(T data); void insert(int row, const QList &datas); //[end] add data diff --git a/examples/TaoQuickShow/Contents/General/Tables.qml b/examples/TaoQuickShow/Contents/General/Tables.qml index 93599ec..c3d9e7d 100644 --- a/examples/TaoQuickShow/Contents/General/Tables.qml +++ b/examples/TaoQuickShow/Contents/General/Tables.qml @@ -9,20 +9,23 @@ Item { id: mainItem width: 800 height: 500 - anchors{ + anchors { centerIn: parent verticalCenterOffset: -100 } Row { spacing: 10 CusLabel { - text: qsTr("selectCount: %1").arg(deviceAddModel.selectedCount) + trans.transString + text: qsTr("selectCount: %1").arg( + deviceAddModel.selectedCount) + trans.transString } CusLabel { - text: qsTr("checkedCount: %1").arg(deviceAddModel.checkedCount) + trans.transString + text: qsTr("checkedCount: %1").arg( + deviceAddModel.checkedCount) + trans.transString } CusLabel { - text: qsTr("visibledCount: %1").arg(deviceAddModel.visibledCount) + trans.transString + text: qsTr("visibledCount: %1").arg( + deviceAddModel.visibledCount) + trans.transString } } CusTextField_Search { @@ -83,10 +86,13 @@ Item { if (index < 0 || index >= count) { return } - if (cusHeader.xList[1] <= mouseX && mouseX <= cusHeader.xList[2]) { + if (cusHeader.xList[1] <= mouseX + && mouseX <= cusHeader.xList[2]) { editInput.x = cusHeader.xList[1] - editInput.y = cusView.y + (parseInt(mouseY / CusConfig.fixedHeight)) * CusConfig.fixedHeight + editInput.y = cusView.y + (parseInt( + mouseY / CusConfig.fixedHeight)) + * CusConfig.fixedHeight editInput.width = cusHeader.widthList[1] editInput.height = CusConfig.fixedHeight editInput.index = index @@ -107,6 +113,55 @@ Item { } } } + Row { + anchors { + left: cusView.left + top: cusView.bottom + topMargin: 4 + } + spacing: 10 + CusButton_Blue { + width: 120 + text: "Generate data" + onClicked: { + deviceAddModel.initData() + } + } + + CusButton_Blue { + width: 120 + text: "Add one" + onClicked: { + deviceAddModel.appendOne() + } + } + CusTextInput { + id: countInput + width: 60 + validator: IntValidator {bottom: 0 ;top: 100 * 10000} + } + CusButton_Blue { + width: 120 + text: "Add" + onClicked: { + deviceAddModel.appendOne() + } + } + CusButton_Blue { + width: 120 + text: "Remove Selected" + onClicked: { + deviceAddModel.removeSelected() + } + } + CusButton_Blue { + width: 120 + text: "Remove Checked" + onClicked: { + deviceAddModel.removeChecked() + } + } + } CusTextField { id: editInput visible: false @@ -165,7 +220,8 @@ Item { text: qsTr(" * Check All rows by header of Column 0") + trans.transString } CusLabel { - text: qsTr(" * Edit Column 1 by double click, and update data to model after edit") + trans.transString + text: qsTr(" * Edit Column 1 by double click, and update data to model after edit") + + trans.transString } CusLabel { text: qsTr(" * Fuzzy search") + trans.transString @@ -174,7 +230,8 @@ Item { text: qsTr(" * Reset column width by drag header splite line") + trans.transString } CusLabel { - text: qsTr(" * Sort by click header, click again can switch ascending or descending") + trans.transString + text: qsTr(" * Sort by click header, click again can switch ascending or descending") + + trans.transString } } } diff --git a/examples/TaoQuickShow/Image.qrc b/examples/TaoQuickShow/Image.qrc index a100867..15f8359 100644 --- a/examples/TaoQuickShow/Image.qrc +++ b/examples/TaoQuickShow/Image.qrc @@ -57,5 +57,6 @@ Image/Button/download_red.png Image/Button/download_white.png Image/Common/wizard.png + Image/Button/expand.png diff --git a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.cpp b/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.cpp deleted file mode 100644 index 807c36a..0000000 --- a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "DeviceAddModel.h" -#include "DeviceAddItem.h" -#include -DeviceAddModel::DeviceAddModel(QObject *parent) - : TaoListModel(parent) -{ - QList objs; - for (int i = 0; i < 20; ++i) { - auto item = new DeviceAddItem; - item->setOnline(i % 7 == 0); - item->setName(QString("item %1").arg(i)); - item->setAddress(QString("192.168.1.%1").arg(100 - i)); - item->setModelString(QString("model %1").arg(i % 2 == 0 ? i : 100 - i)); - objs.append(item); - } - resetData(objs); - setHeaderRoles({ "name", "address", "modelString" }); - QMap callBacks; - callBacks["name"] - = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { return (static_cast(b1))->name() < (static_cast(b2))->name(); }; - callBacks["address"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { - QHostAddress add1(static_cast(b1)->address()); - QHostAddress add2(static_cast(b2)->address()); - return add1.toIPv4Address() < add2.toIPv4Address(); - }; - callBacks["modelString"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { - const QString &s1 = static_cast(b1)->modelString(); - const QString &s2 = static_cast(b2)->modelString(); - auto m1 = s1.mid(6, s1.length() - 6).toInt(); - auto m2 = s2.mid(6, s2.length() - 6).toInt(); - return m1 < m2; - }; - setSortCallbacks(callBacks); -} - -void DeviceAddModel::doUpdateName(int row, const QString &name) -{ - if (row < 0 || row >= rowCount({})) - { - return; - } - const auto &n = name.simplified(); - if (n.isEmpty()) - { - return; - } - static_cast(mDatas.at(row))->setName(name); -} diff --git a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddItem.cpp b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddItem.cpp similarity index 100% rename from examples/TaoQuickShow/Src/DeviceAdd/DeviceAddItem.cpp rename to examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddItem.cpp diff --git a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddItem.h b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddItem.h similarity index 100% rename from examples/TaoQuickShow/Src/DeviceAdd/DeviceAddItem.h rename to examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddItem.h diff --git a/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp new file mode 100644 index 0000000..e268e96 --- /dev/null +++ b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp @@ -0,0 +1,70 @@ +#include "DeviceAddModel.h" +#include "DeviceAddItem.h" +#include +#include +DeviceAddModel::DeviceAddModel(QObject *parent) : TaoListModel(parent) +{ + setHeaderRoles({ "name", "address", "modelString" }); + QMap callBacks; + callBacks["name"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { + return (static_cast(b1))->name() + < (static_cast(b2))->name(); + }; + callBacks["address"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { + QHostAddress add1(static_cast(b1)->address()); + QHostAddress add2(static_cast(b2)->address()); + return add1.toIPv4Address() < add2.toIPv4Address(); + }; + callBacks["modelString"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { + const QString &s1 = static_cast(b1)->modelString(); + const QString &s2 = static_cast(b2)->modelString(); + auto m1 = s1.mid(6, s1.length() - 6).toInt(); + auto m2 = s2.mid(6, s2.length() - 6).toInt(); + return m1 < m2; + }; + setSortCallbacks(callBacks); +} +void DeviceAddModel::initData() +{ + QList objs; + uint64_t num = 0; + const int N = 1000; + DeviceAddItem *pItem = new DeviceAddItem[N]; + auto c1 = std::chrono::high_resolution_clock::now(); + for (int i = 0; i < 256; ++i) { + for (int j = 0; j < 256; ++j) { + for (int k = 0; k < 256; ++k) { + for (int l = 0; l < 256; ++l) { + + auto item = pItem + num; + item->setOnline(num % 7 == 0); + item->setName(QString("item %1").arg(num)); + item->setAddress(QString("%1.%2.%3.%4").arg(i).arg(j).arg(k).arg(l)); + item->setModelString( + QString("model %1").arg(num % 2 == 0 ? num : 0xffffffff - num)); + objs.append(item); + num++; + if (num >= N) { + goto over; + } + } + } + } + } +over: + auto c2 = std::chrono::high_resolution_clock::now(); + auto micro = std::chrono::duration_cast(c2 - c1).count(); + qWarning() << micro; + resetData(objs); +} +void DeviceAddModel::doUpdateName(int row, const QString &name) +{ + if (row < 0 || row >= rowCount({})) { + return; + } + const auto &n = name.simplified(); + if (n.isEmpty()) { + return; + } + static_cast(mDatas.at(row))->setName(name); +} diff --git a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.h b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.h similarity index 92% rename from examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.h rename to examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.h index cf64834..fa13372 100644 --- a/examples/TaoQuickShow/Src/DeviceAdd/DeviceAddModel.h +++ b/examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.h @@ -10,6 +10,8 @@ public: public slots: void doUpdateName(int row, const QString &name); + + void initData(); signals: }; diff --git a/examples/TaoQuickShow/Src/main.cpp b/examples/TaoQuickShow/Src/main.cpp index 5e2a36f..6cbd47f 100644 --- a/examples/TaoQuickShow/Src/main.cpp +++ b/examples/TaoQuickShow/Src/main.cpp @@ -3,7 +3,7 @@ #include "Frameless/TaoFrameLessView.h" #include "Logger/Logger.h" #include "QuickTool/QuickTool.h" -#include "DeviceAdd/DeviceAddModel.h" +#include "DeviceAddTable/DeviceAddModel.h" #include #include #include @@ -56,7 +56,7 @@ int main(int argc, char **argv) #ifdef TAODEBUG view.rootContext()->setContextProperty("isDebug", true); #else - view.rootContext()->setContextProperty("isDebug", false); + view.rootContext()->setContextProperty("isDebug", QVariant(false)); #endif view.rootContext()->setContextProperty("qmlPath", qmlPath); diff --git a/examples/TaoQuickShow/TaoQuickShow.pri b/examples/TaoQuickShow/TaoQuickShow.pri index 7e5d462..87b4a99 100644 --- a/examples/TaoQuickShow/TaoQuickShow.pri +++ b/examples/TaoQuickShow/TaoQuickShow.pri @@ -3,13 +3,13 @@ PRECOMPILED_HEADER = $$PWD/Src/stdafx.h HEADERS += \ $$PWD/Src/AppInfo.h \ - $$PWD/Src/DeviceAdd/DeviceAddItem.h \ - $$PWD/Src/DeviceAdd/DeviceAddModel.h + $$PWD/Src/DeviceAddTable/DeviceAddItem.h \ + $$PWD/Src/DeviceAddTable/DeviceAddModel.h SOURCES += \ $$PWD/Src/AppInfo.cpp \ - $$PWD/Src/DeviceAdd/DeviceAddItem.cpp \ - $$PWD/Src/DeviceAdd/DeviceAddModel.cpp \ + $$PWD/Src/DeviceAddTable/DeviceAddItem.cpp \ + $$PWD/Src/DeviceAddTable/DeviceAddModel.cpp \ $$PWD/Src/main.cpp CONFIG(debug, debug|release) { diff --git a/src/TaoQuick/imports/TaoQuick/Qml/CusScroll/CusScrollBar.qml b/src/TaoQuick/imports/TaoQuick/Qml/CusScroll/CusScrollBar.qml index 987b93d..1dbbf33 100644 --- a/src/TaoQuick/imports/TaoQuick/Qml/CusScroll/CusScrollBar.qml +++ b/src/TaoQuick/imports/TaoQuick/Qml/CusScroll/CusScrollBar.qml @@ -5,6 +5,7 @@ import "../.." ScrollBar { id: cusTirangleTipBorder property bool isSmaller: true + minimumSize: 0.1 contentItem: Rectangle { implicitWidth: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize implicitHeight: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize diff --git a/src/TaoQuick/imports/TaoQuick/Qml/CusTable/CusTableView.qml b/src/TaoQuick/imports/TaoQuick/Qml/CusTable/CusTableView.qml index 4fc05ea..1a56c38 100644 --- a/src/TaoQuick/imports/TaoQuick/Qml/CusTable/CusTableView.qml +++ b/src/TaoQuick/imports/TaoQuick/Qml/CusTable/CusTableView.qml @@ -16,7 +16,7 @@ ListView { clip: true interactive: false snapMode: ListView.SnapToItem - cacheBuffer: 12000 +// cacheBuffer: 12000 property string noDataText: qsTr("No Data") + CusConfig.transString ScrollBar.horizontal: CusScrollBar { @@ -30,6 +30,8 @@ ListView { opacity: cusTableView.contentHeight > cusTableView.height ? 1.0 : 0.0 visible: opacity > 0 active: visible + snapMode: ScrollBar.SnapAlways + stepSize: cusTableView.height/(cusTableView.model.visibledCount * CusConfig.fixedHeight) } CusShortCutKeys { id: tableKeys