更新QQt Gui部分的delegate代码,增加测试用例。
@ -1 +1,53 @@
|
||||
#include <qqtdicthelper.h>
|
||||
|
||||
QQtDictionary& QQtGetDictNode ( QQtDictionary& rootDict, QList<QString>& keyList1, bool numberAsString )
|
||||
{
|
||||
QListIterator<QString> itor ( keyList1 );
|
||||
QQtDictionary* pdict = &rootDict;
|
||||
while ( itor.hasNext() )
|
||||
{
|
||||
const QString& key = itor.next();
|
||||
QQtDictionary& dict = *pdict;
|
||||
|
||||
if ( numberAsString )
|
||||
{
|
||||
pdict = & ( dict[key] );
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
uint nkey = key.toUInt ( &ok );
|
||||
if ( ok )
|
||||
pdict = & ( dict[nkey] );
|
||||
else
|
||||
pdict = & ( dict[key] );
|
||||
}
|
||||
QQtDictionary& dict = *pdict;
|
||||
return dict;
|
||||
}
|
||||
|
||||
QQtOrderedDictionary& QQtGetDictNode ( QQtOrderedDictionary& rootDict, QList<QString>& keyList1, bool numberAsString )
|
||||
{
|
||||
QListIterator<QString> itor ( keyList1 );
|
||||
QQtOrderedDictionary* pdict = &rootDict;
|
||||
while ( itor.hasNext() )
|
||||
{
|
||||
const QString& key = itor.next();
|
||||
QQtOrderedDictionary& dict = *pdict;
|
||||
|
||||
if ( numberAsString )
|
||||
{
|
||||
pdict = & ( dict[key] );
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
uint nkey = key.toUInt ( &ok );
|
||||
if ( ok )
|
||||
pdict = & ( dict[nkey] );
|
||||
else
|
||||
pdict = & ( dict[key] );
|
||||
}
|
||||
QQtOrderedDictionary& dict = *pdict;
|
||||
return dict;
|
||||
}
|
||||
|
@ -26,4 +26,10 @@ typedef QQtOrderedDictionaryList QOrderedDictionaryList;
|
||||
typedef QQtOrderedDictionaryListIterator QOrderedDictionaryListIterator;
|
||||
typedef QQtOrderedDictionaryMutableListIterator QOrderedDictionaryMutableListIterator;
|
||||
|
||||
//C++ []操作符重载超过两层就不能赋值给引用变量了,所以这里对于获取深层引用进行封装。
|
||||
QQtDictionary& QQtGetDictNode ( QQtDictionary& rootDict,
|
||||
QList<QString>& keyList1, bool numberAsString = false );
|
||||
QQtOrderedDictionary& QQtGetDictNode ( QQtOrderedDictionary& rootDict,
|
||||
QList<QString>& keyList1, bool numberAsString = false );
|
||||
|
||||
#endif // QQTDICTHELPER_H
|
||||
|
@ -35,6 +35,41 @@ void QQtDictTreeModel::query ( QQtDictionary& dict )
|
||||
packDictionaryToTreeModel ( dict, 0 );
|
||||
}
|
||||
|
||||
QStringList QQtDictTreeModel::getFullName ( const QModelIndex& index )
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return QStringList();
|
||||
|
||||
QStringList fullname;
|
||||
QModelIndex tempIndex = index;//row 0 parent? NO,在里边。
|
||||
while ( tempIndex.isValid() )
|
||||
{
|
||||
QModelIndex parentIndex = tempIndex.parent();
|
||||
int row = tempIndex.row();
|
||||
QString data = this->index ( row, 0, parentIndex ).data().toString();
|
||||
fullname.push_front ( data );
|
||||
|
||||
tempIndex = tempIndex.parent();
|
||||
}
|
||||
return fullname;
|
||||
}
|
||||
|
||||
bool QQtDictTreeModel::isLeafNode ( const QModelIndex& index )
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return false;
|
||||
|
||||
return index.child ( 0, 0 ).isValid() ? false : true;
|
||||
}
|
||||
|
||||
bool QQtDictTreeModel::isRootNode ( const QModelIndex& index )
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return false;
|
||||
|
||||
return index.parent().isValid() ? false : true;
|
||||
}
|
||||
|
||||
|
||||
void QQtDictTreeModel::packDictionaryToTreeModel ( const QQtDictionary& node, QStandardItem* pobject )
|
||||
{
|
||||
|
@ -22,6 +22,15 @@ public:
|
||||
//这里会更新内部的pdict;
|
||||
virtual void query ( QQtDictionary& dict );
|
||||
|
||||
//无论用户选中哪个Item,这个函数都会计算第一列从根到叶子的值列表。
|
||||
virtual QStringList getFullName ( const QModelIndex& index );
|
||||
|
||||
//查看是否是叶子节点,是否有孩子
|
||||
bool isLeafNode ( const QModelIndex& index );
|
||||
|
||||
//查看是否是Root节点,是否有父亲。这种节点可能有多个。
|
||||
bool isRootNode ( const QModelIndex& index );
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
@ -9,6 +9,7 @@
|
||||
* QDirModel 没有设置RootPath函数
|
||||
* 两者都可以通过QTreeView的setRootIndex来设置RootPath,其实是在QTreeView里面进行过滤。
|
||||
* view->setRootIndex ( model->index ( "the/root/path" ) );
|
||||
* 废弃,使用QQtDictTreeModel代替。
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtFileSystemTreeModel : public QFileSystemModel
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
/**
|
||||
* @brief The QQtFTPTreeModel class
|
||||
* 将FTP解析到QQtDictionary里,然后写入Model。
|
||||
* 废弃,使用QQtDictTreeModel代替。
|
||||
* 未实现
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtFTPTreeModel : public QObject
|
||||
|
@ -8,8 +8,7 @@
|
||||
/**
|
||||
* @brief The QQtJsonTreeModel class
|
||||
* 将Json格式的内容解析到Tree里。
|
||||
* 废弃
|
||||
* 使用QQtDictTreeModel代替。
|
||||
* 废弃,使用QQtDictTreeModel代替。
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtJsonTreeModel : public QQtTreeModel
|
||||
{
|
||||
|
@ -17,7 +17,11 @@ void QQtProgressBarDelegate::drawDisplay ( QPainter* painter, const QStyleOption
|
||||
|
||||
if ( ok )
|
||||
{
|
||||
#if 0
|
||||
int radio = 5;
|
||||
#else
|
||||
int radio = 0;
|
||||
#endif
|
||||
int top = option.rect.top() + radio;
|
||||
int left = option.rect.left() + radio;
|
||||
int width = option.rect.width() - 2 * radio;
|
||||
@ -29,7 +33,7 @@ void QQtProgressBarDelegate::drawDisplay ( QPainter* painter, const QStyleOption
|
||||
//bar.init ( this );
|
||||
|
||||
bar.rect.setRect ( left, top, width, height ); //设置其在表格中的位置
|
||||
bar.state = QStyle::State_Enabled;
|
||||
bar.state = option.state;
|
||||
|
||||
//设置对应model列的值,需要自定义model
|
||||
bar.progress = pos;
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <qqt-local.h>
|
||||
/**
|
||||
* @brief The QQtProgressBarDelegate class
|
||||
* QTableView进度条代理
|
||||
* Qt表格进度条代理
|
||||
*
|
||||
* 不用代理也可以。
|
||||
* QTableWidget::setCellWidget(int row, int column, QWidget *widget)
|
||||
|
@ -8,8 +8,7 @@
|
||||
/**
|
||||
* @brief The QQtXmlTreeModel class
|
||||
* 将XML格式的内容解析到Tree里。
|
||||
* 废弃
|
||||
* 使用QQtDictTreeModel代替。
|
||||
* 废弃,使用QQtDictTreeModel代替。
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtXmlTreeModel : public QQtTreeModel
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <qqtdictionary.h>
|
||||
|
||||
#include <qqtdicthelper.h>
|
||||
#include <QBuffer>
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
@ -34,6 +34,17 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
||||
cc << "Hello";
|
||||
dict = cc;
|
||||
pline() << dict;
|
||||
|
||||
QQtDictionary dict1;
|
||||
dict1["StrKey"][0]["BBB"]["JJJ"][1]["GGG"] = "A Value.";
|
||||
QStringList keyList;
|
||||
keyList << "StrKey" << "0" << "BBB" << "JJJ";
|
||||
QQtDictionary& rd1 = QQtGetDictNode ( dict1, keyList );
|
||||
pline() << rd1;
|
||||
pline() << "-----";
|
||||
keyList << "1";
|
||||
rd1 = QQtGetDictNode ( dict1, keyList );
|
||||
pline() << rd1;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -168,6 +168,17 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
||||
|
||||
pline() << bool ( dict == dict5 ); // !=
|
||||
pline() << bool ( dict2 == dict1 ); // !=
|
||||
|
||||
QQtOrderedDictionary dict6;
|
||||
dict6["StrKey"][0]["BBB"]["JJJ"][1]["GGG"] = "A Value.";
|
||||
QStringList keyList;
|
||||
keyList << "StrKey" << "0" << "BBB" << "JJJ";
|
||||
QQtOrderedDictionary& rd1 = QQtGetDictNode ( dict6, keyList );
|
||||
pline() << rd1;
|
||||
pline() << "-----";
|
||||
keyList << "1";
|
||||
rd1 = QQtGetDictNode ( dict6, keyList );
|
||||
pline() << rd1;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
138733
test/testqqtitemdelegate/AppRoot/rfc.json
Normal file
24
test/testqqtitemdelegate/AppRoot/skin/default.qss
Normal file
@ -0,0 +1,24 @@
|
||||
/*spinbox 抬起样式*/
|
||||
QTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/*按钮按下样式*/
|
||||
QTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
89
test/testqqtitemdelegate/android/AndroidManifest.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0"?>
|
||||
<manifest package="org.qtproject.example.testqqtitemdelegate" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
|
||||
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="testqqtitemdelegate" android:icon="@drawable/icon">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="testqqtitemdelegate" android:screenOrientation="unspecified" android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Application arguments -->
|
||||
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
|
||||
<!-- Application arguments -->
|
||||
|
||||
<meta-data android:name="android.app.lib_name" android:value="testqqtitemdelegate"/>
|
||||
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
|
||||
<meta-data android:name="android.app.repository" android:value="default"/>
|
||||
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
|
||||
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
|
||||
<!-- Deploy Qt libs as part of package -->
|
||||
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
|
||||
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
|
||||
<!-- Run with local libs -->
|
||||
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
|
||||
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so"/>
|
||||
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroid-bundled.jar"/>
|
||||
<meta-data android:name="android.app.static_init_classes" android:value=""/>
|
||||
<!-- Messages maps -->
|
||||
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
|
||||
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
|
||||
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
|
||||
<!-- Messages maps -->
|
||||
|
||||
<!-- Splash screen -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
|
||||
<!-- Splash screen -->
|
||||
|
||||
<!-- Background running -->
|
||||
<!-- Warning: changing this value to true may cause unexpected crashes if the
|
||||
application still try to draw after
|
||||
"applicationStateChanged(Qt::ApplicationSuspended)"
|
||||
signal is sent! -->
|
||||
<meta-data android:name="android.app.background_running" android:value="false"/>
|
||||
<!-- Background running -->
|
||||
|
||||
<!-- auto screen scale factor -->
|
||||
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
|
||||
<!-- auto screen scale factor -->
|
||||
|
||||
<!-- extract android style -->
|
||||
<!-- available android:values :
|
||||
* full - useful QWidget & Quick Controls 1 apps
|
||||
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
|
||||
* none - useful for apps that don't use any of the above Qt modules
|
||||
-->
|
||||
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
|
||||
<!-- extract android style -->
|
||||
</activity>
|
||||
|
||||
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
|
||||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default permissions. -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default features. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
</manifest>
|
After Width: | Height: | Size: 13 KiB |
BIN
test/testqqtitemdelegate/android/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 3.5 KiB |
BIN
test/testqqtitemdelegate/android/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 6.0 KiB |
BIN
test/testqqtitemdelegate/android/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 82 KiB |
11
test/testqqtitemdelegate/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QQtApplication>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
35
test/testqqtitemdelegate/mainwindow.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
|
||||
QFile rfc ( conf_root ( "rfc.json" ) );
|
||||
rfc.open ( QFile::ReadOnly );
|
||||
QByteArray bytes;
|
||||
if ( rfc.isOpen() )
|
||||
bytes = rfc.readAll();
|
||||
rfc.close();
|
||||
|
||||
mDict.fromJson ( bytes );
|
||||
|
||||
mModel = new UserCustomTreeModel ( this );
|
||||
ui->treeView->setModel ( mModel );
|
||||
|
||||
ui->treeView->header()->setSectionResizeMode ( RfcName, QHeaderView::ResizeToContents );
|
||||
ui->treeView->header()->setStretchLastSection ( false );
|
||||
ui->treeView->setEditTriggers ( QTreeView::NoEditTriggers );
|
||||
ui->treeView->setSelectionMode ( QTreeView::SingleSelection );
|
||||
ui->treeView->setItemDelegateForColumn ( RfcDownProgress, new QQtProgressBarDelegate ( this ) );
|
||||
|
||||
mModel->query ( mDict );
|
||||
ui->treeView->resizeColumnToContents ( RfcName );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
30
test/testqqtitemdelegate/mainwindow.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <qqtdicthelper.h>
|
||||
#include <usercustomtreemodel.h>
|
||||
#include <qqtprogressbardelegate.h>
|
||||
#include <qqtframe.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow ( QWidget* parent = 0 );
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
QQtDictionary mDict;
|
||||
UserCustomTreeModel* mModel;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
72
test/testqqtitemdelegate/mainwindow.ui
Normal file
@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>635</width>
|
||||
<height>386</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>testqqtitemdelegate</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>493</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>635</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
74
test/testqqtitemdelegate/testqqtitemdelegate.pro
Normal file
@ -0,0 +1,74 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2018-10-06T08:16:10
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = testqqtitemdelegate
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
include($${PWD}/../../multi-link/add_base_manager.pri)
|
||||
|
||||
CLASSNAME=UserCustomTreeModel
|
||||
add_object_class($${CLASSNAME})
|
||||
HEADERS += $$lower($${CLASSNAME}).h
|
||||
SOURCES += $$lower($${CLASSNAME}).cpp
|
||||
|
||||
add_file(AppRoot/rfc.json)
|
||||
OTHER_FILES += AppRoot/rfc.json
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
add_version(1,0,0,0)
|
||||
add_deploy()
|
||||
add_deploy_config($${PWD}/AppRoot)
|
||||
add_dependent_manager(QQt)
|
||||
system(touch main.cpp)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
equals(QSYS_PRIVATE, macOS) {
|
||||
CONFIG += app_bundle
|
||||
}
|
||||
|
||||
contains(QSYS_PRIVATE, Android|AndroidX86) {
|
||||
CONFIG += mobility
|
||||
MOBILITY =
|
||||
DISTFILES += \
|
||||
android/AndroidManifest.xml
|
||||
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
|
||||
}
|
||||
|
||||
message ($${TARGET} config $${CONFIG})
|
||||
message ($${TARGET} DEFINE $${DEFINES})
|
||||
message ($${TARGET} prelink $${QMAKE_PRE_LINK})
|
||||
message ($${TARGET} postlink $${QMAKE_POST_LINK})
|
122
test/testqqtitemdelegate/usercustomtreemodel.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
#include <usercustomtreemodel.h>
|
||||
|
||||
/**
|
||||
* dict["rfc000.txt"]
|
||||
* ["type"] = "file"
|
||||
* ["postfix"] = "txt"
|
||||
* ["DownTime"] = ""
|
||||
* ["DownStatus"] = ""
|
||||
* ["DownProgress"] = ""
|
||||
* ["url"] = ""
|
||||
* ["local_url"] = ""
|
||||
* [...]
|
||||
* dict["dir_name"]
|
||||
* ["type"] = "dir"
|
||||
* ["rfc000.txt"]
|
||||
* ["type"] = "file"
|
||||
* ["postfix"] = "txt"
|
||||
* ["DownTime"] = ""
|
||||
* ["DownStatus"] = ""
|
||||
* ["DownProgress"] = ""
|
||||
* ["url"] = "..."
|
||||
* [...]
|
||||
*/
|
||||
|
||||
void UserCustomTreeModel::packDictionaryToTreeModel ( const QQtDictionary& node, QStandardItem* pobject )
|
||||
{
|
||||
switch ( node.getType() )
|
||||
{
|
||||
case QQtDictionary::DictValue:
|
||||
{
|
||||
//null, bool, double, string
|
||||
//p3line() << node.getValue().type();
|
||||
QStandardItem* item = new QStandardItem;
|
||||
item->setData ( node.getValue(), Qt::EditRole );
|
||||
pobject ? pobject->appendRow ( item ) : appendRow ( item );
|
||||
|
||||
//pline() << item->index() << pobject->index();
|
||||
//int row = item->index().row();
|
||||
//setData ( index ( row, 1, pobject->index() ), "HHHHHHHH" );
|
||||
//setData ( index ( row, 2, pobject->index() ), "CCCC" );
|
||||
//setData ( pobject->index().child ( row, 3 ), "DDDD" );
|
||||
break;
|
||||
}
|
||||
case QQtDictionary::DictList:
|
||||
{
|
||||
//"name":[a, b, ...]
|
||||
for ( int i = 0; i < node.getList().size(); i++ )
|
||||
{
|
||||
QList<QQtDictionary>& l = node.getList();
|
||||
QStandardItem* item = new QStandardItem;
|
||||
item->setText ( QString::number ( i + 1 ) );
|
||||
pobject ? pobject->appendRow ( item ) : appendRow ( item );
|
||||
packDictionaryToTreeModel ( l[i], item );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QQtDictionary::DictMap:
|
||||
{
|
||||
//"name": {"a":"b", "a2":"b2", "a3":["b31", "b32"], "a4":{"a41":"b41", "a42":"b42"}, ...}
|
||||
for ( QMap<QString, QQtDictionary>::Iterator itor = node.getMap().begin(); itor != node.getMap().end(); itor++ )
|
||||
{
|
||||
//QMap<QString, QQtDictionary>& m = node.getMap();
|
||||
const QString& key = itor.key();
|
||||
const QQtDictionary& srcvalue = itor.value();
|
||||
|
||||
if ( key == "type" )
|
||||
continue;
|
||||
|
||||
QStandardItem* item = new QStandardItem;
|
||||
item->setText ( key );
|
||||
pobject ? pobject->appendRow ( item ) : appendRow ( item );
|
||||
|
||||
item->setColumnCount ( RFCMax );
|
||||
item->removeRows ( 0, item->rowCount() );
|
||||
item->setRowCount ( 0 );
|
||||
|
||||
if ( srcvalue["type"].getValue().toString() == "dir" )
|
||||
packDictionaryToTreeModel ( srcvalue, item );
|
||||
else
|
||||
{
|
||||
//pline() << item->index();
|
||||
int row = item->index().row();
|
||||
//QString lastmodify = srcvalue["postfix"].getValue().toString();
|
||||
QString DownProgress = srcvalue["DownProgress"].getValue().toString();
|
||||
QString DownTime = srcvalue["DownTime"].getValue().toString();
|
||||
QString DownStatus = srcvalue["DownStatus"].getValue().toString();
|
||||
//QString lastmodify = srcvalue["DownTime"].getValue().toString();
|
||||
QString url = srcvalue["url"].getValue().toString();
|
||||
QString localUrl = srcvalue["localUrl"].getValue().toString();
|
||||
//setData ( index ( row, 0 ), "JJJJ" );
|
||||
QModelIndex parentIndex = QModelIndex();
|
||||
if ( pobject )
|
||||
parentIndex = pobject->index();
|
||||
setData ( index ( row, RfcDownTime, parentIndex ), DownTime );
|
||||
setData ( index ( row, RfcDownStatus, parentIndex ), DownStatus );
|
||||
setData ( index ( row, RfcDownProgress, parentIndex ), DownProgress );
|
||||
setData ( index ( row, RfcLocalUrl, parentIndex ), localUrl );
|
||||
setData ( index ( row, RfcUrl, parentIndex ), url );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QQtDictionary::DictMax:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void UserCustomTreeModel::query ( QQtDictionary& dict )
|
||||
{
|
||||
setColumnCount ( RFCMax );
|
||||
setHeaderData ( RfcName, Qt::Horizontal, " Name" );
|
||||
setHeaderData ( RfcLocalUrl, Qt::Horizontal, "Local Path" );
|
||||
setHeaderData ( RfcUrl, Qt::Horizontal, "Url" );
|
||||
setHeaderData ( RfcDownTime, Qt::Horizontal, "Download Time" );
|
||||
setHeaderData ( RfcDownStatus, Qt::Horizontal, "Download Status" );
|
||||
setHeaderData ( RfcDownProgress, Qt::Horizontal, "Download Progress" );
|
||||
|
||||
removeRows ( 0, rowCount() );
|
||||
setRowCount ( 0 );
|
||||
QQtDictTreeModel::query ( dict );
|
||||
}
|
42
test/testqqtitemdelegate/usercustomtreemodel.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef USERCUSTOMTREEMODEL_H
|
||||
#define USERCUSTOMTREEMODEL_H
|
||||
|
||||
#include <qqtdicttreemodel.h>
|
||||
|
||||
enum ERfcSection
|
||||
{
|
||||
RfcName,
|
||||
RfcUrl,
|
||||
RfcLocalUrl,
|
||||
RfcDownStatus,
|
||||
RfcDownTime,
|
||||
RfcDownProgress,
|
||||
|
||||
RFCMax,
|
||||
};
|
||||
|
||||
class UserCustomTreeModel : public QQtDictTreeModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UserCustomTreeModel ( QObject* parent = 0 )
|
||||
: QQtDictTreeModel ( parent ) {}
|
||||
virtual ~UserCustomTreeModel() {}
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// QQtDictTreeModel interface
|
||||
protected:
|
||||
virtual void packDictionaryToTreeModel ( const QQtDictionary& node, QStandardItem* pobject ) override;
|
||||
|
||||
// QQtDictTreeModel interface
|
||||
public:
|
||||
virtual void query ( QQtDictionary& dict ) override;
|
||||
|
||||
};
|
||||
|
||||
#endif // USERCUSTOMTREEMODEL_H
|
||||
|