|
29 | 29 | #include <QCryptographicHash> |
30 | 30 | #include <QMessageBox> |
31 | 31 | #include <QScrollBar> |
| 32 | +#include <QScopedValueRollback> |
32 | 33 | #include <services/pluginmanager.h> |
33 | 34 | #include <multieditor/multieditorwidgetplugin.h> |
34 | 35 |
|
@@ -1293,6 +1294,7 @@ size_t qHash(SqlQueryView::Action action) |
1293 | 1294 | SqlQueryView::Header::Header(SqlQueryView* parent) : |
1294 | 1295 | QHeaderView(Qt::Horizontal, parent) |
1295 | 1296 | { |
| 1297 | + connect(this, &QHeaderView::sectionResized, this, &SqlQueryView::Header::handleSectionResize); |
1296 | 1298 | } |
1297 | 1299 |
|
1298 | 1300 | QSize SqlQueryView::Header::sectionSizeFromContents(int section) const |
@@ -1320,5 +1322,47 @@ void SqlQueryView::Header::mousePressEvent(QMouseEvent *e) |
1320 | 1322 | } |
1321 | 1323 | } |
1322 | 1324 |
|
| 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 | + |
1323 | 1333 | QHeaderView::mousePressEvent(e); |
1324 | 1334 | } |
| 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 | +} |
0 commit comments