1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

add filesystem treemodel, add json treemodel, update sql treemodel

This commit is contained in:
tianduanrui 2017-11-19 10:40:33 +08:00
parent 5b16c3d52e
commit 2cf523d67e
22 changed files with 549 additions and 106 deletions

View File

@ -21,8 +21,11 @@ SUBDIRS = src/qqt.pro
SUBDIRS += examples/exquisite SUBDIRS += examples/exquisite
#can't support ios #can't support ios
#SUBDIRS += examples/qqtprintsupportexample #SUBDIRS += examples/qqtprintsupportexample
#SUBDIRS += examples/tabwidgetexamples #
#SUBDIRS += examples/svgtest SUBDIRS += examples/tabwidgetexamples
#
SUBDIRS += examples/svgtest
SUBDIRS += examples/treeviewexample
#----------------------------------------------------------------- #-----------------------------------------------------------------
#need vlcQt libvlc library #need vlcQt libvlc library

View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,28 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QFileSystemModel"
#include "QDirModel"
#include <QApplication>
#include <qqtsqltreemodel.h>
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),
ui ( new Ui::MainWindow )
{
ui->setupUi ( this );
QFileSystemModel* model = new QFileSystemModel ( this );
//model->setRootPath ( "/Users/abel/Develop/a0-develop/a0-qqtfoundation/examples" );
QDirModel* model2 = new QDirModel ( this );
ui->tv0->setModel ( model2 );
ui->tv0->setRootIndex ( model2->index ( qApp->applicationDirPath() ) );
QQtSqlTreeModel* md0 = new QQtSqlTreeModel ( this );
ui->tv1->setModel ( md0 );
md0->setAbsoluteFilePath ( "/Users/abel/Develop/d1-product/App/db/Manager.db" );
md0->query();
}
MainWindow::~MainWindow()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,58 @@
<?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>800</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QQtTreeWidget" name="tv0"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QTreeView" name="tv1"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QQtTreeWidget</class>
<extends>QTreeView</extends>
<header>qqttreewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,81 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-11-19T09:27:08
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = treeviewexample
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
CONFIG += mobility
MOBILITY =
#-------------------------------------------------
#link qqt library
#if you link a library to your app, on android you must select the running kit to the app, not LibQQt e.g.
#-------------------------------------------------
include(../qqtframe2/link_qqt_library.pri)
#-------------------------------------------------
#install
#-------------------------------------------------
#CONFIG += can_install
can_install:equals(QKIT_PRIVATE, EMBEDDED) {
target.path = /Application
INSTALLS += target
} else: unix {
equals(QKIT_PRIVATE, macOS) {
target.path = /Applications
INSTALLS += target
}
}
#-------------------------------------------------
##project environ
#-------------------------------------------------
#default
message ($${TARGET} config $${CONFIG})
message ($${TARGET} define $${DEFINES})
contains(QKIT_PRIVATE, ANDROID|ANDROIDX86) {
CONFIG += mobility
MOBILITY =
DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}

View File

@ -0,0 +1,10 @@
#include "qqtfilesystemtreemodel.h"
#include <QFile>
#include "qqtcore.h"
#include <QModelIndex>
QQtFileSystemTreeModel::QQtFileSystemTreeModel ( QObject* parent ) : QFileSystemModel ( parent )
{
}

View File

@ -0,0 +1,30 @@
#ifndef QQTFILESYSTEMTREEMODEL_H
#define QQTFILESYSTEMTREEMODEL_H
#include <QFileSystemModel>
#include <QDomDocument>
#include <qqt-local.h>
/**
* @brief The QQtFileSystemTreeModel class
* QFileSystemModel setRootPath
* QDirModel RootPath函数
* QTreeView的setRootIndex来设置RootPath,QTreeView里面进行过滤
* view->setRootIndex ( model->index ( "the/root/path" ) );
*/
class QQTSHARED_EXPORT QQtFileSystemTreeModel : public QFileSystemModel
{
Q_OBJECT
public:
explicit QQtFileSystemTreeModel ( QObject* parent = 0 );
signals:
public slots:
protected:
private:
};
#endif // QQTFILESYSTEMTREEMODEL_H

