Skip to content

Commit c40fb07

Browse files
committed
Do not show the titlebar for the Table Browser dock when there is only one
This saves space and avoids redundancy in the different places where the table name appears. A new toolbar button for adding a new dock is included, so the functionality is still visible (it might be more discoverable now, indeed). Related to issue #2283. See comment in: #2918 (comment)
1 parent f18611a commit c40fb07

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

src/MainWindow.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,8 +3795,13 @@ void MainWindow::tableBrowserTabClosed()
37953795
// the last dock which is closed instead of if there is no dock remaining.
37963796
if(allTableBrowserDocks().size() == 1)
37973797
{
3798-
newTableBrowserTab();
3798+
newTableBrowserTab({}, /* forceHideTitlebar */ true);
37993799
} else {
3800+
// If only one dock will be left, make sure its titlebar is hidden.
3801+
if(allTableBrowserDocks().size() == 2) {
3802+
for(auto dock : allTableBrowserDocks())
3803+
dock->setTitleBarWidget(new QWidget(dock));
3804+
}
38003805
// If the currently active tab is closed activate another tab
38013806
if(currentTableBrowser && sender() == currentTableBrowser->parent())
38023807
{
@@ -3807,7 +3812,7 @@ void MainWindow::tableBrowserTabClosed()
38073812
}
38083813
}
38093814

3810-
TableBrowserDock* MainWindow::newTableBrowserTab(const sqlb::ObjectIdentifier& tableToBrowse)
3815+
TableBrowserDock* MainWindow::newTableBrowserTab(const sqlb::ObjectIdentifier& tableToBrowse, bool forceHideTitleBar)
38113816
{
38123817
// Prepare new dock
38133818
TableBrowserDock* d = new TableBrowserDock(ui->tabBrowsers, this);
@@ -3848,6 +3853,14 @@ TableBrowserDock* MainWindow::newTableBrowserTab(const sqlb::ObjectIdentifier& t
38483853
});
38493854
connect(d->tableBrowser(), &TableBrowser::prepareForFilter, editDock, &EditDialog::promptSaveData);
38503855

3856+
// Restore titlebar for any other widget
3857+
for(auto dock : allTableBrowserDocks())
3858+
dock->setTitleBarWidget(nullptr);
3859+
3860+
// Hide titlebar if it is the only one dock
3861+
if(allTableBrowserDocks().size() == 0 || forceHideTitleBar)
3862+
d->setTitleBarWidget(new QWidget(d));
3863+
38513864
// Set up dock and add it to the tab
38523865
ui->tabBrowsers->addDockWidget(Qt::TopDockWidgetArea, d);
38533866
if(allTableBrowserDocks().size() > 1)

src/MainWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private slots:
238238
void renameSqlTab(int index);
239239
void showContextMenuSqlTabBar(const QPoint& pos);
240240

241-
TableBrowserDock* newTableBrowserTab(const sqlb::ObjectIdentifier& tableToBrowse = {});
241+
TableBrowserDock* newTableBrowserTab(const sqlb::ObjectIdentifier& tableToBrowse = {}, bool forceHideTitleBar = false);
242242
void tableBrowserTabClosed();
243243
void changeTableBrowserTab(TableBrowserDock* dock);
244244
};

src/TableBrowser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@ TableBrowser::TableBrowser(DBBrowserDB* _db, QWidget* parent) :
172172
emit foreignKeyClicked(table, column, value);
173173
});
174174

175+
connect(ui->actionAddDock, &QAction::triggered, this, [this]() {
176+
emit newDockRequested();
177+
});
175178
connect(ui->actionRefresh, &QAction::triggered, this, [this]() {
176179
db->updateSchema();
177180
refresh();
178181
});
179-
180182
connect(ui->fontComboBox, &QFontComboBox::currentFontChanged, this, [this](const QFont &font) {
181183
modifyFormat([font](CondFormat& format) { format.setFontFamily(font.family()); });
182184
});

src/TableBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public slots:
9898
void foreignKeyClicked(sqlb::ObjectIdentifier table, std::string column, QByteArray value);
9999
void dataAboutToBeEdited(const QModelIndex& index);
100100
void prepareForFilter();
101+
void newDockRequested();
101102

102103
private slots:
103104
void clear();

src/TableBrowser.ui

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<property name="toolButtonStyle">
7575
<enum>Qt::ToolButtonIconOnly</enum>
7676
</property>
77+
<addaction name="actionAddDock"/>
7778
<addaction name="actionRefresh"/>
7879
<addaction name="actionClearFilters"/>
7980
<addaction name="actionClearSorting"/>
@@ -808,6 +809,24 @@
808809
<enum>Qt::WidgetShortcut</enum>
809810
</property>
810811
</action>
812+
<action name="actionAddDock">
813+
<property name="icon">
814+
<iconset resource="icons/icons.qrc">
815+
<normaloff>:/icons/new_tab</normaloff>:/icons/new_tab</iconset>
816+
</property>
817+
<property name="text">
818+
<string>New Data Browser</string>
819+
</property>
820+
<property name="toolTip">
821+
<string>Add a new docked Data Browser</string>
822+
</property>
823+
<property name="statusTip">
824+
<string>Add a new docked Data Browser</string>
825+
</property>
826+
<property name="whatsThis">
827+
<string>This button adss a new docked Data Browser, which you can detach and arrange in different layouts.</string>
828+
</property>
829+
</action>
811830
<action name="actionRefresh">
812831
<property name="icon">
813832
<iconset resource="icons/icons.qrc">

src/TableBrowserDock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ TableBrowserDock::TableBrowserDock(QWidget* parent, MainWindow* mainWindow)
3434
setWindowTitle(QString::fromStdString(table.toDisplayString()));
3535
});
3636

37+
connect(browser, &TableBrowser::newDockRequested, this, &TableBrowserDock::newDockRequested);
38+
3739
// Update view
3840
browser->refresh();
3941

0 commit comments

Comments
 (0)