diff --git a/CMakeLists.txt b/CMakeLists.txt index dc09e748..e2c5f737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ endif() set(SQLB_HDR src/gen_version.h - src/sqlitedb.h src/sqlitetypes.h src/grammar/sqlite3TokenTypes.hpp src/grammar/Sqlite3Lexer.hpp @@ -35,6 +34,7 @@ set(SQLB_HDR ) set(SQLB_MOC_HDR + src/sqlitedb.h src/AboutDialog.h src/CreateIndexDialog.h src/EditDialog.h diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b0a503ce..3d45232c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -64,8 +64,9 @@ MainWindow::~MainWindow() void MainWindow::init() { - // Init the SQL log dock - db.mainWindow = this; + // Connect SQL logging and database state setting to main window + connect(&db, SIGNAL(dbChanged(bool)), this, SLOT(dbState(bool))); + connect(&db, SIGNAL(sqlExecuted(QString, int)), this, SLOT(logSql(QString,int))); // Set the validator for the goto line edit ui->editGoto->setValidator(gotoValidator); diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 7c436a30..bce0868a 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -1,6 +1,5 @@ #include "sqlitedb.h" #include "sqlitetablemodel.h" -#include "MainWindow.h" #include #include @@ -89,7 +88,7 @@ bool DBBrowserDB::setRestorePoint(const QString& pointname) QString query = QString("SAVEPOINT %1;").arg(pointname); sqlite3_exec(_db, query.toUtf8(), NULL, NULL, NULL); savepointList.append(pointname); - if(mainWindow) mainWindow->dbState(getDirty()); + emit dbChanged(getDirty()); } return true; } @@ -104,7 +103,7 @@ bool DBBrowserDB::save(const QString& pointname) QString query = QString("RELEASE %1;").arg(pointname); sqlite3_exec(_db, query.toUtf8(), NULL,NULL,NULL); savepointList.removeAll(pointname); - if(mainWindow) mainWindow->dbState(getDirty()); + emit dbChanged(getDirty()); } return true; } @@ -121,7 +120,7 @@ bool DBBrowserDB::revert(const QString& pointname) query = QString("RELEASE %1;").arg(pointname); sqlite3_exec(_db, query.toUtf8(), NULL, NULL, NULL); savepointList.removeAll(pointname); - if(mainWindow) mainWindow->dbState(getDirty()); + emit dbChanged(getDirty()); } return true; } @@ -218,7 +217,7 @@ bool DBBrowserDB::close() _db = 0; objMap.clear(); savepointList.clear(); - if(mainWindow) mainWindow->dbState(getDirty()); + emit dbChanged(getDirty()); // Return true to tell the calling function that the closing wasn't cancelled by the user return true; @@ -764,24 +763,21 @@ DBBrowserObject DBBrowserDB::getObjectByName(const QString& name) const void DBBrowserDB::logSQL(QString statement, int msgtype) { - if(mainWindow) + // Replace binary log messages by a placeholder text instead of printing gibberish + for(int i=0;i ...")); + statement.truncate(32); + statement.append(QObject::tr("... ...")); - // early exit if we detect a binary character, - // to prevent checking all characters in a potential big string - break; - } + // early exit if we detect a binary character, + // to prevent checking all characters in a potential big string + break; } - - mainWindow->logSql(statement, msgtype); } + + emit sqlExecuted(statement, msgtype); } void DBBrowserDB::updateSchema( ) diff --git a/src/sqlitedb.h b/src/sqlitedb.h index 814c85e1..01a785b2 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -7,7 +7,6 @@ #include #include -class MainWindow; class sqlite3; enum @@ -47,12 +46,13 @@ private: QString table_name; // The name of the table this object references, interesting for views, triggers and indices }; - -class DBBrowserDB +class DBBrowserDB : public QObject { + Q_OBJECT + public: - DBBrowserDB (): _db( 0 ), mainWindow(0) {} - ~DBBrowserDB (){} + explicit DBBrowserDB () : _db( 0 ) {} + virtual ~DBBrowserDB (){} bool open ( const QString & db); bool create ( const QString & db); bool close(); @@ -118,7 +118,9 @@ public: QString lastErrorMessage; QString curDBFilename; - MainWindow* mainWindow; +signals: + void sqlExecuted(QString sql, int msgtype); + void dbChanged(bool dirty); private: QStringList savepointList;