View File

@ -0,0 +1,130 @@
#include "qqtjsontreemodel.h"
#include <QFile>
#include "qqtcore.h"
#include <QModelIndex>
QQtJsonTreeModel::QQtJsonTreeModel ( QObject* parent ) : QQtTreeModel ( parent )
{
}
void QQtJsonTreeModel::setFilePath ( QString fileName )
{
QFile file ( fileName );
if ( !file.open ( QFile::ReadOnly | QFile::Text ) )
{
pline() << "Error: Cannot read file " << qPrintable ( fileName )
<< ": " << qPrintable ( file.errorString() )
<< endl;
return;
}
QString errorStr;
int errorLine;
int errorColumn;
QDomDocument doc;
if ( !doc.setContent ( &file, false, &errorStr, &errorLine,
&errorColumn ) )
{
pline() << "Error: Parse error at line " << errorLine << ", "
<< "column " << errorColumn << ": "
<< qPrintable ( errorStr ) << endl;
return;
}
file.close();
clear();
QDomElement rootElement = doc.documentElement();
parseChildElement ( rootElement );
return;
}
bool QQtJsonTreeModel::query ( QString condition )
{
Q_UNUSED ( condition )
//TODO:
return true;
}
/**
* @brief QQTXmlTreeModel::parseChildElement
* @param element
* @param parent
*
*/
void QQtJsonTreeModel::parseChildElement ( const QDomElement& element, QStandardItem* itemParent )
{
/**
* @brief element name
*/
QStandardItem* item = new QStandardItem();
item->setData ( element.nodeName(), Qt::EditRole );
item->setData ( element.text(), Qt::UserRole );
if ( element.isNull() && !element.hasChildNodes() )
item->setData ( itemParent->data ( Qt::UserRole ), Qt::EditRole );
pline() << element.nodeName() << element.text();
if ( itemParent )
{
itemParent->appendRow ( item );
//if column is not enough
//setItem(indexFromItem(itemParent).row(), 0, item);
}
else
{
//first time ok. also
//appendRow(item);
setItem ( 0, 0, item );
}
/**
* @brief element attibute
*/
QDomNamedNodeMap nodeMap = element.attributes();
if ( nodeMap.count() > columnCount() )
setColumnCount ( nodeMap.count() );
for ( int i = 0; i < nodeMap.count(); i++ )
{
QString attName = nodeMap.item ( i ).nodeName();
QString attValue = nodeMap.item ( i ).nodeValue();
QStandardItem* _item = new QStandardItem();
_item->setData ( attName, Qt::UserRole );
_item->setData ( attValue, Qt::EditRole );
pline() << attName << attValue << itemParent;
if ( itemParent )
{
itemParent->setChild ( item->index().row(), i + 1, _item );
/**
* @brief more than two column need this
*/
//setItem(indexFromItem(item).row(), i+1, _item);
}
else
//first time
setItem ( indexFromItem ( item ).row(), i + 1, _item );
}
/**
* child element
*/
QDomNode child = element.firstChild();
while ( !child.isNull() )
{
parseChildElement ( child.toElement(), item );
child = child.nextSibling();
}
}

View File

@ -0,0 +1,35 @@
#ifndef QQTJSONTREEMODEL_H
#define QQTJSONTREEMODEL_H
#include <qqttreemodel.h>
#include <QDomDocument>
#include <qqt-local.h>
class QQTSHARED_EXPORT QQtJsonTreeModel : public QQtTreeModel
{
Q_OBJECT
public:
explicit QQtJsonTreeModel ( QObject* parent = 0 );
signals:
public slots:
// QQtJsonTreeModel interface
public:
bool query ( QString condition ) override;
void setFilePath ( QString xmlfile ) override;
protected:
/**
* @brief parseChildElement
* @param element
*/
void parseChildElement ( const QDomElement& element, QStandardItem* itemParent = 0 );
private:
QDomDocument doc;
};
#endif // QQTJSONTREEMODEL_H

View File

