Skip to content

Commit 4455318

Browse files
committed
Initial commit
0 parents  commit 4455318

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1992
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-*

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## SQLite Editor
2+
3+
4+
The goal of this project is to build an easy-to-use, yet feature-filled SQLite tables / contents editor. This is built in Qt \ QML.
5+
6+
7+
![image](readme-misc/screenshot-01.png)

app/SQLiteEditor/SQLiteEditor.pro

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TEMPLATE = app
2+
3+
QT += qml quick sql core widgets
4+
5+
HEADERS += \
6+
dbthread.h \
7+
sqlitemodel.h
8+
9+
SOURCES += main.cpp \
10+
dbthread.cpp \
11+
sqlitemodel.cpp
12+
13+
RESOURCES += qml.qrc
14+
15+
# Additional import path used to resolve QML modules in Qt Creator's code model
16+
QML_IMPORT_PATH =
17+
18+
# Default rules for deployment.
19+
include(deployment.pri)

app/SQLiteEditor/dbthread.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "dbthread.h"
2+
3+
#define DATABASE_DRIVER "QSQLITE"
4+
5+
class DbWorker : public QObject
6+
{
7+
Q_OBJECT
8+
9+
public:
10+
DbWorker( QObject* parent = 0, QString databasePath = "");
11+
~DbWorker();
12+
13+
public slots:
14+
void slotExecute( const QString& query );
15+
16+
signals:
17+
void results( const QList<QSqlRecord>& records );
18+
19+
private:
20+
QSqlDatabase m_database;
21+
};
22+
23+
//
24+
25+
DbWorker::DbWorker( QObject* parent, QString databasePath )
26+
: QObject( parent )
27+
{
28+
// thread-specific connection, see db.h
29+
QUuid uuid = QUuid::createUuid();
30+
m_database = QSqlDatabase::addDatabase( DATABASE_DRIVER, uuid.toString());
31+
m_database.setDatabaseName(databasePath);
32+
33+
if (!m_database.open())
34+
{
35+
qDebug() << "Unable to connect to database, giving up:" << m_database.lastError().text();
36+
return;
37+
}
38+
}
39+
40+
DbWorker::~DbWorker()
41+
{
42+
m_database.close();
43+
}
44+
45+
void DbWorker::slotExecute( const QString& query )
46+
{
47+
QList<QSqlRecord> recs;
48+
QSqlQuery sql(query, m_database);
49+
//sql.setForwardOnly(true);
50+
while(sql.next())
51+
{
52+
recs.push_back(sql.record());
53+
}
54+
qDebug() << Q_FUNC_INFO << "query is\"" << query << "\"and records count is" << recs.count();
55+
emit results(recs);
56+
}
57+
58+
59+
// DbThread
60+
DbThread::DbThread(QObject *parent, QString databaseFilePath) :
61+
QThread(parent)
62+
{
63+
m_databaseFilePath = databaseFilePath;
64+
}
65+
66+
DbThread::~DbThread()
67+
{
68+
delete m_worker;
69+
}
70+
71+
void DbThread::execute(const QString &query)
72+
{
73+
emit executefwd(query);
74+
}
75+
76+
void DbThread::run()
77+
{
78+
emit ready(false);
79+
emit progress("DbThread is starting..one moment please..");
80+
81+
m_worker = new DbWorker(0, m_databaseFilePath);
82+
83+
connect( this, SIGNAL( executefwd( const QString& ) ),
84+
m_worker, SLOT( slotExecute( const QString& ) ) );
85+
86+
qRegisterMetaType< QList<QSqlRecord> >( "QList<QSqlRecord>" );
87+
88+
// forward final signal
89+
connect( m_worker, SIGNAL( results( const QList<QSqlRecord>& ) ),
90+
this, SIGNAL( results( const QList<QSqlRecord>& ) ) );
91+
92+
93+
94+
emit progress( "Press 'Go' to run a query." );
95+
emit ready(true);
96+
97+
exec(); // our event loop
98+
99+
}
100+
101+
#include "dbthread.moc"

app/SQLiteEditor/dbthread.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef DBTHREAD_H
2+
#define DBTHREAD_H
3+
4+
#include <QList>
5+
#include <QThread>
6+
#include <QMutex>
7+
#include <QWaitCondition>
8+
#include <QSqlDatabase>
9+
#include <QSqlRecord>
10+
#include <QString>
11+
#include <QDebug>
12+
#include <QSqlError>
13+
#include <QSqlQuery>
14+
#include <QUuid>
15+
16+
class DbWorker;
17+
18+
class DbThread : public QThread
19+
{
20+
Q_OBJECT
21+
public:
22+
explicit DbThread(QObject *parent = 0, QString databaseFilePath = "");
23+
~DbThread();
24+
25+
void execute( const QString& query );
26+
27+
signals:
28+
void progress( const QString& msg );
29+
void ready(bool);
30+
void results( const QList<QSqlRecord>& records );
31+
32+
protected:
33+
void run();
34+
35+
signals:
36+
void executefwd( const QString& query );
37+
38+
private:
39+
DbWorker* m_worker;
40+
QString m_databaseFilePath;
41+
42+
};
43+
44+
#endif // DBTHREAD_H

