Skip to content

Commit

Permalink
MainWindow: Add new dock showing the DB schema
Browse files Browse the repository at this point in the history
See issue sqlitebrowser#75.
  • Loading branch information
MKleusberg committed Aug 22, 2014
1 parent 547a4d8 commit beae692
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
17 changes: 14 additions & 3 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ void MainWindow::init()
ui->dbTreeWidget->setColumnHidden(1, true);
ui->dbTreeWidget->setColumnWidth(0, 300);

// Set up DB schema dock
ui->treeSchemaDock->setModel(dbStructureModel);
ui->treeSchemaDock->setColumnHidden(1, true);
ui->treeSchemaDock->setColumnWidth(0, 300);

// Add keyboard shortcuts
QList<QKeySequence> shortcuts = ui->actionExecuteSql->shortcuts();
shortcuts.push_back(QKeySequence(tr("Ctrl+Return")));
Expand All @@ -102,17 +107,21 @@ void MainWindow::init()
popupTableMenu->addSeparator();
popupTableMenu->addAction(ui->actionExportCsvPopup);

// Set state of checkable menu actions
// Add menu item for log dock
ui->viewMenu->insertAction(ui->viewDBToolbarAction, ui->dockLog->toggleViewAction());
ui->viewMenu->actions().at(0)->setShortcut(QKeySequence(tr("Ctrl+L")));
ui->viewMenu->actions().at(0)->setIcon(QIcon(":/icons/log_dock"));
ui->viewDBToolbarAction->setChecked(!ui->toolbarDB->isHidden());

// Plot view menu
// Add menu item for plot dock
ui->viewMenu->insertAction(ui->viewDBToolbarAction, ui->dockPlot->toggleViewAction());
ui->viewMenu->actions().at(1)->setShortcut(QKeySequence(tr("Ctrl+P")));
ui->viewMenu->actions().at(1)->setIcon(QIcon(":/icons/log_dock"));

// Add menu item for schema dock
ui->viewMenu->insertAction(ui->viewDBToolbarAction, ui->dockSchema->toggleViewAction());
ui->viewMenu->actions().at(2)->setIcon(QIcon(":/icons/log_dock"));

// Set statusbar fields
statusEncodingLabel = new QLabel(ui->statusbar);
statusEncodingLabel->setEnabled(false);
Expand All @@ -130,7 +139,8 @@ void MainWindow::init()
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));

// Load window settings
tabifyDockWidget(ui->dockPlot, ui->dockLog);
tabifyDockWidget(ui->dockLog, ui->dockPlot);
tabifyDockWidget(ui->dockLog, ui->dockSchema);
restoreGeometry(PreferencesDialog::getSettingsValue("MainWindow", "geometry").toByteArray());
restoreState(PreferencesDialog::getSettingsValue("MainWindow", "windowState").toByteArray());
ui->comboLogSubmittedBy->setCurrentIndex(ui->comboLogSubmittedBy->findText(PreferencesDialog::getSettingsValue("SQLLogDock", "Log").toString()));
Expand Down Expand Up @@ -229,6 +239,7 @@ void MainWindow::populateStructure()
db.updateSchema();
dbStructureModel->reloadData(&db);
ui->dbTreeWidget->expandToDepth(0);
ui->treeSchemaDock->expandToDepth(0);

if(!db.isOpen())
return;
Expand Down
52 changes: 43 additions & 9 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>444</height>
<width>575</width>
<height>458</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -764,7 +764,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>20</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
Expand Down Expand Up @@ -1014,7 +1014,16 @@
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -1068,6 +1077,31 @@
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="dockSchema">
<property name="windowTitle">
<string>DB Schema</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QTreeView" name="treeSchemaDock">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="animated">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="fileNewAction">
<property name="icon">
<iconset resource="icons/icons.qrc">
Expand Down Expand Up @@ -1487,17 +1521,17 @@
<extends>QTableWidget</extends>
<header>ExtendedTableWidget.h</header>
</customwidget>
<customwidget>
<class>SqlTextEdit</class>
<extends>QTextEdit</extends>
<header>sqltextedit.h</header>
</customwidget>
<customwidget>
<class>QCustomPlot</class>
<extends>QWidget</extends>
<header>qcustomplot.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SqlTextEdit</class>
<extends>QTextEdit</extends>
<header>sqltextedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>dbTreeWidget</tabstop>
Expand Down

0 comments on commit beae692

Please sign in to comment.