mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Remove dependency to main window from DBBrowserDB class
Get rid of the dependency to the MainWindow class in the DBBrowserDB class. It was only used for calling the log SQL and set database state functions anyway. The same result can be achieved emitting Qt slots.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "sqlitedb.h"
|
||||
#include "sqlitetablemodel.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
@@ -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.size();i++)
|
||||
{
|
||||
// Replace binary log messages by a placeholder text instead of printing gibberish
|
||||
for(int i=0;i<statement.size();i++)
|
||||
if(statement.at(i) < 32 && statement.at(i) != '\n')
|
||||
{
|
||||
if(statement.at(i) < 32 && statement.at(i) != '\n')
|
||||
{
|
||||
statement.truncate(32);
|
||||
statement.append(QObject::tr("... <string can not be logged, contains binary data> ..."));
|
||||
statement.truncate(32);
|
||||
statement.append(QObject::tr("... <string can not be logged, contains binary data> ..."));
|
||||
|
||||
// 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( )
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <QMultiMap>
|
||||
#include <QByteArray>
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user