@ -2,69 +2,90 @@
#include "qqtcore.h" #include "qqtcore.h"
#include "qqtsql.h" #include "qqtsql.h"
QQTSqlTreeModel::QQTSqlTreeModel(QObject* parent) : QQtSqlTreeModel::QQtSqlTreeModel ( QObject* parent ) :
QQTTreeModel(parent) QQtTreeModel ( parent )
{ {
m_db = newDatabaseConn(); m_db = newDatabaseConn();
} }
void QQTSqlTreeModel::setFilePath(QString dbname) void QQtSqlTreeModel::setFilePath ( QString dbname )
{ {
if (dbname.isEmpty()) if ( dbname.isEmpty() )
{ {
return; return;
} }
setDatabaseName(m_db, dbname); setDatabaseName ( m_db, dbname );
} }
bool QQTSqlTreeModel::query(QString condition) void QQtSqlTreeModel::setAbsoluteFilePath ( QString dbname )
{ {
Q_UNUSED(condition) if ( dbname.isEmpty() )
{
return;
}
if ( m_db.isOpen() )
m_db.close();
m_db.setDatabaseName ( QString ( "%1" ).arg ( dbname ) );
if ( !m_db.open() )
{
QMessageBox::warning ( 0, QObject::tr ( "QSQLITE %1 Error" ).arg ( m_db.databaseName() ),
m_db.lastError().text() );
return;
}
}
bool QQtSqlTreeModel::query ( QString condition )
{
Q_UNUSED ( condition )
//TODO: //TODO:
return parseDatabase(); return parseDatabase();
} }
bool QQTSqlTreeModel::parseDatabase() bool QQtSqlTreeModel::parseDatabase()
{ {
QStringList tables = m_db.tables(QSql::Tables); QStringList tables = m_db.tables ( QSql::Tables );
QStringListIterator itor(tables); pline() << tables;
QStringListIterator itor ( tables );
while (itor.hasNext()) while ( itor.hasNext() )
{ {
QString table = itor.next(); QString table = itor.next();
parseTable(table); parseTable ( table );
} }
return true; return true;
} }
bool QQTSqlTreeModel::parseTable(QString tableName) bool QQtSqlTreeModel::parseTable ( QString tableName )
{ {
QQTTableModel* mdl = new QQTTableModel(this, m_db); QQtTableModel* mdl = new QQtTableModel ( this, m_db );
mdl->setTable(tableName); mdl->setTable ( tableName );
mdl->query(""); mdl->query ( "" );
tableModelList.push_back(mdl);; tableModelList.push_back ( mdl );;
QStandardItem* itemParent = new QStandardItem; QStandardItem* itemParent = new QStandardItem;
itemParent->setData(tableName, Qt::EditRole); itemParent->setData ( tableName, Qt::EditRole );
appendRow(itemParent); appendRow ( itemParent );
if (columnCount() < mdl->columnCount()) if ( columnCount() < mdl->columnCount() )
setColumnCount(mdl->columnCount()); setColumnCount ( mdl->columnCount() );
for (int i = 0; i < mdl->rowCount(); i++) for ( int i = 0; i < mdl->rowCount(); i++ )
{ {
QStandardItem* _item = new QStandardItem; QStandardItem* _item = new QStandardItem;
_item->setData(mdl->index(i, 0).data(Qt::DisplayRole), Qt::EditRole); _item->setData ( mdl->index ( i, 0 ).data ( Qt::DisplayRole ), Qt::EditRole );
itemParent->appendRow(_item); itemParent->appendRow ( _item );
for (int j = 1; j < mdl->columnCount(); j++) for ( int j = 1; j < mdl->columnCount(); j++ )
{ {
QStandardItem* __item = new QStandardItem; QStandardItem* __item = new QStandardItem;
__item->setData(mdl->index(i, j).data(Qt::DisplayRole), Qt::EditRole); __item->setData ( mdl->index ( i, j ).data ( Qt::DisplayRole ), Qt::EditRole );
//pline() << __item->data(Qt::EditRole).toByteArray(); //pline() << __item->data(Qt::EditRole).toByteArray();
itemParent->setChild(_item->index().row(), j, __item); itemParent->setChild ( _item->index().row(), j, __item );
//setItem(indexFromItem(_item).row(), j, __item); //setItem(indexFromItem(_item).row(), j, __item);
} }
} }

View File

@ -6,25 +6,30 @@
#include <QList> #include <QList>
#include <qqt-local.h> #include <qqt-local.h>
class QQTSHARED_EXPORT QQTSqlTreeModel : public QQTTreeModel /**
* @brief The QQtSqlTreeModel class
*
*/
class QQTSHARED_EXPORT QQtSqlTreeModel : public QQtTreeModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTSqlTreeModel(QObject* parent = 0); explicit QQtSqlTreeModel ( QObject* parent = 0 );
//TODO: //TODO:
QSqlDatabase& database() { return m_db; }
void setAbsoluteFilePath ( QString dbname );
// QQTVirtualTreeModel interface // QQtSqlTreeModel interface
public: public:
bool query(QString condition) override; virtual bool query ( QString condition = "" ) override;
void setFilePath(QString dbname) override; virtual void setFilePath ( QString dbname ) override;
protected: protected:
bool parseDatabase(); virtual bool parseDatabase();
bool parseTable(QString tableName); virtual bool parseTable ( QString tableName );
private: private:
QSqlDatabase m_db; QSqlDatabase m_db;
QList<QQTTableModel*> tableModelList; QList<QQtTableModel*> tableModelList;
}; };
#endif // QQTSQLTREEMODEL_H #endif // QQTSQLTREEMODEL_H

