1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-19 20:22:56 +08:00

update model

This commit is contained in:
jared 2020-11-07 22:56:31 +08:00
parent c3042aed1e
commit 0f02e51143
13 changed files with 152 additions and 65 deletions

4
.gitignore vendored
View File

@ -9,4 +9,6 @@ bin
*.VC.* *.VC.*
*.stash *.stash
*.cbt *.cbt
debug debug
*.ipch
*qmlcache.qrc

View File

@ -24,7 +24,7 @@ public:
//[begin] add data //[begin] add data
void append(const QList<T> &datas); void append(const QList<T> &datas);
void prepend(T obj); void prepend(T data);
void insert(int row, const QList<T> &datas); void insert(int row, const QList<T> &datas);
//[end] add data //[end] add data

View File

@ -9,20 +9,23 @@ Item {
id: mainItem id: mainItem
width: 800 width: 800
height: 500 height: 500
anchors{ anchors {
centerIn: parent centerIn: parent
verticalCenterOffset: -100 verticalCenterOffset: -100
} }
Row { Row {
spacing: 10 spacing: 10
CusLabel { CusLabel {
text: qsTr("selectCount: %1").arg(deviceAddModel.selectedCount) + trans.transString text: qsTr("selectCount: %1").arg(
deviceAddModel.selectedCount) + trans.transString
} }
CusLabel { CusLabel {
text: qsTr("checkedCount: %1").arg(deviceAddModel.checkedCount) + trans.transString text: qsTr("checkedCount: %1").arg(
deviceAddModel.checkedCount) + trans.transString
} }
CusLabel { CusLabel {
text: qsTr("visibledCount: %1").arg(deviceAddModel.visibledCount) + trans.transString text: qsTr("visibledCount: %1").arg(
deviceAddModel.visibledCount) + trans.transString
} }
} }
CusTextField_Search { CusTextField_Search {
@ -83,10 +86,13 @@ Item {
if (index < 0 || index >= count) { if (index < 0 || index >= count) {
return 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.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.width = cusHeader.widthList[1]
editInput.height = CusConfig.fixedHeight editInput.height = CusConfig.fixedHeight
editInput.index = index 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 { CusTextField {
id: editInput id: editInput
visible: false visible: false
@ -165,7 +220,8 @@ Item {
text: qsTr(" * Check All rows by header of Column 0") + trans.transString text: qsTr(" * Check All rows by header of Column 0") + trans.transString
} }
CusLabel { 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 { CusLabel {
text: qsTr(" * Fuzzy search") + trans.transString text: qsTr(" * Fuzzy search") + trans.transString
@ -174,7 +230,8 @@ Item {
text: qsTr(" * Reset column width by drag header splite line") + trans.transString text: qsTr(" * Reset column width by drag header splite line") + trans.transString
} }
CusLabel { 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
} }
} }
} }

View File

@ -57,5 +57,6 @@
<file>Image/Button/download_red.png</file> <file>Image/Button/download_red.png</file>
<file>Image/Button/download_white.png</file> <file>Image/Button/download_white.png</file>
<file>Image/Common/wizard.png</file> <file>Image/Common/wizard.png</file>
<file>Image/Button/expand.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -1,48 +0,0 @@
#include "DeviceAddModel.h"
#include "DeviceAddItem.h"
#include <QHostAddress>
DeviceAddModel::DeviceAddModel(QObject *parent)
: TaoListModel(parent)
{
QList<TaoListItemBase *> 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<QString, SortCallback> callBacks;
callBacks["name"]
= [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool { return (static_cast<DeviceAddItem *>(b1))->name() < (static_cast<DeviceAddItem *>(b2))->name(); };
callBacks["address"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool {
QHostAddress add1(static_cast<DeviceAddItem *>(b1)->address());
QHostAddress add2(static_cast<DeviceAddItem *>(b2)->address());
return add1.toIPv4Address() < add2.toIPv4Address();
};
callBacks["modelString"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool {
const QString &s1 = static_cast<DeviceAddItem *>(b1)->modelString();
const QString &s2 = static_cast<DeviceAddItem *>(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<DeviceAddItem *>(mDatas.at(row))->setName(name);
}

View File

@ -0,0 +1,70 @@
#include "DeviceAddModel.h"
#include "DeviceAddItem.h"
#include <QHostAddress>
#include <chrono>
DeviceAddModel::DeviceAddModel(QObject *parent) : TaoListModel(parent)
{
setHeaderRoles({ "name", "address", "modelString" });
QMap<QString, SortCallback> callBacks;
callBacks["name"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool {
return (static_cast<DeviceAddItem *>(b1))->name()
< (static_cast<DeviceAddItem *>(b2))->name();
};
callBacks["address"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool {
QHostAddress add1(static_cast<DeviceAddItem *>(b1)->address());
QHostAddress add2(static_cast<DeviceAddItem *>(b2)->address());
return add1.toIPv4Address() < add2.toIPv4Address();
};
callBacks["modelString"] = [](TaoListItemBase *b1, TaoListItemBase *b2) -> bool {
const QString &s1 = static_cast<DeviceAddItem *>(b1)->modelString();
const QString &s2 = static_cast<DeviceAddItem *>(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<TaoListItemBase *> 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<std::chrono::milliseconds>(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<DeviceAddItem *>(mDatas.at(row))->setName(name);
}

View File

@ -10,6 +10,8 @@ public:
public slots: public slots:
void doUpdateName(int row, const QString &name); void doUpdateName(int row, const QString &name);
void initData();
signals: signals:
}; };

View File

@ -3,7 +3,7 @@
#include "Frameless/TaoFrameLessView.h" #include "Frameless/TaoFrameLessView.h"
#include "Logger/Logger.h" #include "Logger/Logger.h"
#include "QuickTool/QuickTool.h" #include "QuickTool/QuickTool.h"
#include "DeviceAdd/DeviceAddModel.h" #include "DeviceAddTable/DeviceAddModel.h"
#include <QDir> #include <QDir>
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlContext> #include <QQmlContext>
@ -56,7 +56,7 @@ int main(int argc, char **argv)
#ifdef TAODEBUG #ifdef TAODEBUG
view.rootContext()->setContextProperty("isDebug", true); view.rootContext()->setContextProperty("isDebug", true);
#else #else
view.rootContext()->setContextProperty("isDebug", false); view.rootContext()->setContextProperty("isDebug", QVariant(false));
#endif #endif
view.rootContext()->setContextProperty("qmlPath", qmlPath); view.rootContext()->setContextProperty("qmlPath", qmlPath);

View File

@ -3,13 +3,13 @@ PRECOMPILED_HEADER = $$PWD/Src/stdafx.h
HEADERS += \ HEADERS += \
$$PWD/Src/AppInfo.h \ $$PWD/Src/AppInfo.h \
$$PWD/Src/DeviceAdd/DeviceAddItem.h \ $$PWD/Src/DeviceAddTable/DeviceAddItem.h \
$$PWD/Src/DeviceAdd/DeviceAddModel.h $$PWD/Src/DeviceAddTable/DeviceAddModel.h
SOURCES += \ SOURCES += \
$$PWD/Src/AppInfo.cpp \ $$PWD/Src/AppInfo.cpp \
$$PWD/Src/DeviceAdd/DeviceAddItem.cpp \ $$PWD/Src/DeviceAddTable/DeviceAddItem.cpp \
$$PWD/Src/DeviceAdd/DeviceAddModel.cpp \ $$PWD/Src/DeviceAddTable/DeviceAddModel.cpp \
$$PWD/Src/main.cpp $$PWD/Src/main.cpp
CONFIG(debug, debug|release) { CONFIG(debug, debug|release) {

View File

@ -5,6 +5,7 @@ import "../.."
ScrollBar { ScrollBar {
id: cusTirangleTipBorder id: cusTirangleTipBorder
property bool isSmaller: true property bool isSmaller: true
minimumSize: 0.1
contentItem: Rectangle { contentItem: Rectangle {
implicitWidth: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize implicitWidth: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize
implicitHeight: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize implicitHeight: isSmaller ? CusConfig.scrollBarSize_Smaller : CusConfig.scrollBarSize

View File

@ -16,7 +16,7 @@ ListView {
clip: true clip: true
interactive: false interactive: false
snapMode: ListView.SnapToItem snapMode: ListView.SnapToItem
cacheBuffer: 12000 // cacheBuffer: 12000
property string noDataText: qsTr("No Data") + CusConfig.transString property string noDataText: qsTr("No Data") + CusConfig.transString
ScrollBar.horizontal: CusScrollBar { ScrollBar.horizontal: CusScrollBar {
@ -30,6 +30,8 @@ ListView {
opacity: cusTableView.contentHeight > cusTableView.height ? 1.0 : 0.0 opacity: cusTableView.contentHeight > cusTableView.height ? 1.0 : 0.0
visible: opacity > 0 visible: opacity > 0
active: visible active: visible
snapMode: ScrollBar.SnapAlways
stepSize: cusTableView.height/(cusTableView.model.visibledCount * CusConfig.fixedHeight)
} }
CusShortCutKeys { CusShortCutKeys {
id: tableKeys id: tableKeys