diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index afdb02a9..6b424f00 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -20,7 +20,6 @@ #include "PreferencesDialog.h" #include "EditDialog.h" #include "FindDialog.h" -#include "SQLLogDock.h" #include "SQLiteSyntaxHighlighter.h" MainWindow::MainWindow(QWidget* parent) @@ -46,10 +45,10 @@ MainWindow::~MainWindow() void MainWindow::init() { - // Create the SQL log dock - logWin = new SQLLogDock(this); - db.logWin = logWin; - addDockWidget(Qt::BottomDockWidgetArea, logWin); + // Init the SQL log dock + db.mainWindow = this; + sqliteHighlighterLogUser = new SQLiteSyntaxHighlighter(ui->editLogUser->document()); + sqliteHighlighterLogApp = new SQLiteSyntaxHighlighter(ui->editLogApplication->document()); // Set up the db tree widget ui->dbTreeWidget->setColumnHidden(1, true); @@ -60,7 +59,7 @@ void MainWindow::init() ui->editGoto->setValidator(gotoValidator); // Create the SQL sytax highlighter - sqliteHighlighter = new SQLiteSyntaxHighlighter(ui->sqlTextEdit->document()); + sqliteHighlighterTabSql = new SQLiteSyntaxHighlighter(ui->sqlTextEdit->document()); // Set up DB model queryResultListModel = new QStandardItemModel(this); @@ -87,23 +86,20 @@ void MainWindow::init() popupFieldMenu->addAction(ui->editDeleteFieldActionPopup); // Set state of checkable menu actions - ui->sqlLogAction->setChecked(!logWin->isHidden()); + ui->sqlLogAction->setChecked(!ui->dockLog->isHidden()); ui->viewDBToolbarAction->setChecked(!ui->toolbarDB->isHidden()); // Connect some more signals and slots connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int))); - connect(ui->sqlLogAction, SIGNAL(toggled(bool)), logWin, SLOT(setVisible(bool))); connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel())); connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway())); connect(editWin, SIGNAL(updateRecordText(int, int , QString)), this, SLOT(updateRecordText(int, int , QString))); - connect(logWin, SIGNAL(goingAway()), this, SLOT(logWinAway())); - connect(logWin, SIGNAL(dbState(bool)),this, SLOT(dbState(bool))); // Load window settings QSettings settings(QApplication::organizationName(), QApplication::organizationName()); restoreGeometry(settings.value("MainWindow/geometry").toByteArray()); restoreState(settings.value("MainWindow/windowState").toByteArray()); - logWin->comboLogType()->setCurrentIndex(logWin->comboLogType()->findText(settings.value("SQLLogDock/Log", "Application").toString())); + ui->comboLogSubmittedBy->setCurrentIndex(ui->comboLogSubmittedBy->findText(settings.value("SQLLogDock/Log", "Application").toString())); // Set other window settings setAcceptDrops(true); @@ -168,7 +164,9 @@ void MainWindow::populateStructure() } db.updateSchema(); QStringList tblnames = db.getBrowsableObjectNames(); - sqliteHighlighter->setTableNames(tblnames); + sqliteHighlighterTabSql->setTableNames(tblnames); + sqliteHighlighterLogUser->setTableNames(tblnames); + sqliteHighlighterLogApp->setTableNames(tblnames); QMap typeToParentItem; QTreeWidgetItem* itemTables = new QTreeWidgetItem(ui->dbTreeWidget); @@ -285,7 +283,7 @@ void MainWindow::fileClose() populateStructure(); loadPragmas(); activateFields(false); - logWin->clearLog(); + ui->buttonLogClear->click(); } void MainWindow::fileExit() @@ -309,7 +307,7 @@ void MainWindow::closeEvent( QCloseEvent* event ) QSettings settings(QApplication::organizationName(), QApplication::organizationName()); settings.setValue("MainWindow/geometry", saveGeometry()); settings.setValue("MainWindow/windowState", saveState()); - settings.setValue("SQLLogDock/Log", logWin->comboLogType()->currentText()); + settings.setValue("SQLLogDock/Log", ui->comboLogSubmittedBy->currentText()); fileExit(); QMainWindow::closeEvent(event); } @@ -658,11 +656,6 @@ void MainWindow::updateRecordText(int row, int col, QString newtext) } -void MainWindow::logWinAway() -{ - ui->sqlLogAction->toggle(); -} - void MainWindow::editWinAway() { editWin->hide(); @@ -1151,3 +1144,15 @@ void MainWindow::savePragmas() db.setPragma("user_version", QString::number(ui->spinPragmaUserVersion->value())); db.setPragma("wal_autocheckpoint", QString::number(ui->spinPragmaWalAutoCheckpoint->value())); } + +void MainWindow::logSql(const QString& sql, int msgtype) +{ + if(msgtype == kLogMsg_User) + { + ui->editLogUser->append(sql); + ui->editLogUser->verticalScrollBar()->setValue(ui->editLogUser->verticalScrollBar()->maximum()); + } else { + ui->editLogApplication->append(sql); + ui->editLogApplication->verticalScrollBar()->setValue(ui->editLogApplication->verticalScrollBar()->maximum()); + } +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 6d8b7944..4018bc6c 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -8,7 +8,6 @@ #define ORDERMODE_DESC 1 class QDragEnterEvent; -class SQLLogDock; class EditDialog; class FindDialog; class SQLiteSyntaxHighlighter; @@ -29,14 +28,15 @@ public: private: Ui::MainWindow* ui; - SQLLogDock * logWin; QStandardItemModel *queryResultListModel; QMenu *popupTableMenu; QMenu *popupFieldMenu; QMenu *recentFilesMenu; - SQLiteSyntaxHighlighter* sqliteHighlighter; + SQLiteSyntaxHighlighter* sqliteHighlighterTabSql; + SQLiteSyntaxHighlighter* sqliteHighlighterLogUser; + SQLiteSyntaxHighlighter* sqliteHighlighterLogApp; enum { MaxRecentFiles = 5 }; QAction *recentFileActs[MaxRecentFiles]; @@ -66,6 +66,8 @@ protected: public slots: virtual void fileOpen( const QString & fileName ); + virtual void logSql(const QString &sql, int msgtype); + virtual void dbState(bool dirty); private slots: virtual void createTreeContextMenu(const QPoint & qPoint); @@ -100,14 +102,12 @@ private slots: virtual void helpWhatsThis(); virtual void helpAbout(); virtual void updateRecordText( int row, int col, QString newtext ); - virtual void logWinAway(); virtual void editWinAway(); virtual void editText( int row, int col ); virtual void doubleClickTable( int row, int col ); virtual void executeQuery(); virtual void importTableFromCSV(); virtual void exportTableToCSV(); - virtual void dbState( bool dirty ); virtual void fileSave(); virtual void fileRevert(); virtual void exportDatabaseToSQL(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 165395a0..451c561d 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -1029,6 +1029,98 @@ + + + QDockWidget::AllDockWidgetFeatures + + + SQL Log + + + 8 + + + + + + + + + &Show SQL submitted by + + + comboLogSubmittedBy + + + + + + + + User + + + + + Application + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Clear + + + + + + + + + 0 + + + + + Monospace + 10 + + + + true + + + + + + Monospace + 10 + + + + true + + + + + + + @@ -1416,6 +1508,8 @@ spinPragmaUserVersion spinPragmaWalAutoCheckpoint buttonBoxPragmas + comboLogSubmittedBy + buttonLogClear @@ -1492,8 +1586,8 @@ populateTable(QString) - 87 - 91 + 59 + 82 399 @@ -1508,8 +1602,8 @@ addRecord() - 623 - 91 + 584 + 82 399 @@ -1524,8 +1618,8 @@ deleteRecord() - 733 - 91 + 687 + 82 399 @@ -1541,7 +1635,7 @@ 22 - 559 + 321 399 @@ -1557,7 +1651,7 @@ 114 - 559 + 321 399 @@ -1572,8 +1666,8 @@ navigateGoto() - 461 - 559 + 443 + 321 399 @@ -1588,8 +1682,8 @@ navigateGoto() - 644 - 558 + 511 + 321 399 @@ -1604,8 +1698,8 @@ browseFind(bool) - 143 - 91 + 141 + 81 399 @@ -1620,8 +1714,8 @@ browseRefresh() - 173 - 91 + 171 + 81 399 @@ -1684,8 +1778,8 @@ doubleClickTable(int,int) - 399 - 325 + 99 + 113 399 @@ -1716,8 +1810,8 @@ executeQuery() - 82 - 302 + 86 + 177 399 @@ -2004,8 +2098,8 @@ loadPragmas() - 243 - 551 + 247 + 705 -1 @@ -2020,8 +2114,8 @@ savePragmas() - 715 - 550 + 360 + 705 802 @@ -2029,6 +2123,86 @@ + + buttonLogClear + clicked() + editLogApplication + clear() + + + 750 + 392 + + + 642 + 454 + + + + + buttonLogClear + clicked() + editLogUser + clear() + + + 754 + 387 + + + 611 + 426 + + + + + comboLogSubmittedBy + currentIndexChanged(int) + stackLog + setCurrentIndex(int) + + + 193 + 392 + + + 399 + 492 + + + + + sqlLogAction + toggled(bool) + dockLog + setVisible(bool) + + + -1 + -1 + + + 399 + 467 + + + + + dockLog + visibilityChanged(bool) + sqlLogAction + setChecked(bool) + + + 399 + 467 + + + -1 + -1 + + + fileOpen() diff --git a/src/SQLLogDock.cpp b/src/SQLLogDock.cpp deleted file mode 100644 index a597d1c6..00000000 --- a/src/SQLLogDock.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include "SQLLogDock.h" -#include -#include "sqlitedb.h" -#include "SQLiteSyntaxHighlighter.h" - -/* - * Constructs a sqlLogForm as a child of 'parent', with the - * name 'name' and widget flags set to 'f'. - * - * The dialog will by default be modeless, unless you set 'modal' to - * true to construct a modal dialog. - */ -SQLLogDock::SQLLogDock(QWidget* parent) - : QDockWidget(tr("SQL Log"), parent) -{ - setupUi(); -} - -void SQLLogDock::setupUi() -{ - contentWidget = new QWidget(this); - this->setWidget(contentWidget); - if (this->objectName().isEmpty()) - this->setObjectName(QString::fromUtf8("sqlLogForm")); - vboxLayout = new QVBoxLayout(contentWidget); - vboxLayout->setMargin(2); - vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); - - hboxLayout = new QHBoxLayout(); - hboxLayout->setSpacing(3); - hboxLayout->setObjectName(QString::fromUtf8("hboxLayout")); - textLabel1 = new QLabel(this); - textLabel1->setObjectName(QString::fromUtf8("textLabel1")); - textLabel1->setWordWrap(false); - - hboxLayout->addWidget(textLabel1); - - m_comboLogType = new QComboBox(this); - m_comboLogType->setObjectName(QString::fromUtf8("comboBox3")); - - hboxLayout->addWidget(m_comboLogType); - - spacer10 = new QSpacerItem(150, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - hboxLayout->addItem(spacer10); - - clearButton = new QPushButton(this); - clearButton->setObjectName(QString::fromUtf8("clearButton")); - - hboxLayout->addWidget(clearButton); - - vboxLayout->addLayout(hboxLayout); - - logStack = new QStackedWidget(this); - logStack->setObjectName(QString::fromUtf8("logStack")); - WStackPage = new QWidget(logStack); - WStackPage->setObjectName(QString::fromUtf8("WStackPage")); - gridLayout = new QGridLayout(WStackPage); - gridLayout->setSpacing(3); - gridLayout->setContentsMargins(11, 11, 11, 11); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - gridLayout->setContentsMargins(0, 0, 0, 0); - userLogText = new QTextEdit(WStackPage); - userLogText->setObjectName(QString::fromUtf8("userLogText")); - userLogText->setReadOnly(true); - - QFont font; - font.setFamily("Courier"); - font.setFixedPitch(true); - font.setPixelSize(11); - userLogText->setFont(font); - - mUserSqliteHighlighter = new SQLiteSyntaxHighlighter(userLogText->document()); - - gridLayout->addWidget(userLogText, 0, 0, 1, 1); - logStack->addWidget(WStackPage); - WStackPage->setLayout(gridLayout); - - WStackPage1 = new QWidget(logStack); - WStackPage1->setObjectName(QString::fromUtf8("WStackPage1")); - vboxLayout1 = new QVBoxLayout(WStackPage1); - vboxLayout1->setSpacing(3); - vboxLayout1->setContentsMargins(11, 11, 11, 11); - vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1")); - vboxLayout1->setContentsMargins(0, 0, 0, 0); - appLogText = new QTextEdit(WStackPage1); - appLogText->setObjectName(QString::fromUtf8("appLogText")); - appLogText->setReadOnly(true); - appLogText->setFont(font); - - mAppSqliteHighlighter = new SQLiteSyntaxHighlighter(appLogText->document()); - - logStack->addWidget(WStackPage1); - vboxLayout1->addWidget(appLogText); - WStackPage1->setLayout(vboxLayout1); - - vboxLayout->addWidget(logStack); - contentWidget->setLayout(vboxLayout); - - - retranslateUi(); - QObject::connect(clearButton, SIGNAL(clicked()), this, SLOT(clearLog())); - QObject::connect(m_comboLogType, SIGNAL(currentIndexChanged(int)), logStack, SLOT(setCurrentIndex(int))); - - QMetaObject::connectSlotsByName(this); -} - -void SQLLogDock::retranslateUi() -{ - this->setWindowTitle(QObject::tr("SQL Log")); - textLabel1->setText(QObject::tr("Show SQL submitted by:")); - m_comboLogType->clear(); - m_comboLogType->insertItems(0, QStringList() - << QObject::tr("User") - << QObject::tr("Application") - ); - clearButton->setText(QObject::tr("Clear")); -} // retranslateUi - - -/* - * Destroys the object and frees any allocated resources - */ -SQLLogDock::~SQLLogDock() -{ - // no need to delete child widgets, Qt does it all for us -} - -/* - * Sets the strings of the subwidgets using the current - * language. - */ -void SQLLogDock::languageChange() -{ - retranslateUi(); -} - -void SQLLogDock::closeEvent( QCloseEvent * ) -{ - emit goingAway(); -} - -void SQLLogDock::log( QString & statement, int msgtype) -{ - QScrollBar* sb = 0; - if (msgtype==kLogMsg_User) - { - userLogText->append(statement); - sb = userLogText->verticalScrollBar(); - } else { - appLogText->append(statement); - sb = appLogText->verticalScrollBar(); - } - sb->setValue(sb->maximum()); -} - -void SQLLogDock::msgDBDirtyState( bool dirty) -{ - emit dbState(dirty); -} - - -void SQLLogDock::clearLog() -{ - if (logStack->currentIndex()==kLogMsg_User) - { - userLogText->clear(); - } else { - appLogText->clear(); -} -} - diff --git a/src/SQLLogDock.h b/src/SQLLogDock.h deleted file mode 100644 index 1f4ff097..00000000 --- a/src/SQLLogDock.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SQLLOGFORM_H -#define SQLLOGFORM_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class SQLiteSyntaxHighlighter; - -class SQLLogDock : public QDockWidget -{ - Q_OBJECT - -public: - SQLLogDock(QWidget* parent = 0); - ~SQLLogDock(); - - QComboBox* comboLogType() { return m_comboLogType; } - SQLiteSyntaxHighlighter* userSqliteHighlighter() { return mUserSqliteHighlighter; } - SQLiteSyntaxHighlighter* appSqliteHighlighter() { return mAppSqliteHighlighter; } - -private: - QWidget* contentWidget; - QVBoxLayout *vboxLayout; - QHBoxLayout *hboxLayout; - QLabel *textLabel1; - QComboBox *m_comboLogType; - QSpacerItem *spacer10; - QPushButton *clearButton; - QStackedWidget *logStack; - QWidget *WStackPage; - QGridLayout *gridLayout; - QTextEdit *userLogText; - QWidget *WStackPage1; - QVBoxLayout *vboxLayout1; - QTextEdit *appLogText; - - SQLiteSyntaxHighlighter* mUserSqliteHighlighter; - SQLiteSyntaxHighlighter* mAppSqliteHighlighter; - - void setupUi(); - void retranslateUi(); - -public slots: - virtual void closeEvent( QCloseEvent * ); - virtual void log( QString & statement, int msgtype ); - virtual void msgDBDirtyState( bool dirty ); - virtual void clearLog(); - -signals: - void goingAway(); - void dbState(bool dirty); - -protected slots: - virtual void languageChange(); - -}; - -#endif // SQLLOGFORM_H diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 9aceb5c7..bed8aab4 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -1,9 +1,9 @@ #include "sqlitedb.h" #include "sqlbrowser_util.h" +#include "MainWindow.h" #include #include #include -#include "SQLLogDock.h" #include #include @@ -20,19 +20,15 @@ bool DBBrowserDB::isOpen ( ) void DBBrowserDB::setDirty(bool dirtyval) { dirty = dirtyval; - if (logWin) - { - logWin->msgDBDirtyState(dirty); - } + if(mainWindow) + mainWindow->dbState(dirtyval); } void DBBrowserDB::setDirtyDirect(bool dirtyval) { dirty = dirtyval; - if (logWin) - { - logWin->msgDBDirtyState(dirty); - } + if(mainWindow) + mainWindow->dbState(dirtyval); } bool DBBrowserDB::getDirty() @@ -863,7 +859,7 @@ int DBBrowserDB::getRecordCount() void DBBrowserDB::logSQL(QString statement, int msgtype) { - if (logWin) + if(mainWindow) { /*limit log message to a sensible size, this will truncate some binary messages*/ int loglimit = 300; @@ -872,7 +868,7 @@ void DBBrowserDB::logSQL(QString statement, int msgtype) statement.truncate(32); statement.append(QObject::tr("... ...")); } - logWin->log(statement, msgtype); + mainWindow->logSql(statement, msgtype); } } @@ -1101,26 +1097,26 @@ bool DBBrowserDB::setPragma(QString pragma, QString value) if(pragma == "journal_mode") { if(value == "0") - value = "delete"; + value = "\"delete\""; else if(value == "1") - value = "truncate"; + value = "\"truncate\""; else if(value == "2") - value = "persist"; + value = "\"persist\""; else if(value == "3") - value = "memory"; + value = "\"memory\""; else if(value == "4") - value = "wal"; + value = "\"wal\""; else if(value == "5") - value = "off"; + value = "\"off\""; else - value = "delete"; + value = "\"delete\""; } else if(value == "locking_mode") { if(value == "0") - value = "normal"; + value = "\"normal\""; else if(value == "1") - value = "exclusive"; + value = "\"exclusive\""; else - value = "normal"; + value = "\"normal\""; } else if(pragma == "encoding") { if(value == "0") value = "\"utf-8\""; diff --git a/src/sqlitedb.h b/src/sqlitedb.h index d3b3a683..288b9699 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -5,8 +5,7 @@ #include #include #include - -class SQLLogDock; +class MainWindow; enum { @@ -82,7 +81,7 @@ private: class DBBrowserDB { public: - DBBrowserDB (): _db( 0 ) , hasValidBrowseSet(false), curEncoding(kEncodingUTF8) {} + DBBrowserDB (): _db( 0 ) , hasValidBrowseSet(false), curEncoding(kEncodingUTF8), mainWindow(0) {} ~DBBrowserDB (){} bool open ( const QString & db); bool create ( const QString & db); @@ -143,7 +142,7 @@ public: int curEncoding; QString curNewData; - SQLLogDock * logWin; + MainWindow* mainWindow; private: diff --git a/src/src.pro b/src/src.pro index 6f1efdfe..f8ee7450 100644 --- a/src/src.pro +++ b/src/src.pro @@ -13,7 +13,6 @@ CONFIG += qt \ HEADERS += \ sqlitedb.h \ sqlbrowser_util.h \ - SQLLogDock.h \ MainWindow.h \ SQLiteSyntaxHighlighter.h \ CreateIndexDialog.h \ @@ -29,7 +28,6 @@ HEADERS += \ SOURCES += \ sqlitedb.cpp \ sqlbrowser_util.c \ - SQLLogDock.cpp \ main.cpp \ MainWindow.cpp \ SQLiteSyntaxHighlighter.cpp \