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:
parent
5b16c3d52e
commit
2cf523d67e
7
QQt.pro
7
QQt.pro
@ -21,8 +21,11 @@ SUBDIRS = src/qqt.pro
|
||||
SUBDIRS += examples/exquisite
|
||||
#can't support ios
|
||||
#SUBDIRS += examples/qqtprintsupportexample
|
||||
#SUBDIRS += examples/tabwidgetexamples
|
||||
#SUBDIRS += examples/svgtest
|
||||
#
|
||||
SUBDIRS += examples/tabwidgetexamples
|
||||
#
|
||||
SUBDIRS += examples/svgtest
|
||||
SUBDIRS += examples/treeviewexample
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
#need vlcQt libvlc library
|
||||
|
11
examples/treeviewexample/main.cpp
Normal file
11
examples/treeviewexample/main.cpp
Normal 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();
|
||||
}
|
28
examples/treeviewexample/mainwindow.cpp
Normal file
28
examples/treeviewexample/mainwindow.cpp
Normal 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;
|
||||
}
|
22
examples/treeviewexample/mainwindow.h
Normal file
22
examples/treeviewexample/mainwindow.h
Normal 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
|
58
examples/treeviewexample/mainwindow.ui
Normal file
58
examples/treeviewexample/mainwindow.ui
Normal 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>
|
81
examples/treeviewexample/treeviewexample.pro
Normal file
81
examples/treeviewexample/treeviewexample.pro
Normal 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
|
||||
}
|
||||
|
10
src/gui/qqtfilesystemtreemodel.cpp
Normal file
10
src/gui/qqtfilesystemtreemodel.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "qqtfilesystemtreemodel.h"
|
||||
#include <QFile>
|
||||
#include "qqtcore.h"
|
||||
#include <QModelIndex>
|
||||
|
||||
QQtFileSystemTreeModel::QQtFileSystemTreeModel ( QObject* parent ) : QFileSystemModel ( parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
30
src/gui/qqtfilesystemtreemodel.h
Normal file
30
src/gui/qqtfilesystemtreemodel.h
Normal 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
|
130
src/gui/qqtjsontreemodel.cpp
Normal file
130
src/gui/qqtjsontreemodel.cpp
Normal 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();
|
||||
}
|
||||
}
|
35
src/gui/qqtjsontreemodel.h
Normal file
35
src/gui/qqtjsontreemodel.h
Normal 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
|
@ -2,69 +2,90 @@
|
||||
#include "qqtcore.h"
|
||||
#include "qqtsql.h"
|
||||
|
||||
QQTSqlTreeModel::QQTSqlTreeModel(QObject* parent) :
|
||||
QQTTreeModel(parent)
|
||||
QQtSqlTreeModel::QQtSqlTreeModel ( QObject* parent ) :
|
||||
QQtTreeModel ( parent )
|
||||
{
|
||||
m_db = newDatabaseConn();
|
||||
}
|
||||
|
||||
void QQTSqlTreeModel::setFilePath(QString dbname)
|
||||
void QQtSqlTreeModel::setFilePath ( QString dbname )
|
||||
{
|
||||
if (dbname.isEmpty())
|
||||
if ( dbname.isEmpty() )
|
||||
{
|
||||
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:
|
||||
return parseDatabase();
|
||||
}
|
||||
|
||||
bool QQTSqlTreeModel::parseDatabase()
|
||||
bool QQtSqlTreeModel::parseDatabase()
|
||||
{
|
||||
QStringList tables = m_db.tables(QSql::Tables);
|
||||
QStringListIterator itor(tables);
|
||||
QStringList tables = m_db.tables ( QSql::Tables );
|
||||
pline() << tables;
|
||||
QStringListIterator itor ( tables );
|
||||
|
||||
while (itor.hasNext())
|
||||
while ( itor.hasNext() )
|
||||
{
|
||||
QString table = itor.next();
|
||||
parseTable(table);
|
||||
parseTable ( table );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QQTSqlTreeModel::parseTable(QString tableName)
|
||||
bool QQtSqlTreeModel::parseTable ( QString tableName )
|
||||
{
|
||||
QQTTableModel* mdl = new QQTTableModel(this, m_db);
|
||||
mdl->setTable(tableName);
|
||||
mdl->query("");
|
||||
tableModelList.push_back(mdl);;
|
||||
QQtTableModel* mdl = new QQtTableModel ( this, m_db );
|
||||
mdl->setTable ( tableName );
|
||||
mdl->query ( "" );
|
||||
tableModelList.push_back ( mdl );;
|
||||
|
||||
QStandardItem* itemParent = new QStandardItem;
|
||||
itemParent->setData(tableName, Qt::EditRole);
|
||||
appendRow(itemParent);
|
||||
itemParent->setData ( tableName, Qt::EditRole );
|
||||
appendRow ( itemParent );
|
||||
|
||||
if (columnCount() < mdl->columnCount())
|
||||
setColumnCount(mdl->columnCount());
|
||||
if ( columnCount() < 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;
|
||||
_item->setData(mdl->index(i, 0).data(Qt::DisplayRole), Qt::EditRole);
|
||||
itemParent->appendRow(_item);
|
||||
_item->setData ( mdl->index ( i, 0 ).data ( Qt::DisplayRole ), Qt::EditRole );
|
||||
itemParent->appendRow ( _item );
|
||||
|
||||
for (int j = 1; j < mdl->columnCount(); j++)
|
||||
for ( int j = 1; j < mdl->columnCount(); j++ )
|
||||
{
|
||||
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();
|
||||
itemParent->setChild(_item->index().row(), j, __item);
|
||||
itemParent->setChild ( _item->index().row(), j, __item );
|
||||
//setItem(indexFromItem(_item).row(), j, __item);
|
||||
}
|
||||
}
|
||||
|
@ -6,25 +6,30 @@
|
||||
#include <QList>
|
||||
#include <qqt-local.h>
|
||||
|
||||
class QQTSHARED_EXPORT QQTSqlTreeModel : public QQTTreeModel
|
||||
/**
|
||||
* @brief The QQtSqlTreeModel class
|
||||
* 按照树的样式来显示数据库
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtSqlTreeModel : public QQtTreeModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQTSqlTreeModel(QObject* parent = 0);
|
||||
explicit QQtSqlTreeModel ( QObject* parent = 0 );
|
||||
|
||||
//TODO:
|
||||
QSqlDatabase& database() { return m_db; }
|
||||
void setAbsoluteFilePath ( QString dbname );
|
||||
|
||||
// QQTVirtualTreeModel interface
|
||||
// QQtSqlTreeModel interface
|
||||
public:
|
||||
bool query(QString condition) override;
|
||||
void setFilePath(QString dbname) override;
|
||||
|
||||
virtual bool query ( QString condition = "" ) override;
|
||||
virtual void setFilePath ( QString dbname ) override;
|
||||
protected:
|
||||
bool parseDatabase();
|
||||
bool parseTable(QString tableName);
|
||||
virtual bool parseDatabase();
|
||||
virtual bool parseTable ( QString tableName );
|
||||
private:
|
||||
QSqlDatabase m_db;
|
||||
QList<QQTTableModel*> tableModelList;
|
||||
QList<QQtTableModel*> tableModelList;
|
||||
};
|
||||
|
||||
#endif // QQTSQLTREEMODEL_H
|
||||
|
@ -1,17 +1,17 @@
|
||||
#include "qqttablemodel.h"
|
||||
|
||||
QQTTableModel::QQTTableModel(QObject* parent, QSqlDatabase db):
|
||||
QQtTableModel::QQtTableModel(QObject* parent, QSqlDatabase db):
|
||||
QSqlRelationalTableModel(parent, db)
|
||||
{
|
||||
}
|
||||
|
||||
void QQTTableModel::query(QString filter)
|
||||
void QQtTableModel::query(QString filter)
|
||||
{
|
||||
setFilter(filter);
|
||||
select();
|
||||
}
|
||||
|
||||
QVariant QQTTableModel::data(const QModelIndex& index, int role) const
|
||||
QVariant QQtTableModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Qt::ItemFlags QQTTableModel::flags(const QModelIndex& index) const
|
||||
Qt::ItemFlags QQtTableModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
return QSqlRelationalTableModel::flags(index);
|
||||
}
|
||||
|
@ -5,14 +5,14 @@
|
||||
#include <qqt-local.h>
|
||||
|
||||
/**
|
||||
* @brief The QQTTableModel class
|
||||
* @brief The QQtTableModel class
|
||||
* QQTSqlRelationalTableModel 方便起见,仅仅使用这个model
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQTTableModel : public QSqlRelationalTableModel
|
||||
class QQTSHARED_EXPORT QQtTableModel : public QSqlRelationalTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQTTableModel(QObject* parent = 0, QSqlDatabase db = QSqlDatabase());
|
||||
explicit QQtTableModel(QObject* parent = 0, QSqlDatabase db = QSqlDatabase());
|
||||
|
||||
void query(QString filter);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "qqttreemodel.h"
|
||||
|
||||
QQTTreeModel::QQTTreeModel(QObject* parent) : QStandardItemModel(parent)
|
||||
QQtTreeModel::QQtTreeModel(QObject* parent) : QStandardItemModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -9,11 +9,11 @@
|
||||
* define the tree model's functions name.
|
||||
*/
|
||||
|
||||
class QQTSHARED_EXPORT QQTTreeModel : public QStandardItemModel
|
||||
class QQTSHARED_EXPORT QQtTreeModel : public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQTTreeModel(QObject* parent = 0);
|
||||
explicit QQtTreeModel(QObject* parent = 0);
|
||||
|
||||
/**
|
||||
* @brief query
|
||||
|
@ -3,19 +3,19 @@
|
||||
#include "qqtcore.h"
|
||||
#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)
|
||||
<< ": " << qPrintable(file.errorString())
|
||||
pline() << "Error: Cannot read file " << qPrintable ( fileName )
|
||||
<< ": " << qPrintable ( file.errorString() )
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
@ -26,12 +26,12 @@ void QQTXmlTreeModel::setFilePath(QString fileName)
|
||||
|
||||
QDomDocument doc;
|
||||
|
||||
if (!doc.setContent(&file, false, &errorStr, &errorLine,
|
||||
&errorColumn))
|
||||
if ( !doc.setContent ( &file, false, &errorStr, &errorLine,
|
||||
&errorColumn ) )
|
||||
{
|
||||
pline() << "Error: Parse error at line " << errorLine << ", "
|
||||
<< "column " << errorColumn << ": "
|
||||
<< qPrintable(errorStr) << endl;
|
||||
<< qPrintable ( errorStr ) << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -39,14 +39,14 @@ void QQTXmlTreeModel::setFilePath(QString fileName)
|
||||
|
||||
clear();
|
||||
QDomElement rootElement = doc.documentElement();
|
||||
parseChildElement(rootElement);
|
||||
parseChildElement ( rootElement );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool QQTXmlTreeModel::query(QString condition)
|
||||
bool QQTXmlTreeModel::query ( QString condition )
|
||||
{
|
||||
Q_UNUSED(condition)
|
||||
Q_UNUSED ( condition )
|
||||
//TODO:
|
||||
return true;
|
||||
}
|
||||
@ -57,24 +57,24 @@ bool QQTXmlTreeModel::query(QString condition)
|
||||
* @param parent
|
||||
* 这套递归代码,第一次和最后一次不同。
|
||||
*/
|
||||
void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardItem* itemParent)
|
||||
void QQTXmlTreeModel::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);
|
||||
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);
|
||||
if ( element.isNull() && !element.hasChildNodes() )
|
||||
item->setData ( itemParent->data ( Qt::UserRole ), Qt::EditRole );
|
||||
|
||||
pline() << element.nodeName() << element.text();
|
||||
|
||||
if (itemParent)
|
||||
if ( itemParent )
|
||||
{
|
||||
itemParent->appendRow(item);
|
||||
itemParent->appendRow ( item );
|
||||
//if column is not enough
|
||||
//setItem(indexFromItem(itemParent).row(), 0, item);
|
||||
}
|
||||
@ -82,7 +82,7 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
|
||||
{
|
||||
//first time ok. also
|
||||
//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();
|
||||
|
||||
if (nodeMap.count() > columnCount())
|
||||
setColumnCount(nodeMap.count());
|
||||
if ( nodeMap.count() > columnCount() )
|
||||
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 attValue = nodeMap.item(i).nodeValue();
|
||||
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);
|
||||
_item->setData ( attName, Qt::UserRole );
|
||||
_item->setData ( attValue, Qt::EditRole );
|
||||
|
||||
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
|
||||
@ -114,7 +114,7 @@ void QQTXmlTreeModel::parseChildElement(const QDomElement& element, QStandardIte
|
||||
}
|
||||
else
|
||||
//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();
|
||||
|
||||
while (!child.isNull())
|
||||
while ( !child.isNull() )
|
||||
{
|
||||
parseChildElement(child.toElement(), item);
|
||||
parseChildElement ( child.toElement(), item );
|
||||
child = child.nextSibling();
|
||||
}
|
||||
}
|
||||
|
@ -5,28 +5,28 @@
|
||||
#include <QDomDocument>
|
||||
#include <qqt-local.h>
|
||||
|
||||
class QQTSHARED_EXPORT QQTXmlTreeModel : public QQTTreeModel
|
||||
class QQTSHARED_EXPORT QQTXmlTreeModel : public QQtTreeModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QQTXmlTreeModel(QObject* parent = 0);
|
||||
explicit QQTXmlTreeModel ( QObject* parent = 0 );
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
// QQTTreeModel interface
|
||||
// QQtTreeModel interface
|
||||
public:
|
||||
bool query(QString condition) override;
|
||||
void setFilePath(QString xmlfile) override;
|
||||
bool query ( QString condition ) override;
|
||||
void setFilePath ( QString xmlfile ) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief parseChildElement
|
||||
* @param element
|
||||
*/
|
||||
void parseChildElement(const QDomElement& element, QStandardItem* itemParent = 0);
|
||||
void parseChildElement ( const QDomElement& element, QStandardItem* itemParent = 0 );
|
||||
|
||||
private:
|
||||
QDomDocument doc;
|
||||
|
@ -12,23 +12,9 @@
|
||||
#if you succeed with LibQQt, please thumb up.
|
||||
#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
|
||||
HEADERS += $$PWD/qqt.h \
|
||||
@ -71,6 +57,8 @@ SOURCES += \
|
||||
$$PWD/gui/qqtsqltreemodel.cpp \
|
||||
$$PWD/gui/qqttablemodel.cpp \
|
||||
$$PWD/gui/qqttreemodel.cpp \
|
||||
$$PWD/gui/qqtfilesystemtreemodel.cpp \
|
||||
$$PWD/gui/qqtjsontreemodel.cpp \
|
||||
$$PWD/gui/qqtxmltreemodel.cpp
|
||||
|
||||
HEADERS += \
|
||||
@ -78,6 +66,8 @@ HEADERS += \
|
||||
$$PWD/gui/qqtsqltreemodel.h \
|
||||
$$PWD/gui/qqttablemodel.h \
|
||||
$$PWD/gui/qqttreemodel.h \
|
||||
$$PWD/gui/qqtfilesystemtreemodel.h \
|
||||
$$PWD/gui/qqtjsontreemodel.h \
|
||||
$$PWD/gui/qqtxmltreemodel.h \
|
||||
$$PWD/gui/qqtgui.h
|
||||
|
||||
@ -431,3 +421,22 @@ contains (DEFINES, __WEBSOCKETSUPPORT__) {
|
||||
$$PWD/network/qqtwebclient.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
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ QQtTableWidget::QQtTableWidget(QWidget* parent) :
|
||||
QQtTableView(parent)
|
||||
{
|
||||
m_db = newDatabaseConn();
|
||||
m_model = new QQTTableModel(this, m_db);
|
||||
m_model = new QQtTableModel(this, m_db);
|
||||
setModel(m_model);
|
||||
/*
|
||||
* 如果没有这个函数,程序存在启动崩溃的情况。
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
void selectedRows(int column, QMap<int, QStringList>& ids);
|
||||
private:
|
||||
QQTTableModel* m_model;
|
||||
QQtTableModel* m_model;
|
||||
QSqlDatabase m_db;
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QQTTreeModel* mModel;
|
||||
QQtTreeModel* mModel;
|
||||
};
|
||||
|
||||
#endif // QQTTREEWIDGET_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user