Skip to content

Commit ea8eba1

Browse files
author
Paweł Salawa
committed
#5383 Double-click on column separator in data view now supports resizing all selected columns at once.
1 parent 9b2967a commit ea8eba1

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- ADDED: #5150 Added the Disable Blinkinig Cursor (for SQL Editor) option in the configuration dialog.
2626
- ADDED: #4232 Application will warn in status field if the open database was recently edited by a higher version of SQLite and that it may potentially cause some issues.
2727
- ADDED: #5552 Support for new syntax variants of ALTER TABLE.
28+
- ADDED: #5383 Double-click on column separator in data view now supports resizing all selected columns at once.
2829
- ADDED: #5566 Added Columns node to Views in Database List.
2930
- ADDED: #5570 In Configuration dialog the Reset To Defaults button was added for hotkeys page.
3031
- ADDED: #3934 Windows executables in the official release are now signed thanks to the SignPath.io.

SQLiteStudio3/guiSQLiteStudio/datagrid/sqlqueryview.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QCryptographicHash>
3030
#include <QMessageBox>
3131
#include <QScrollBar>
32+
#include <QScopedValueRollback>
3233
#include <services/pluginmanager.h>
3334
#include <multieditor/multieditorwidgetplugin.h>
3435

@@ -1293,6 +1294,7 @@ size_t qHash(SqlQueryView::Action action)
12931294
SqlQueryView::Header::Header(SqlQueryView* parent) :
12941295
QHeaderView(Qt::Horizontal, parent)
12951296
{
1297+
connect(this, &QHeaderView::sectionResized, this, &SqlQueryView::Header::handleSectionResize);
12961298
}
12971299

12981300
QSize SqlQueryView::Header::sectionSizeFromContents(int section) const
@@ -1320,5 +1322,47 @@ void SqlQueryView::Header::mousePressEvent(QMouseEvent *e)
13201322
}
13211323
}
13221324

1325+
if (e->button() == Qt::LeftButton)
1326+
{
1327+
lastSectionSizes.clear();
1328+
int sectionCount = count();
1329+
for (int i = 0; i < sectionCount; i++)
1330+
lastSectionSizes[i] = sectionSize(i);
1331+
}
1332+
13231333
QHeaderView::mousePressEvent(e);
13241334
}
1335+
1336+
void SqlQueryView::Header::mouseDoubleClickEvent(QMouseEvent* e)
1337+
{
1338+
dblClickResizing = true;
1339+
QHeaderView::mouseDoubleClickEvent(e);
1340+
dblClickResizing = false;
1341+
}
1342+
1343+
void SqlQueryView::Header::handleSectionResize(int logicalIndex, int oldSize, int newSize)
1344+
{
1345+
Q_UNUSED(oldSize);
1346+
Q_UNUSED(newSize);
1347+
1348+
if (ignoreResizing)
1349+
return;
1350+
1351+
QScopedValueRollback scopedIgnore(ignoreResizing, true);
1352+
1353+
SqlQueryView* view = qobject_cast<SqlQueryView*>(parentWidget());
1354+
QList<int> cols = view->selectionModel()->selectedColumns() | MAP(idx, {return idx.column();});
1355+
if (cols.size() <= 1 || !cols.contains(logicalIndex))
1356+
return;
1357+
1358+
if (dblClickResizing)
1359+
{
1360+
for (int col : cols)
1361+
{
1362+
if (col == logicalIndex)
1363+
continue;
1364+
1365+
view->resizeColumnToContents(col);
1366+
}
1367+
}
1368+
}

SQLiteStudio3/guiSQLiteStudio/datagrid/sqlqueryview.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CFG_KEY_LIST(SqlQueryView, QObject::tr("Data grid view"),
3636
CFG_KEY_ENTRY(DELETE_ROW, Qt::Key_Delete, QObject::tr("Delete selected data row"))
3737
CFG_KEY_ENTRY(INSERT_ROW, Qt::Key_Insert, QObject::tr("Insert new data row"))
3838
CFG_KEY_ENTRY(OPEN_VALUE_EDITOR, Qt::Key_F4, QObject::tr("Open contents of selected cell in a separate editor"))
39-
CFG_KEY_ENTRY(ADJUST_ROWS_SIZE, Qt::ALT | Qt::ALT | Qt::Key_H, QObject::tr("Toggle the height adjustment of rows"))
39+
CFG_KEY_ENTRY(ADJUST_ROWS_SIZE, Qt::ALT | Qt::Key_Z, QObject::tr("Toggle the height adjustment of rows"))
4040
CFG_KEY_ENTRY(INCR_FONT_SIZE, Qt::CTRL | Qt::Key_Plus, QObject::tr("Increase font size", "data view"))
4141
CFG_KEY_ENTRY(DECR_FONT_SIZE, Qt::CTRL | Qt::Key_Minus, QObject::tr("Decrease font size", "data view"))
4242
)
@@ -117,6 +117,14 @@ class GUI_API_EXPORT SqlQueryView : public QTableView, public ExtActionContainer
117117

118118
QSize sectionSizeFromContents(int section) const;
119119
void mousePressEvent(QMouseEvent *e);
120+
void mouseDoubleClickEvent(QMouseEvent *e) override;
121+
122+
private:
123+
void handleSectionResize(int logicalIndex, int oldSize, int newSize);
124+
125+
bool dblClickResizing = false;
126+
bool ignoreResizing = false;
127+
QHash<int, int> lastSectionSizes;
120128
};
121129

122130
void init();

0 commit comments

Comments
 (0)