mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-19 20:22:56 +08:00
update model
This commit is contained in:
parent
c3042aed1e
commit
0f02e51143
4
.gitignore
vendored
4
.gitignore
vendored
@ -9,4 +9,6 @@ bin
|
||||
*.VC.*
|
||||
*.stash
|
||||
*.cbt
|
||||
debug
|
||||
debug
|
||||
*.ipch
|
||||
*qmlcache.qrc
|
@ -24,7 +24,7 @@ public:
|
||||
|
||||
//[begin] add data
|
||||
void append(const QList<T> &datas);
|
||||
void prepend(T obj);
|
||||
void prepend(T data);
|
||||
void insert(int row, const QList<T> &datas);
|
||||
//[end] add data
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,5 +57,6 @@
|
||||
<file>Image/Button/download_red.png</file>
|
||||
<file>Image/Button/download_white.png</file>
|
||||
<file>Image/Common/wizard.png</file>
|
||||
<file>Image/Button/expand.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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);
|
||||
}
|
70
examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp
Normal file
70
examples/TaoQuickShow/Src/DeviceAddTable/DeviceAddModel.cpp
Normal 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);
|
||||
}
|
@ -10,6 +10,8 @@ public:
|
||||
|
||||
public slots:
|
||||
void doUpdateName(int row, const QString &name);
|
||||
|
||||
void initData();
|
||||
signals:
|
||||
|
||||
};
|
@ -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 <QDir>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlContext>
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user