├── bin
├── QtCore4.dll
├── QtGui4.dll
├── QtSql4.dll
├── QtXml4.dll
├── SQLiteDatabaseManage.exe
├── database
│ └── dbtest.db
├── libgcc_s_dw2-1.dll
├── mingwm10.dll
└── sqldrivers
│ ├── qsqlite4.dll
│ └── qsqlodbc4.dll
└── src
├── Makefile
├── Makefile.Debug
├── Makefile.Release
├── SQLiteDatabaseManage.pro
├── SQLiteDatabaseManage.pro.user
├── SQLiteDatabaseManage.qrc
├── codeeditor.cpp
├── codeeditor.h
├── createindexwidget.cpp
├── createindexwidget.h
├── datatypedelegate.cpp
├── datatypedelegate.h
├── exportwizard.cpp
├── exportwizard.h
├── finddialog.cpp
├── finddialog.h
├── highlighter.cpp
├── highlighter.h
├── images
├── activity.png
├── background.png
├── closeconnect.png
├── columns.png
├── copy.png
├── createindex.png
├── cut.png
├── database.png
├── delete.png
├── deleteindex.png
├── deleterow.png
├── displayindex.png
├── exit.png
├── find.png
├── icon.png
├── index.png
├── insertrow.png
├── isnull.png
├── key.png
├── new.png
├── newsqlfile.png
├── open.png
├── opentable.png
├── paste.png
├── primary.png
├── refresh.png
├── renametable.png
├── run.png
├── runsql.png
├── save.png
├── saveall.png
├── sqlfileopen.png
├── sqlfilesave.png
├── tableadd.png
├── tabledelete.png
├── tableedit.png
├── tablemultiple.png
├── trigger.png
└── view.png
├── importwizard.cpp
├── importwizard.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── modifytablefieldwidget.cpp
├── modifytablefieldwidget.h
├── mydockwidget.cpp
├── mydockwidget.h
├── mylistmodel.cpp
├── mylistmodel.h
├── newdialog.cpp
├── newdialog.h
├── newtablewidget.cpp
├── newtablewidgett.h
├── object_script.SQLiteDatabaseManage.Debug
├── object_script.SQLiteDatabaseManage.Release
├── qexcel.cpp
├── qexcel.h
├── qss
└── SQLite Database Manage.qss
├── querywidget.cpp
├── querywidget.h
├── sqltextedit.cpp
├── sqltextedit.h
├── systemtableview.cpp
├── systemtableview.h
├── tableview.cpp
├── tableview.h
├── tabwidget.cpp
├── tabwidget.h
├── translations
├── SQLiteDatabaseManage.qm
└── SQLiteDatabaseManage.ts
├── workthread.cpp
└── workthread.h
/bin/QtCore4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/QtCore4.dll
--------------------------------------------------------------------------------
/bin/QtGui4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/QtGui4.dll
--------------------------------------------------------------------------------
/bin/QtSql4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/QtSql4.dll
--------------------------------------------------------------------------------
/bin/QtXml4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/QtXml4.dll
--------------------------------------------------------------------------------
/bin/SQLiteDatabaseManage.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/SQLiteDatabaseManage.exe
--------------------------------------------------------------------------------
/bin/database/dbtest.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/database/dbtest.db
--------------------------------------------------------------------------------
/bin/libgcc_s_dw2-1.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/libgcc_s_dw2-1.dll
--------------------------------------------------------------------------------
/bin/mingwm10.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/mingwm10.dll
--------------------------------------------------------------------------------
/bin/sqldrivers/qsqlite4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/sqldrivers/qsqlite4.dll
--------------------------------------------------------------------------------
/bin/sqldrivers/qsqlodbc4.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/bin/sqldrivers/qsqlodbc4.dll
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | #############################################################################
2 | # Makefile for building: SQLiteDatabaseManage
3 | # Generated by qmake (2.01a) (Qt 4.8.1) on: ?? ?? 16 18:33:32 2014
4 | # Project: SQLiteDatabaseManage.pro
5 | # Template: app
6 | # Command: g:\qtsdk\desktop\qt\4.8.1\mingw\bin\qmake.exe -spec ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\win32-g++ CONFIG+=release -o Makefile SQLiteDatabaseManage.pro
7 | #############################################################################
8 |
9 | first: release
10 | install: release-install
11 | uninstall: release-uninstall
12 | MAKEFILE = Makefile
13 | QMAKE = g:\qtsdk\desktop\qt\4.8.1\mingw\bin\qmake.exe
14 | DEL_FILE = del
15 | CHK_DIR_EXISTS= if not exist
16 | MKDIR = mkdir
17 | COPY = copy /y
18 | COPY_FILE = $(COPY)
19 | COPY_DIR = xcopy /s /q /y /i
20 | INSTALL_FILE = $(COPY_FILE)
21 | INSTALL_PROGRAM = $(COPY_FILE)
22 | INSTALL_DIR = $(COPY_DIR)
23 | DEL_FILE = del
24 | SYMLINK =
25 | DEL_DIR = rmdir
26 | MOVE = move
27 | CHK_DIR_EXISTS= if not exist
28 | MKDIR = mkdir
29 | SUBTARGETS = \
30 | release \
31 | debug
32 |
33 | release: $(MAKEFILE).Release FORCE
34 | $(MAKE) -f $(MAKEFILE).Release
35 | release-make_default: $(MAKEFILE).Release FORCE
36 | $(MAKE) -f $(MAKEFILE).Release
37 | release-make_first: $(MAKEFILE).Release FORCE
38 | $(MAKE) -f $(MAKEFILE).Release first
39 | release-all: $(MAKEFILE).Release FORCE
40 | $(MAKE) -f $(MAKEFILE).Release all
41 | release-clean: $(MAKEFILE).Release FORCE
42 | $(MAKE) -f $(MAKEFILE).Release clean
43 | release-distclean: $(MAKEFILE).Release FORCE
44 | $(MAKE) -f $(MAKEFILE).Release distclean
45 | release-install: $(MAKEFILE).Release FORCE
46 | $(MAKE) -f $(MAKEFILE).Release install
47 | release-uninstall: $(MAKEFILE).Release FORCE
48 | $(MAKE) -f $(MAKEFILE).Release uninstall
49 | debug: $(MAKEFILE).Debug FORCE
50 | $(MAKE) -f $(MAKEFILE).Debug
51 | debug-make_default: $(MAKEFILE).Debug FORCE
52 | $(MAKE) -f $(MAKEFILE).Debug
53 | debug-make_first: $(MAKEFILE).Debug FORCE
54 | $(MAKE) -f $(MAKEFILE).Debug first
55 | debug-all: $(MAKEFILE).Debug FORCE
56 | $(MAKE) -f $(MAKEFILE).Debug all
57 | debug-clean: $(MAKEFILE).Debug FORCE
58 | $(MAKE) -f $(MAKEFILE).Debug clean
59 | debug-distclean: $(MAKEFILE).Debug FORCE
60 | $(MAKE) -f $(MAKEFILE).Debug distclean
61 | debug-install: $(MAKEFILE).Debug FORCE
62 | $(MAKE) -f $(MAKEFILE).Debug install
63 | debug-uninstall: $(MAKEFILE).Debug FORCE
64 | $(MAKE) -f $(MAKEFILE).Debug uninstall
65 |
66 | Makefile: SQLiteDatabaseManage.pro ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/win32-g++/qmake.conf ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/qconfig.pri \
67 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/modules/qt_webkit_version.pri \
68 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/qt_functions.prf \
69 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/qt_config.prf \
70 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/exclusive_builds.prf \
71 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/default_pre.prf \
72 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/default_pre.prf \
73 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/release.prf \
74 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/debug_and_release.prf \
75 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/default_post.prf \
76 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/default_post.prf \
77 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/qaxcontainer.prf \
78 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/rtti.prf \
79 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/exceptions.prf \
80 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/stl.prf \
81 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/shared.prf \
82 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/warn_on.prf \
83 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/qt.prf \
84 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/thread.prf \
85 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/moc.prf \
86 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/win32/windows.prf \
87 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/resources.prf \
88 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/uic.prf \
89 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/yacc.prf \
90 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/lex.prf \
91 | ../../../QtSDK/Desktop/Qt/4.8.1/mingw/mkspecs/features/include_source_dir.prf \
92 | g:/QtSDK/Desktop/Qt/4.8.1/mingw/lib/qtmain.prl \
93 | g:/QtSDK/Desktop/Qt/4.8.1/mingw/lib/QAxContainer.prl
94 | $(QMAKE) -spec ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\win32-g++ CONFIG+=release -o Makefile SQLiteDatabaseManage.pro
95 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\qconfig.pri:
96 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\modules\qt_webkit_version.pri:
97 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\qt_functions.prf:
98 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\qt_config.prf:
99 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\exclusive_builds.prf:
100 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\default_pre.prf:
101 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\default_pre.prf:
102 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\release.prf:
103 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\debug_and_release.prf:
104 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\default_post.prf:
105 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\default_post.prf:
106 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\qaxcontainer.prf:
107 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\rtti.prf:
108 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\exceptions.prf:
109 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\stl.prf:
110 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\shared.prf:
111 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\warn_on.prf:
112 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\qt.prf:
113 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\thread.prf:
114 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\moc.prf:
115 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\win32\windows.prf:
116 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\resources.prf:
117 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\uic.prf:
118 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\yacc.prf:
119 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\lex.prf:
120 | ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\features\include_source_dir.prf:
121 | g:\QtSDK\Desktop\Qt\4.8.1\mingw\lib\qtmain.prl:
122 | g:\QtSDK\Desktop\Qt\4.8.1\mingw\lib\QAxContainer.prl:
123 | qmake: qmake_all FORCE
124 | @$(QMAKE) -spec ..\..\..\QtSDK\Desktop\Qt\4.8.1\mingw\mkspecs\win32-g++ CONFIG+=release -o Makefile SQLiteDatabaseManage.pro
125 |
126 | qmake_all: FORCE
127 |
128 | make_default: release-make_default debug-make_default FORCE
129 | make_first: release-make_first debug-make_first FORCE
130 | all: release-all debug-all FORCE
131 | clean: release-clean debug-clean FORCE
132 | distclean: release-distclean debug-distclean FORCE
133 | -$(DEL_FILE) Makefile
134 |
135 | check: first
136 |
137 | release-mocclean: $(MAKEFILE).Release
138 | $(MAKE) -f $(MAKEFILE).Release mocclean
139 | debug-mocclean: $(MAKEFILE).Debug
140 | $(MAKE) -f $(MAKEFILE).Debug mocclean
141 | mocclean: release-mocclean debug-mocclean
142 |
143 | release-mocables: $(MAKEFILE).Release
144 | $(MAKE) -f $(MAKEFILE).Release mocables
145 | debug-mocables: $(MAKEFILE).Debug
146 | $(MAKE) -f $(MAKEFILE).Debug mocables
147 | mocables: release-mocables debug-mocables
148 | FORCE:
149 |
150 | $(MAKEFILE).Release: Makefile
151 | $(MAKEFILE).Debug: Makefile
152 |
--------------------------------------------------------------------------------
/src/SQLiteDatabaseManage.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2012-03-23T14:09:02
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | TARGET = SQLiteDatabaseManage
10 | TEMPLATE = app
11 | CONFIG += qaxcontainer
12 |
13 | SOURCES += main.cpp\
14 | mainwindow.cpp \
15 | newdialog.cpp \
16 | tabwidget.cpp \
17 | finddialog.cpp \
18 | codeeditor.cpp \
19 | newtablewidget.cpp \
20 | datatypedelegate.cpp \
21 | highlighter.cpp \
22 | mydockwidget.cpp \
23 | exportwizard.cpp \
24 | querywidget.cpp \
25 | tableview.cpp \
26 | systemtableview.cpp \
27 | modifytablefieldwidget.cpp \
28 | createindexwidget.cpp \
29 | importwizard.cpp \
30 | mylistmodel.cpp \
31 | workthread.cpp
32 |
33 | HEADERS += mainwindow.h \
34 | newdialog.h \
35 | tabwidget.h \
36 | finddialog.h \
37 | codeeditor.h \
38 | newtablewidgett.h \
39 | datatypedelegate.h \
40 | highlighter.h \
41 | mydockwidget.h \
42 | exportwizard.h \
43 | querywidget.h \
44 | tableview.h \
45 | systemtableview.h \
46 | modifytablefieldwidget.h \
47 | createindexwidget.h \
48 | importwizard.h \
49 | mylistmodel.h \
50 | workthread.h
51 |
52 | RESOURCES += \
53 | SQLiteDatabaseManage.qrc
54 |
55 | QT += sql
56 |
57 | QT += xml
58 |
59 | TRANSLATIONS = SQLiteDatabaseManage.ts
60 |
--------------------------------------------------------------------------------
/src/SQLiteDatabaseManage.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/new.png
4 | images/open.png
5 | images/cut.png
6 | images/copy.png
7 | images/paste.png
8 | images/save.png
9 | images/icon.png
10 | images/run.png
11 | images/find.png
12 | images/isnull.png
13 | images/sqlfileopen.png
14 | images/sqlfilesave.png
15 | images/tableadd.png
16 | images/tabledelete.png
17 | images/exit.png
18 | images/delete.png
19 | images/deleterow.png
20 | images/insertrow.png
21 | images/renametable.png
22 | images/tableedit.png
23 | images/opentable.png
24 | images/database.png
25 | images/tablemultiple.png
26 | images/index.png
27 | images/createindex.png
28 | images/closeconnect.png
29 | images/deleteindex.png
30 | images/displayindex.png
31 | images/primary.png
32 | images/newsqlfile.png
33 | images/columns.png
34 | images/trigger.png
35 | images/saveall.png
36 | images/refresh.png
37 | images/runsql.png
38 | images/view.png
39 | images/key.png
40 | translations/SQLiteDatabaseManage.qm
41 | qss/SQLite Database Manage.qss
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/codeeditor.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of the examples of the Qt Toolkit.
8 | **
9 | ** $QT_BEGIN_LICENSE:BSD$
10 | ** You may use this file under the terms of the BSD license as follows:
11 | **
12 | ** "Redistribution and use in source and binary forms, with or without
13 | ** modification, are permitted provided that the following conditions are
14 | ** met:
15 | ** * Redistributions of source code must retain the above copyright
16 | ** notice, this list of conditions and the following disclaimer.
17 | ** * Redistributions in binary form must reproduce the above copyright
18 | ** notice, this list of conditions and the following disclaimer in
19 | ** the documentation and/or other materials provided with the
20 | ** distribution.
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 | ** the names of its contributors may be used to endorse or promote
23 | ** products derived from this software without specific prior written
24 | ** permission.
25 | **
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 | ** $QT_END_LICENSE$
38 | **
39 | ****************************************************************************/
40 |
41 | #include
42 |
43 | #include "codeeditor.h"
44 | #include "mainwindow.h"
45 | #include "mylistmodel.h"
46 | #include
47 |
48 |
49 | //![constructor]
50 |
51 | CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent), font("", 11)
52 | {
53 | lineNumberArea = new LineNumberArea(this);
54 |
55 | listView = new MyListView(parent);
56 | listView->resize(180, 140);
57 | // listView->setMaximumWidth(500);
58 | listView->setIconSize(QSize(13, 13));
59 | // listView->setHidden(true);
60 | listView->setVisible(false);
61 |
62 | // sourceModel = new QStringListModel(this);
63 | // setSourceList();
64 | // sourceModel->setStringList(sourceList);
65 |
66 | listModel = new MyListModel(this);
67 |
68 | proxyModel = new QSortFilterProxyModel(this);
69 | // proxyModel->setSourceModel(sourceModel);
70 | proxyModel->setSourceModel(listModel);
71 | proxyModel->setFilterKeyColumn(0);
72 |
73 | listView->setModel(proxyModel);
74 | listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
75 |
76 | connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
77 | connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
78 | connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
79 |
80 | connect(document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(textChanged(int,int,int)));
81 | connect(listView, SIGNAL(inputChanged(QKeyEvent*)), this, SLOT(keyPressEvent(QKeyEvent*)));
82 |
83 | updateLineNumberAreaWidth(0);
84 | highlightCurrentLine();
85 | }
86 |
87 | CodeEditor::~CodeEditor()
88 | {
89 | delete listView;
90 | delete listModel;
91 | delete proxyModel;
92 | }
93 |
94 | //![constructor]
95 |
96 | //![extraAreaWidth]
97 |
98 | int CodeEditor::lineNumberAreaWidth()
99 | {
100 | int digits = 1;
101 | int max = qMax(1, blockCount());
102 | while (max >= 10) {
103 | max /= 10;
104 | ++digits;
105 | }
106 |
107 | int space = 18 + fontMetrics().width(QLatin1Char('9')) * digits;
108 |
109 | return space;
110 | }
111 |
112 | //![extraAreaWidth]
113 |
114 | //![slotUpdateExtraAreaWidth]
115 |
116 | void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
117 | {
118 | setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
119 | }
120 |
121 | //![slotUpdateExtraAreaWidth]
122 |
123 | //![slotUpdateRequest]
124 |
125 | void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
126 | {
127 | if (dy)
128 | lineNumberArea->scroll(0, dy);
129 | else
130 | lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
131 |
132 | if (rect.contains(viewport()->rect()))
133 | updateLineNumberAreaWidth(0);
134 | }
135 |
136 | //![slotUpdateRequest]
137 |
138 | //![resizeEvent]
139 |
140 | void CodeEditor::resizeEvent(QResizeEvent *e)
141 | {
142 | QPlainTextEdit::resizeEvent(e);
143 |
144 | QRect cr = contentsRect();
145 | lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
146 | }
147 |
148 | //![resizeEvent]
149 |
150 | //![cursorPositionChanged]
151 |
152 | void CodeEditor::highlightCurrentLine()
153 | {
154 | QList extraSelections;
155 |
156 | if (!isReadOnly()) {
157 | QTextEdit::ExtraSelection selection;
158 |
159 | QColor lineColor = QColor(Qt::yellow).lighter(160);
160 |
161 | selection.format.setBackground(lineColor);
162 | selection.format.setProperty(QTextFormat::FullWidthSelection, true);
163 | selection.cursor = textCursor();
164 | selection.cursor.clearSelection();
165 | extraSelections.append(selection);
166 | }
167 |
168 | setExtraSelections(extraSelections);
169 | }
170 |
171 | //![cursorPositionChanged]
172 |
173 | //![extraAreaPaintEvent_0]
174 |
175 | void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
176 | {
177 | QPainter painter(lineNumberArea);
178 | painter.setFont(font);
179 | painter.fillRect(event->rect(), Qt::lightGray);
180 |
181 | //![extraAreaPaintEvent_0]
182 |
183 | //![extraAreaPaintEvent_1]
184 | QTextBlock block = firstVisibleBlock();
185 | int blockNumber = block.blockNumber();
186 | int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
187 | int bottom = top + (int) blockBoundingRect(block).height();
188 | //![extraAreaPaintEvent_1]
189 |
190 | //![extraAreaPaintEvent_2]
191 | while (block.isValid() && top <= event->rect().bottom()) {
192 | if (block.isVisible() && bottom >= event->rect().top()) {
193 | QString number = QString::number(blockNumber + 1);
194 | painter.setPen(Qt::black);
195 | painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
196 | Qt::AlignHCenter, number);
197 | }
198 |
199 | block = block.next();
200 | top = bottom;
201 | bottom = top + (int) blockBoundingRect(block).height();
202 | ++blockNumber;
203 | }
204 | }
205 | //![extraAreaPaintEvent_2]
206 |
207 | void CodeEditor::keyPressEvent(QKeyEvent *e)
208 | {
209 | int key = e->key();
210 |
211 | if (!listView->isHidden())
212 | {
213 | // listView->activateWindow();
214 | // qDebug() << listView->isActiveWindow();
215 | // listView->setFocus();
216 | QString s;
217 | int i, len;
218 | QTextCursor t;
219 | QModelIndex index;
220 | switch (key)
221 | {
222 | case Qt::Key_Return :
223 | case Qt::Key_Enter :
224 | s = listView->currentIndex().data(Qt::DisplayRole).toString();
225 | t = textCursor();
226 | i = begin;
227 | len = end - begin - 1;
228 |
229 | t.setPosition(i + 1);
230 |
231 | t.insertText(s);
232 | for (i = 0; i < len; ++i)
233 | t.deleteChar();
234 |
235 | setTextCursor(t);
236 |
237 | listView->hide();
238 | setFocus();
239 | break;
240 | case Qt::Key_Down :
241 | i = listView->currentIndex().row() + 1;
242 | if (i == proxyModel->rowCount())
243 | index = proxyModel->index(0, 0);
244 | else
245 | index = proxyModel->index(i, 0);
246 | listView->setCurrentIndex(index);
247 | break;
248 | case Qt::Key_Up :
249 | i = listView->currentIndex().row() - 1;
250 | // qDebug() << i << proxyModel->rowCount();
251 | if (i == -1)
252 | index = proxyModel->index(proxyModel->rowCount() - 1, 0);
253 | else
254 | index = proxyModel->index(i, 0);
255 | listView->setCurrentIndex(index);
256 | break;
257 | // case Qt::Key_Delete :
258 | case Qt::Key_Space :
259 | case Qt::Key_Backspace :
260 | case Qt::Key_Left :
261 | case Qt::Key_Right :
262 | listView->hide();
263 | default :
264 | // listView->clearFocus();
265 | // setFocus();
266 | // qDebug() << key;
267 | QPlainTextEdit::keyPressEvent(e);
268 | }
269 | }
270 | else
271 | QPlainTextEdit::keyPressEvent(e);
272 | }
273 |
274 | void CodeEditor::setSourceList()
275 | {
276 | }
277 |
278 | void CodeEditor::addString(const QSet &str)
279 | {
280 | // sourceList.clear();
281 | // setSourceList();
282 | // sourceList.append(strList);
283 | // sourceModel->setStringList(sourceList);
284 |
285 | listModel->setCurrentSet(str);
286 | proxyModel->setSourceModel(listModel);
287 | }
288 |
289 |
290 | void CodeEditor::textChanged(int position, int charsRemoved, int charsAdded)
291 | {
292 | if (!MainWindow::getCurrentAssociate())
293 | return;
294 |
295 | if (charsRemoved > charsAdded)
296 | return;
297 | // if (sqlCodeEditor->toPlainText() == "select * from")
298 | // {
299 | QString text = toPlainText();
300 | if (text[position] == ' ')
301 | return;
302 | // qDebug() << position << charsRemoved << charsAdded;
303 | // qDebug() << sqlCodeEditor->document()->characterAt(position);
304 | // qDebug() << sqlCodeEditor->document()->characterAt(position).unicode();
305 | // qDebug() << text[position];
306 | // qDebug() << text << position;
307 |
308 | for (begin = position - 1; begin >= 0; --begin)
309 | {
310 | if (text[begin] == ' ' || text[begin] == '\n' || text[begin] == ','
311 | || text[begin] == ';' || text[begin] == '(')
312 | break;
313 | }
314 |
315 | for (end = position; end <= document()->characterCount(); ++end)
316 | {
317 | if (text[end] == ' ' || text[end] == '\n'
318 | || text[end] == ';' || text[end] == ')')
319 | break;
320 | }
321 | QString temp = text.mid(begin + 1, end - begin - 1);
322 | // qDebug() << temp << begin << end;
323 |
324 | if (listModel->isMatch(temp))
325 | {
326 | // qDebug() << "1";
327 | listView->hide();
328 | return;
329 | }
330 |
331 | QRegExp regExp("\\b" + temp, Qt::CaseInsensitive);
332 | // if (regExp.captureCount() == 0)
333 | // {
334 | // qDebug() << regExp.capturedTexts();
335 | // listView->hide();
336 | // return;
337 | // }
338 |
339 | proxyModel->setFilterRegExp(regExp);
340 |
341 | int count = proxyModel->rowCount();
342 | if (count == 0 || count == listModel->count())
343 | {
344 | listView->hide();
345 | return;
346 | }
347 |
348 | QRect rect = cursorRect();
349 | // QRect rect = viewport()->rect();
350 | // QTextCursor testCursor = textCursor();
351 | // qDebug() << listView->spacing();
352 | // if (count < 10)
353 | //listView->resize(180, count * (listView->fontMetrics().height() + 7));
354 | // else
355 | // listView->resize(listView->width(), listView->sizeHint().height());
356 | // int y = pos().y();
357 | // int x = pos().x();
358 | QTextCursor tc = textCursor();
359 | // qDebug() << tc.blockNumber() << tc.positionInBlock() << rect.x() << rect.y();
360 | // int x = 4 + tc.positionInBlock() * 7 + 50;
361 | // int y = 4 + tc.blockNumber() * 15 + 66;
362 | int x = tc.positionInBlock() * 7 + 54;
363 | int y = rect.y() + 66;
364 | listView->move(x, y);
365 | // listView->move(rect.x() + 50, rect.y() + 66);
366 | // listView->move(rect.y() / 15 * 7 + 41 + x, y + rect.y() + 50);
367 | listView->show();
368 | listView->setCurrentIndex(proxyModel->index(0, 0));
369 | // listView->activateWindow();
370 | listView->setFocus();
371 | // listView->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
372 | // listView->topLevelWidget();
373 | // listView->raise();
374 | }
375 |
376 |
377 |
378 |
379 | MyListView::MyListView(QWidget *parent) : QListView(parent)
380 | {
381 | setSpacing(1);
382 | }
383 |
384 | void MyListView::keyPressEvent(QKeyEvent *event)
385 | {
386 | emit inputChanged(event);
387 | }
388 |
389 |
--------------------------------------------------------------------------------
/src/codeeditor.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of the examples of the Qt Toolkit.
8 | **
9 | ** $QT_BEGIN_LICENSE:BSD$
10 | ** You may use this file under the terms of the BSD license as follows:
11 | **
12 | ** "Redistribution and use in source and binary forms, with or without
13 | ** modification, are permitted provided that the following conditions are
14 | ** met:
15 | ** * Redistributions of source code must retain the above copyright
16 | ** notice, this list of conditions and the following disclaimer.
17 | ** * Redistributions in binary form must reproduce the above copyright
18 | ** notice, this list of conditions and the following disclaimer in
19 | ** the documentation and/or other materials provided with the
20 | ** distribution.
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 | ** the names of its contributors may be used to endorse or promote
23 | ** products derived from this software without specific prior written
24 | ** permission.
25 | **
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 | ** $QT_END_LICENSE$
38 | **
39 | ****************************************************************************/
40 |
41 | #ifndef CODEEDITOR_H
42 | #define CODEEDITOR_H
43 |
44 | #include "mylistmodel.h"
45 | #include
46 | #include
47 | #include
48 |
49 | QT_BEGIN_NAMESPACE
50 | class QPaintEvent;
51 | class QResizeEvent;
52 | class QSize;
53 | class QWidget;
54 | class MyListView;
55 | class QStringListModel;
56 | class QSortFilterProxyModel;
57 | QT_END_NAMESPACE
58 |
59 | class LineNumberArea;
60 |
61 | //![codeeditordefinition]
62 |
63 | class CodeEditor : public QPlainTextEdit
64 | {
65 | Q_OBJECT
66 |
67 | public:
68 | CodeEditor(QWidget *parent = 0);
69 | ~CodeEditor();
70 |
71 | void lineNumberAreaPaintEvent(QPaintEvent *event);
72 | int lineNumberAreaWidth();
73 | void addString(const QSet &str);
74 |
75 | protected:
76 | void resizeEvent(QResizeEvent *event);
77 |
78 | protected slots:
79 | void keyPressEvent(QKeyEvent *e);
80 |
81 | private slots:
82 | void updateLineNumberAreaWidth(int newBlockCount);
83 | void highlightCurrentLine();
84 | void updateLineNumberArea(const QRect &, int);
85 |
86 | void textChanged(int, int, int);
87 |
88 | private:
89 | void setSourceList();
90 |
91 | private:
92 | QWidget *lineNumberArea;
93 | QFont font;
94 |
95 | MyListView *listView;
96 | MyListModel *listModel;
97 | // QStringListModel *sourceModel;
98 | QSortFilterProxyModel *proxyModel;
99 | // QStringList sourceList;
100 |
101 | int begin;
102 | int end;
103 | };
104 |
105 | //![codeeditordefinition]
106 | //![extraarea]
107 |
108 | class LineNumberArea : public QWidget
109 | {
110 | public:
111 | LineNumberArea(CodeEditor *editor) : QWidget(editor) {
112 | codeEditor = editor;
113 | }
114 |
115 | QSize sizeHint() const {
116 | return QSize(codeEditor->lineNumberAreaWidth(), 0);
117 | }
118 |
119 | protected:
120 | void paintEvent(QPaintEvent *event) {
121 | codeEditor->lineNumberAreaPaintEvent(event);
122 | }
123 |
124 | private:
125 | CodeEditor *codeEditor;
126 | };
127 |
128 | //![extraarea]
129 |
130 | class MyListView : public QListView
131 | {
132 | Q_OBJECT
133 |
134 | public:
135 | MyListView(QWidget *parent = 0);
136 |
137 | signals:
138 | void inputChanged(QKeyEvent *event);
139 |
140 | protected:
141 | void keyPressEvent(QKeyEvent *event);
142 | };
143 |
144 | #endif
145 |
--------------------------------------------------------------------------------
/src/createindexwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "createindexwidget.h"
2 | #include "datatypedelegate.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | CreateIndexWidget::CreateIndexWidget(const QString &cName, const QString &tName,
17 | QWidget *parent) :
18 | QWidget(parent), connectName(cName), tableName(tName)
19 | {
20 | typeList << tr("Ascending") << tr("Descending");
21 |
22 | tableWidget = new QTableWidget;
23 | QHBoxLayout *topLayout = new QHBoxLayout;
24 | topLayout->addWidget(tableWidget);
25 | QGroupBox *groupBox = new QGroupBox(tableName);
26 | groupBox->setLayout(topLayout);
27 |
28 | indexNameLabel = new QLabel(tr("In&dex Name:"));
29 | indexNameLineEdit = new QLineEdit;
30 | indexNameLabel->setBuddy(indexNameLineEdit);
31 | QRegExp regExp("[A-Za-z].*");
32 | indexNameLineEdit->setValidator(new QRegExpValidator(regExp, this));
33 | createButton = new QPushButton(tr("Create"));
34 | createButton->setEnabled(false);
35 |
36 | QHBoxLayout *hboxLayout = new QHBoxLayout;
37 | hboxLayout->addWidget(indexNameLabel);
38 | hboxLayout->addWidget(indexNameLineEdit);
39 | hboxLayout->addStretch();
40 | hboxLayout->addWidget(createButton);
41 |
42 | createInformation = new QPlainTextEdit;
43 | createInformation->setReadOnly(true);
44 | // createInformation->setMaximumHeight(100);
45 | QHBoxLayout *bottomLayout = new QHBoxLayout;
46 | bottomLayout->addWidget(createInformation);
47 | QGroupBox *resultBox = new QGroupBox(tr("Result"));
48 | resultBox->setLayout(bottomLayout);
49 | resultBox->setMaximumHeight(200);
50 |
51 | QVBoxLayout *mainLayout = new QVBoxLayout;
52 | mainLayout->addWidget(groupBox);
53 | mainLayout->addLayout(hboxLayout);
54 | mainLayout->addWidget(resultBox);
55 |
56 | setLayout(mainLayout);
57 |
58 | setTableWidget();
59 |
60 | // setWindowTitle(tr("Create Index"));
61 |
62 | // resize(570, 410);
63 |
64 | connect(indexNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(lineEditChanged(const QString&)));
65 | connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem*)));
66 | connect(createButton, SIGNAL(clicked()), this, SLOT(createButtonClicked()));
67 | }
68 |
69 | void CreateIndexWidget::setTableWidget()
70 | {
71 | DataTypeDelegate *dataTypeDelegate = new DataTypeDelegate(1, 2, 3);
72 | dataTypeDelegate->setComboBoxItem(typeList);
73 | tableWidget->setItemDelegate(dataTypeDelegate);
74 | tableWidget->setColumnCount(4);
75 | tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Field")
76 | << tr("Asc/Desc") << tr("Primary")
77 | << tr("IsUse"));
78 | tableWidget->setColumnHidden(2, true);
79 | QSqlDatabase db = QSqlDatabase::database(connectName);
80 | QSqlRecord record = db.record(tableName);
81 | tableWidget->setRowCount(record.count());
82 | for (int i = 0; i < record.count(); ++i)
83 | {
84 | QString fieldName = record.fieldName(i);
85 | QTableWidgetItem *item = new QTableWidgetItem(fieldName);
86 | tableWidget->setItem(i, 0, item);
87 | }
88 |
89 | // tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
90 | }
91 |
92 | void CreateIndexWidget::lineEditChanged(const QString &str)
93 | {
94 | somethingChanged(str);
95 | }
96 |
97 | void CreateIndexWidget::tableItemChanged(QTableWidgetItem*)
98 | {
99 | QString str = indexNameLineEdit->text();
100 | somethingChanged(str);
101 | }
102 |
103 | void CreateIndexWidget::somethingChanged(const QString &str)
104 | {
105 | bool b = false;
106 | for (int i = 0; i < tableWidget->rowCount(); ++i)
107 | {
108 | QTableWidgetItem *item = tableWidget->item(i, 3);
109 | QTableWidgetItem *typeItem = tableWidget->item(i, 1);
110 | if (item && typeItem && item->data(Qt::DisplayRole).toBool() && !typeItem->text().isEmpty())
111 | {
112 | b = true;
113 | break;
114 | }
115 | }
116 | createButton->setEnabled(!str.isEmpty() && b);
117 | }
118 |
119 | void CreateIndexWidget::createButtonClicked()
120 | {
121 | QString str = tr("create index %1 on %2 (").arg(indexNameLineEdit->text())
122 | .arg(tableName);
123 | for (int i = 0; i < tableWidget->rowCount(); ++i)
124 | {
125 | QTableWidgetItem *item = tableWidget->item(i, 3);
126 | QTableWidgetItem *typeItem = tableWidget->item(i, 1);
127 | if (item && typeItem && item->data(Qt::DisplayRole).toBool() && !typeItem->text().isEmpty())
128 | {
129 | str += tableWidget->item(i, 0)->text();
130 | str += " ";
131 | QString typeText = typeItem->text();
132 | if (typeText == "Ascending")
133 | str += "ASC";
134 | else
135 | str += "DESC";
136 |
137 | str += ",";
138 | }
139 | }
140 | int index = str.lastIndexOf(',');
141 | str.replace(index, 1, ')');
142 |
143 | QSqlDatabase db = QSqlDatabase::database(connectName);
144 | QSqlQuery query(db);
145 | query.exec(str);
146 | QString informationStr;
147 | informationStr = createInformation->toPlainText();
148 | if (query.isActive())
149 | {
150 | informationStr += tr("Index %1 created successfully.\n").arg(indexNameLineEdit->text());
151 | createInformation->setPlainText(informationStr);
152 | indexNameList.push_back(indexNameLineEdit->text());
153 | }
154 | else
155 | {
156 | informationStr += query.lastError().text();
157 | createInformation->setPlainText(informationStr + "\n");
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/src/createindexwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef CREATEINDEXWIDGET_H
2 | #define CREATEINDEXWIDGET_H
3 |
4 | #include
5 | class QTableWidget;
6 | class QLabel;
7 | class QLineEdit;
8 | class QPushButton;
9 | class CodeEditor;
10 | class QPlainTextEdit;
11 | class QTableWidgetItem;
12 |
13 | class CreateIndexWidget : public QWidget
14 | {
15 | Q_OBJECT
16 | public:
17 | explicit CreateIndexWidget(const QString &cName, const QString &tName,
18 | QWidget *parent = 0);
19 |
20 | public:
21 | QStringList getIndexName() { return indexNameList; }
22 |
23 | private slots:
24 | void lineEditChanged(const QString&);
25 | void tableItemChanged(QTableWidgetItem*);
26 | void createButtonClicked();
27 |
28 | private:
29 | void setTableWidget();
30 | void somethingChanged(const QString &str);
31 |
32 | private:
33 | QString connectName;
34 | QString tableName;
35 | QStringList typeList;
36 | QStringList indexNameList;
37 |
38 | QTableWidget *tableWidget;
39 | QLabel *indexNameLabel;
40 | QLineEdit *indexNameLineEdit;
41 | QPushButton *createButton;
42 | QPlainTextEdit *createInformation;
43 | };
44 |
45 | #endif // CREATEINDEXWIDGET_H
46 |
--------------------------------------------------------------------------------
/src/datatypedelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "datatypedelegate.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | DataTypeDelegate::DataTypeDelegate(int dataTypeColumn, int primary, int isNull, QObject *parent)
8 | : QItemDelegate(parent), primaryPixmap(QPixmap(":images/primary.png")), isNullPixmap(QPixmap(":images/isnull.png"))
9 | {
10 | this->dataTypeColumn = dataTypeColumn;
11 | this->primary = primary;
12 | this->isNull = isNull;
13 | typeList << tr("INTEGER") << tr("REAL")
14 | << tr("TEXT") << tr("BLOB");
15 | }
16 |
17 | void DataTypeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
18 | {
19 | if (index.column() == dataTypeColumn)
20 | {
21 | QString text = index.model()->data(index, Qt::DisplayRole).toString();
22 | drawDisplay(painter, option, option.rect, text);
23 | drawFocus(painter, option, option.rect);
24 | }
25 | else if (index.column() == isNull)
26 | {
27 | bool is = index.model()->data(index, Qt::DisplayRole).toBool();
28 | if (is)
29 | {
30 | int x = option.rect.x() + (option.rect.width() / 2) - (isNullPixmap.width() / 2);
31 | int y = option.rect.y() + (option.rect.height() / 2) - (isNullPixmap.height() / 2);
32 | painter->drawPixmap(x, y, isNullPixmap);
33 | }
34 | else
35 | painter->drawText(option.rect, "");
36 | }
37 | else if (index.column() == primary)
38 | {
39 | bool is = index.model()->data(index, Qt::DisplayRole).toBool();
40 | if (is)
41 | {
42 | int x = option.rect.x() + (option.rect.width() / 2) - (primaryPixmap.width() / 2);
43 | int y = option.rect.y() + (option.rect.height() / 2) - (primaryPixmap.height() / 2);
44 | painter->drawPixmap(x, y, primaryPixmap);
45 | }
46 | else
47 | painter->drawText(option.rect, "");
48 | }
49 | else
50 | {
51 | QItemDelegate::paint(painter, option, index);
52 | }
53 | }
54 |
55 | QWidget* DataTypeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
56 | {
57 | if (index.column() == dataTypeColumn)
58 | {
59 | QComboBox *comboBox = new QComboBox(parent);
60 | comboBox->addItems(typeList);
61 | QString text = index.data(Qt::DisplayRole).toString();
62 | int index = comboBox->findText(text);
63 | comboBox->setCurrentIndex(index);
64 | connect(comboBox, SIGNAL(editTextChanged(QString)), this, SLOT(comboBoxEditTextChanged()));
65 | return comboBox;
66 | }
67 | else
68 | {
69 | return QItemDelegate::createEditor(parent, option, index);
70 | }
71 | }
72 |
73 | void DataTypeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
74 | {
75 | if (index.column() == dataTypeColumn)
76 | {
77 | QString text = index.model()->data(index, Qt::DisplayRole).toString();
78 | QComboBox *comboBox = qobject_cast(editor);
79 | comboBox->setCurrentIndex(comboBox->findText(text));
80 | }
81 | else
82 | {
83 | QItemDelegate::setEditorData(editor, index);
84 | }
85 | }
86 |
87 | void DataTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
88 | {
89 | if (index.column() == dataTypeColumn)
90 | {
91 | QComboBox *comboBox = qobject_cast(editor);
92 | QString text = comboBox->currentText();
93 |
94 | model->setData(index, text);
95 | }
96 | else
97 | {
98 | QItemDelegate::setModelData(editor, model, index);
99 | }
100 | }
101 |
102 | bool DataTypeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
103 | {
104 | if (index.column() == 0 || index.column() == 1)
105 | return QItemDelegate::editorEvent(event, model, option, index);
106 |
107 | if (event->type() == QEvent::MouseButtonPress)
108 | {
109 | bool is = !model->data(index, Qt::DisplayRole).toBool();
110 | model->setData(index, is);
111 | // if (index.column() == 2 && is)
112 | // {
113 | // emit primaryChanged(index.row());
114 | // }
115 | return false; //so that the selection can change
116 | }
117 |
118 | return true;
119 | }
120 |
121 | void DataTypeDelegate::comboBoxEditTextChanged()
122 | {
123 | QComboBox *comboBox = qobject_cast(sender());
124 | emit commitData(comboBox);
125 | emit closeEditor(comboBox);
126 | }
127 |
--------------------------------------------------------------------------------
/src/datatypedelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef DATATYPEDELEGATE_H
2 | #define DATATYPEDELEGATE_H
3 |
4 | #include
5 |
6 |
7 | class DataTypeDelegate : public QItemDelegate
8 | {
9 | Q_OBJECT
10 |
11 | public:
12 | DataTypeDelegate(int dataTypeColumn, int primary, int isNull, QObject *parent = 0);
13 |
14 | void paint(QPainter *painter, const QStyleOptionViewItem &option,
15 | const QModelIndex &index) const;
16 | QWidget* createEditor(QWidget *parent,
17 | const QStyleOptionViewItem &option,
18 | const QModelIndex &index) const;
19 | void setEditorData(QWidget *editor, const QModelIndex &index) const;
20 | void setModelData(QWidget *editor, QAbstractItemModel *model,
21 | const QModelIndex &index) const;
22 |
23 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
24 |
25 | void setComboBoxItem(const QStringList &itemList) { typeList = itemList; }
26 |
27 | //signals:
28 | // void primaryChanged(int row);
29 |
30 | private slots:
31 | void comboBoxEditTextChanged();
32 |
33 | private:
34 | int dataTypeColumn;
35 | int primary;
36 | int isNull;
37 |
38 | QPixmap primaryPixmap;
39 | QPixmap isNullPixmap;
40 |
41 | QStringList typeList;
42 | };
43 |
44 | #endif // DATATYPEDELEGATE_H
45 |
--------------------------------------------------------------------------------
/src/exportwizard.h:
--------------------------------------------------------------------------------
1 | #ifndef EXPORTWIZARD_H
2 | #define EXPORTWIZARD_H
3 |
4 | #include
5 | class QLabel;
6 | class QLineEdit;
7 | class QComboBox;
8 | class QPushButton;
9 | class QGroupBox;
10 | class QRadioButton;
11 | class ExportInfoPage;
12 | class QSqlDatabase;
13 | class QListView;
14 | class MyStringListModel;
15 | class QProgressBar;
16 | class ImportWorkThread;
17 | class ExportFinishInfoPage;
18 | class ExportWorkThread;
19 | class ExportExcelWorkThread;
20 | class ExportTxtWorkThread;
21 | class ExportXmlWorkThread;
22 |
23 | class ExportWizard : public QWizard
24 | {
25 | Q_OBJECT
26 | public:
27 | explicit ExportWizard(const QMap &str, QWidget *parent = 0);
28 |
29 | public:
30 | void accept();
31 |
32 | public:
33 | enum
34 | {
35 | PageIntro,
36 | PageSourceInfo,
37 | PageTargetInfo,
38 | PageTargetTxtInfo,
39 | PageTargetXmlInfo,
40 | PageTargetExcelInfo,
41 | PageTargetAccessInfo,
42 | PageTargetSQLServerInfo,
43 | PageFinishInfo
44 | };
45 |
46 | private slots:
47 | void workFinish();
48 | void excelWorkFinish();
49 | void txtWorkFinish();
50 | void xmlWorkFinish();
51 | void setProgress(int);
52 |
53 | private:
54 | void exportData(QSqlDatabase &source, QSqlDatabase &target);
55 | void exportExcel(QSqlDatabase &source, const QString &target);
56 | void exportTxt(QSqlDatabase &source, const QString &directory);
57 | void exportXml(QSqlDatabase &source, const QString &directory);
58 |
59 | private:
60 | const QMap &strMap;
61 | ExportInfoPage *exportInfo;
62 | ExportFinishInfoPage *exportFinishInfo;
63 |
64 | ExportWorkThread *workThread;
65 | ExportExcelWorkThread *excelWorkThread;
66 | ExportTxtWorkThread *txtWorkThread;
67 | ExportXmlWorkThread *xmlWorkThread;
68 | };
69 |
70 | class ExportIntroPage : public QWizardPage
71 | {
72 | Q_OBJECT
73 |
74 | public:
75 | ExportIntroPage(QWidget *parent = 0);
76 |
77 | private:
78 | QLabel *label;
79 | };
80 |
81 | class ExportInfoPage : public QWizardPage
82 | {
83 | Q_OBJECT
84 |
85 | public:
86 | ExportInfoPage(const QMap &str, QWidget *parent = 0);
87 |
88 | public:
89 | void initializePage();
90 | QStringList getUseTableList() const;
91 | QString getSource() const;
92 |
93 | private slots:
94 | void databaseChanged(const QString &text);
95 | void selectAllClicked();
96 | void unselectAllClicked();
97 |
98 | private:
99 | QLabel *sourceDatabaseLabel;
100 | QComboBox *sourceDatabaseComcoBox;
101 | // QLabel *sourceTableLabel;
102 | // QComboBox *sourceTableComcoBox;
103 |
104 | QListView *listView;
105 | QPushButton *selectAllButton;
106 | QPushButton *unSelectAllButton;
107 | MyStringListModel *model;
108 |
109 | const QMap &strMap;
110 | };
111 |
112 | class ExportTragetInfoPage : public QWizardPage
113 | {
114 | Q_OBJECT
115 |
116 | public:
117 | ExportTragetInfoPage(QWidget *parent = 0);
118 |
119 | public:
120 | int nextId() const;
121 |
122 | private:
123 | QGroupBox *groupBox;
124 | QRadioButton *excelRadioButton;
125 | QRadioButton *xmlRadioButton;
126 | QRadioButton *txtRadioButton;
127 | QRadioButton *accessRadioButton;
128 | QRadioButton *sqlserverRadioButton;
129 | };
130 |
131 | class ExportTxtInfoPage : public QWizardPage
132 | {
133 | Q_OBJECT
134 |
135 | public:
136 | ExportTxtInfoPage(QWidget *parent = 0);
137 |
138 | public:
139 | int nextId() const;
140 |
141 | private slots:
142 | void selectPath();
143 |
144 | private:
145 | QLabel *targetLabel;
146 | QLineEdit *targetLineEdit;
147 | QPushButton *targetButton;
148 |
149 | QGroupBox *groupBox;
150 | QRadioButton *commaRadioButton;
151 | };
152 |
153 | class ExportXmlInfoPage : public QWizardPage
154 | {
155 | Q_OBJECT
156 |
157 | public:
158 | ExportXmlInfoPage(QWidget *parent = 0);
159 |
160 | public:
161 | int nextId() const;
162 |
163 | private slots:
164 | void selectPath();
165 |
166 | private:
167 | QLabel *targetLabel;
168 | QLineEdit *targetLineEdit;
169 | QPushButton *targetButton;
170 |
171 | };
172 |
173 | class ExportExcelInfoPage : public QWizardPage
174 | {
175 | Q_OBJECT
176 |
177 | public:
178 | ExportExcelInfoPage(QWidget *parent = 0);
179 |
180 | public:
181 | int nextId() const;
182 |
183 | private slots:
184 | void selectPath();
185 |
186 | private:
187 | QLabel *targetLabel;
188 | QLineEdit *targetLineEdit;
189 | QPushButton *targetButton;
190 | };
191 |
192 | class ExportAccessInfoPage : public QWizardPage
193 | {
194 | Q_OBJECT
195 |
196 | public:
197 | ExportAccessInfoPage(QWidget *parent = 0);
198 |
199 | int nextId() const;
200 |
201 | private slots:
202 | void selectPath();
203 |
204 | private:
205 | QLabel *targetLabel;
206 | QLineEdit *targetLineEdit;
207 | QPushButton *targetButton;
208 | };
209 |
210 | class ExportSQLServerInfoPage : public QWizardPage
211 | {
212 | Q_OBJECT
213 |
214 | public:
215 | ExportSQLServerInfoPage(QWidget *parent = 0);
216 |
217 | public:
218 | int nextId() const;
219 |
220 | private slots:
221 | void testConnect();
222 |
223 | private:
224 | QLabel *databaseNameLabel;
225 | QLineEdit *databaseNameLineEdit;
226 | QLabel *hostNameLabel;
227 | QLineEdit *hostNameLineEdit;
228 | QLabel *userNameLabel;
229 | QLineEdit *userNameLineEdit;
230 | QLabel *passwordLabel;
231 | QLineEdit *passwordLineEdit;
232 | QLabel *portLabel;
233 | QLineEdit *portLineEdit;
234 |
235 | QPushButton *testConnectButton;
236 | };
237 |
238 | class ExportFinishInfoPage : public QWizardPage
239 | {
240 | Q_OBJECT
241 |
242 | public:
243 | ExportFinishInfoPage(QWidget *parent = 0);
244 |
245 | public:
246 | void initializePage();
247 |
248 | public:
249 | QProgressBar *progressBar;
250 | };
251 |
252 | #endif // EXPORTWIZARD_H
253 |
--------------------------------------------------------------------------------
/src/finddialog.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "finddialog.h"
4 |
5 | FindDialog::FindDialog(QWidget *parent)
6 | : QDialog(parent)
7 | {
8 | label = new QLabel(tr("Find &what:"));
9 | lineEdit = new QLineEdit;
10 | label->setBuddy(lineEdit);
11 |
12 | caseCheckBox = new QCheckBox(tr("Match &case"));
13 | backwardCheckBox = new QCheckBox(tr("Search &backward"));
14 |
15 | findButton = new QPushButton(tr("&Find"));
16 | findButton->setDefault(true);
17 | findButton->setEnabled(false);
18 |
19 | closeButton = new QPushButton(tr("Close"));
20 |
21 | connect(lineEdit, SIGNAL(textChanged(const QString &)),
22 | this, SLOT(enableFindButton(const QString &)));
23 | connect(findButton, SIGNAL(clicked()),
24 | this, SLOT(findClicked()));
25 | connect(closeButton, SIGNAL(clicked()),
26 | this, SLOT(close()));
27 |
28 | QHBoxLayout *topLeftLayout = new QHBoxLayout;
29 | topLeftLayout->addWidget(label);
30 | topLeftLayout->addWidget(lineEdit);
31 |
32 | QVBoxLayout *leftLayout = new QVBoxLayout;
33 | leftLayout->addLayout(topLeftLayout);
34 | leftLayout->addWidget(caseCheckBox);
35 | leftLayout->addWidget(backwardCheckBox);
36 |
37 | QVBoxLayout *rightLayout = new QVBoxLayout;
38 | rightLayout->addWidget(findButton);
39 | rightLayout->addWidget(closeButton);
40 | rightLayout->addStretch();
41 |
42 | QHBoxLayout *mainLayout = new QHBoxLayout;
43 | mainLayout->addLayout(leftLayout);
44 | mainLayout->addLayout(rightLayout);
45 | setLayout(mainLayout);
46 |
47 | setWindowTitle(tr("Find"));
48 | setFixedHeight(sizeHint().height());
49 | }
50 |
51 | void FindDialog::findClicked()
52 | {
53 | QString text = lineEdit->text();
54 | Qt::CaseSensitivity cs =
55 | caseCheckBox->isChecked() ? Qt::CaseSensitive
56 | : Qt::CaseInsensitive;
57 | if (backwardCheckBox->isChecked()) {
58 | emit findPrevious(text, cs);
59 | } else {
60 | emit findNext(text, cs);
61 | }
62 | }
63 |
64 | void FindDialog::enableFindButton(const QString &text)
65 | {
66 | findButton->setEnabled(!text.isEmpty());
67 | }
68 |
--------------------------------------------------------------------------------
/src/finddialog.h:
--------------------------------------------------------------------------------
1 | #ifndef FINDDIALOG_H
2 | #define FINDDIALOG_H
3 |
4 | #include
5 |
6 | class QCheckBox;
7 | class QLabel;
8 | class QLineEdit;
9 | class QPushButton;
10 |
11 | class FindDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | FindDialog(QWidget *parent = 0);
17 |
18 | signals:
19 | void findNext(const QString &str, Qt::CaseSensitivity cs);
20 | void findPrevious(const QString &str, Qt::CaseSensitivity cs);
21 |
22 | private slots:
23 | void findClicked();
24 | void enableFindButton(const QString &text);
25 |
26 | private:
27 | QLabel *label;
28 | QLineEdit *lineEdit;
29 | QCheckBox *caseCheckBox;
30 | QCheckBox *backwardCheckBox;
31 | QPushButton *findButton;
32 | QPushButton *closeButton;
33 | };
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/src/highlighter.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of the examples of the Qt Toolkit.
8 | **
9 | ** $QT_BEGIN_LICENSE:BSD$
10 | ** You may use this file under the terms of the BSD license as follows:
11 | **
12 | ** "Redistribution and use in source and binary forms, with or without
13 | ** modification, are permitted provided that the following conditions are
14 | ** met:
15 | ** * Redistributions of source code must retain the above copyright
16 | ** notice, this list of conditions and the following disclaimer.
17 | ** * Redistributions in binary form must reproduce the above copyright
18 | ** notice, this list of conditions and the following disclaimer in
19 | ** the documentation and/or other materials provided with the
20 | ** distribution.
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 | ** the names of its contributors may be used to endorse or promote
23 | ** products derived from this software without specific prior written
24 | ** permission.
25 | **
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 | ** $QT_END_LICENSE$
38 | **
39 | ****************************************************************************/
40 |
41 | #include "highlighter.h"
42 | #include
43 | #include
44 | #include
45 |
46 | //! [0]
47 | Highlighter::Highlighter(QTextDocument *parent)
48 | : QSyntaxHighlighter(parent)
49 | {
50 | initialization();
51 | initializationKeyWord();
52 | }
53 | //! [6]
54 |
55 | //! [7]
56 | void Highlighter::highlightBlock(const QString &text)
57 | {
58 | foreach (const HighlightingRule &rule, highlightingRules) {
59 | QRegExp expression(rule.pattern);
60 | int index = expression.indexIn(text);
61 | while (index >= 0) {
62 | int length = expression.matchedLength();
63 | setFormat(index, length, rule.format);
64 | index = expression.indexIn(text, index + length);
65 | }
66 | }
67 | //! [7] //! [8]
68 | setCurrentBlockState(0);
69 | //! [8]
70 |
71 | //! [9]
72 | int startIndex = 0;
73 | if (previousBlockState() != 1)
74 | startIndex = commentStartExpression.indexIn(text);
75 |
76 | //! [9] //! [10]
77 | while (startIndex >= 0) {
78 | //! [10] //! [11]
79 | int endIndex = commentEndExpression.indexIn(text, startIndex);
80 | int commentLength;
81 | if (endIndex == -1) {
82 | setCurrentBlockState(1);
83 | commentLength = text.length() - startIndex;
84 | } else {
85 | commentLength = endIndex - startIndex
86 | + commentEndExpression.matchedLength();
87 | }
88 | setFormat(startIndex, commentLength, multiLineCommentFormat);
89 | startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
90 | }
91 | }
92 | //! [11]
93 |
94 | void Highlighter::initialization()
95 | {
96 | HighlightingRule rule;
97 |
98 | singleLineCommentFormat.setForeground(Qt::red);
99 | rule.pattern = QRegExp("//[^\n]*");
100 | rule.format = singleLineCommentFormat;
101 | highlightingRules.append(rule);
102 |
103 | multiLineCommentFormat.setForeground(Qt::red);
104 | //! [3]
105 |
106 | //! [4]
107 | // quotationFormat.setForeground(Qt::darkGreen);
108 | // rule.pattern = QRegExp("\".*\"");
109 | // rule.format = quotationFormat;
110 | // highlightingRules.append(rule);
111 | //! [4]
112 |
113 | //! [5]
114 | // functionFormat.setFontItalic(true);
115 | // functionFormat.setForeground(Qt::blue);
116 | // rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
117 | // rule.format = functionFormat;
118 | // highlightingRules.append(rule);
119 | //! [5]
120 |
121 | //! [6]
122 | commentStartExpression = QRegExp("/\\*");
123 | commentEndExpression = QRegExp("\\*/");
124 | }
125 |
126 | void Highlighter::initializationKeyWord()
127 | {
128 | HighlightingRule rule;
129 |
130 | keywordFormat.setForeground(Qt::darkMagenta);
131 | keywordFormat.setFontWeight(QFont::Bold);
132 |
133 | QStringList keywordPatterns;
134 |
135 | keywordPatterns << "\\bselect\\b" << "\\bSELECT\\b" << "\\binsert\\b"
136 | << "\\bINSERT\\b" << "\\bcreate\\b" << "\\bCREATE\\b"
137 | << "\\bfrom\\b" << "\\bFROM\\b" << "\\bdrop\\b"
138 | << "\\bDROP\\b" << "\\binto\\b" << "\\bINTO\\b"
139 | << "\\bwhere\\b" << "\\bWHERE\\b" << "\\btable\\b"
140 | << "\\bTABLE\\b" << "\\brename\\b" << "\\bRENAME\\b"
141 | << "\\bindex\\b" << "\\bINDEX\\b" << "\\bview\\b"
142 | << "\\bVIEW\\b" << "\\bschema\\b" << "\\bSCHEMA\\b"
143 | << "\\balter\\b" << "\\bALTER\\b" << "\\bon\\b"
144 | << "\\bON\\b" << "\\bin\\b" << "\\bIN\\b"
145 | << "\\basc\\b" << "\\bASC\\b" << "\\bdesc\\b"
146 | << "\\bDESC\\b" << "\\bvalues\\b" << "\\bVALUES\\b"
147 | << "\\bPRIMARY KEY\\b" << "\\bprimary key\\b"
148 | << "\\band\\b" << "\\AND\\" << "\\bor\\b" << "\\bOR\\b"
149 | << "\\bbetween\\b" << "\\bBETWEEN\\b" << "\\bgroup\\b"
150 | << "\\bGROUP\\B" << "\\bby\\b" << "\\bBY\\b" << "\\bdelete\\b"
151 | << "\\bDELETE\\b" << "\\bas\\b" << "\\bAS\\b" << "\\btrigger\\b"
152 | << "\\bTRIGGER\\b" << "\\blike\\b" << "\\bLIKE\\b";
153 |
154 | foreach (const QString &pattern, keywordPatterns)
155 | {
156 | rule.pattern = QRegExp(pattern);
157 | rule.format = keywordFormat;
158 | highlightingRules.append(rule);
159 | }
160 | }
161 |
162 | void Highlighter::addString(const QSet &str)
163 | {
164 | highlightingRules.clear();
165 | initialization();
166 | initializationKeyWord();
167 |
168 | HighlightingRule rule;
169 |
170 | keywordFormat.setForeground(Qt::darkGreen);
171 | // QString temp;
172 | // foreach (const QString &pattern, str)
173 | // {
174 | // temp = "\\b" + pattern + "\\b";
175 | // rule.pattern = QRegExp(temp);
176 | // rule.format = keywordFormat;
177 | // highlightingRules.append(rule);
178 | // }
179 |
180 | QSet::const_iterator begin = str.begin();
181 | while (begin != str.end())
182 | {
183 | rule.pattern = QRegExp("\\b" + *begin + "\\b");
184 | rule.format = keywordFormat;
185 | highlightingRules.append(rule);
186 | ++begin;
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/src/highlighter.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 | ** All rights reserved.
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
6 | **
7 | ** This file is part of the examples of the Qt Toolkit.
8 | **
9 | ** $QT_BEGIN_LICENSE:BSD$
10 | ** You may use this file under the terms of the BSD license as follows:
11 | **
12 | ** "Redistribution and use in source and binary forms, with or without
13 | ** modification, are permitted provided that the following conditions are
14 | ** met:
15 | ** * Redistributions of source code must retain the above copyright
16 | ** notice, this list of conditions and the following disclaimer.
17 | ** * Redistributions in binary form must reproduce the above copyright
18 | ** notice, this list of conditions and the following disclaimer in
19 | ** the documentation and/or other materials provided with the
20 | ** distribution.
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 | ** the names of its contributors may be used to endorse or promote
23 | ** products derived from this software without specific prior written
24 | ** permission.
25 | **
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 | ** $QT_END_LICENSE$
38 | **
39 | ****************************************************************************/
40 |
41 | #ifndef HIGHLIGHTER_H
42 | #define HIGHLIGHTER_H
43 |
44 | #include
45 |
46 | #include
47 | #include
48 | #include
49 |
50 | QT_BEGIN_NAMESPACE
51 | class QTextDocument;
52 | QT_END_NAMESPACE
53 |
54 | //! [0]
55 | class Highlighter : public QSyntaxHighlighter
56 | {
57 | Q_OBJECT
58 |
59 | public:
60 | Highlighter(QTextDocument *parent = 0);
61 | void addString(const QSet &str);
62 |
63 | protected:
64 | void highlightBlock(const QString &text);
65 |
66 | private:
67 | void initializationKeyWord();
68 | void initialization();
69 |
70 | private:
71 | struct HighlightingRule
72 | {
73 | QRegExp pattern;
74 | QTextCharFormat format;
75 | };
76 | QVector highlightingRules;
77 |
78 | QRegExp commentStartExpression;
79 | QRegExp commentEndExpression;
80 |
81 | QTextCharFormat keywordFormat;
82 | // QTextCharFormat classFormat;
83 | QTextCharFormat singleLineCommentFormat;
84 | QTextCharFormat multiLineCommentFormat;
85 | QTextCharFormat quotationFormat;
86 | // QTextCharFormat functionFormat;
87 | };
88 | //! [0]
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/src/images/activity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/activity.png
--------------------------------------------------------------------------------
/src/images/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/background.png
--------------------------------------------------------------------------------
/src/images/closeconnect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/closeconnect.png
--------------------------------------------------------------------------------
/src/images/columns.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/columns.png
--------------------------------------------------------------------------------
/src/images/copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/copy.png
--------------------------------------------------------------------------------
/src/images/createindex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/createindex.png
--------------------------------------------------------------------------------
/src/images/cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/cut.png
--------------------------------------------------------------------------------
/src/images/database.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/database.png
--------------------------------------------------------------------------------
/src/images/delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/delete.png
--------------------------------------------------------------------------------
/src/images/deleteindex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/deleteindex.png
--------------------------------------------------------------------------------
/src/images/deleterow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/deleterow.png
--------------------------------------------------------------------------------
/src/images/displayindex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/displayindex.png
--------------------------------------------------------------------------------
/src/images/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/exit.png
--------------------------------------------------------------------------------
/src/images/find.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/find.png
--------------------------------------------------------------------------------
/src/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/icon.png
--------------------------------------------------------------------------------
/src/images/index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/index.png
--------------------------------------------------------------------------------
/src/images/insertrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/insertrow.png
--------------------------------------------------------------------------------
/src/images/isnull.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/isnull.png
--------------------------------------------------------------------------------
/src/images/key.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/key.png
--------------------------------------------------------------------------------
/src/images/new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/new.png
--------------------------------------------------------------------------------
/src/images/newsqlfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/newsqlfile.png
--------------------------------------------------------------------------------
/src/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/open.png
--------------------------------------------------------------------------------
/src/images/opentable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/opentable.png
--------------------------------------------------------------------------------
/src/images/paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/paste.png
--------------------------------------------------------------------------------
/src/images/primary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/primary.png
--------------------------------------------------------------------------------
/src/images/refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/refresh.png
--------------------------------------------------------------------------------
/src/images/renametable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/renametable.png
--------------------------------------------------------------------------------
/src/images/run.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/run.png
--------------------------------------------------------------------------------
/src/images/runsql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/runsql.png
--------------------------------------------------------------------------------
/src/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/save.png
--------------------------------------------------------------------------------
/src/images/saveall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/saveall.png
--------------------------------------------------------------------------------
/src/images/sqlfileopen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/sqlfileopen.png
--------------------------------------------------------------------------------
/src/images/sqlfilesave.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/sqlfilesave.png
--------------------------------------------------------------------------------
/src/images/tableadd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/tableadd.png
--------------------------------------------------------------------------------
/src/images/tabledelete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/tabledelete.png
--------------------------------------------------------------------------------
/src/images/tableedit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/tableedit.png
--------------------------------------------------------------------------------
/src/images/tablemultiple.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/tablemultiple.png
--------------------------------------------------------------------------------
/src/images/trigger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/trigger.png
--------------------------------------------------------------------------------
/src/images/view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/images/view.png
--------------------------------------------------------------------------------
/src/importwizard.h:
--------------------------------------------------------------------------------
1 | #ifndef IMPORTWIZARD_H
2 | #define IMPORTWIZARD_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "qexcel.h"
9 | class QLabel;
10 | class QLineEdit;
11 | class QGroupBox;
12 | class QRadioButton;
13 | class QComboBox;
14 | class QCheckBox;
15 | class QProgressBar;
16 | class ImportProgressInfoPage;
17 | class ImportTableInfoPage;
18 | class ImportTargetInfoPage;
19 | class QSqlDatabase;
20 | class QListView;
21 | class MyStringListModel;
22 | class ImportWorkThread;
23 | class ImportExcelWorkThread;
24 | class ImportTxtWorkThread;
25 | class ImportXmlWorkThread;
26 |
27 | class ImportWizard : public QWizard
28 | {
29 | Q_OBJECT
30 | public:
31 | explicit ImportWizard(const QMap &str, QWidget *parent = 0);
32 | void accept();
33 |
34 | public:
35 | enum
36 | {
37 | PageIntro,
38 | PageSourceInfo,
39 | PageSourceTxtInfo,
40 | PageSoruceExcelInfo,
41 | PageSourceAccessInfo,
42 | PageSourceSQLServerInfo,
43 | PageSourceMySQLInfo,
44 | PageSourceXmlInfo,
45 | PageTableInfo,
46 | PageTargetInfo,
47 | PageFinishInfo
48 | };
49 |
50 | private slots:
51 | void workFinish();
52 | void excelWorkFinish();
53 | void xmlWorkFinish();
54 | void txtWorkFinish();
55 | void setProgress(int);
56 | void setMaxProgress(int);
57 |
58 | private:
59 | void importExcel(const QString &source, QSqlDatabase &target);
60 | void importTxt(const QString &source, QSqlDatabase &target);
61 | void importXml(const QString &filePath, QSqlDatabase &target);
62 | QSqlDatabase getTargetDatabase();
63 | void importData(QSqlDatabase &source, QSqlDatabase &target);
64 |
65 | private:
66 | ImportTableInfoPage *importTable;
67 | ImportTargetInfoPage *importTarget;
68 | ImportProgressInfoPage *progressPage;
69 | const QMap &strMap;
70 |
71 | ImportWorkThread *workThread;
72 | ImportTxtWorkThread *txtWorkThread;
73 | ImportExcelWorkThread *excelWorkThread;
74 | ImportXmlWorkThread *xmlWorkThread;
75 | };
76 |
77 | class ImportIntroPage : public QWizardPage
78 | {
79 | Q_OBJECT
80 |
81 | public:
82 | ImportIntroPage(QWidget *parent = 0);
83 |
84 | private:
85 | QLabel *label;
86 | };
87 |
88 | class ImportInfoPage : public QWizardPage
89 | {
90 | Q_OBJECT
91 |
92 | public:
93 | ImportInfoPage(QWidget *parent = 0);
94 |
95 | public:
96 | int nextId() const;
97 |
98 | private:
99 | // QLabel *sourceLabel;
100 | // QLineEdit *sourceLineEdit;
101 | // QPushButton *sourceButton;
102 |
103 | QGroupBox *groupBox;
104 | QRadioButton *excelRadioButton;
105 | QRadioButton *xmlRadioButton;
106 | QRadioButton *txtRadioButton;
107 | QRadioButton *accessRadioButton;
108 | QRadioButton *sqlserverRadioButton;
109 | QRadioButton *mysqlRadioButton;
110 | };
111 |
112 | class ImportTxtInfoPage : public QWizardPage
113 | {
114 | Q_OBJECT
115 |
116 | public:
117 | ImportTxtInfoPage(QWidget *parent = 0);
118 |
119 | public:
120 | int nextId() const;
121 |
122 | private slots:
123 | void selectPath();
124 |
125 | private:
126 | QLabel *sourceLabel;
127 | QLineEdit *sourceLineEdit;
128 | QPushButton *sourceButton;
129 |
130 | QGroupBox *groupBox;
131 | QRadioButton *commaRadioButton;
132 | };
133 |
134 | class ImportAccessInfoPage : public QWizardPage
135 | {
136 | Q_OBJECT
137 |
138 | public:
139 | ImportAccessInfoPage(QWidget *parent = 0);
140 |
141 | int nextId() const;
142 |
143 | private slots:
144 | void databaseConnect();
145 | void selectPath();
146 |
147 | private:
148 | QLabel *sourceLabel;
149 | QLineEdit *sourceLineEdit;
150 | QPushButton *sourceButton;
151 |
152 | QLabel *connectInfoLabel;
153 | QLabel *userNameLabel;
154 | QLineEdit *userNameLineEdit;
155 | QLabel *passwordLabel;
156 | QLineEdit *passwordLineEdit;
157 | QCheckBox *passwordCheckBox;
158 |
159 | QPushButton *testConnectButton;
160 | };
161 |
162 | class ImportExcelInfoPage : public QWizardPage
163 | {
164 | Q_OBJECT
165 |
166 | public:
167 | ImportExcelInfoPage(QWidget *parent = 0);
168 |
169 | public:
170 | int nextId() const;
171 |
172 | private slots:
173 | void selectPath();
174 | void excelConnect();
175 |
176 | private:
177 | QLabel *sourceLabel;
178 | QLineEdit *sourceLineEdit;
179 | QPushButton *sourceButton;
180 |
181 | QPushButton *testConnectButton;
182 | };
183 |
184 | class ImportSQLServerInfoPage : public QWizardPage
185 | {
186 | Q_OBJECT
187 |
188 | public:
189 | ImportSQLServerInfoPage(QWidget *parent = 0);
190 |
191 | public:
192 | int nextId() const;
193 |
194 | private slots:
195 | void testConnect();
196 |
197 | private:
198 | QLabel *databaseNameLabel;
199 | QLineEdit *databaseNameLineEdit;
200 | QLabel *hostNameLabel;
201 | QLineEdit *hostNameLineEdit;
202 | QLabel *userNameLabel;
203 | QLineEdit *userNameLineEdit;
204 | QLabel *passwordLabel;
205 | QLineEdit *passwordLineEdit;
206 | QLabel *portLabel;
207 | QLineEdit *portLineEdit;
208 |
209 | QPushButton *testConnectButton;
210 | };
211 |
212 | class ImportMySQLInfoPage : public QWizardPage
213 | {
214 | Q_OBJECT
215 |
216 | public:
217 | ImportMySQLInfoPage(QWidget *parent = 0);
218 |
219 | public:
220 | int nextId() const;
221 |
222 | private slots:
223 | void testConnect();
224 |
225 | private:
226 | QLabel *databaseNameLabel;
227 | QLineEdit *databaseNameLineEdit;
228 | QLabel *hostNameLabel;
229 | QLineEdit *hostNameLineEdit;
230 | QLabel *userNameLabel;
231 | QLineEdit *userNameLineEdit;
232 | QLabel *passwordLabel;
233 | QLineEdit *passwordLineEdit;
234 | QLabel *portLabel;
235 | QLineEdit *portLineEdit;
236 |
237 | QPushButton *testConnectButton;
238 | };
239 |
240 | class ImportXmlInfoPqge : public QWizardPage
241 | {
242 | Q_OBJECT
243 |
244 | public:
245 | ImportXmlInfoPqge(QWidget *parent = 0);
246 |
247 | public:
248 | int nextId() const;
249 |
250 | private slots:
251 | void selectPath();
252 |
253 | private:
254 | QLabel *sourceLabel;
255 | QLineEdit *sourceLineEdit;
256 | QPushButton *selectButton;
257 | };
258 |
259 | class ImportTableInfoPage : public QWizardPage
260 | {
261 | Q_OBJECT
262 |
263 | public:
264 | ImportTableInfoPage(QWidget *parent = 0);
265 |
266 | public:
267 | void initializePage();
268 | QStringList getUseTableList() const;
269 |
270 | private:
271 | void initAccessTable();
272 | void initExcelTable();
273 | void initSqlserverTable();
274 | void initXmlTable();
275 |
276 | private slots:
277 | void selectAllClicked();
278 | void unselectAllClicked();
279 |
280 | private:
281 | QListView *listView;
282 | QPushButton *selectAllButton;
283 | QPushButton *unSelectAllButton;
284 | MyStringListModel *model;
285 | };
286 |
287 | class ImportTargetInfoPage : public QWizardPage
288 | {
289 | Q_OBJECT
290 |
291 | public:
292 | ImportTargetInfoPage(const QMap &str, QWidget *parent = 0);
293 | QString getTarget() const;
294 |
295 | private slots:
296 | void checkBoxChanged(int state);
297 | void textChanged(const QString&);
298 | void selectPath();
299 |
300 | private:
301 | QLabel *targetLabel;
302 | QComboBox *targetComboBox;
303 |
304 | QCheckBox *checkBox;
305 |
306 | QLabel *newDatabaseNameLabel;
307 | QLineEdit *newDatabaseNameLineEdit;
308 | QPushButton *newDatabasePathButton;
309 | };
310 |
311 | class ImportProgressInfoPage : public QWizardPage
312 | {
313 | Q_OBJECT
314 |
315 | public:
316 | ImportProgressInfoPage(QWidget *parent = 0);
317 |
318 | void initializePage();
319 |
320 | public:
321 | QProgressBar *progressBar;
322 | };
323 |
324 | #endif // IMPORTWIZARD_H
325 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "mainwindow.h"
9 |
10 | int main(int argc, char *argv[])
11 | {
12 | QApplication app(argc, argv);
13 |
14 | QSettings settings("SQLite Database Manage.ini", QSettings::IniFormat);
15 | int b = settings.value("Language").toInt();
16 |
17 | QTranslator translator(0);
18 | if (b == 0)
19 | {
20 | translator.load( ":/translations/SQLiteDatabaseManage.qm", "." );
21 | app.installTranslator(&translator);
22 | }
23 |
24 | QFile file(":/qss/SQLite Database Manage.qss");
25 | file.open(QFile::ReadOnly);
26 | app.setStyleSheet(file.readAll());
27 | // QTextCodec::codecForName("GB2313");
28 | // if (QTextCodec::codecForName("UTF-16"))
29 | // qDebug() << "yes";
30 | // QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
31 | // QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
32 |
33 | // qDebug() << QTextCodec::codecForLocale()->name();
34 | MainWindow w;
35 | // w.setWindowFlags(Qt::FramelessWindowHint);
36 | w.show();
37 | // w.resize(1300, 600);
38 | // qDebug() << QApplication::style()->metaObject()->className();
39 |
40 | return app.exec();
41 | }
42 |
--------------------------------------------------------------------------------
/src/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include "tabwidget.h"
7 |
8 | class QLabel;
9 | class QLineEdit;
10 | class QPushButton;
11 | class QTreeWidget;
12 | class QTableWidget;
13 | class QTextEdit;
14 | class QSplitter;
15 | class QAction;
16 | class QMenu;
17 | class QToolBar;
18 | class QTreeWidgetItem;
19 | class QSqlQuery;
20 | class QTableWidgetItem;
21 | class QFont;
22 | class TabWidget;
23 | class FindDialog;
24 | class QGroupBox;
25 | class QDockWidget;
26 | class QTreeView;
27 | class CodeEditor;
28 | class Highlighter;
29 | class MyDockWidget;
30 | class QActionGroup;
31 | class QComboBox;
32 |
33 | class MainWindow : public QMainWindow
34 | {
35 | Q_OBJECT
36 |
37 | public:
38 | MainWindow(QWidget *parent = 0);
39 | ~MainWindow();
40 |
41 | public:
42 | static bool getCurrentShow() { return isShowMenu; }
43 | static bool getCurrentReadOnly() { return isReadOnlyMenu; }
44 | static bool getCurrentAssociate() { return isAssociate; }
45 |
46 | protected:
47 | void dragEnterEvent(QDragEnterEvent *event);
48 | void dropEvent(QDropEvent *event);
49 |
50 | private:
51 | void createActions();
52 | void createMenus();
53 | void createToolBars();
54 | void createStatusBar();
55 | void showTreeContextMenu();
56 | bool createConnect(const QString &databaseName);
57 | void setTreeData(const QStringList &databaseName);
58 | void readSettings();
59 | void writeSettings();
60 | bool findExist(const QStringList &databaseName);
61 | void createTableTreeItem(const QString &connectName, QTreeWidgetItem *parentItem, QTreeWidgetItem *systemTableItem);
62 | void createViewTreeItem(const QString &connectName, QTreeWidgetItem *parentItem);
63 | void setActionPrivate(bool editBool, bool executeBool);
64 | void setNoTabWidgetAction();
65 | void setTableViewAction();
66 | void setSystemTableViewAction();
67 | void setQueryWidgetAction();
68 | void setCreateIndexWidgetAction();
69 | void setNewTableWidgetAction();
70 | void setModifyTableFieldWidgetAction();
71 | void setTableAction(bool);
72 | void setTableIndexAction(bool, bool);
73 | void setAction(QTreeWidgetItem *item);
74 | void updateRecentFileActions();
75 |
76 | protected:
77 | void closeEvent(QCloseEvent *event);
78 |
79 | private slots:
80 | void openDatabaseFile();
81 | void openSql();
82 | void treeItemDoubleClicked(QTreeWidgetItem * item, int column);
83 | void setReadOnly(bool isRead);
84 | void Associate(bool);
85 | void slotShowTreeContextMenu(QTreeWidgetItem *, int);
86 | void newDatabase();
87 | void setShowGrid(bool isShow);
88 | void showDockWidget(bool);
89 | void find();
90 | void closeDatabaseConnect();
91 | void createNewTable();
92 | void openNewTable();
93 | void deleteTable();
94 | void renameTheTable();
95 | void modifyTableField();
96 | void createNewQuery();
97 | void createIndex();
98 | void displayIndex();
99 | void deleteIndex();
100 | void dropTrigger();
101 | void dropView();
102 | void styleChanged(QAction *action);
103 | void languageChanged(QAction *action);
104 | void queryChanged(const QString &database);
105 | void tabWidgetChanged(WidgetType type);
106 | void refreshData();
107 | void exportData();
108 | void importData();
109 | void openRecentFile();
110 | void analyzeDatabase();
111 | void vacuumDatabase();
112 | void about();
113 |
114 | private:
115 | MyDockWidget *dockWidget;
116 | QTreeWidget *treeWidget;
117 |
118 | TabWidget *tabWidget;
119 |
120 | QSplitter *rightSplitter;
121 |
122 | QMenu *fileMenu;
123 | QMenu *editMenu;
124 | QMenu *databaseMenu;
125 | QMenu *executeMenu;
126 | QMenu *helpMenu;
127 | QMenu *optionsMenu;
128 | QMenu *dataMenu;
129 |
130 | QToolBar *fileToolBar;
131 | QToolBar *editToolBar;
132 | QToolBar *executeToolBar;
133 |
134 | QAction *newAction;
135 | QAction *openAction;
136 | QAction *saveAction;
137 | QAction *saveAllAction;
138 | QAction *exitAction;
139 |
140 | QAction *cutAction;
141 | QAction *copyAction;
142 | QAction *pasteAction;
143 | QAction *deleteAction;
144 | QAction *insertRowAction;
145 | QAction *deleteRowAction;
146 | QAction *findAction;
147 |
148 | QAction *analysisSqlAction;
149 | QAction *runLineSqlAction;
150 | QAction *runSqlAction;
151 | QAction *saveSqlAction;
152 | QAction *openSqlAction;
153 |
154 | QAction *showGridAction;
155 | QAction *readOnlyAction;
156 | QAction *showDockWidgetAction;
157 | QAction *associateAction;
158 |
159 | QAction *exportAction;
160 | QAction *importAction;
161 |
162 | QAction *analyzeAction;
163 | QAction *vacuumAction;
164 |
165 | QActionGroup *styleGroupAction;
166 | QActionGroup *languageGroupAction;
167 |
168 | QAction *aboutAction;
169 | QAction *aboutQtAction;
170 |
171 | QAction *closeConnectAction;
172 |
173 | QAction *createNewTableAction;
174 | QAction *refreshAction;
175 |
176 | QAction *openTableAction;
177 | QAction *renameTableAction;
178 | QAction *deleteTableAction;
179 | QAction *modifyTableFieldAction;
180 |
181 | QAction *createNewSQLAction;
182 | QAction *createNewIndexAction;
183 | // QAction *displayIndexAction;
184 | QAction *deleteIndexAction;
185 |
186 | QAction *dropTriggerAction;
187 |
188 | QAction *dropViewAction;
189 |
190 | static bool isShowMenu;
191 | static bool isReadOnlyMenu;
192 | static bool isAssociate;
193 |
194 | FindDialog *findDialog;
195 |
196 | QComboBox *comboBox;
197 |
198 | QMenu *recentFileMenu;
199 | enum { MaxRecentFiles = 5 };
200 | QAction *recentFileAction[MaxRecentFiles];
201 | };
202 |
203 | #endif // MAINWINDOW_H
204 |
--------------------------------------------------------------------------------
/src/modifytablefieldwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "modifytablefieldwidget.h"
2 | #include "datatypedelegate.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | ModifyTableFieldWidget::ModifyTableFieldWidget(const QString &connectName, const QString &tableName, QWidget *parent) :
18 | QWidget(parent)
19 | {
20 | this->connectName = connectName;
21 | this->tableName = tableName;
22 |
23 | groupBox = new QGroupBox(tableName, this);
24 | tableWidget = new QTableWidget;
25 | DataTypeDelegate *dataTypeDelegate = new DataTypeDelegate(1, 2, 3);
26 | tableWidget->setItemDelegate(dataTypeDelegate);
27 | tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
28 | QVBoxLayout *topLayout = new QVBoxLayout;
29 | topLayout->addWidget(tableWidget);
30 | groupBox->setLayout(topLayout);
31 |
32 | addButton = new QPushButton(tr("Add"));
33 | submitButton = new QPushButton(tr("Submit"));
34 | deleteButton = new QPushButton(tr("Delete"));
35 | QHBoxLayout *bottomLayout = new QHBoxLayout;
36 | bottomLayout->addStretch();
37 | bottomLayout->addWidget(addButton);
38 | bottomLayout->addWidget(deleteButton);
39 | bottomLayout->addWidget(submitButton);
40 |
41 | QVBoxLayout *mainLayout = new QVBoxLayout;
42 | mainLayout->addWidget(groupBox);
43 | mainLayout->addLayout(bottomLayout);
44 |
45 | setLayout(mainLayout);
46 | // setWindowTitle(tr("Set Table Field"));
47 |
48 | setTableWidget();
49 |
50 | // resize(550, 300);
51 |
52 | // connect(dataTypeDelegate, SIGNAL(primaryChanged(int)), this, SLOT(setPrimary(int)));
53 | connect(addButton, SIGNAL(clicked()), this, SLOT(addRow()));
54 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
55 | connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
56 | }
57 |
58 | void ModifyTableFieldWidget::setTableWidget()
59 | {
60 | QSqlDatabase db = QSqlDatabase::database(connectName);
61 | QSqlRecord record = db.record(tableName);
62 | // for (int i = 0; i < record.count(); ++i)
63 | // qDebug() << record.field(i).requiredStatus() << endl;
64 | // record.isNull();
65 | // db.primaryIndex(tableName);
66 | tableWidget->setRowCount(record.count());
67 | tableWidget->setColumnCount(4);
68 | tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Field")
69 | << tr("Type") << tr("Primary")
70 | << tr("Allow Null"));
71 |
72 |
73 | // QSqlQuery query(db);
74 | // query.exec(tr("select sql from sqlite_master where tbl_name='%1'").arg(tableName));
75 | // if (!query.isActive())
76 | // {
77 | // QMessageBox::information(this, tr("SQLite GUI"), query.lastError().text());
78 | // return;
79 | // }
80 | // if (query.next())
81 | // {
82 | // QString sql = query.value(0).toString();
83 | // int firstIndex = sql.indexOf(tr("("));
84 | // QString str = sql.mid(firstIndex + 1, sql.size() - firstIndex - 2);
85 | // analysisFiedl(str, record);
86 | // }
87 |
88 |
89 | QSqlIndex primaryRecord = db.primaryIndex(tableName);
90 | for (int i = 0; i < record.count(); ++i)
91 | {
92 | QString fieldName = record.fieldName(i);
93 | QTableWidgetItem *fieldNameItem = new QTableWidgetItem(fieldName);
94 | tableWidget->setItem(i, 0, fieldNameItem);
95 |
96 | int value = record.field(i).type();
97 | // qDebug() << record.fieldName(i) << record.field(i).type();
98 | QString fieldType;
99 | switch (value)
100 | {
101 | case QVariant::String :
102 | fieldType = "TEXT";
103 | break;
104 | case QVariant::ByteArray :
105 | fieldType = "BLOB";
106 | break;
107 | case QVariant::Int :
108 | fieldType = "INTEGER";
109 | break;
110 | case QVariant::Double :
111 | fieldType = "REAL";
112 | break;
113 | default:
114 | fieldType = "TEXT";
115 | }
116 | QTableWidgetItem *fieldTypeItem = new QTableWidgetItem(fieldType);
117 | tableWidget->setItem(i, 1, fieldTypeItem);
118 |
119 | bool primary = false;
120 | if (primaryRecord.contains(fieldName))
121 | primary = true;
122 | QTableWidgetItem *primaryItem = new QTableWidgetItem;
123 | primaryItem->setData(Qt::DisplayRole, primary);
124 | tableWidget->setItem(i, 2, primaryItem);
125 |
126 | bool isNull = !record.field(i).requiredStatus();
127 | QTableWidgetItem *isNullItem = new QTableWidgetItem;
128 | isNullItem->setData(Qt::DisplayRole, isNull);
129 | tableWidget->setItem(i, 3, isNullItem);
130 |
131 | originalStr.push_back(Field(fieldName, fieldType, primary, isNull));
132 | }
133 |
134 | }
135 |
136 | //void ModifyTableFieldWidget::analysisFiedl(const QString &str, const QSqlRecord &record)
137 | //{
138 | // QStringList strList = str.split(tr(","));
139 |
140 | // for (int i = 0; i < strList.size(); ++i)
141 | // {
142 | // QStringList singleField = strList[i].split(tr(" "), QString::SkipEmptyParts);
143 |
144 | //// QString fieldName = singleField[0];
145 | // QString fieldName = record.fieldName(i);
146 | // QTableWidgetItem *fieldNameItem = new QTableWidgetItem(fieldName);
147 | // tableWidget->setItem(i, 0, fieldNameItem);
148 | // Field recordField(fieldName);
149 |
150 | // QTableWidgetItem *isNullItem = new QTableWidgetItem;
151 | // isNullItem->setData(Qt::DisplayRole, true);
152 | // tableWidget->setItem(i, 3, isNullItem);
153 |
154 | // for (int j = 1; j < singleField.size(); ++j)
155 | // {
156 | // QString fieldStr = singleField[j].toUpper();
157 | // if (fieldStr == tr("INTEGER") ||
158 | // fieldStr == tr("TEXT") ||
159 | // fieldStr == tr("BLOB") ||
160 | // fieldStr == tr("REAL"))
161 | // {
162 | // QTableWidgetItem *typeItem = new QTableWidgetItem(fieldStr);
163 | // tableWidget->setItem(i, 1, typeItem);
164 | // recordField.type = fieldStr;
165 | // }
166 | // else if (fieldStr == tr("PRIMARY"))
167 | // {
168 | // QTableWidgetItem *primaryItem = new QTableWidgetItem;
169 | // primaryItem->setData(Qt::DisplayRole, true);
170 | // tableWidget->setItem(i, 2, primaryItem);
171 | // recordField.primary = true;
172 | // break;
173 | // }
174 | // else if (fieldStr == tr("NOT"))
175 | // {
176 | // QTableWidgetItem *item = tableWidget->item(i, 3);
177 | // item->setData(Qt::DisplayRole, false);
178 | // recordField.isNull = false;
179 | // break;
180 | // }
181 | // }
182 | // originalStr.push_back(recordField);
183 | // }
184 | //}
185 |
186 | //void ModifyTableFieldWidget::setPrimary(int row)
187 | //{
188 | // for (int i = 0; i < tableWidget->rowCount(); ++i)
189 | // {
190 | // if (i != row)
191 | // {
192 | // QTableWidgetItem *item = tableWidget->item(i,2);
193 | // if (item)
194 | // item->setData(Qt::DisplayRole, QVariant(false));
195 | // }
196 | // }
197 | //}
198 |
199 | void ModifyTableFieldWidget::addRow()
200 | {
201 | int row = tableWidget->rowCount();
202 | tableWidget->insertRow(row);
203 | QTableWidgetItem *item = new QTableWidgetItem;
204 | QTableWidgetItem *isNullItem = new QTableWidgetItem;
205 | isNullItem->setData(Qt::DisplayRole, true);
206 | tableWidget->setItem(row, 0, item);
207 | tableWidget->setItem(row, 3, isNullItem);
208 | tableWidget->editItem(item);
209 | }
210 |
211 | void ModifyTableFieldWidget::deleteRow()
212 | {
213 | QList item = tableWidget->selectedItems();
214 |
215 | if (!item.isEmpty())
216 | {
217 | int row = item.first()->row();
218 | tableWidget->removeRow(row);
219 | originalStr.removeAt(row);
220 | }
221 | }
222 |
223 | void ModifyTableFieldWidget::submit()
224 | {
225 | int r = QMessageBox::warning(this, tr("SQLite Database Manage"),
226 | tr("Are you sure save your changes?"),
227 | QMessageBox::Yes | QMessageBox::Default,
228 | QMessageBox::No,
229 | QMessageBox::Cancel | QMessageBox::Escape);
230 |
231 | if (r == QMessageBox::No || r == QMessageBox::Cancel)
232 | return;
233 |
234 |
235 | QList newFieldList;
236 | for (int i = 0; i < tableWidget->rowCount(); ++i)
237 | {
238 | Field field;
239 | QTableWidgetItem *fieldNameItem = tableWidget->item(i, 0);
240 | if (fieldNameItem)
241 | {
242 | QString fieldName = fieldNameItem->text();
243 | if (fieldName.isEmpty())
244 | return;
245 |
246 | field.name = fieldName;
247 | }
248 |
249 | QTableWidgetItem *fieldTypeItem = tableWidget->item(i, 1);
250 | if (fieldTypeItem)
251 | {
252 | QString fieldType = fieldTypeItem->text();
253 | if (fieldType.isEmpty())
254 | fieldType = "TEXT";
255 | field.type = fieldType;
256 | }
257 |
258 | QTableWidgetItem *primaryItem = tableWidget->item(i, 2);
259 | if (primaryItem)
260 | {
261 | field.primary = primaryItem->data(Qt::DisplayRole).toBool();
262 | }
263 |
264 | QTableWidgetItem *isNullItem = tableWidget->item(i, 3);
265 | if (isNullItem)
266 | {
267 | field.isNull = isNullItem->data(Qt::DisplayRole).toBool();
268 | }
269 |
270 | newFieldList.push_back(field);
271 | }
272 |
273 | // for (int i = 0; i < newFieldList.size(); ++i)
274 | // {
275 | // Field temp = newFieldList[i];
276 | // qDebug() << temp.name << " " << temp.type << " " << temp.primary << temp.isNull << endl;
277 | // INSERT INTO fieldtest2(int,text,blob) select int,text,blob FROM fieldtest
278 | // }
279 |
280 | QString str = createNewTableStr(newFieldList);
281 | QSqlDatabase db = QSqlDatabase::database(connectName);
282 | // QSqlQuery query(db);
283 | // query.exec(str);
284 | db.transaction();
285 | db.exec(str);
286 | str = oldTableInsertToNewTableStr(newFieldList);
287 | // query.exec(str);
288 | db.exec(str);
289 | newFieldInsertToNewTable(db, newFieldList);
290 |
291 | db.exec(tr("drop table %1").arg(tableName));
292 | db.exec(tr("alter table temp%1temp rename to %2").arg(tableName).arg(tableName));
293 | db.commit();
294 | }
295 |
296 | QString ModifyTableFieldWidget::createNewTableStr(const QList &newFieldList)
297 | {
298 | QString str = tr("create table temp%1temp(").arg(tableName);
299 | QString primaryField;
300 | for (int i = 0; i < newFieldList.size(); ++i)
301 | {
302 | str = str + "'" + newFieldList[i].name + "' " + newFieldList[i].type;
303 | // str += newFieldList[i].name;
304 | // str += tr(" ");
305 | // str += newFieldList[i].type;
306 | if (newFieldList[i].primary)
307 | {
308 | primaryField = primaryField + "'" + newFieldList[i].name + "',";
309 | // str += tr(" primary key");
310 | }
311 | else if (!newFieldList[i].isNull)
312 | {
313 | str += tr(" not null");
314 | }
315 | str += ",";
316 | }
317 |
318 | int index;
319 | if (!primaryField.isEmpty())
320 | {
321 | primaryField = "primary key(" + primaryField;
322 | str += primaryField;
323 | index = str.lastIndexOf(',');
324 | str.replace(index, 2, "))");
325 | }
326 | else
327 | {
328 | index = str.lastIndexOf(',');
329 | str.replace(index, 1, ')');
330 | }
331 | // qDebug() << str << endl;
332 |
333 | return str;
334 | }
335 |
336 | QString ModifyTableFieldWidget::oldTableInsertToNewTableStr(const QList &newFieldList)
337 | {
338 | // INSERT INTO fieldtest2(int,text,blob) select int,text,blob FROM fieldtest
339 | QString oriStr;
340 | QString newFieldStr = "(";
341 | // qDebug() << "o\t" << originalStr.size() << endl << "n\t" << newFieldList.size() << endl;
342 | for (int i = 0; i < originalStr.size(); ++i)
343 | {
344 | // oriStr = oriStr + "'" + originalStr[i].name + "',";
345 | oriStr += originalStr[i].name;
346 | oriStr += ",";
347 |
348 | newFieldStr = newFieldStr + "'" + newFieldList[i].name + "',";
349 | // newFieldStr += newFieldList[i].name;
350 | // newFieldStr += ",";
351 | }
352 | int index = oriStr.lastIndexOf(",");
353 | oriStr.replace(index, 1, " ");
354 | index = newFieldStr.lastIndexOf(",");
355 | newFieldStr.replace(index, 1, ")");
356 |
357 | QString str = tr("insert into temp%1temp%2 select %3from %4").arg(tableName).arg(newFieldStr).arg(oriStr).arg(tableName);
358 | // qDebug() << str << endl;
359 | return str;
360 | }
361 |
362 | void ModifyTableFieldWidget::newFieldInsertToNewTable(QSqlDatabase &db, const QList &newFieldList)
363 | {
364 | const QString str = tr("alter table temp%1temp add column ").arg(tableName);
365 | QString queryStr;
366 | for (int i = originalStr.size(); i < newFieldList.size(); ++i)
367 | {
368 | queryStr = str + "'" + newFieldList[i].name + "' ";
369 | // queryStr += tr(" ");
370 | queryStr += newFieldList[i].type;
371 | if (!queryStr.isNull())
372 | {
373 | queryStr += tr(" not null default ''");
374 | }
375 | db.exec(queryStr);
376 | // if (!query.isActive())
377 | // {
378 | // QMessageBox::information(this, tr("SQLite GUI"), query.lastError().text());
379 | // }
380 | }
381 | }
382 |
--------------------------------------------------------------------------------
/src/modifytablefieldwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef MODIFYTABLEFIELDWIDGET_H
2 | #define MODIFYTABLEFIELDWIDGET_H
3 |
4 | #include
5 |
6 | class QGroupBox;
7 | class QTableWidget;
8 | class QPushButton;
9 | class QTableWidgetItem;
10 | class QSqlQuery;
11 | class QSqlRecord;
12 | class QSqlDatabase;
13 |
14 | struct Field
15 | {
16 | Field(const QString &n = "", const QString &t = "", bool p = false, bool i = true)
17 | : name(n), type(t), primary(p), isNull(i) {}
18 | QString name;
19 | QString type;
20 | bool primary;
21 | bool isNull;
22 | };
23 |
24 | class ModifyTableFieldWidget : public QWidget
25 | {
26 | Q_OBJECT
27 | public:
28 | explicit ModifyTableFieldWidget(const QString &connectName, const QString &tableName, QWidget *parent = 0);
29 |
30 | private slots:
31 | // void setPrimary(int row);
32 | void addRow();
33 | void deleteRow();
34 | void submit();
35 |
36 | private:
37 | void setTableWidget();
38 | // void analysisFiedl(const QString &str, const QSqlRecord &record);
39 | QString createNewTableStr(const QList &newFieldList);
40 | QString oldTableInsertToNewTableStr(const QList &newFieldList);
41 | void newFieldInsertToNewTable(QSqlDatabase &db, const QList &newFieldList);
42 |
43 | private:
44 | QGroupBox *groupBox;
45 | QTableWidget *tableWidget;
46 | QPushButton *addButton;
47 | QPushButton *submitButton;
48 | QPushButton *deleteButton;
49 |
50 | QString connectName;
51 | QString tableName;
52 |
53 | QList originalStr;
54 | };
55 |
56 | #endif // MODIFYTABLEFIELDWIDGET_H
57 |
--------------------------------------------------------------------------------
/src/mydockwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "mydockwidget.h"
2 |
3 | MyDockWidget::MyDockWidget(const QString &title, QWidget *parent) :
4 | QDockWidget(title, parent)
5 | {
6 | }
7 |
8 | void MyDockWidget::closeEvent(QCloseEvent*)
9 | {
10 | hide();
11 | emit dockWidgetShow(false);
12 | }
13 |
--------------------------------------------------------------------------------
/src/mydockwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef MYDOCKWIDGET_H
2 | #define MYDOCKWIDGET_H
3 |
4 | #include
5 |
6 | class MyDockWidget : public QDockWidget
7 | {
8 | Q_OBJECT
9 | public:
10 | explicit MyDockWidget(const QString &title, QWidget *parent = 0);
11 |
12 | signals:
13 | void dockWidgetShow(bool);
14 |
15 | protected:
16 | void closeEvent(QCloseEvent*);
17 |
18 | };
19 |
20 | #endif // MYDOCKWIDGET_H
21 |
--------------------------------------------------------------------------------
/src/mylistmodel.cpp:
--------------------------------------------------------------------------------
1 | #include "mylistmodel.h"
2 | #include
3 | #include
4 |
5 | MyListModel::MyListModel(QObject *parent) :
6 | QAbstractListModel(parent)
7 | {
8 |
9 | }
10 |
11 | int MyListModel::rowCount(const QModelIndex& /* parent */) const
12 | {
13 | return str.size();
14 | }
15 |
16 | int MyListModel::columnCount(const QModelIndex& /* parent */) const
17 | {
18 | return 1;
19 | }
20 |
21 | QVariant MyListModel::data(const QModelIndex &index, int role) const
22 | {
23 | if (!index.isValid())
24 | return QVariant();
25 |
26 | if (role == Qt::DisplayRole)
27 | {
28 | return *(str.begin() + index.row());
29 | }
30 | // else if (role == Qt::DecorationRole)
31 | // {
32 | // return QIcon(":/images/columns.png");
33 | // }
34 |
35 | return QVariant();
36 | }
37 |
38 | void MyListModel::setSourceString()
39 | {
40 | str << "select" << "insert" << "table" << "create" << "from" << "primary" << "key"
41 | << "drop" << "view" << "index" << "trigger" << "delete" << "alter" << "where"
42 | << "and" << "or" << "in" << "between" << "on" << "values" << "group" << "by"
43 | << "asc" << "desc" << "into" << "rename" << "like";
44 | }
45 |
46 | void MyListModel::setCurrentSet(const QSet &s)
47 | {
48 | str.clear();
49 | setSourceString();
50 | str.unite(s);
51 | // qDebug() << str;
52 | }
53 |
54 | int MyListModel::count() const
55 | {
56 | return str.count();
57 | }
58 |
59 | bool MyListModel::isMatch(const QString &s) const
60 | {
61 | return str.contains(s);
62 | }
63 |
64 |
65 |
66 |
67 | MyStringListModel::MyStringListModel(QObject *parent) :
68 | QAbstractListModel(parent)
69 | {
70 | }
71 |
72 | void MyStringListModel::setStringList(const QStringList &source)
73 | {
74 | str = source;
75 | isUseList.clear();
76 | for (int i = 0; i < source.size(); ++i)
77 | isUseList.push_back(Qt::Checked);
78 |
79 | reset();
80 | // qDebug() << str;
81 | }
82 |
83 | int MyStringListModel::rowCount(const QModelIndex &/*parent*/) const
84 | {
85 | return str.size();
86 | }
87 |
88 | int MyStringListModel::columnCount(const QModelIndex &/*parent*/) const
89 | {
90 | return 1;
91 | }
92 |
93 | QVariant MyStringListModel::data(const QModelIndex &index, int role) const
94 | {
95 | if (!index.isValid())
96 | return QVariant();
97 |
98 | if (role == Qt::DisplayRole)
99 | {
100 | return *(str.begin() + index.row());
101 | }
102 | else if (role == Qt::CheckStateRole)
103 | {
104 | return isUseList[index.row()];
105 | // return Qt::Checked;
106 | }
107 |
108 | return QVariant();
109 | }
110 |
111 | bool MyStringListModel::setData(const QModelIndex &index, const QVariant &value, int role)
112 | {
113 | if (role == Qt::CheckStateRole)
114 | {
115 | isUseList[index.row()] = value.toInt();
116 | return true;
117 | }
118 |
119 | return QAbstractItemModel::setData(index, value, role);
120 | }
121 |
122 | Qt::ItemFlags MyStringListModel::flags(const QModelIndex &/*index*/) const
123 | {
124 | return Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
125 | }
126 |
127 | void MyStringListModel::selectAll()
128 | {
129 | for (int i = 0; i < isUseList.size(); ++i)
130 | {
131 | isUseList[i] = Qt::Checked;
132 | }
133 | }
134 |
135 | void MyStringListModel::unselectAll()
136 | {
137 | for (int i = 0; i < isUseList.size(); ++i)
138 | {
139 | isUseList[i] = Qt::Unchecked;
140 | }
141 | }
142 |
143 | QStringList MyStringListModel::getUseStringList() const
144 | {
145 | QStringList strList;
146 | for (int i = 0; i < isUseList.size(); ++i)
147 | {
148 | if (isUseList[i] == Qt::Checked)
149 | strList += str[i];
150 | }
151 | return strList;
152 | }
153 |
--------------------------------------------------------------------------------
/src/mylistmodel.h:
--------------------------------------------------------------------------------
1 | #ifndef MYLISTMODEL_H
2 | #define MYLISTMODEL_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class MyListModel : public QAbstractListModel
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit MyListModel(QObject *parent = 0);
14 |
15 | public:
16 | void setCurrentSet(const QSet &s);
17 | int count() const;
18 | bool isMatch(const QString &s) const;
19 |
20 | public:
21 | int rowCount(const QModelIndex &parent) const;
22 | int columnCount(const QModelIndex &parent) const;
23 | QVariant data(const QModelIndex &index, int role) const;
24 |
25 | private:
26 | void setSourceString();
27 |
28 | private:
29 | QSet str;
30 | };
31 |
32 | class MyStringListModel : public QAbstractListModel
33 | {
34 | Q_OBJECT
35 |
36 | public:
37 | explicit MyStringListModel(QObject *parent = 0);
38 |
39 | public:
40 | void setStringList(const QStringList &);
41 | void selectAll();
42 | void unselectAll();
43 | QStringList getUseStringList() const;
44 |
45 | public:
46 | int rowCount(const QModelIndex &parent) const;
47 | int columnCount(const QModelIndex &parent) const;
48 | QVariant data(const QModelIndex &index, int role) const;
49 | bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
50 | Qt::ItemFlags flags(const QModelIndex & index) const ;
51 |
52 | private:
53 | QStringList str;
54 | QVector isUseList;
55 | };
56 |
57 | #endif // MYLISTMODEL_H
58 |
--------------------------------------------------------------------------------
/src/newdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "newdialog.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | NewDialog::NewDialog(QWidget *parent) :
15 | QDialog(parent)
16 | {
17 | nameLabel = new QLabel(tr("&File Name:"));
18 | nameLineEdit = new QLineEdit;
19 | nameLabel->setBuddy(nameLineEdit);
20 | locationsLabel = new QLabel(tr("File Locations:"));
21 | fileLocationStr = QApplication::applicationDirPath() + "/";
22 | //fileLocationStr.replace(QString(("/")), QString(("\\")));
23 | fileLocationsLabel = new QLabel(fileLocationStr);
24 | fileLocationsButton = new QPushButton(tr("Select"));
25 | okButton = new QPushButton(tr("OK"));
26 | okButton->setEnabled(false);
27 | cancelButton = new QPushButton(tr("Cancel"));
28 | checkBox = new QCheckBox(tr("Create and connect"));
29 | checkBox->setChecked(true);
30 |
31 | QGroupBox *groupBox = new QGroupBox(this);
32 | QGridLayout *topLayout = new QGridLayout;
33 | topLayout->addWidget(nameLabel, 0, 0);
34 | topLayout->addWidget(nameLineEdit, 0, 1, 1, 6);
35 | topLayout->addWidget(fileLocationsButton, 0, 7);
36 | topLayout->addWidget(locationsLabel, 1, 0);
37 | topLayout->addWidget(fileLocationsLabel, 1, 1, 1, 6);
38 | groupBox->setLayout(topLayout);
39 |
40 | QHBoxLayout *bottomLayout = new QHBoxLayout;
41 | bottomLayout->addWidget(checkBox);
42 | bottomLayout->addStretch();
43 | bottomLayout->addWidget(okButton);
44 | bottomLayout->addWidget(cancelButton);
45 |
46 | QVBoxLayout *mainLayout = new QVBoxLayout;
47 | mainLayout->addWidget(groupBox);
48 | mainLayout->addLayout(bottomLayout);
49 |
50 | setLayout(mainLayout);
51 |
52 | setWindowTitle(tr("New Database File"));
53 |
54 | setFixedHeight(sizeHint().height());
55 |
56 | connect(fileLocationsButton, SIGNAL(clicked()), this, SLOT(selectClicked()));
57 | connect(nameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(isTextEmpty()));
58 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
59 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
60 | }
61 |
62 | void NewDialog::selectClicked()
63 | {
64 | QString databaseName = QFileDialog::getSaveFileName(this,
65 | tr("New Database file"), ".",
66 | tr("Database files (*.db)"));
67 | if (!databaseName.isEmpty())
68 | {
69 | int index = databaseName.lastIndexOf("/");
70 | nameLineEdit->setText(databaseName.mid(index + 1));
71 | fileLocationStr = databaseName.left(index + 1);
72 | // fileLocationStr.replace(QString(("/")), QString(("\\")));
73 | fileLocationsLabel->setText(fileLocationStr);
74 | }
75 | }
76 |
77 | void NewDialog::isTextEmpty()
78 | {
79 | okButton->setEnabled(!nameLineEdit->text().isEmpty());
80 | }
81 |
82 | bool NewDialog::checkState() const
83 | {
84 | return checkBox->isChecked();
85 | }
86 |
87 | QString NewDialog::fileName() const
88 | {
89 | return nameLineEdit->text();
90 | }
91 |
92 | QString NewDialog::fileLocationName()
93 | {
94 | return fileLocationStr.replace(QString(("/")), QString(("\\")));
95 | }
96 |
--------------------------------------------------------------------------------
/src/newdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef NEWDIALOG_H
2 | #define NEWDIALOG_H
3 |
4 | #include
5 | class QLabel;
6 | class QLineEdit;
7 | class QComboBox;
8 | class QCheckBox;
9 |
10 | class NewDialog : public QDialog
11 | {
12 | Q_OBJECT
13 | public:
14 | explicit NewDialog(QWidget *parent = 0);
15 |
16 | public:
17 | bool checkState() const;
18 | QString fileLocationName();
19 | QString fileName() const;
20 |
21 | private slots:
22 | void selectClicked();
23 | void isTextEmpty();
24 |
25 | private:
26 | QLabel *nameLabel;
27 | QLabel *fileLocationsLabel;
28 | QLabel *locationsLabel;
29 | QLineEdit *nameLineEdit;
30 | QPushButton *fileLocationsButton;
31 | QPushButton *okButton;
32 | QPushButton *cancelButton;
33 | QCheckBox *checkBox;
34 | QString fileLocationStr;
35 | };
36 |
37 | #endif // NEWDIALOG_H
38 |
--------------------------------------------------------------------------------
/src/newtablewidget.cpp:
--------------------------------------------------------------------------------
1 | #include "newtablewidgett.h"
2 | #include "datatypedelegate.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | NewTableWidget::NewTableWidget(const QString &c, QWidget *parent) :
15 | QWidget(parent), connectName(c)
16 | {
17 | tableWidget = new QTableWidget;
18 | tableWidget->setRowCount(1);
19 | tableWidget->setColumnCount(4);
20 | DataTypeDelegate *dataTypeDelegate = new DataTypeDelegate(1, 2, 3);
21 | tableWidget->setItemDelegate(dataTypeDelegate);
22 | tableWidget->setHorizontalHeaderLabels(
23 | QStringList() << tr("Field Name") << tr("Data Type")
24 | << tr("Primary") << tr("Allow Null"));
25 |
26 | QHBoxLayout *mainLayout = new QHBoxLayout;
27 | mainLayout->addWidget(tableWidget);
28 | setLayout(mainLayout);
29 |
30 | connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem*)));
31 | // connect(dataTypeDelegate, SIGNAL(primaryChanged(int)), this, SLOT(setPrimary(int)));
32 | }
33 |
34 | NewTableWidget::~NewTableWidget()
35 | {
36 | // delete tableWidget;
37 | }
38 |
39 | void NewTableWidget::tableItemChanged(QTableWidgetItem *item)
40 | {
41 | if (item->column() != 0)
42 | return;
43 |
44 | if (item->text().isEmpty())
45 | return;
46 |
47 | int rows = tableWidget->rowCount();
48 | int count = 0;
49 | for (int i = 0; i < rows; ++i)
50 | {
51 | QTableWidgetItem *firstItem = tableWidget->item(i, 0);
52 | if (firstItem && !firstItem->data(Qt::DisplayRole).toString().isEmpty())
53 | {
54 | ++count;
55 | }
56 | }
57 | if (count == rows)
58 | {
59 | tableWidget->insertRow(rows);
60 | }
61 | }
62 |
63 | //void NewTableWidget::setPrimary(int row)
64 | //{
65 | // for (int i = 0; i < tableWidget->rowCount(); ++i)
66 | // {
67 | // if (i != row)
68 | // {
69 | // QTableWidgetItem *item = tableWidget->item(i,2);
70 | // if (item)
71 | // item->setData(Qt::DisplayRole, QVariant(false));
72 | // }
73 | // }
74 | //}
75 |
76 | bool NewTableWidget::save()
77 | {
78 | int r = QMessageBox::warning(this, tr("Save New Table"),
79 | tr("Do you want to save your changes?"),
80 | QMessageBox::Yes | QMessageBox::Default,
81 | QMessageBox::No,
82 | QMessageBox::Cancel | QMessageBox::Escape);
83 |
84 | if (r == QMessageBox::Cancel)
85 | {
86 | return false;
87 | }
88 | else if (r == QMessageBox::No)
89 | {
90 | return true;
91 | }
92 |
93 |
94 | bool ok = false;
95 | QString newTableName = QInputDialog::getText(this, tr("Edit Table Name"),
96 | tr("Save new table name:"),
97 | QLineEdit::Normal, tr("New Table"),
98 | &ok, 0, Qt::ImhNoPredictiveText);
99 |
100 | ok = !newTableName.isEmpty() && ok;
101 | if (ok)
102 | {
103 | QString sqlStr = tr("create table '") + newTableName + "' (";
104 | int i = 0;
105 | int rowCount = tableWidget->rowCount();
106 | QString primaryField;
107 | while (i < rowCount - 1)
108 | {
109 | QString fieldName = tableWidget->item(i, 0)->data(Qt::DisplayRole).toString();
110 |
111 | QTableWidgetItem *item = tableWidget->item(i, 1);
112 | QString fieldType;
113 | if (item)
114 | fieldType = item->data(Qt::DisplayRole).toString();
115 |
116 | item = tableWidget->item(i, 2);
117 | bool isPrimary = false;
118 | if (item)
119 | isPrimary = tableWidget->item(i, 2)->data(Qt::DisplayRole).toBool();
120 |
121 | // sqlStr += fieldName;
122 | sqlStr = sqlStr + "'" + fieldName + "'";
123 | sqlStr.append(tr(" ")).append(fieldType);
124 |
125 | if (isPrimary)
126 | primaryField = primaryField + "'"+ fieldName + "',";
127 | else
128 | {
129 | item = tableWidget->item(i, 3);
130 | bool isNull = false;
131 | if (item)
132 | isNull = item->data(Qt::DisplayRole).toBool();
133 |
134 | if (!isNull)
135 | {
136 | sqlStr += tr(" not null");
137 | }
138 | }
139 |
140 | sqlStr.append(tr(","));
141 | ++i;
142 | }
143 | int index;
144 | if (!primaryField.isEmpty())
145 | {
146 | primaryField = "primary key(" + primaryField;
147 | sqlStr += primaryField;
148 | index = sqlStr.lastIndexOf(',');
149 | sqlStr.replace(index, 2, "))");
150 | // qDebug() << sqlStr << endl;
151 | }
152 | else
153 | {
154 | index = sqlStr.lastIndexOf(',');
155 | sqlStr.replace(index, 1, ')');
156 | }
157 |
158 | QSqlDatabase db = QSqlDatabase::database(connectName);
159 | QSqlQuery query(db);
160 | query.exec(sqlStr);
161 | if (!query.isActive())
162 | {
163 | QMessageBox::information(this, tr("SQLite Database Manage"), query.lastError().text());
164 | return false;
165 | }
166 | }
167 | return ok;
168 | }
169 |
170 | void NewTableWidget::closeEvent(QCloseEvent *event)
171 | {
172 | if (save())
173 | event->accept();
174 | else
175 | event->ignore();
176 | }
177 |
--------------------------------------------------------------------------------
/src/newtablewidgett.h:
--------------------------------------------------------------------------------
1 | #ifndef FIELDWIDGET_H
2 | #define FIELDWIDGET_H
3 |
4 | #include
5 |
6 | class QTableWidget;
7 | class QTableWidgetItem;
8 |
9 | class NewTableWidget : public QWidget
10 | {
11 | Q_OBJECT
12 | public:
13 | NewTableWidget(const QString&, QWidget *parent = 0);
14 | ~NewTableWidget();
15 |
16 | private:
17 | bool save();
18 |
19 | protected:
20 | void closeEvent(QCloseEvent *event);
21 |
22 | private slots:
23 | void tableItemChanged(QTableWidgetItem*);
24 | // void setPrimary(int);
25 |
26 | private:
27 | const QString connectName;
28 |
29 | QTableWidget *tableWidget;
30 | };
31 |
32 | #endif // FIELDWIDGET_H
33 |
--------------------------------------------------------------------------------
/src/object_script.SQLiteDatabaseManage.Debug:
--------------------------------------------------------------------------------
1 | INPUT(
2 | ./debug\main.o
3 | ./debug\mainwindow.o
4 | ./debug\newdialog.o
5 | ./debug\tabwidget.o
6 | ./debug\finddialog.o
7 | ./debug\codeeditor.o
8 | ./debug\newtablewidget.o
9 | ./debug\datatypedelegate.o
10 | ./debug\highlighter.o
11 | ./debug\mydockwidget.o
12 | ./debug\exportwizard.o
13 | ./debug\querywidget.o
14 | ./debug\tableview.o
15 | ./debug\systemtableview.o
16 | ./debug\modifytablefieldwidget.o
17 | ./debug\createindexwidget.o
18 | ./debug\importwizard.o
19 | ./debug\mylistmodel.o
20 | ./debug\workthread.o
21 | ./debug\moc_mainwindow.o
22 | ./debug\moc_newdialog.o
23 | ./debug\moc_tabwidget.o
24 | ./debug\moc_finddialog.o
25 | ./debug\moc_codeeditor.o
26 | ./debug\moc_newtablewidgett.o
27 | ./debug\moc_datatypedelegate.o
28 | ./debug\moc_highlighter.o
29 | ./debug\moc_mydockwidget.o
30 | ./debug\moc_exportwizard.o
31 | ./debug\moc_querywidget.o
32 | ./debug\moc_tableview.o
33 | ./debug\moc_systemtableview.o
34 | ./debug\moc_modifytablefieldwidget.o
35 | ./debug\moc_createindexwidget.o
36 | ./debug\moc_importwizard.o
37 | ./debug\moc_mylistmodel.o
38 | ./debug\moc_workthread.o
39 | ./debug\qrc_SQLiteDatabaseManage.o
40 | );
41 |
--------------------------------------------------------------------------------
/src/object_script.SQLiteDatabaseManage.Release:
--------------------------------------------------------------------------------
1 | INPUT(
2 | ./release\main.o
3 | ./release\mainwindow.o
4 | ./release\newdialog.o
5 | ./release\tabwidget.o
6 | ./release\finddialog.o
7 | ./release\codeeditor.o
8 | ./release\newtablewidget.o
9 | ./release\datatypedelegate.o
10 | ./release\highlighter.o
11 | ./release\mydockwidget.o
12 | ./release\exportwizard.o
13 | ./release\querywidget.o
14 | ./release\tableview.o
15 | ./release\systemtableview.o
16 | ./release\modifytablefieldwidget.o
17 | ./release\createindexwidget.o
18 | ./release\importwizard.o
19 | ./release\mylistmodel.o
20 | ./release\workthread.o
21 | ./release\moc_mainwindow.o
22 | ./release\moc_newdialog.o
23 | ./release\moc_tabwidget.o
24 | ./release\moc_finddialog.o
25 | ./release\moc_codeeditor.o
26 | ./release\moc_newtablewidgett.o
27 | ./release\moc_datatypedelegate.o
28 | ./release\moc_highlighter.o
29 | ./release\moc_mydockwidget.o
30 | ./release\moc_exportwizard.o
31 | ./release\moc_querywidget.o
32 | ./release\moc_tableview.o
33 | ./release\moc_systemtableview.o
34 | ./release\moc_modifytablefieldwidget.o
35 | ./release\moc_createindexwidget.o
36 | ./release\moc_importwizard.o
37 | ./release\moc_mylistmodel.o
38 | ./release\moc_workthread.o
39 | ./release\qrc_SQLiteDatabaseManage.o
40 | );
41 |
--------------------------------------------------------------------------------
/src/qexcel.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/qexcel.cpp
--------------------------------------------------------------------------------
/src/qexcel.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/qexcel.h
--------------------------------------------------------------------------------
/src/qss/SQLite Database Manage.qss:
--------------------------------------------------------------------------------
1 |
2 | QStatusBar {
3 | font: 10pt;
4 | }
5 |
6 | QPlainTextEdit:hover {
7 | border: 2px groove gray;
8 | border-color: deepskyblue;
9 | }
10 |
11 | QLineEdit:hover {
12 | border-radius: 2px;
13 | border: 2px groove;
14 | border-color: deepskyblue
15 | }
16 |
17 | QGroupBox {
18 | border: 1px groove gray;
19 | border-radius: 2px;
20 | /* border-color: deepskyblue;*/
21 | margin-top: 2ex;
22 | }
23 |
24 |
25 | QGroupBox::title {
26 | font: bold;
27 | /* color: red;*/
28 | subcontrol-origin: margin;
29 | subcontrol-position: top center;
30 | padding: 0 3px;
31 | }
32 |
33 |
34 | /*
35 | QTableView {
36 | selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5,
37 | stop: 0 darkgreen, stop: 1 lightgreen);
38 | }
39 | */
40 |
41 | /*
42 | QTreeView {
43 | alternate-background-color: yellow;
44 | }
45 |
46 | QTreeView {
47 | show-decoration-selected: 1;
48 | }
49 |
50 | QTreeView::item {
51 | border: 1px solid #d9d9d9;
52 | border-top-color: transparent;
53 | border-bottom-color: transparent;
54 | }
55 |
56 | QTreeView::item:hover {
57 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
58 | border: 1px solid #bfcde4;
59 | }
60 |
61 | QTreeView::item:selected {
62 | border: 1px solid #567dbc;
63 | }
64 |
65 | QTreeView::item:selected:active{
66 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
67 | }
68 |
69 | QTreeView::item:selected:!active {
70 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf);
71 | }
72 | */
73 |
74 | QToolTip {
75 | /* background-color: springgreen;*/
76 | /* border-color: gray;*/
77 | border-color: black;
78 | border-width: 2px;
79 | border-style: solid;
80 | padding: 1px 5px;
81 | /* font: bold;*/
82 | }
83 |
84 | QTabWidget::pane { /* The tab widget frame */
85 | border: 1px groove gray;
86 | background-color: white;
87 | }
88 |
89 | QTabWidget::tab-bar {
90 | left: 5px; /* move to the right by 5px */
91 | }
92 |
93 | /* Style the tab using the tab sub-control. Note that
94 | it reads QTabBar _not_ QTabWidget */
95 | /*
96 | QTabBar::tab {
97 | background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
98 | stop: 0 deepskyblue, stop: 0.4 #DDDDDD,
99 | stop: 0.5 #D8D8D8, stop: 1.0 lightblue);
100 |
101 | border: 1px solid aqua;
102 | border-bottom-color: aqua;
103 | border-top-left-radius: 4px;
104 | border-top-right-radius: 4px;
105 | min-width: 8ex;
106 | padding: 2px;
107 | }
108 |
109 | QTabBar::tab:selected, QTabBar::tab:hover {
110 | background: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5,
111 | stop: 0 red, stop: 1 white);
112 | }
113 |
114 |
115 | QTabBar::tab:selected {
116 | border-color: deepskyblue;
117 | border-bottom-color: aqua;
118 | }
119 |
120 |
121 | QTabBar::tab:!selected {
122 | margin-top: 2px;
123 | }
124 | */
125 |
--------------------------------------------------------------------------------
/src/querywidget.cpp:
--------------------------------------------------------------------------------
1 | #include "querywidget.h"
2 | #include "codeeditor.h"
3 | #include "highlighter.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | QueryWidget::QueryWidget(const QString &c, QWidget *parent) :
26 | QWidget(parent), connectName(c), font("", 10)
27 | {
28 | groupBox = new QGroupBox(tr("SQL"));
29 | sqlCodeEditor = new CodeEditor(parent);
30 | // font.setUnderline(true);
31 |
32 | sqlCodeEditor->setFont(font);
33 | // sqlCodeEditor->setToolTip(tr("SQL Statement"));
34 | highlighter = new Highlighter(sqlCodeEditor->document());
35 |
36 | QHBoxLayout *textLayout = new QHBoxLayout;
37 | textLayout->addWidget(sqlCodeEditor);
38 | groupBox = new QGroupBox(tr("SQL"));
39 | groupBox->setLayout(textLayout);
40 |
41 | tabWidget = new QTabWidget;
42 | resultText = new QPlainTextEdit;
43 | resultText->setReadOnly(true);
44 | tabWidget->addTab(resultText, tr("Result"));
45 | // tabWidget->setVisible(false);
46 |
47 | QVBoxLayout *mainLayout = new QVBoxLayout;
48 | mainLayout ->addWidget(groupBox);
49 | mainLayout->addWidget(tabWidget);
50 |
51 | setLayout(mainLayout);
52 |
53 | databaseInitialize();
54 | // sqlCodeEditor->setParent(this);
55 |
56 | // listWidget->addItems(QStringList() << "select" << "a" << "b" << "c" << "d" << "e" << "f");
57 | // connect(sqlCodeEditor, SIGNAL(textChanged()), this, SLOT(textChanged()));
58 | }
59 |
60 | QueryWidget::~QueryWidget()
61 | {
62 | // qDebug() << "~QueryWidget";
63 | // delete highlighter;
64 | // delete sqlCodeEditor;
65 | // delete groupBox;
66 | // delete resultText;
67 | // delete tabWidget;
68 | for (int i = 0; i < tableView.size(); ++i)
69 | {
70 | delete tableModelList[i];
71 | // delete tableView[i];
72 | }
73 | }
74 |
75 | void QueryWidget::onSqlExecute()
76 | {
77 | QSqlDatabase db = QSqlDatabase::database(connectName);
78 |
79 | QString str = sqlCodeEditor->toPlainText();
80 | QStringList sqlCodeList = str.split(';', QString::SkipEmptyParts);
81 | // QStringList sqlCodeList = QStringList(str);
82 | // QStringList sqlCodeList = str.split(QRegExp(//[^\n]*), QString::SkipEmptyParts);
83 | // qDebug() << sqlCodeList;
84 | // return;
85 |
86 | // QSqlQuery query(db);
87 |
88 | // Test insert data
89 | // QString sql = "insert into testTable values('";
90 |
91 | // time.restart();
92 | // db.transaction();
93 | // for (int i = 50000; i < 150000; ++i)
94 | // {
95 | // QString str = sql + QString::number(i) + "'";
96 | // str = str + tr(",'%1','%2','%3','%4','%5','%6','%7','%8','%9')").arg(i+1).arg(i+2)
97 | // .arg(i+3).arg(i+4).arg(i+5).arg(i+6).arg(i+7).arg(i+8).arg(i+9);
98 | //// qDebug() << str;
99 | //// query.exec(str);
100 | // db.exec(str);
101 | // }
102 | // db.commit();
103 | // resultText->setPlainText(tr("%1 ms").arg(time.elapsed()));
104 | // return;
105 |
106 | int cnt = 1;
107 | resultText->clear();
108 | for (int i = 0; i < tableView.size(); ++i)
109 | {
110 | delete tableView[i];
111 | delete tableModelList[i];
112 | }
113 | tableView.clear();
114 | tableModelList.clear();
115 | time.restart();
116 | db.transaction();
117 | for (int i = 0; i < sqlCodeList.size(); ++i)
118 | {
119 | // qDebug() << sqlCodeList[i] << endl;
120 | // QString sqlCode = sqlCodeList[i].toUpper();
121 | // query.exec(sqlCodeList[i]);
122 | QSqlQuery query = db.exec(sqlCodeList[i]);
123 | if (!query.isActive())
124 | {
125 | resultText->setPlainText(query.lastError().text());
126 | return;
127 | }
128 | if (query.isSelect())
129 | {
130 | createNewTable(cnt++, sqlCodeList[i]);
131 | }
132 | }
133 | db.commit();
134 | resultText->setPlainText(tr("Query Sucessfully\nTime elapsed: %1 ms").arg(time.elapsed()));
135 | // tabWidget->setVisible(true);
136 | }
137 |
138 | void QueryWidget::createNewTable(int num, const QString &query)
139 | {
140 | QSqlDatabase db = QSqlDatabase::database(connectName);
141 | QSqlTableModel *model = new QSqlTableModel(this, db);
142 | model->QSqlQueryModel::setQuery(query, db);
143 | if (model->lastError().isValid())
144 | {
145 | delete model;
146 | return;
147 | }
148 | QTableView *view = new QTableView;
149 | view->setModel(model);
150 | view->setEditTriggers(QAbstractItemView::NoEditTriggers);
151 | view->resizeColumnsToContents();
152 | tableView.push_back(view);
153 | tableModelList.push_back(model);
154 | tabWidget->addTab(view, tr("Table") + QString::number(num));
155 | }
156 |
157 | void QueryWidget::saveAs()
158 | {
159 | QString sqlFileName = QFileDialog::getSaveFileName(this, tr("Save as"), "",
160 | tr("Database files (*.sql)"));
161 | if (!sqlFileName.isEmpty())
162 | {
163 | QFile file(sqlFileName);
164 | file.open(QIODevice::WriteOnly);
165 | QString str = sqlCodeEditor->toPlainText();
166 | str.replace("\n", "\r\n");
167 | file.write(str.toAscii());
168 | file.close();
169 | }
170 | }
171 |
172 | void QueryWidget::openSql()
173 | {
174 | QString sqlFileName = QFileDialog::getOpenFileName(this,
175 | tr("Open SQL file"), ".",
176 | tr("Sql files (*.sql | *.txt)"));
177 | if (!sqlFileName.isEmpty())
178 | {
179 | QFile file(sqlFileName);
180 | file.open(QIODevice::ReadOnly);
181 | QTextStream stream(&file);
182 | sqlCodeEditor->setPlainText(stream.readAll());
183 | file.close();
184 | }
185 | }
186 |
187 | void QueryWidget::closeEvent(QCloseEvent *event)
188 | {
189 | int r = QMessageBox::warning(this, tr("Save New Query"),
190 | tr("Do you want to save your changes?"),
191 | QMessageBox::Yes | QMessageBox::Default,
192 | QMessageBox::No,
193 | QMessageBox::Cancel | QMessageBox::Escape);
194 |
195 | if (r == QMessageBox::Cancel)
196 | {
197 | event->ignore();
198 | return;
199 | }
200 |
201 | if (r == QMessageBox::Yes)
202 | saveAs();
203 |
204 | event->accept();
205 | }
206 |
207 | void QueryWidget::runLineSql()
208 | {
209 | QString sqlStr = sqlCodeEditor->textCursor().selection().toPlainText();
210 | if (!sqlStr.isEmpty())
211 | {
212 | for (int i = 0; i < tableView.size(); ++i)
213 | {
214 | delete tableView[i];
215 | delete tableModelList[i];
216 | }
217 | tableView.clear();
218 | tableModelList.clear();
219 |
220 | resultText->clear();
221 | QSqlDatabase db = QSqlDatabase::database(connectName);
222 | QSqlQuery query(db);
223 | time.restart();
224 | query.exec(sqlStr);
225 | if (!query.isActive())
226 | {
227 | resultText->setPlainText(query.lastError().text());
228 | return;
229 | }
230 | if (query.isSelect())
231 | {
232 | createNewTable(1, sqlStr);
233 | QString str = tr("%1\nQuery Sucessfully\nTime elapsed: %2 ms").arg(sqlStr).arg(time.elapsed());
234 | resultText->setPlainText(str);
235 | }
236 | else
237 | {
238 | QString rows = QString::number(query.numRowsAffected());
239 | QString str = tr("%1\nQuery Sucessfully\nRow(s) affected: %2\nTime elapsed: %3 ms").arg(sqlStr).arg(rows).arg(time.elapsed());
240 | resultText->setPlainText(str);
241 | }
242 | // tabWidget->setVisible(true);
243 | }
244 | }
245 |
246 | void QueryWidget::analysisSql()
247 | {
248 | QString sqlStr = sqlCodeEditor->textCursor().selection().toPlainText();
249 | if (!sqlStr.isEmpty())
250 | {
251 | for (int i = 0; i < tableView.size(); ++i)
252 | {
253 | delete tableView[i];
254 | delete tableModelList[i];
255 | }
256 | tableView.clear();
257 | tableModelList.clear();
258 |
259 | QSqlDatabase db = QSqlDatabase::database(connectName);
260 | QSqlQuery query(db);
261 |
262 | resultText->clear();
263 | if (!query.prepare(sqlStr))
264 | {
265 | resultText->setPlainText(query.lastError().text());
266 | return;
267 | }
268 | resultText->setPlainText(tr("Analysis Sucessfully"));
269 | // tabWidget->setVisible(true);
270 | }
271 | }
272 |
273 | void QueryWidget::setConnectName(const QString &connectName)
274 | {
275 | this->connectName = connectName;
276 | databaseInitialize();
277 | }
278 |
279 | void QueryWidget::databaseInitialize()
280 | {
281 | QSqlDatabase db = QSqlDatabase::database(connectName);
282 | QStringList tableName = db.tables(QSql::Tables);
283 | QSet fieldName;
284 | // qDebug() << "next" << db.tables(QSql::Views);
285 | for (int i = 0; i < tableName.size(); ++i)
286 | {
287 | QSqlRecord record = db.record(tableName[i]);
288 | for (int j = 0; j < record.count(); ++j)
289 | {
290 | QString name = record.fieldName(j);
291 | fieldName.insert(name);
292 | }
293 | }
294 |
295 | QSet str = fieldName + QSet::fromList(db.tables(QSql::AllTables));
296 | // qDebug() << str;
297 | sqlCodeEditor->addString(str);
298 | highlighter->addString(str);
299 | }
300 |
301 | void QueryWidget::copy()
302 | {
303 | sqlCodeEditor->copy();
304 | }
305 |
306 | void QueryWidget::paste()
307 | {
308 | sqlCodeEditor->paste();
309 | }
310 |
311 | void QueryWidget::cut()
312 | {
313 | sqlCodeEditor->cut();
314 | }
315 |
316 | void QueryWidget::del()
317 | {
318 | sqlCodeEditor->insertPlainText("");
319 | }
320 |
321 | void QueryWidget::findNext(const QString &str)
322 | {
323 | if (sqlCodeEditor->find(str))
324 | {
325 | activateWindow();
326 | }
327 | else
328 | {
329 | QApplication::beep();
330 | }
331 | setFocus();
332 | }
333 |
334 | void QueryWidget::findPrevious(const QString &str)
335 | {
336 | if (sqlCodeEditor->find(str, QTextDocument::FindBackward))
337 | {
338 | activateWindow();
339 | }
340 | else
341 | {
342 | QApplication::beep();
343 | }
344 | setFocus();
345 | }
346 |
--------------------------------------------------------------------------------
/src/querywidget.h:
--------------------------------------------------------------------------------
1 | #ifndef QUERYWIDGET_H
2 | #define QUERYWIDGET_H
3 |
4 | #include
5 | #include
6 | class QGroupBox;
7 | class CodeEditor;
8 | class Highlighter;
9 | class QTabWidget;
10 | class QPlainTextEdit;
11 | class QTableView;
12 | class QSqlTableModel;
13 |
14 | class QueryWidget : public QWidget
15 | {
16 | Q_OBJECT
17 | public:
18 | explicit QueryWidget(const QString &, QWidget *parent = 0);
19 | ~QueryWidget();
20 |
21 | public:
22 | void onSqlExecute();
23 | void createNewTable(int num, const QString &query);
24 | void saveAs();
25 | void analysisSql();
26 | void openSql();
27 | void runLineSql();
28 | void setConnectName(const QString &connectName);
29 | void copy();
30 | void paste();
31 | void cut();
32 | void del();
33 | void findNext(const QString &str);
34 | void findPrevious(const QString &str);
35 |
36 | protected:
37 | void closeEvent(QCloseEvent *event);
38 |
39 | private:
40 | void databaseInitialize();
41 |
42 | private:
43 | QString connectName;
44 |
45 | QGroupBox *groupBox;
46 | CodeEditor *sqlCodeEditor;
47 | Highlighter *highlighter;
48 |
49 | QTabWidget *tabWidget;
50 | QPlainTextEdit *resultText;
51 | QList tableView;
52 | QList tableModelList;
53 |
54 | QFont font;
55 |
56 | QTime time;
57 | };
58 |
59 | #endif // QUERYWIDGET_H
60 |
--------------------------------------------------------------------------------
/src/sqltextedit.cpp:
--------------------------------------------------------------------------------
1 | #include "sqltextedit.h"
2 |
3 | QString sqlList[] = {"select", "from", "insert", "\0"};
4 |
5 | SqlTextEdit::SqlTextEdit(QWidget *parent) :
6 | QTextEdit(parent)
7 | {
8 | connect(this, SIGNAL(textChanged()), this, SLOT(somethingChanged()));
9 |
10 | }
11 |
12 | void SqlTextEdit::somethingChanged()
13 | {
14 | // QString str = toPlainText();
15 | }
16 |
--------------------------------------------------------------------------------
/src/sqltextedit.h:
--------------------------------------------------------------------------------
1 | #ifndef SQLTEXTEDIT_H
2 | #define SQLTEXTEDIT_H
3 |
4 | #include
5 |
6 | class SqlTextEdit : public QTextEdit
7 | {
8 | Q_OBJECT
9 | public:
10 | explicit SqlTextEdit(QWidget *parent = 0);
11 |
12 | private slots:
13 | void somethingChanged();
14 | };
15 |
16 | #endif // SQLTEXTEDIT_H
17 |
--------------------------------------------------------------------------------
/src/systemtableview.cpp:
--------------------------------------------------------------------------------
1 | #include "systemtableview.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | SystemTableView::SystemTableView(const QString &connectName, const QString &tableName, QWidget *parent) :
10 | QTableView(parent)
11 | {
12 | QSqlDatabase db = QSqlDatabase::database(connectName);
13 | model = new QSqlTableModel(0, db);
14 | model->setTable(tableName);
15 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
16 | model->select();
17 |
18 | // QSqlRecord record = model->record();
19 | // for (int i = 0; i < record.count(); ++i)
20 | // {
21 | // model->setHeaderData(i, Qt::Horizontal, record.fieldName(i));
22 | // }
23 |
24 | this->setModel(model);
25 | this->resizeColumnsToContents();
26 | this->setEditTriggers(QAbstractItemView::NoEditTriggers);
27 |
28 | copyAction = new QAction(tr("&Copy"), this);
29 | copyAction->setIcon(QIcon(":/images/copy.png"));
30 | copyAction->setStatusTip(tr("Copy the current selection's contents "
31 | "to the clipboard"));
32 | connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
33 | addAction(copyAction);
34 | setContextMenuPolicy(Qt::ActionsContextMenu);
35 |
36 | }
37 |
38 | SystemTableView::~SystemTableView()
39 | {
40 | // qDebug() << "~SystemTableView";
41 | delete model;
42 | delete copyAction;
43 | }
44 |
45 | void SystemTableView::copy()
46 | {
47 | QItemSelectionModel *selectModel = selectionModel();
48 | if (!selectModel)
49 | return;
50 |
51 | QString str;
52 | QModelIndexList indexList = selectModel->selectedIndexes();
53 | QMap strMap;
54 |
55 | for (int i = indexList.size() - 1; i >= 0; --i)
56 | {
57 | strMap.insertMulti(indexList[i].row(), indexList[i].data(Qt::DisplayRole).toString());
58 | }
59 |
60 | QList rowList = strMap.uniqueKeys();
61 |
62 | for (int i = 0; i < rowList.size(); ++i)
63 | {
64 | if (i > 0)
65 | str += "\n";
66 |
67 | QMap::iterator it = strMap.lowerBound(rowList[i]);
68 | QMap::iterator itUpper = strMap.upperBound(rowList[i]);
69 | while (it != itUpper)
70 | {
71 | str += it.value();
72 | if (++it != itUpper)
73 | str += "\t";
74 | }
75 | }
76 |
77 | QApplication::clipboard()->setText(str);
78 | }
79 |
--------------------------------------------------------------------------------
/src/systemtableview.h:
--------------------------------------------------------------------------------
1 | #ifndef SYSTEMTABLEVIEW_H
2 | #define SYSTEMTABLEVIEW_H
3 |
4 | #include
5 | class QSqlTableModel;
6 |
7 | class SystemTableView : public QTableView
8 | {
9 | Q_OBJECT
10 | public:
11 | explicit SystemTableView(const QString &connectName, const QString &tableName, QWidget *parent = 0);
12 | ~SystemTableView();
13 |
14 | public slots:
15 | void copy();
16 |
17 | private:
18 | QSqlTableModel *model;
19 |
20 | QAction *copyAction;
21 | };
22 |
23 | #endif // SYSTEMTABLEVIEW_H
24 |
--------------------------------------------------------------------------------
/src/tableview.cpp:
--------------------------------------------------------------------------------
1 | #include "tableview.h"
2 | #include "mainwindow.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 |
21 | TableView::TableView(const QString &connectName, const QString &tableName, QWidget *parent) :
22 | QWidget(parent)
23 | {
24 | QSqlDatabase db = QSqlDatabase::database(connectName);
25 | QSqlQuery query(db);
26 | query.exec(tr("select count(*) from %1").arg(tableName));
27 | uint rowCount = 0;
28 | while (query.next())
29 | {
30 | rowCount = query.value(0).toUInt();
31 | }
32 | //qDebug() << rowCount;
33 | uint page = rowCount / rowNumber;
34 | pageCount = rowCount % rowNumber ? page + 1 : page;
35 | // qDebug() << db.primaryIndex(tableName).fieldName(0) << endl;
36 | model = new QSqlTableModel(this, db);
37 | model->setTable(tableName);
38 | model->setFilter(tr(" 1=1 limit 0,%1").arg(rowNumber));
39 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
40 | model->select();
41 |
42 | // QSqlRecord record = model->record();
43 | // for (int i = 0; i < record.count(); ++i)
44 | // {
45 | // model->setHeaderData(i, Qt::Horizontal, record.fieldName(i));
46 | // }
47 |
48 | view = new QTableView(this);
49 | view->setModel(model);
50 | view->resizeColumnsToContents();
51 | view->setSelectionMode(QAbstractItemView::ContiguousSelection);
52 |
53 | QHBoxLayout *bottomLayout = new QHBoxLayout();
54 | firstButton = new QPushButton(tr("First"));
55 | firstButton->setEnabled(false);
56 | prevButton = new QPushButton(tr("Previous"));
57 | prevButton->setEnabled(false);
58 | //prevButton->setIcon();
59 | pageNumberlineEdit = new QLineEdit();
60 | pageNumberlineEdit->setEnabled(false);
61 | pageNumberlineEdit->setText("1");
62 | pageNumberlineEdit->setFixedWidth(50);
63 | pageNumberlineEdit->setAlignment(Qt::AlignHCenter);
64 | QLabel *label = new QLabel(tr("/"));
65 | QLabel *countLabel = new QLabel(QString::number(pageCount));
66 | nextButton = new QPushButton(tr("Next"));
67 | nextButton->setEnabled(pageCount > 1);
68 | endButton = new QPushButton(tr("End"));
69 | endButton->setEnabled(pageCount > 1);
70 | bottomLayout->addStretch();
71 | bottomLayout->addWidget(firstButton);
72 | bottomLayout->addWidget(prevButton);
73 | bottomLayout->addWidget(pageNumberlineEdit);
74 | bottomLayout->addWidget(label);
75 | bottomLayout->addWidget(countLabel);
76 | bottomLayout->addWidget(nextButton);
77 | bottomLayout->addWidget(endButton);
78 | bottomLayout->addStretch();
79 |
80 | QVBoxLayout *mainLayout = new QVBoxLayout();
81 | mainLayout->addWidget(view);
82 | mainLayout->addLayout(bottomLayout);
83 |
84 | setLayout(mainLayout);
85 |
86 | // setSortingEnabled(true);
87 |
88 | createMenu();
89 | connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
90 | connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged()));
91 | connect(firstButton, SIGNAL(clicked()), this, SLOT(firstButtonClicked()));
92 | connect(prevButton, SIGNAL(clicked()), this, SLOT(prevButtonClicked()));
93 | connect(nextButton, SIGNAL(clicked()), this, SLOT(nextButtonClicked()));
94 | connect(endButton, SIGNAL(clicked()), this, SLOT(endButtonClicked()));
95 |
96 | setWindowTitle(tr("%1[*]").arg(tableName));
97 | setWindowModified(false);
98 |
99 | }
100 |
101 | TableView::~TableView()
102 | {
103 | // qDebug() << "~TableView";
104 | delete model;
105 | // delete cutAction;
106 | // delete copyAction;
107 | // delete pasteAction;
108 | // delete deleteAction;
109 | // delete insertRowAction;
110 | // delete deleteRowAction;
111 | // delete tableMenu;
112 | }
113 |
114 | void TableView::createMenu()
115 | {
116 | cutAction = new QAction(tr("Cu&t"), this);
117 | cutAction->setIcon(QIcon(":/images/cut.png"));
118 | cutAction->setShortcut(tr("Ctrl+X"));
119 | cutAction->setStatusTip(tr("Cut the current selection's contents "
120 | "to the clipboard"));
121 | connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
122 |
123 | copyAction = new QAction(tr("&Copy"), this);
124 | copyAction->setIcon(QIcon(":/images/copy.png"));
125 | copyAction->setShortcut(tr("Ctrl+C"));
126 | copyAction->setStatusTip(tr("Copy the current selection's contents "
127 | "to the clipboard"));
128 | connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
129 |
130 | pasteAction = new QAction(tr("&Paste"), this);
131 | pasteAction->setIcon(QIcon(":/images/paste.png"));
132 | pasteAction->setShortcut(tr("Ctrl+V"));
133 | pasteAction->setStatusTip(tr("Paste the clipboard's contents into "
134 | "the current selection"));
135 | connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
136 |
137 | deleteAction = new QAction(tr("&Delete"), this);
138 | deleteAction->setIcon(QIcon(":/images/delete.png"));
139 | deleteAction->setShortcut(tr("Del"));
140 | deleteAction->setStatusTip(tr("Delete the current selection's "
141 | "contents"));
142 | connect(deleteAction, SIGNAL(triggered()), this, SLOT(del()));
143 |
144 | insertRowAction = new QAction(tr("&Insert row"), this);
145 | insertRowAction->setIcon(QIcon(":/images/insertrow.png"));
146 | insertRowAction->setStatusTip(tr("Insert a row in current Table"));
147 | connect(insertRowAction, SIGNAL(triggered()), this, SLOT(insertRow()));
148 |
149 | deleteRowAction = new QAction(tr("&Delete rows"), this);
150 | deleteRowAction->setIcon(QIcon(":/images/deleterow.png"));
151 | deleteRowAction->setStatusTip(tr("Delete the current selection's rows"));
152 | connect(deleteRowAction, SIGNAL(triggered()), this, SLOT(delRow()));
153 |
154 |
155 | tableMenu = new QMenu(this);
156 | tableMenu->addAction(cutAction);
157 | tableMenu->addAction(copyAction);
158 | tableMenu->addAction(pasteAction);
159 | tableMenu->addAction(deleteAction);
160 | tableMenu->addSeparator();
161 | tableMenu->addAction(insertRowAction);
162 | tableMenu->addAction(deleteRowAction);
163 | this->setContextMenuPolicy(Qt::CustomContextMenu);
164 | }
165 |
166 | void TableView::showMenu(const QPoint &)
167 | {
168 | tableMenu->exec(QCursor::pos());
169 | }
170 |
171 | void TableView::cut()
172 | {
173 | if (MainWindow::getCurrentReadOnly())
174 | {
175 | QMessageBox::information(this, tr("SQLite Database Manage"),
176 | tr("The information cannot be cut because the "
177 | "current settings is Read Only."));
178 | }
179 | else
180 | {
181 | copy();
182 | del();
183 | }
184 | }
185 |
186 | void TableView::copy()
187 | {
188 | QItemSelectionModel *selectModel = view->selectionModel();
189 | if (!selectModel)
190 | return;
191 |
192 | QString str;
193 | QModelIndexList indexList = selectModel->selectedIndexes();
194 | QMap strMap;
195 |
196 | for (int i = indexList.size() - 1; i >= 0; --i)
197 | {
198 | strMap.insertMulti(indexList[i].row(), indexList[i].data(Qt::DisplayRole).toString());
199 | }
200 |
201 | QList rowList = strMap.uniqueKeys();
202 |
203 | for (int i = 0; i < rowList.size(); ++i)
204 | {
205 | if (i > 0)
206 | str += "\n";
207 |
208 | QMap::iterator it = strMap.lowerBound(rowList[i]);
209 | QMap::iterator itUpper = strMap.upperBound(rowList[i]);
210 | while (it != itUpper)
211 | {
212 | str += it.value();
213 | if (++it != itUpper)
214 | str += "\t";
215 | }
216 | }
217 |
218 | QApplication::clipboard()->setText(str);
219 | }
220 |
221 | void TableView::paste()
222 | {
223 | if (MainWindow::getCurrentReadOnly())
224 | {
225 | QMessageBox::information(this, tr("SQLite Database Manage"),
226 | tr("The information cannot be pasted because the "
227 | "current settings is Read Only."));
228 | return;
229 | }
230 |
231 | QItemSelectionModel *selectModel = view->selectionModel();
232 | if (!selectModel)
233 | return;
234 |
235 | QString str = QApplication::clipboard()->text();
236 | QStringList rows = str.split('\n');
237 | int numRows = rows.count();
238 | int numColumns = rows.first().count('\t') + 1;
239 | QModelIndexList indexList = selectModel->selectedIndexes();
240 |
241 | if (numRows * numColumns != indexList.size())
242 | {
243 | QMessageBox::information(this, tr("SQLite Database Manage"),
244 | tr("The information cannot be pasted because the copy "
245 | "and paste areas aren't the same size."));
246 | return;
247 | }
248 |
249 | QMap strMap;
250 | for (int i = numRows - 1; i >= 0; --i)
251 | {
252 | QStringList strList = rows[i].split('\t');
253 | for (int j = 0; j < numColumns; ++j)
254 | {
255 | strMap.insertMulti(j, strList[j]);
256 | }
257 | }
258 |
259 | QList strValue = strMap.values();
260 |
261 | for (int i = 0; i < indexList.size(); ++i)
262 | {
263 | model->setData(indexList[i], strValue[i]);
264 | }
265 |
266 | }
267 |
268 | void TableView::del()
269 | {
270 | if (MainWindow::getCurrentReadOnly())
271 | {
272 | QMessageBox::information(this, tr("SQLite Database Manage"),
273 | tr("The row cannot be delete because the "
274 | "current settings is Read Only."));
275 | return;
276 | }
277 |
278 | QItemSelectionModel *selectModel = view->selectionModel();
279 | if (!selectModel)
280 | return;
281 |
282 | QModelIndexList indexList = selectModel->selectedIndexes();
283 | for (int i = 0; i < indexList.size(); ++i)
284 | {
285 | model->setData(indexList[i], tr(""));
286 | }
287 |
288 | }
289 |
290 | void TableView::insertRow()
291 | {
292 | if (MainWindow::getCurrentReadOnly())
293 | {
294 | QMessageBox::information(this, tr("SQLite Database Manage"),
295 | tr("The row cannot be insert because the "
296 | "current settings is Read Only."));
297 | return;
298 | }
299 |
300 | int row = model->rowCount();
301 | model->insertRow(row);
302 |
303 | QModelIndex index = model->index(row, 0);
304 | view->setCurrentIndex(index);
305 | view->edit(index);
306 |
307 | }
308 |
309 | void TableView::delRow()
310 | {
311 | if (MainWindow::getCurrentReadOnly())
312 | {
313 | QMessageBox::information(this, tr("SQLite Database Manage"),
314 | tr("The row cannot be delete because the "
315 | "current settings is Read Only."));
316 | return;
317 | }
318 |
319 | int ok = QMessageBox::warning(this, tr("SQLite Database Manage"),
320 | tr("Are you sure delete the current rows"),
321 | QMessageBox::Yes | QMessageBox::Default,
322 | QMessageBox::No,
323 | QMessageBox::Cancel | QMessageBox::Escape);
324 |
325 | if (ok == QMessageBox::Yes)
326 | {
327 | // qDebug() << selectionModel()->selectedRows(0).count();
328 | // qDebug() << selectionModel()->selectedRows(0).begin()->row();
329 |
330 | const int rowCount = view->selectionModel()->selectedRows(0).count();
331 | int row = view->selectionModel()->selectedRows(0).begin()->row();
332 | for (int i = 0; i < rowCount; ++i)
333 | {
334 | model->removeRow(row++);
335 | }
336 | // model->removeRow(currentIndex().row());
337 | model->submitAll();
338 |
339 | }
340 | }
341 |
342 | void TableView::setRead(bool b)
343 | {
344 | if (b)
345 | {
346 | view->setEditTriggers(QAbstractItemView::NoEditTriggers);
347 | }
348 | else
349 | {
350 | view->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::AnyKeyPressed);
351 | }
352 | }
353 |
354 | void TableView::setShowGrid(bool b)
355 | {
356 | view->setShowGrid(b);
357 | }
358 |
359 | void TableView::dataChanged()
360 | {
361 | if (!isWindowModified())
362 | {
363 | setWindowModified(true);
364 | emit tableDataChanged(model->database().connectionName(), model->tableName(), true);
365 | }
366 | }
367 |
368 | void TableView::save()
369 | {
370 | model->database().transaction();
371 | if (model->submitAll())
372 | {
373 | model->database().commit();
374 | setWindowModified(false);
375 | emit tableDataChanged(model->database().connectionName(), model->tableName(), false);
376 | setWindowModified(false);
377 | }
378 | else
379 | {
380 | model->database().rollback();
381 | QMessageBox::warning(this, tr("Cached Table"),
382 | tr("The database reported an error: %1")
383 | .arg(model->lastError().text()));
384 | }
385 | }
386 |
387 | void TableView::findNext(const QString &str, Qt::CaseSensitivity cs)
388 | {
389 | int row = view->currentIndex().row();
390 | int column = view->currentIndex().column() + 1;
391 | int RowCount = model->rowCount();
392 | int ColumnCount = model->columnCount();
393 |
394 | while (row < RowCount)
395 | {
396 | while (column < ColumnCount)
397 | {
398 | QModelIndex findIndex = model->index(row, column);
399 | if (findIndex.data(Qt::DisplayRole).toString().contains(str, cs))
400 | {
401 | view->clearSelection();
402 | view->setCurrentIndex(findIndex);
403 | activateWindow();
404 | return;
405 | }
406 | ++column;
407 | }
408 | column = 0;
409 | ++row;
410 | }
411 |
412 | QApplication::beep();
413 | }
414 |
415 | void TableView::findPrevious(const QString &str, Qt::CaseSensitivity cs)
416 | {
417 | int row = view->currentIndex().row();
418 | int column = view->currentIndex().column() - 1;
419 | int ColumnCount = model->columnCount();
420 |
421 | while (row >= 0)
422 | {
423 | while (column >= 0)
424 | {
425 | QModelIndex findIndex = model->index(row, column);
426 | if (findIndex.data(Qt::DisplayRole).toString().contains(str, cs))
427 | {
428 | view->clearSelection();
429 | view->setCurrentIndex(findIndex);
430 | activateWindow();
431 | return;
432 | }
433 | --column;
434 | }
435 | column = ColumnCount - 1;
436 | --row;
437 | }
438 | QApplication::beep();
439 | }
440 |
441 | void TableView::firstButtonClicked()
442 | {
443 | model->setFilter(tr(" 1=1 limit 0,%1").arg(rowNumber));
444 | pageNumberlineEdit->setText("1");
445 |
446 | firstButton->setEnabled(false);
447 | prevButton->setEnabled(false);
448 | nextButton->setEnabled(pageCount > 1);
449 | endButton->setEnabled(pageCount > 1);
450 | }
451 |
452 | void TableView::prevButtonClicked()
453 | {
454 | bool b = false;
455 | uint number = pageNumberlineEdit->text().toUInt(&b);
456 | if (b)
457 | {
458 | --number;
459 | int startNumber = (number - 1) * rowNumber;
460 | model->setFilter(tr(" 1=1 limit %1,%2").arg(startNumber).arg(rowNumber));
461 | pageNumberlineEdit->setText(QString::number(number));
462 |
463 | firstButton->setEnabled(number > 1);
464 | prevButton->setEnabled(number > 1);
465 | nextButton->setEnabled(number < pageCount);
466 | endButton->setEnabled(number < pageCount);
467 | }
468 | }
469 |
470 | void TableView::nextButtonClicked()
471 | {
472 | bool b = false;
473 | uint number = pageNumberlineEdit->text().toUInt(&b);
474 | if (b)
475 | {
476 | int startNumber = number * rowNumber;
477 | ++number;
478 | model->setFilter(tr(" 1=1 limit %1,%2").arg(startNumber).arg(rowNumber));
479 | pageNumberlineEdit->setText(QString::number(number));
480 |
481 | firstButton->setEnabled(number > 1);
482 | prevButton->setEnabled(number > 1);
483 | nextButton->setEnabled(number < pageCount);
484 | endButton->setEnabled(number < pageCount);
485 | }
486 | }
487 |
488 | void TableView::endButtonClicked()
489 | {
490 | model->setFilter(tr(" 1=1 limit %1,%2").arg((pageCount - 1) * rowNumber).arg(rowNumber));
491 | pageNumberlineEdit->setText(QString::number(pageCount));
492 | firstButton->setEnabled(pageCount > 1);
493 | prevButton->setEnabled(pageCount > 1);
494 | nextButton->setEnabled(false);
495 | endButton->setEnabled(false);
496 | }
497 |
--------------------------------------------------------------------------------
/src/tableview.h:
--------------------------------------------------------------------------------
1 | #ifndef TABLEVIEW_H
2 | #define TABLEVIEW_H
3 |
4 | #include
5 | class QSqlTableModel;
6 | class QTableView;
7 | class QMenu;
8 | class QLineEdit;
9 | class QPushButton;
10 |
11 | class TableView : public QWidget
12 | {
13 | Q_OBJECT
14 | public:
15 | explicit TableView(const QString &connectName, const QString &tableName, QWidget *parent = 0);
16 | ~TableView();
17 |
18 | signals:
19 | void tableDataChanged(const QString&,const QString&, bool);
20 |
21 | public:
22 | void setRead(bool);
23 | void setShowGrid(bool);
24 | void save();
25 | void findNext(const QString &str, Qt::CaseSensitivity cs);
26 | void findPrevious(const QString &str, Qt::CaseSensitivity cs);
27 |
28 | public slots:
29 | void cut();
30 | void copy();
31 | void paste();
32 | void del();
33 | void insertRow();
34 | void delRow();
35 |
36 | private slots:
37 | void showMenu(const QPoint &);
38 | void dataChanged();
39 | void firstButtonClicked();
40 | void prevButtonClicked();
41 | void nextButtonClicked();
42 | void endButtonClicked();
43 |
44 | private:
45 | void createMenu();
46 |
47 | private:
48 | QSqlTableModel *model;
49 | QTableView *view;
50 | QMenu *tableMenu;
51 | QAction *cutAction;
52 | QAction *copyAction;
53 | QAction *pasteAction;
54 | QAction *deleteAction;
55 | QAction *insertRowAction;
56 | QAction *deleteRowAction;
57 | QLineEdit *pageNumberlineEdit;
58 | QPushButton *firstButton;
59 | QPushButton *prevButton;
60 | QPushButton *nextButton;
61 | QPushButton *endButton;
62 | static const uint rowNumber = 100;
63 | uint pageCount;
64 | };
65 |
66 | #endif // TABLEVIEW_H
67 |
--------------------------------------------------------------------------------
/src/tabwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "tabwidget.h"
2 | #include "mainwindow.h"
3 | #include "querywidget.h"
4 | #include "newtablewidgett.h"
5 | #include "modifytablefieldwidget.h"
6 | #include "systemtableview.h"
7 | #include "createindexwidget.h"
8 | #include "tableview.h"
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | TabWidget::TabWidget(QWidget *parent) :
24 | QTabWidget(parent)
25 | {
26 | setTabsClosable(true);
27 | setMovable(true);
28 | connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(tableClose(int)));
29 | connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentWidgetChanged(int)));
30 | }
31 |
32 | void TabWidget::createNewTableView(const QString &connectName, const QString &tableName)
33 | {
34 | // if (findText(title))
35 | // return;
36 |
37 | // QSqlDatabase db = QSqlDatabase::database(connectName);
38 |
39 | // QTableView *view = new QTableView;
40 | // setReadOnlyPrivate(view, MainWindow::getcurrentReadOnly());
41 | // view->setShowGrid(MainWindow::getcurrentShow());
42 |
43 | // QSqlTableModel *model = new QSqlTableModel(this, db);
44 | // model->setTable(title);
45 | // model->setEditStrategy(QSqlTableModel::OnManualSubmit);
46 | // model->select();
47 |
48 | // QSqlRecord record = model->record();
49 |
50 | // for (int i = 0; i < record.count(); ++i)
51 | // {
52 | // model->setHeaderData(i, Qt::Horizontal, record.fieldName(i));
53 | //// qDebug() << record.fieldName(i) << endl;
54 | //// int r = model->record(i).field(i).type();
55 | //// qDebug() << r << endl;
56 | //// if (r == QVariant::Int)
57 | //// qDebug() << "Int" << endl;
58 | //// if (r == QVariant::Invalid)
59 | //// qDebug() << "NULL" << endl;
60 | // }
61 | //// qDebug() << title << connectName << endl;
62 | // view->setModel(model);
63 | // view->resizeColumnsToContents();
64 |
65 | // view->setSelectionMode(QAbstractItemView::ContiguousSelection);
66 |
67 | //// connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged()));
68 |
69 | //// tableViewList.push_back(newTableView);
70 | //// tableModelList.push_back(model);
71 |
72 | int index = connectName.lastIndexOf("\\");
73 | QString name = connectName.mid(index + 1) + '-' + tableName;
74 |
75 | if (findText(name) != -1)
76 | return;
77 |
78 | TableView *view = new TableView(connectName, tableName, this);
79 | //setReadOnlyPrivate(view, MainWindow::getCurrentReadOnly());
80 | view->setRead(MainWindow::getCurrentReadOnly());
81 | view->setShowGrid(MainWindow::getCurrentShow());
82 | connect(view, SIGNAL(tableDataChanged(QString,QString,bool)), this, SLOT(tableDataChanged(QString,QString,bool)));
83 |
84 | addTab(view, name);
85 | setCurrentWidget(view);
86 | }
87 |
88 | void TabWidget::tableDataChanged(const QString &connectName, const QString &tableName, bool b)
89 | {
90 | int index = connectName.lastIndexOf("\\");
91 | QString name = connectName.mid(index + 1) + '-' + tableName;
92 |
93 | index = findText(name);
94 | if (index != -1)
95 | {
96 | QString temp = "";
97 | if (b)
98 | temp = "*";
99 |
100 | setTabText(index, name + temp);
101 | }
102 | }
103 |
104 | void TabWidget::createNewQuery(const QString &connectName)
105 | {
106 | // QSqlDatabase db = QSqlDatabase::database(connectName);
107 |
108 | // QSqlTableModel *model = new QSqlTableModel(this, db);
109 |
110 | // model->QSqlQueryModel::setQuery(query, db);
111 | // if (model->lastError().isValid())
112 | // {
113 | // QMessageBox::warning(this, tr("SQLite GUI"), model->lastError().text());
114 | // delete model;
115 | // return;
116 | // }
117 |
118 | // QTableView *newTableView = new QTableView;
119 | // newTableView->setModel(model);
120 | // newTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
121 | // newTableView->resizeColumnsToContents();
122 | // newTableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
123 |
124 | // addTab(newTableView, query);
125 | // setCurrentWidget(newTableView);
126 | // tableViewList.push_back(newTableView);
127 | // tableModelList.push_back(model);
128 | // qDebug() << connectName << endl;
129 |
130 | int index = connectName.lastIndexOf("\\");
131 | QString title = connectName.mid(index + 1) + tr("-SQL");
132 |
133 | if (findText(title) != -1)
134 | return;
135 |
136 | QueryWidget *queryWidget = new QueryWidget(connectName, this);
137 | addTab(queryWidget, title);
138 | setCurrentWidget(queryWidget);
139 | }
140 |
141 | void TabWidget::onSqlExecute()
142 | {
143 | // QWidget *w = currentWidget();
144 | // if (w)
145 | // {
146 | // QString className = w->metaObject()->className();
147 | // if (className == tr("QueryWidget"))
148 | // {
149 | // QueryWidget *queryWidget = (QueryWidget*)w;
150 | // queryWidget->onSqlExecute();
151 | // }
152 | // }
153 | QString className = getCurrentClassName();
154 | if (className == "QueryWidget")
155 | {
156 | static_cast(currentWidget())->onSqlExecute();
157 | }
158 | }
159 |
160 | void TabWidget::createNewTable(const QString &connectName)
161 | {
162 | int index = connectName.lastIndexOf("\\");
163 | QString title = connectName.mid(index + 1) + tr("-New Table");
164 |
165 | if (findText(title) != -1)
166 | return;
167 |
168 | NewTableWidget *widget = new NewTableWidget(connectName, this);
169 | addTab(widget, title);
170 | setCurrentWidget(widget);
171 | }
172 |
173 | void TabWidget::createSystemTable(const QString &connectName, const QString &tableName)
174 | {
175 | int index = connectName.lastIndexOf("\\");
176 | QString name = connectName.mid(index + 1) + '-' + tableName;
177 |
178 | if (findText(name) != -1)
179 | return;
180 |
181 | SystemTableView *systemTable = new SystemTableView(connectName, tableName, this);
182 | addTab(systemTable, name);
183 | setCurrentWidget(systemTable);
184 | }
185 |
186 | void TabWidget::createModifyTableField(const QString &connectName, const QString &tableName)
187 | {
188 | int index = connectName.lastIndexOf("\\");
189 | QString title = connectName.mid(index + 1) + "-" + tableName + tr("-Modify Field");
190 |
191 | if (findText(title) != -1)
192 | return;
193 |
194 | ModifyTableFieldWidget *w = new ModifyTableFieldWidget(connectName, tableName, this);
195 | addTab(w, title);
196 | setCurrentWidget(w);
197 |
198 | }
199 |
200 | void TabWidget::createIndex(const QString &connectName, const QString &tableName)
201 | {
202 | int index = connectName.lastIndexOf("\\");
203 | QString title = connectName.mid(index + 1) + "-" + tableName + tr("-Create Index");
204 | if (findText(title) != -1)
205 | return;
206 |
207 | CreateIndexWidget *w = new CreateIndexWidget(connectName, tableName, this);
208 | addTab(w, title);
209 | setCurrentWidget(w);
210 | }
211 |
212 | void TabWidget::tableClose(int index)
213 | {
214 | QWidget *w = widget(index);
215 | // QString className = w->metaObject()->className();
216 | // if (className == tr("NewTableWidget"))
217 | // {
218 | // NewTableWidget *newTableWidget = (NewTableWidget*)w;
219 | // newTableWidget->save();
220 | // }
221 | if (w->isWindowModified())
222 | {
223 | int r = QMessageBox::warning(this, tr("SQLite Database Manage"),
224 | tr("The document has been modified.\n"
225 | "Do you want to save your changes?"),
226 | QMessageBox::Yes | QMessageBox::Default,
227 | QMessageBox::No,
228 | QMessageBox::Cancel | QMessageBox::Escape);
229 |
230 | if (r == QMessageBox::Cancel)
231 | {
232 | return;
233 | }
234 | else if (r == QMessageBox::Yes)
235 | {
236 | static_cast(w)->save();
237 | }
238 | }
239 | if (!w->close())
240 | return;
241 |
242 | removeTab(index);
243 | delete w;
244 | // QTableView *tableView = (QTableView*)widget(index);
245 | // if (tableView->isWindowModified())
246 | // {
247 | // int r = QMessageBox::warning(this, tr("SQLite GUI"),
248 | // tr("The document has been modified.\n"
249 | // "Do you want to save your changes?"),
250 | // QMessageBox::Yes | QMessageBox::Default,
251 | // QMessageBox::No,
252 | // QMessageBox::Cancel | QMessageBox::Escape);
253 |
254 | // if (r == QMessageBox::Cancel)
255 | // {
256 | // return;
257 | // }
258 | // else if (r == QMessageBox::Yes)
259 | // {
260 | // save(index);
261 | // }
262 | // }
263 | // removeTab(index);
264 | // QTableView *view = tableViewList.value(index);
265 | // view->model();
266 | // delete view;
267 | // QSqlTableModel *model = tableModelList.value(index);
268 | // delete model;
269 | // tableViewList.removeAt(index);
270 | // tableModelList.removeAt(index);
271 | }
272 |
273 | void TabWidget::save()
274 | {
275 | // QSqlTableModel* model = tableModelList[index];
276 |
277 | // model->database().transaction();
278 | // if (model->submitAll())
279 | // {
280 | // model->database().commit();
281 | // }
282 | // else
283 | // {
284 | // model->database().rollback();
285 | // QMessageBox::warning(this, tr("Cached Table"),
286 | // tr("The database reported an error: %1")
287 | // .arg(model->lastError().text()));
288 | // return false;
289 | // }
290 | // return true;
291 |
292 | QWidget *w = currentWidget();
293 | if (w && w->isWindowModified())
294 | {
295 | static_cast(w)->save();
296 | }
297 | }
298 |
299 | void TabWidget::setReadOnly(bool isRead)
300 | {
301 | // for (int i = 0; i < tableViewList.size(); ++i)
302 | // {
303 | // setReadOnlyPrivate(tableViewList[i], isRead);
304 | // }
305 |
306 | for (int i = 0; i < count(); ++i)
307 | {
308 | QWidget *w = widget(i);
309 | QString className = w->metaObject()->className();
310 | if (className == "TableView")
311 | {
312 | static_cast(w)->setRead(isRead);
313 | }
314 | }
315 | }
316 |
317 | void TabWidget::setReadOnlyPrivate(QTableView *view, bool isRead)
318 | {
319 | if (isRead)
320 | {
321 | view->setEditTriggers(QAbstractItemView::NoEditTriggers);
322 | }
323 | else
324 | {
325 | view->setEditTriggers(
326 | QAbstractItemView::DoubleClicked | QAbstractItemView::AnyKeyPressed);
327 | }
328 | }
329 |
330 | void TabWidget::setShowGrid(bool isShow)
331 | {
332 | // for (int i = 0; i < tableViewList.size(); ++i)
333 | // {
334 | // tableViewList[i]->setShowGrid(isShow);
335 | // }
336 |
337 | for (int i = 0; i < count(); ++i)
338 | {
339 | QWidget *w = widget(i);
340 | QString className = w->metaObject()->className();
341 | if (className == "TableView")
342 | {
343 | static_cast(w)->setShowGrid(isShow);
344 | }
345 | }
346 | }
347 |
348 | void TabWidget::copy()
349 | {
350 | QString className = getCurrentClassName();
351 | if (className == "TableView")
352 | {
353 | static_cast(currentWidget())->copy();
354 | }
355 | else if (className == "QueryWidget")
356 | {
357 | static_cast(currentWidget())->copy();
358 | }
359 | else
360 | {
361 | static_cast(currentWidget())->copy();
362 | }
363 | }
364 |
365 | void TabWidget::paste()
366 | {
367 | // if (MainWindow::getcurrentReadOnly())
368 | // {
369 | // QMessageBox::information(this, tr("SQLite GUI"),
370 | // tr("The information cannot be pasted because the "
371 | // "current settings is Read Only."));
372 | // return;
373 | // }
374 |
375 |
376 | QString className = getCurrentClassName();
377 | if (className == "TableView")
378 | {
379 | static_cast(currentWidget())->paste();
380 | }
381 | else
382 | {
383 | static_cast(currentWidget())->paste();
384 | }
385 | }
386 |
387 | void TabWidget::cut()
388 | {
389 | if (getCurrentClassName() == "TableView")
390 | {
391 | static_cast(currentWidget())->cut();
392 | }
393 | else
394 | {
395 | static_cast(currentWidget())->cut();
396 | }
397 | }
398 |
399 | void TabWidget::del()
400 | {
401 | // if (MainWindow::getcurrentReadOnly())
402 | // {
403 | // QMessageBox::information(this, tr("SQLite"),
404 | // tr("The row cannot be delete because the "
405 | // "current settings is Read Only."));
406 | // return;
407 | // }
408 |
409 | if (getCurrentClassName() == "TableView")
410 | {
411 | static_cast(currentWidget())->del();
412 | }
413 | else
414 | {
415 | static_cast(currentWidget())->del();
416 | }
417 | }
418 |
419 |
420 | void TabWidget::insertRow()
421 | {
422 | if (getCurrentClassName() == "TableView")
423 | {
424 | static_cast(currentWidget())->insertRow();
425 | }
426 |
427 | }
428 |
429 | void TabWidget::delRow()
430 | {
431 | if (getCurrentClassName() == "TableView")
432 | {
433 | static_cast(currentWidget())->delRow();
434 | }
435 | }
436 |
437 | void TabWidget::findNext(const QString &str, Qt::CaseSensitivity cs)
438 | {
439 | if (getCurrentClassName() == "TableView")
440 | {
441 | static_cast(currentWidget())->findNext(str, cs);
442 | }
443 | else
444 | {
445 | static_cast(currentWidget())->findNext(str);
446 | }
447 |
448 |
449 | // QTableView *currentView = (QTableView*)currentWidget();
450 |
451 | // if (!currentView)
452 | // return;
453 |
454 | // QSqlTableModel *model = (QSqlTableModel*)currentView->model();
455 |
456 | // int row = currentView->currentIndex().row();
457 | // int column = currentView->currentIndex().column() + 1;
458 | // int RowCount = model->rowCount();
459 | // int ColumnCount = model->columnCount();
460 |
461 | // while (row < RowCount)
462 | // {
463 | // while (column < ColumnCount)
464 | // {
465 | // QModelIndex findIndex = model->index(row, column);
466 | // if (findIndex.data(Qt::DisplayRole).toString().contains(str, cs))
467 | // {
468 | // currentView->clearSelection();
469 | // currentView->setCurrentIndex(findIndex);
470 | // currentView->activateWindow();
471 | // return;
472 | // }
473 | // ++column;
474 | // }
475 | // column = 0;
476 | // ++row;
477 | // }
478 |
479 | // QApplication::beep();
480 | }
481 |
482 | void TabWidget::findPrevious(const QString &str, Qt::CaseSensitivity cs)
483 | {
484 | if (getCurrentClassName() == "TableView")
485 | {
486 | static_cast(currentWidget())->findPrevious(str, cs);
487 | }
488 | else
489 | {
490 | static_cast(currentWidget())->findPrevious(str);
491 | }
492 |
493 | // QTableView *currentView = (QTableView*)currentWidget();
494 |
495 | // if (!currentView)
496 | // return;
497 |
498 | // QSqlTableModel *model = (QSqlTableModel*)currentView->model();
499 |
500 | // int row = currentView->currentIndex().row();
501 | // int column = currentView->currentIndex().column() - 1;
502 | // int ColumnCount = model->columnCount();
503 |
504 | // while (row >= 0)
505 | // {
506 | // while (column >= 0)
507 | // {
508 | // QModelIndex findIndex = model->index(row, column);
509 | // if (findIndex.data(Qt::DisplayRole).toString().contains(str, cs))
510 | // {
511 | // currentView->clearSelection();
512 | // currentView->setCurrentIndex(findIndex);
513 | // currentView->activateWindow();
514 | // return;
515 | // }
516 | // --column;
517 | // }
518 | // column = ColumnCount - 1;
519 | // --row;
520 | // }
521 | // QApplication::beep();
522 | }
523 |
524 | void TabWidget::saveAll()
525 | {
526 | for (int i = 0; i < count(); ++i)
527 | {
528 | QWidget *w = widget(i);
529 | if (w->isWindowModified())
530 | {
531 | static_cast(w)->save();
532 | }
533 | }
534 | // for (int i = 0; i < count(); ++i)
535 | // {
536 | // if (save(i))
537 | // {
538 | // QTableView *view = tableViewList[i];
539 | // view->setWindowModified(false);
540 | // }
541 | // }
542 | }
543 |
544 | void TabWidget::saveSqlAs()
545 | {
546 | if (getCurrentClassName() == "QueryWidget")
547 | {
548 | static_cast(currentWidget())->saveAs();
549 | }
550 | }
551 |
552 | void TabWidget::openSql(const QString &connectName)
553 | {
554 | QWidget *w = currentWidget();
555 | if (w)
556 | {
557 | if (getCurrentClassName() != "QueryWidget")
558 | createNewQuery(connectName);
559 |
560 | static_cast(currentWidget())->openSql();
561 | }
562 | }
563 |
564 | int TabWidget::findText(const QString &text)
565 | {
566 | for (int i = 0; i < count(); ++i)
567 | {
568 | QString tabTextStr = tabText(i);
569 | if (tabTextStr.size() - 1 == text.size() && tabTextStr.endsWith('*'))
570 | {
571 | tabTextStr.remove(tabTextStr.size() - 1, 1);
572 | }
573 | if (tabTextStr.size() == text.size())
574 | {
575 | if (tabTextStr == text)
576 | {
577 | setCurrentIndex(i);
578 | return i;
579 | }
580 | }
581 | }
582 | return -1;
583 | }
584 |
585 | void TabWidget::runLineSql()
586 | {
587 | if (getCurrentClassName() == "QueryWidget")
588 | {
589 | static_cast(currentWidget())->runLineSql();
590 | }
591 | }
592 |
593 | void TabWidget::analysisSql()
594 | {
595 | if (getCurrentClassName() == "QueryWidget")
596 | {
597 | static_cast(currentWidget())->analysisSql();
598 | }
599 | }
600 |
601 | void TabWidget::queryChanged(const QString &database, const QString &connectName)
602 | {
603 | QWidget *w = currentWidget();
604 | if (w)
605 | {
606 | if (findText(database) != -1)
607 | {
608 | QMessageBox::information(this, tr("SQLite Database Manage"), tr("The Query already exist"));
609 | return;
610 | }
611 | QString className = w->metaObject()->className();
612 | if (className == "QueryWidget")
613 | {
614 | QueryWidget *queryWidget = (QueryWidget*)w;
615 | queryWidget->setConnectName(connectName);
616 | setTabText(currentIndex(), database + "-SQL");
617 | }
618 | }
619 | }
620 |
621 | QString TabWidget::getCurrentClassName() const
622 | {
623 | QWidget *w = currentWidget();
624 | if (w)
625 | {
626 | return w->metaObject()->className();
627 | }
628 |
629 | return "";
630 | }
631 |
632 | void TabWidget::currentWidgetChanged(int index)
633 | {
634 | // qDebug() << index;
635 | if (index == -1)
636 | {
637 | emit widgetChanged(NOWIDGET);
638 | return;
639 | }
640 |
641 | QWidget *w = widget(index);
642 | QString className = w->metaObject()->className();
643 | WidgetType type;
644 | if (className == "TableView")
645 | {
646 | type = TABLEVIEW;
647 | }
648 | else if (className == "SystemTableView")
649 | {
650 | type = SYSTEMTABLEVIEW;
651 | }
652 | else if (className == "QueryWidget")
653 | {
654 | type = QUERYWIDGET;
655 | }
656 | else if (className == "CreateIndexWidget")
657 | {
658 | type = CREATEINDEXWIDGET;
659 | }
660 | else if (className == "NewTableWidget")
661 | {
662 | type = NEWTABLEWIDGET;
663 | }
664 | else
665 | {
666 | type = MODIFYTABLEFIELDWIDGET;
667 | }
668 | emit widgetChanged(type);
669 | }
670 |
671 |
--------------------------------------------------------------------------------
/src/tabwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef TABWIDGET_H
2 | #define TABWIDGET_H
3 |
4 | #include
5 | #include
6 | class QSqlTableModel;
7 |
8 | enum WidgetType
9 | {
10 | NOWIDGET = -1,
11 | TABLEVIEW = 0,
12 | SYSTEMTABLEVIEW = 1,
13 | QUERYWIDGET = 2,
14 | CREATEINDEXWIDGET = 3,
15 | NEWTABLEWIDGET = 4,
16 | MODIFYTABLEFIELDWIDGET = 5
17 | };
18 |
19 | class TabWidget : public QTabWidget
20 | {
21 | Q_OBJECT
22 | public:
23 | explicit TabWidget(QWidget *parent = 0);
24 |
25 | signals:
26 | void widgetChanged(WidgetType type);
27 |
28 | public:
29 | void setReadOnly(bool isRead);
30 | void setShowGrid(bool isShow);
31 | void createNewTableView(const QString &connectName, const QString &tableName);
32 | void createNewQuery(const QString &connectName);
33 | void createSystemTable(const QString &connectName, const QString &tableName);
34 | void createModifyTableField(const QString &connectName, const QString &tableName);
35 | void createIndex(const QString &connectName, const QString &tableName);
36 | void createNewTable(const QString &connectName);
37 | void openSql(const QString &connectName);
38 | void queryChanged(const QString &database, const QString &connectName);
39 |
40 | public slots:
41 | void analysisSql();
42 | void onSqlExecute();
43 | void runLineSql();
44 | void save();
45 | void saveSqlAs();
46 | void saveAll();
47 | void cut();
48 | void copy();
49 | void paste();
50 | void del();
51 | void insertRow();
52 | void delRow();
53 | void findNext(const QString &str, Qt::CaseSensitivity cs);
54 | void findPrevious(const QString &str, Qt::CaseSensitivity cs);
55 |
56 | private slots:
57 | void tableClose(int index);
58 | void currentWidgetChanged(int index);
59 | void tableDataChanged(const QString &connectName, const QString &tableName, bool b);
60 |
61 | private:
62 | void setReadOnlyPrivate(QTableView *view, bool isRead);
63 | int findText(const QString &text);
64 | QString getCurrentClassName() const;
65 | };
66 |
67 | #endif // TABWIDGET_H
68 |
--------------------------------------------------------------------------------
/src/translations/SQLiteDatabaseManage.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Finalcheat/SQLiteDatabaseManage/cd459bc80bf89f382a1c80044479499573561149/src/translations/SQLiteDatabaseManage.qm
--------------------------------------------------------------------------------
/src/workthread.cpp:
--------------------------------------------------------------------------------
1 | #include "workthread.h"
2 | #include "qt_windows.h"
3 | #include "qexcel.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | ImportWorkThread::ImportWorkThread(QSqlDatabase &s, const QStringList &l, QSqlDatabase &t) :
17 | source(s), tableNameList(l), target(t)
18 | {
19 |
20 | }
21 |
22 | void ImportWorkThread::run()
23 | {
24 | source.transaction();
25 | target.transaction();
26 | for (int i = 0; i < tableNameList.size(); ++i)
27 | {
28 | QString sqlStr = "create table '" + tableNameList[i] + "'(";
29 | QSqlRecord record = source.record(tableNameList[i]);
30 |
31 | QSqlIndex primaryIndex = source.primaryIndex(tableNameList[i]);
32 | QString primaryName;
33 |
34 | for (int j = 0; j < record.count(); ++j)
35 | {
36 | QString fieldName = record.fieldName(j);
37 | if (primaryIndex.contains(fieldName))
38 | {
39 | primaryName += "'";
40 | primaryName += fieldName;
41 | primaryName += "',";
42 | }
43 | sqlStr += "'";
44 | sqlStr += fieldName;
45 | sqlStr += "',";
46 | }
47 |
48 | int index;
49 | if (primaryName.isEmpty())
50 | {
51 | index = sqlStr.lastIndexOf(',');
52 | sqlStr.replace(index, 1, ')');
53 | }
54 | else
55 | {
56 | sqlStr = sqlStr + "primary key(" + primaryName;
57 | index = sqlStr.lastIndexOf(',');
58 | sqlStr.replace(index, 2, "))");
59 | }
60 |
61 | // qDebug() << sqlStr;
62 | // targetQuery.exec(sqlStr);
63 | target.exec(sqlStr);
64 |
65 | QSqlQuery sourceQuery = source.exec("select * from " + tableNameList[i]);
66 |
67 | while (sourceQuery.next())
68 | {
69 | sqlStr.clear();
70 | sqlStr = "insert into '" + tableNameList[i] + "' values (";
71 | for (int column = 0; column < record.count(); ++column)
72 | {
73 | sqlStr += "'";
74 | QString fieldValue = sourceQuery.value(column).toString();
75 | sqlStr += fieldValue;
76 | sqlStr += "'";
77 | sqlStr += ",";
78 | }
79 | index = sqlStr.lastIndexOf(',');
80 | sqlStr.replace(index, 1, ')');
81 | // qDebug() << sqlStr;
82 | // targetQuery.exec(sqlStr);
83 | target.exec(sqlStr);
84 | }
85 | emit finishPos(i + 1);
86 | }
87 | source.commit();
88 | target.commit();
89 | }
90 |
91 | ExportWorkThread::ExportWorkThread(QSqlDatabase &s, const QStringList &l, QSqlDatabase &t) :
92 | source(s), tableNameList(l), target(t)
93 | {
94 |
95 | }
96 |
97 | void ExportWorkThread::run()
98 | {
99 | source.transaction();
100 | target.transaction();
101 | for (int i = 0; i < tableNameList.size(); ++i)
102 | {
103 | QString sqlStr = "create table \"" + tableNameList[i] + "\"(";
104 | QSqlRecord record = source.record(tableNameList[i]);
105 |
106 | for (int j = 0; j < record.count(); ++j)
107 | {
108 | QString fieldName = record.fieldName(j);
109 | sqlStr += "\"";
110 | sqlStr += fieldName;
111 | sqlStr += "\" text,";
112 | }
113 |
114 | int index = sqlStr.lastIndexOf(',');
115 | sqlStr.replace(index, 1, ')');
116 |
117 |
118 | // qDebug() << sqlStr;
119 | // targetQuery.exec(sqlStr);
120 | target.exec(sqlStr);
121 |
122 | QSqlQuery sourceQuery = source.exec("select * from " + tableNameList[i]);
123 |
124 | while (sourceQuery.next())
125 | {
126 | sqlStr.clear();
127 | sqlStr = "insert into \"" + tableNameList[i] + "\" values (";
128 | for (int column = 0; column < record.count(); ++column)
129 | {
130 | sqlStr += "'";
131 | QString fieldValue = sourceQuery.value(column).toString();
132 | sqlStr += fieldValue;
133 | sqlStr += "'";
134 | sqlStr += ",";
135 | }
136 | index = sqlStr.lastIndexOf(',');
137 | sqlStr.replace(index, 1, ')');
138 | // qDebug() << sqlStr;
139 | // targetQuery.exec(sqlStr);
140 | target.exec(sqlStr);
141 | }
142 | emit finishPos(i + 1);
143 | }
144 | source.commit();
145 | target.commit();
146 | }
147 |
148 | ImportTxtWorkThread::ImportTxtWorkThread(const QString &s, QSqlDatabase &t) :
149 | source(s), target(t)
150 | {
151 |
152 | }
153 |
154 | void ImportTxtWorkThread::run()
155 | {
156 | if (!QFile::exists(source))
157 | return;
158 |
159 | QFile file(source);
160 | file.open(QIODevice::ReadOnly);
161 |
162 | QTextStream stream(&file);
163 | // stream.setCodec(QTextCodec::codecForName("GB2313"));
164 | // stream.readAll();
165 | QString str = stream.readAll();
166 | // qDebug() << str;
167 | // return;
168 | int index = source.lastIndexOf("/");
169 | QString tableName = source.mid(index + 1, source.size() - index - 5);
170 | QStringList strList = str.split("\n", QString::SkipEmptyParts);
171 | if (!strList.empty())
172 | {
173 | // QStringList fieldList = strList[0].spit(",");
174 | QString sql = "create table '" + tableName + "'(";
175 | sql += strList[0];
176 | sql += ')';
177 | // qDebug() << sql;
178 |
179 | // QSqlQuery query(target);
180 | target.transaction();
181 | target.exec(sql);
182 |
183 | sql = "insert into '" + tableName + "' values(";
184 | for (int i = 1; i < strList.size(); ++i)
185 | {
186 | QString insertSql = sql + strList[i] + ')';
187 | // qDebug() << insertSql;
188 | target.exec(insertSql);
189 | emit finishPos(i);
190 | }
191 | target.commit();
192 | }
193 | file.close();
194 | }
195 |
196 | ExportTxtWorkThread::ExportTxtWorkThread(QSqlDatabase &s, const QStringList &t, const QString &d) :
197 | source(s), tableNameList(t),directory(d)
198 | {
199 | }
200 |
201 | void ExportTxtWorkThread::run()
202 | {
203 | source.transaction();
204 | // qDebug() << directory;
205 | QSqlQuery query;
206 | for (int i = 0; i < tableNameList.size(); ++i)
207 | {
208 | query = source.exec("select * from '" + tableNameList[i] + "'");
209 | QString str;
210 | QSqlRecord record = query.record();
211 | for (int j = 0; j < record.count(); ++j)
212 | {
213 | str += "\"";
214 | str += record.fieldName(j);
215 | str += "\",";
216 | }
217 |
218 | int index = str.lastIndexOf(",");
219 | str.replace(index, 1, "\r\n");
220 |
221 | while (query.next())
222 | {
223 | for (int k = 0; k < record.count(); ++k)
224 | {
225 | str += "\"";
226 | str += query.value(k).toString();
227 | str += "\",";
228 | }
229 | index = str.lastIndexOf(",");
230 | str.replace(index, 1, "\r\n");
231 | }
232 |
233 | QFile file(directory + "\\" + tableNameList[i] + ".txt");
234 | file.open(QIODevice::WriteOnly);
235 | file.write(str.toAscii());
236 | file.close();
237 | emit finishPos(i + 1);
238 | }
239 | source.commit();
240 | }
241 |
242 |
243 | ImportExcelWorkThread::ImportExcelWorkThread(const QString &f, const QStringList &l, QSqlDatabase &t) :
244 | filePath(f), tableNameList(l), target(t)
245 | {
246 | // HRESULT r = OleInitialize(0);
247 | // if (r != S_OK && r != S_FALSE)
248 | // {
249 | // qWarning("Qt: Could not initialize OLE (error %x)", (unsigned int)r);
250 | // }
251 | // if (excel.open(filePath))
252 | // qDebug() << "yes";
253 | }
254 |
255 | void ImportExcelWorkThread::run()
256 | {
257 | // qDebug() << source;
258 | // QExcel excel(source);
259 |
260 | // if (excel.isNull())
261 | // return;
262 |
263 | // QStringList tableNameList = importTable->getUseTableList();
264 |
265 | // QSqlQuery query(target);
266 |
267 | // HRESULT r = OleInitialize(0);
268 | // if (r != S_OK && r != S_FALSE)
269 | // {
270 | // qWarning("Qt: Could not initialize OLE (error %x)", (unsigned int)r);
271 | // return;
272 | // }
273 |
274 | // {
275 | // QExcel excel;
276 | // excel.open(filePath);
277 |
278 | // target.transaction();
279 | // for (int i = 0; i < tableNameList.size(); ++i)
280 | // {
281 | // QString sqlStr = "create table '" + tableNameList[i] + "'(";
282 | // excel.selectSheet(tableNameList[i]);
283 | //// qDebug() << sqlStr;
284 | // int topLeftRow, topLeftColumn, bottomRightRow, bottomRightColumn;
285 | // excel.getUsedRange(&topLeftRow, &topLeftColumn, &bottomRightRow, &bottomRightColumn);
286 | // // qDebug() << topLeftRow << endl << topLeftColumn << endl << bottomRightRow <
5 | #include
6 | #include
7 | #include
8 |
9 | class ImportWorkThread : public QThread
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | ImportWorkThread(QSqlDatabase &s, const QStringList &l, QSqlDatabase &t);
15 |
16 | signals:
17 | void finishPos(int value);
18 |
19 | public:
20 | void run();
21 |
22 | private:
23 | QSqlDatabase source;
24 | const QStringList tableNameList;
25 | QSqlDatabase target;
26 | };
27 |
28 | class ExportWorkThread : public QThread
29 | {
30 | Q_OBJECT
31 |
32 | public:
33 | ExportWorkThread(QSqlDatabase &s, const QStringList &l, QSqlDatabase &t);
34 |
35 | signals:
36 | void finishPos(int value);
37 |
38 | public:
39 | void run();
40 |
41 | private:
42 | QSqlDatabase source;
43 | const QStringList tableNameList;
44 | QSqlDatabase target;
45 | };
46 |
47 | class ImportTxtWorkThread : public QThread
48 | {
49 | Q_OBJECT
50 |
51 | public:
52 | ImportTxtWorkThread(const QString &s, QSqlDatabase &t);
53 |
54 | signals:
55 | void finishPos(int value);
56 |
57 | public:
58 | void run();
59 |
60 | private:
61 | const QString source;
62 | QSqlDatabase target;
63 | };
64 |
65 | class ExportTxtWorkThread : public QThread
66 | {
67 | Q_OBJECT
68 |
69 | public:
70 | ExportTxtWorkThread(QSqlDatabase &s, const QStringList &t, const QString &d);
71 |
72 | signals:
73 | void finishPos(int value);
74 |
75 | public:
76 | void run();
77 |
78 | private:
79 | QSqlDatabase source;
80 | const QStringList tableNameList;
81 | const QString directory;
82 | };
83 |
84 | class ImportExcelWorkThread : public QThread
85 | {
86 | Q_OBJECT
87 |
88 | public:
89 | ImportExcelWorkThread(const QString &f, const QStringList &l, QSqlDatabase &t);
90 |
91 | signals:
92 | void finishPos(int value);
93 |
94 | public:
95 | void run();
96 |
97 | private:
98 | const QString filePath;
99 | const QStringList tableNameList;
100 | QSqlDatabase target;
101 | };
102 |
103 | class ExportExcelWorkThread : public QThread
104 | {
105 | Q_OBJECT
106 |
107 | public:
108 | ExportExcelWorkThread(QSqlDatabase &s, const QStringList &l, const QString &f);
109 |
110 | signals:
111 | void finishPos(int value);
112 |
113 | public:
114 | void run();
115 |
116 | private:
117 | QSqlDatabase source;
118 | const QStringList tableNameList;
119 | const QString filePath;
120 | };
121 |
122 | class ImportXmlWorkThread : public QThread
123 | {
124 | Q_OBJECT
125 |
126 | public:
127 | ImportXmlWorkThread(const QString &f, const QStringList &l, QSqlDatabase &t);
128 |
129 | signals:
130 | void finishPos(int value);
131 | void maxProgress(int maxValue);
132 |
133 | public:
134 | void run();
135 |
136 | private:
137 | const QString filePath;
138 | const QStringList tableNameList;
139 | QSqlDatabase target;
140 | };
141 |
142 | class ExportXmlWorkThread : public QThread
143 | {
144 | Q_OBJECT
145 |
146 | public:
147 | ExportXmlWorkThread(QSqlDatabase &s, const QStringList &t, const QString &d);
148 |
149 | signals:
150 | void finishPos(int value);
151 |
152 | public:
153 | void run();
154 |
155 | private:
156 | QSqlDatabase source;
157 | const QStringList tableNameList;
158 | const QString directory;
159 | };
160 |
161 | #endif // WORKTHREAD_H
162 |
--------------------------------------------------------------------------------