app/SQLiteEditor/deployment.pri

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
android-no-sdk {
2+
target.path = /data/user/qt
3+
export(target.path)
4+
INSTALLS += target
5+
} else:android {
6+
x86 {
7+
target.path = /libs/x86
8+
} else: armeabi-v7a {
9+
target.path = /libs/armeabi-v7a
10+
} else {
11+
target.path = /libs/armeabi
12+
}
13+
export(target.path)
14+
INSTALLS += target
15+
} else:unix {
16+
isEmpty(target.path) {
17+
qnx {
18+
target.path = /tmp/$${TARGET}/bin
19+
} else {
20+
target.path = /opt/$${TARGET}/bin
21+
}
22+
export(target.path)
23+
}
24+
INSTALLS += target
25+
}
26+
27+
export(INSTALLS)

app/SQLiteEditor/generate-qrc.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Generate qrc
4+
5+
QMLBASEDIR=qml
6+
TMPQRC=.qml.qrc
7+
QRC=qml.qrc
8+
9+
#<RCC>
10+
# <qresource prefix="/">
11+
# <file>main_ios.qml</file>
12+
# <file>home.qml</file>
13+
# <file>dev.qml</file>
14+
# <file>img/triangular.png</file>
15+
# </qresource>
16+
#</RCC>
17+
18+
{
19+
echo "<RCC>"
20+
echo -ne '\t'
21+
echo "<qresource prefix=\"/\">"
22+
for i in `find ${QMLBASEDIR} -type f | grep -v .DS_Store`;
23+
do
24+
echo -ne '\t\t'
25+
echo "<file>${i}</file>"
26+
done;
27+
echo -ne '\t'
28+
echo "</qresource>"
29+
echo "</RCC>"
30+
} >> ${TMPQRC}
31+
32+
33+
mv ${TMPQRC} ${QRC}
34+
cat ${QRC}

app/SQLiteEditor/main.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <QApplication>
2+
#include <QQmlContext>
3+
#include <QtQml>
4+
#include <QQmlApplicationEngine>
5+
#include <QClipboard>
6+
7+
class Clipboard : public QObject {
8+
Q_OBJECT
9+
public:
10+
explicit Clipboard(QObject* parent = 0) {
11+
Q_UNUSED(parent)
12+
}
13+
14+
Q_INVOKABLE void setText(QString text) {
15+
QClipboard *clipboard = QApplication::clipboard();
16+
clipboard->setText(text);
17+
}
18+
};
19+
20+
int main(int argc, char *argv[])
21+
{
22+
QApplication app(argc, argv);
23+
24+
QQmlApplicationEngine engine;
25+
qmlRegisterType<Clipboard>("st.app", 1, 0, "Clipboard");
26+
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
27+
28+
// Step 1: get access to the root object
29+
QObject *rootObject = engine.rootObjects().first();
30+
QObject *qmlObject = rootObject->findChild<QObject*>("mainWindow");
31+
32+
33+
return app.exec();
34+
}
35+
36+
#include "main.moc"

app/SQLiteEditor/qml.qrc

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>qml/img/icon-tables.png</file>
4+
<file>qml/main.qml</file>
5+
<file>qml/utils/AccentBottom.qml</file>
6+
<file>qml/utils/AccentLeft.qml</file>
7+
<file>qml/utils/AccentRight.qml</file>
8+
<file>qml/utils/AccentTop.qml</file>
9+
<file>qml/utils/ActionSheet.qml</file>
10+
<file>qml/utils/AsyncImage.qml</file>
11+
<file>qml/utils/BaseButtonTheme.qml</file>
12+
<file>qml/utils/BaseIcon.qml</file>
13+
<file>qml/utils/BaseTabBarPage.qml</file>
14+
<file>qml/utils/BaseWindow.qml</file>
15+
<file>qml/utils/Blurtangle.qml</file>
16+
<file>qml/utils/ClickGuard.qml</file>
17+
<file>qml/utils/Config.qml</file>
18+
<file>qml/utils/Fill.qml</file>
19+
<file>qml/utils/GestureArea.qml</file>
20+
<file>qml/utils/HorizontalSpacer.qml</file>
21+
<file>qml/utils/Log.qml</file>
22+
<file>qml/utils/Model.qml</file>
23+
<file>qml/utils/Platform.qml</file>
24+
<file>qml/utils/PlatformiOS.qml</file>
25+
<file>qml/utils/RootItem.qml</file>
26+
<file>qml/utils/SafeLoader.qml</file>
27+
<file>qml/utils/TabBarButton.qml</file>
28+
<file>qml/utils/TabBarController.qml</file>
29+
<file>qml/utils/Theme.qml</file>
30+
<file>qml/utils/VerticalSpacer.qml</file>
31+
<file>qml/views/Label.qml</file>
32+
<file>qml/views/Header.qml</file>
33+
<file>qml/views/AppWindow.qml</file>
34+
<file>qml/views/Theme.qml</file>
35+
<file>qml/views/YosemiteButton.qml</file>
36+
</qresource>
37+
</RCC>
2.5 KB
Loading

0 commit comments

Comments
 (0)