View File

@ -1,17 +1,17 @@
#include "qqttablemodel.h" #include "qqttablemodel.h"
QQTTableModel::QQTTableModel(QObject* parent, QSqlDatabase db): QQtTableModel::QQtTableModel(QObject* parent, QSqlDatabase db):
QSqlRelationalTableModel(parent, db) QSqlRelationalTableModel(parent, db)
{ {
} }
void QQTTableModel::query(QString filter) void QQtTableModel::query(QString filter)
{ {
setFilter(filter); setFilter(filter);
select(); select();
} }
QVariant QQTTableModel::data(const QModelIndex& index, int role) const QVariant QQtTableModel::data(const QModelIndex& index, int role) const
{ {
switch (role) switch (role)
{ {
@ -26,12 +26,12 @@ QVariant QQTTableModel::data(const QModelIndex& index, int role) const
} }
bool QQTTableModel::setData(const QModelIndex& index, const QVariant& value, int role) bool QQtTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{ {
return QSqlRelationalTableModel::setData(index, value, role); return QSqlRelationalTableModel::setData(index, value, role);
} }
Qt::ItemFlags QQTTableModel::flags(const QModelIndex& index) const Qt::ItemFlags QQtTableModel::flags(const QModelIndex& index) const
{ {
return QSqlRelationalTableModel::flags(index); return QSqlRelationalTableModel::flags(index);
} }

View File

@ -5,14 +5,14 @@
#include <qqt-local.h> #include <qqt-local.h>
/** /**
* @brief The QQTTableModel class * @brief The QQtTableModel class
* QQTSqlRelationalTableModel 便使model * QQTSqlRelationalTableModel 便使model
*/ */
class QQTSHARED_EXPORT QQTTableModel : public QSqlRelationalTableModel class QQTSHARED_EXPORT QQtTableModel : public QSqlRelationalTableModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTTableModel(QObject* parent = 0, QSqlDatabase db = QSqlDatabase()); explicit QQtTableModel(QObject* parent = 0, QSqlDatabase db = QSqlDatabase());
void query(QString filter); void query(QString filter);

View File

@ -1,6 +1,6 @@
#include "qqttreemodel.h" #include "qqttreemodel.h"
QQTTreeModel::QQTTreeModel(QObject* parent) : QStandardItemModel(parent) QQtTreeModel::QQtTreeModel(QObject* parent) : QStandardItemModel(parent)
{ {
} }

View File

@ -9,11 +9,11 @@
* define the tree model's functions name. * define the tree model's functions name.
*/ */
class QQTSHARED_EXPORT QQTTreeModel : public QStandardItemModel class QQTSHARED_EXPORT QQtTreeModel : public QStandardItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTTreeModel(QObject* parent = 0); explicit QQtTreeModel(QObject* parent = 0);
/** /**
* @brief query * @brief query

View File

@ -3,19 +3,19 @@
#include "qqtcore.h" #include "qqtcore.h"
#include <QModelIndex> #include <QModelIndex>
QQTXmlTreeModel::QQTXmlTreeModel(QObject* parent) : QQTTreeModel(parent) QQTXmlTreeModel::QQTXmlTreeModel ( QObject* parent ) : QQtTreeModel ( parent )
{ {
} }
void QQTXmlTreeModel::setFilePath(QString fileName) void QQTXmlTreeModel::setFilePath ( QString fileName )
{ {
QFile file(fileName); QFile file ( fileName );
if (!file.open(QFile::ReadOnly | QFile::Text)) if ( !file.open ( QFile::ReadOnly | QFile::Text ) )
{ {
pline() << "Error: Cannot read file " << qPrintable(fileName) pline() << "Error: Cannot read file " << qPrintable ( fileName )
<< ": " << qPrintable(file.errorString()) << ": " << qPrintable ( file.errorString() )
<< endl; << endl;
return; return;
} }
@ -26,12 +26,12 @@ void QQTXmlTreeModel::setFilePath(QString fileName)
QDomDocument doc; QDomDocument doc;
if (!doc.setContent(&file, false, &errorStr, &errorLine, if ( !doc.setContent ( &file, false, &errorStr, &errorLine,
&errorColumn)) &errorColumn ) )
{ {
pline() << "Error: Parse error at line " << errorLine << ", " pline() << "Error: Parse error at line " << errorLine << ", "
<< "column " << errorColumn << ": " << "column " << errorColumn << ": "
<< qPrintable(errorStr) << endl; << qPrintable ( errorStr ) << endl;
return; return;
} }
@ -39,14 +39,14 @@ void QQTXmlTreeModel::setFilePath(QString fileName)
clear(); clear();
QDomElement rootElement = doc.documentElement(); QDomElement rootElement = doc.documentElement();
parseChildElement(rootElement); parseChildElement ( rootElement );
return; return;
} }
bool QQTXmlTreeModel::query(QString condition) bool QQTXmlTreeModel::query ( QString condition )
{ {
Q_UNUSED(condition) Q_UNUSED ( condition )
//TODO: //TODO:
return true; return true;
} }
@ -57,24 +57,24 @@ bool QQTXmlTreeModel::query(QString condition)
* @param parent * @param parent
* *
*/ */
void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardItem* itemParent) void QQTXmlTreeModel::parseChildElement ( const QDomElement& element, QStandardItem* itemParent )
{ {
/** /**
* @brief element name * @brief element name
*/ */
QStandardItem* item = new QStandardItem(); QStandardItem* item = new QStandardItem();
item->setData(element.nodeName(), Qt::EditRole); item->setData ( element.nodeName(), Qt::EditRole );
item->setData(element.text(), Qt::UserRole); item->setData ( element.text(), Qt::UserRole );
if (element.isNull() && !element.hasChildNodes()) if ( element.isNull() && !element.hasChildNodes() )
item->setData(itemParent->data(Qt::UserRole), Qt::EditRole); item->setData ( itemParent->data ( Qt::UserRole ), Qt::EditRole );
pline() << element.nodeName() << element.text(); pline() << element.nodeName() << element.text();
if (itemParent) if ( itemParent )
{ {
itemParent->appendRow(item); itemParent->appendRow ( item );
//if column is not enough //if column is not enough
//setItem(indexFromItem(itemParent).row(), 0, item); //setItem(indexFromItem(itemParent).row(), 0, item);
} }
@ -82,7 +82,7 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
{ {
//first time ok. also //first time ok. also
//appendRow(item); //appendRow(item);
setItem(0, 0, item); setItem ( 0, 0, item );
} }
/** /**
@ -90,22 +90,22 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
*/ */
QDomNamedNodeMap nodeMap = element.attributes(); QDomNamedNodeMap nodeMap = element.attributes();
if (nodeMap.count() > columnCount()) if ( nodeMap.count() > columnCount() )
setColumnCount(nodeMap.count()); setColumnCount ( nodeMap.count() );
for (int i = 0; i < nodeMap.count(); i++) for ( int i = 0; i < nodeMap.count(); i++ )
{ {
QString attName = nodeMap.item(i).nodeName(); QString attName = nodeMap.item ( i ).nodeName();
QString attValue = nodeMap.item(i).nodeValue(); QString attValue = nodeMap.item ( i ).nodeValue();
QStandardItem* _item = new QStandardItem(); QStandardItem* _item = new QStandardItem();
_item->setData(attName, Qt::UserRole); _item->setData ( attName, Qt::UserRole );
_item->setData(attValue, Qt::EditRole); _item->setData ( attValue, Qt::EditRole );
pline() << attName << attValue << itemParent; pline() << attName << attValue << itemParent;
if (itemParent) if ( itemParent )
{ {
itemParent->setChild(item->index().row(), i + 1, _item); itemParent->setChild ( item->index().row(), i + 1, _item );
/** /**
* @brief more than two column need this * @brief more than two column need this
@ -114,7 +114,7 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
} }
else else
//first time //first time
setItem(indexFromItem(item).row(), i + 1, _item); setItem ( indexFromItem ( item ).row(), i + 1, _item );
} }
/** /**
@ -122,9 +122,9 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
*/ */
QDomNode child = element.firstChild(); QDomNode child = element.firstChild();
while (!child.isNull()) while ( !child.isNull() )
{ {
parseChildElement(child.toElement(), item); parseChildElement ( child.toElement(), item );
child = child.nextSibling(); child = child.nextSibling();
} }
} }

View File

@ -5,28 +5,28 @@
#include <QDomDocument> #include <QDomDocument>
#include <qqt-local.h> #include <qqt-local.h>
class QQTSHARED_EXPORT QQTXmlTreeModel : public QQTTreeModel class QQTSHARED_EXPORT QQTXmlTreeModel : public QQtTreeModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTXmlTreeModel(QObject* parent = 0); explicit QQTXmlTreeModel ( QObject* parent = 0 );
signals: signals:
public slots: public slots:
// QQTTreeModel interface // QQtTreeModel interface
public: public:
bool query(QString condition) override; bool query ( QString condition ) override;
void setFilePath(QString xmlfile) override; void setFilePath ( QString xmlfile ) override;
protected: protected:
/** /**
* @brief parseChildElement * @brief parseChildElement
* @param element * @param element
*/ */
void parseChildElement(const QDomElement& element, QStandardItem* itemParent = 0); void parseChildElement ( const QDomElement& element, QStandardItem* itemParent = 0 );
private: private:
QDomDocument doc; QDomDocument doc;

View File

@ -12,23 +12,9 @@
#if you succeed with LibQQt, please thumb up. #if you succeed with LibQQt, please thumb up.
#2017年11月10日18:53:56 #2017年11月10日18:53:56
#------------------------------------------------- #-------------------------------------------------
SOURCES +=
HEADERS +=
SOURCES += \
$$PWD/svgwidgets/qqtsvgwidget.cpp \
$$PWD/svgwidgets/qqtsvgpushbutton.cpp \
$$PWD/svgwidgets/qqtsvgcheckbox.cpp \
$$PWD/svgwidgets/qqtsvgradiobutton.cpp \
$$PWD/svgwidgets/qqtgraphicssvgitem.cpp \
$$PWD/svgwidgets/qqtsvglabel.cpp \
$$PWD/svgwidgets/qqtsvgprogressbar.cpp
HEADERS += \
$$PWD/svgwidgets/qqtsvgwidget.h \
$$PWD/svgwidgets/qqtsvgpushbutton.h \
$$PWD/svgwidgets/qqtsvgcheckbox.h \
$$PWD/svgwidgets/qqtsvgradiobutton.h \
$$PWD/svgwidgets/qqtgraphicssvgitem.h \
$$PWD/svgwidgets/qqtsvglabel.h \
$$PWD/svgwidgets/qqtsvgprogressbar.h
#root dir #root dir
HEADERS += $$PWD/qqt.h \ HEADERS += $$PWD/qqt.h \
@ -71,6 +57,8 @@ SOURCES += \
$$PWD/gui/qqtsqltreemodel.cpp \ $$PWD/gui/qqtsqltreemodel.cpp \
$$PWD/gui/qqttablemodel.cpp \ $$PWD/gui/qqttablemodel.cpp \
$$PWD/gui/qqttreemodel.cpp \ $$PWD/gui/qqttreemodel.cpp \
$$PWD/gui/qqtfilesystemtreemodel.cpp \
$$PWD/gui/qqtjsontreemodel.cpp \
$$PWD/gui/qqtxmltreemodel.cpp $$PWD/gui/qqtxmltreemodel.cpp
HEADERS += \ HEADERS += \
@ -78,6 +66,8 @@ HEADERS += \
$$PWD/gui/qqtsqltreemodel.h \ $$PWD/gui/qqtsqltreemodel.h \
$$PWD/gui/qqttablemodel.h \ $$PWD/gui/qqttablemodel.h \
$$PWD/gui/qqttreemodel.h \ $$PWD/gui/qqttreemodel.h \
$$PWD/gui/qqtfilesystemtreemodel.h \
$$PWD/gui/qqtjsontreemodel.h \
$$PWD/gui/qqtxmltreemodel.h \ $$PWD/gui/qqtxmltreemodel.h \
$$PWD/gui/qqtgui.h $$PWD/gui/qqtgui.h
@ -431,3 +421,22 @@ contains (DEFINES, __WEBSOCKETSUPPORT__) {
$$PWD/network/qqtwebclient.h \ $$PWD/network/qqtwebclient.h \
$$PWD/network/qqtwebserver.h $$PWD/network/qqtwebserver.h
} }
contains (DEFINES, __SVGWIDGETS__) {
SOURCES += \
$$PWD/svgwidgets/qqtsvgwidget.cpp \
$$PWD/svgwidgets/qqtsvgpushbutton.cpp \
$$PWD/svgwidgets/qqtsvgcheckbox.cpp \
$$PWD/svgwidgets/qqtsvgradiobutton.cpp \
$$PWD/svgwidgets/qqtgraphicssvgitem.cpp \
$$PWD/svgwidgets/qqtsvglabel.cpp \
$$PWD/svgwidgets/qqtsvgprogressbar.cpp
HEADERS += \
$$PWD/svgwidgets/qqtsvgwidget.h \
$$PWD/svgwidgets/qqtsvgpushbutton.h \
$$PWD/svgwidgets/qqtsvgcheckbox.h \
$$PWD/svgwidgets/qqtsvgradiobutton.h \
$$PWD/svgwidgets/qqtgraphicssvgitem.h \
$$PWD/svgwidgets/qqtsvglabel.h \
$$PWD/svgwidgets/qqtsvgprogressbar.h
}

View File

@ -7,7 +7,7 @@ QQtTableWidget::QQtTableWidget(QWidget* parent) :
QQtTableView(parent) QQtTableView(parent)
{ {
m_db = newDatabaseConn(); m_db = newDatabaseConn();
m_model = new QQTTableModel(this, m_db); m_model = new QQtTableModel(this, m_db);
setModel(m_model); setModel(m_model);
/* /*
* *

View File

@ -29,7 +29,7 @@ public:
void selectedRows(int column, QMap<int, QStringList>& ids); void selectedRows(int column, QMap<int, QStringList>& ids);
private: private:
QQTTableModel* m_model; QQtTableModel* m_model;
QSqlDatabase m_db; QSqlDatabase m_db;
}; };

View File

@ -17,7 +17,7 @@ public:
public slots: public slots:
private: private:
QQTTreeModel* mModel; QQtTreeModel* mModel;
}; };
#endif // QQTTREEWIDGET_H #endif // QQTTREEWIDGET_H