Skip to content

Commit fd725c2

Browse files
author
MarcoFalke
committed
Merge #204: Drop buggy TableViewLastColumnResizingFixer class
3913d1e qt: Drop buggy TableViewLastColumnResizingFixer class (Hennadii Stepanov) Pull request description: In Qt 5 the last column resizing with dragging its left edge works out-of-the-box. The current `TableViewLastColumnResizingFixer` implementation could put the last column content out of the view port and confuse a user: ![Screenshot from 2021-01-31 18-04-32](https://user-images.githubusercontent.com/32963518/106390022-fd6bd180-63ee-11eb-9216-6e5117f8dc96.png) Historical context: - bitcoin/bitcoin#2862 - bitcoin/bitcoin#3626 - bitcoin/bitcoin#3738 - bitcoin/bitcoin#3920 #205 is a nice addition. ACKs for top commit: jarolrod: ACK 3913d1e, tested on macOS 11.1 Qt 5.15.2 Talkless: tACK 3913d1e, tested on Debian Sid. Can confirm that behavior in previous commit does not produce scroll bar, last column gets "hidden". This PR makes clear that there's more to see in the view. promag: Tested ACK 3913d1e on macos. Tree-SHA512: 12582dfce54bb1db3d9934ae092e305d32e9760cc99b0265322e161fa7f54b7d6fb6cefedf700783f767d5c3a56a8545c8d2f5ade66596c4e67b8a5287063e8a
2 parents 8d7d5f2 + 3913d1e commit fd725c2

File tree

6 files changed

+4
-182
lines changed

6 files changed

+4
-182
lines changed

src/qt/guiutil.cpp

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -470,120 +470,6 @@ bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
470470
return QObject::eventFilter(watched, event);
471471
}
472472

473-
void TableViewLastColumnResizingFixer::connectViewHeadersSignals()
474-
{
475-
connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &TableViewLastColumnResizingFixer::on_sectionResized);
476-
connect(tableView->horizontalHeader(), &QHeaderView::geometriesChanged, this, &TableViewLastColumnResizingFixer::on_geometriesChanged);
477-
}
478-
479-
// We need to disconnect these while handling the resize events, otherwise we can enter infinite loops.
480-
void TableViewLastColumnResizingFixer::disconnectViewHeadersSignals()
481-
{
482-
disconnect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &TableViewLastColumnResizingFixer::on_sectionResized);
483-
disconnect(tableView->horizontalHeader(), &QHeaderView::geometriesChanged, this, &TableViewLastColumnResizingFixer::on_geometriesChanged);
484-
}
485-
486-
// Setup the resize mode, handles compatibility for Qt5 and below as the method signatures changed.
487-
// Refactored here for readability.
488-
void TableViewLastColumnResizingFixer::setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
489-
{
490-
tableView->horizontalHeader()->setSectionResizeMode(logicalIndex, resizeMode);
491-
}
492-
493-
void TableViewLastColumnResizingFixer::resizeColumn(int nColumnIndex, int width)
494-
{
495-
tableView->setColumnWidth(nColumnIndex, width);
496-
tableView->horizontalHeader()->resizeSection(nColumnIndex, width);
497-
}
498-
499-
int TableViewLastColumnResizingFixer::getColumnsWidth()
500-
{
501-
int nColumnsWidthSum = 0;
502-
for (int i = 0; i < columnCount; i++)
503-
{
504-
nColumnsWidthSum += tableView->horizontalHeader()->sectionSize(i);
505-
}
506-
return nColumnsWidthSum;
507-
}
508-
509-
int TableViewLastColumnResizingFixer::getAvailableWidthForColumn(int column)
510-
{
511-
int nResult = lastColumnMinimumWidth;
512-
int nTableWidth = tableView->horizontalHeader()->width();
513-
514-
if (nTableWidth > 0)
515-
{
516-
int nOtherColsWidth = getColumnsWidth() - tableView->horizontalHeader()->sectionSize(column);
517-
nResult = std::max(nResult, nTableWidth - nOtherColsWidth);
518-
}
519-
520-
return nResult;
521-
}
522-
523-
// Make sure we don't make the columns wider than the table's viewport width.
524-
void TableViewLastColumnResizingFixer::adjustTableColumnsWidth()
525-
{
526-
disconnectViewHeadersSignals();
527-
resizeColumn(lastColumnIndex, getAvailableWidthForColumn(lastColumnIndex));
528-
connectViewHeadersSignals();
529-
530-
int nTableWidth = tableView->horizontalHeader()->width();
531-
int nColsWidth = getColumnsWidth();
532-
if (nColsWidth > nTableWidth)
533-
{
534-
resizeColumn(secondToLastColumnIndex,getAvailableWidthForColumn(secondToLastColumnIndex));
535-
}
536-
}
537-
538-
// Make column use all the space available, useful during window resizing.
539-
void TableViewLastColumnResizingFixer::stretchColumnWidth(int column)
540-
{
541-
disconnectViewHeadersSignals();
542-
resizeColumn(column, getAvailableWidthForColumn(column));
543-
connectViewHeadersSignals();
544-
}
545-
546-
// When a section is resized this is a slot-proxy for ajustAmountColumnWidth().
547-
void TableViewLastColumnResizingFixer::on_sectionResized(int logicalIndex, int oldSize, int newSize)
548-
{
549-
adjustTableColumnsWidth();
550-
int remainingWidth = getAvailableWidthForColumn(logicalIndex);
551-
if (newSize > remainingWidth)
552-
{
553-
resizeColumn(logicalIndex, remainingWidth);
554-
}
555-
}
556-
557-
// When the table's geometry is ready, we manually perform the stretch of the "Message" column,
558-
// as the "Stretch" resize mode does not allow for interactive resizing.
559-
void TableViewLastColumnResizingFixer::on_geometriesChanged()
560-
{
561-
if ((getColumnsWidth() - this->tableView->horizontalHeader()->width()) != 0)
562-
{
563-
disconnectViewHeadersSignals();
564-
resizeColumn(secondToLastColumnIndex, getAvailableWidthForColumn(secondToLastColumnIndex));
565-
connectViewHeadersSignals();
566-
}
567-
}
568-
569-
/**
570-
* Initializes all internal variables and prepares the
571-
* the resize modes of the last 2 columns of the table and
572-
*/
573-
TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent) :
574-
QObject(parent),
575-
tableView(table),
576-
lastColumnMinimumWidth(lastColMinimumWidth),
577-
allColumnsMinimumWidth(allColsMinimumWidth)
578-
{
579-
columnCount = tableView->horizontalHeader()->count();
580-
lastColumnIndex = columnCount - 1;
581-
secondToLastColumnIndex = columnCount - 2;
582-
tableView->horizontalHeader()->setMinimumSectionSize(allColumnsMinimumWidth);
583-
setViewHeaderResizeMode(secondToLastColumnIndex, QHeaderView::Interactive);
584-
setViewHeaderResizeMode(lastColumnIndex, QHeaderView::Interactive);
585-
}
586-
587473
#ifdef WIN32
588474
fs::path static StartupShortcutPath()
589475
{

src/qt/guiutil.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -181,45 +181,6 @@ namespace GUIUtil
181181
bool eventFilter(QObject* watched, QEvent* event) override;
182182
};
183183

184-
/**
185-
* Makes a QTableView last column feel as if it was being resized from its left border.
186-
* Also makes sure the column widths are never larger than the table's viewport.
187-
* In Qt, all columns are resizable from the right, but it's not intuitive resizing the last column from the right.
188-
* Usually our second to last columns behave as if stretched, and when on stretch mode, columns aren't resizable
189-
* interactively or programmatically.
190-
*
191-
* This helper object takes care of this issue.
192-
*
193-
*/
194-
class TableViewLastColumnResizingFixer: public QObject
195-
{
196-
Q_OBJECT
197-
198-
public:
199-
TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
200-
void stretchColumnWidth(int column);
201-
202-
private:
203-
QTableView* tableView;
204-
int lastColumnMinimumWidth;
205-
int allColumnsMinimumWidth;
206-
int lastColumnIndex;
207-
int columnCount;
208-
int secondToLastColumnIndex;
209-
210-
void adjustTableColumnsWidth();
211-
int getAvailableWidthForColumn(int column);
212-
int getColumnsWidth();
213-
void connectViewHeadersSignals();
214-
void disconnectViewHeadersSignals();
215-
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
216-
void resizeColumn(int nColumnIndex, int width);
217-
218-
private Q_SLOTS:
219-
void on_sectionResized(int logicalIndex, int oldSize, int newSize);
220-
void on_geometriesChanged();
221-
};
222-
223184
bool GetStartOnSystemStartup();
224185
bool SetStartOnSystemStartup(bool fAutoStart);
225186

src/qt/receivecoinsdialog.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
2525
QDialog(parent, GUIUtil::dialog_flags),
2626
ui(new Ui::ReceiveCoinsDialog),
27-
columnResizingFixer(nullptr),
2827
model(nullptr),
2928
platformStyle(_platformStyle)
3029
{
@@ -78,20 +77,19 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
7877
QTableView* tableView = ui->recentRequestsView;
7978

8079
tableView->verticalHeader()->hide();
81-
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
8280
tableView->setModel(_model->getRecentRequestsTableModel());
8381
tableView->setAlternatingRowColors(true);
8482
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
8583
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
8684
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
8785
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
8886
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
87+
tableView->horizontalHeader()->setMinimumSectionSize(MINIMUM_COLUMN_WIDTH);
88+
tableView->horizontalHeader()->setStretchLastSection(true);
8989

9090
connect(tableView->selectionModel(),
9191
&QItemSelectionModel::selectionChanged, this,
9292
&ReceiveCoinsDialog::recentRequestsView_selectionChanged);
93-
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
94-
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
9593

9694
if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
9795
ui->useBech32->setCheckState(Qt::Checked);
@@ -235,14 +233,6 @@ void ReceiveCoinsDialog::on_removeRequestButton_clicked()
235233
model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
236234
}
237235

238-
// We override the virtual resizeEvent of the QWidget to adjust tables column
239-
// sizes as the tables width is proportional to the dialogs width.
240-
void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
241-
{
242-
QWidget::resizeEvent(event);
243-
columnResizingFixer->stretchColumnWidth(RecentRequestsTableModel::Message);
244-
}
245-
246236
QModelIndex ReceiveCoinsDialog::selectedRow()
247237
{
248238
if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel())

src/qt/receivecoinsdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ public Q_SLOTS:
5151

5252
private:
5353
Ui::ReceiveCoinsDialog *ui;
54-
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
5554
WalletModel *model;
5655
QMenu *contextMenu;
5756
const PlatformStyle *platformStyle;
5857

5958
QModelIndex selectedRow();
6059
void copyColumnToClipboard(int column);
61-
virtual void resizeEvent(QResizeEvent *event) override;
6260

6361
private Q_SLOTS:
6462
void on_receiveButton_clicked();

src/qt/transactionview.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ void TransactionView::setModel(WalletModel *_model)
217217

218218
transactionProxyModel->setSortRole(Qt::EditRole);
219219

220-
transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
221220
transactionView->setModel(transactionProxyModel);
222221
transactionView->setAlternatingRowColors(true);
223222
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
@@ -231,8 +230,8 @@ void TransactionView::setModel(WalletModel *_model)
231230
transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH);
232231
transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH);
233232
transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
234-
235-
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, AMOUNT_MINIMUM_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this);
233+
transactionView->horizontalHeader()->setMinimumSectionSize(MINIMUM_COLUMN_WIDTH);
234+
transactionView->horizontalHeader()->setStretchLastSection(true);
236235

237236
if (_model->getOptionsModel())
238237
{
@@ -623,14 +622,6 @@ void TransactionView::focusTransaction(const uint256& txid)
623622
}
624623
}
625624

626-
// We override the virtual resizeEvent of the QWidget to adjust tables column
627-
// sizes as the tables width is proportional to the dialogs width.
628-
void TransactionView::resizeEvent(QResizeEvent* event)
629-
{
630-
QWidget::resizeEvent(event);
631-
columnResizingFixer->stretchColumnWidth(TransactionTableModel::ToAddress);
632-
}
633-
634625
// Need to override default Ctrl+C action for amount as default behaviour is just to copy DisplayRole text
635626
bool TransactionView::eventFilter(QObject *obj, QEvent *event)
636627
{

src/qt/transactionview.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ class TransactionView : public QWidget
8282

8383
QWidget *createDateRangeWidget();
8484

85-
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer{nullptr};
86-
87-
virtual void resizeEvent(QResizeEvent* event) override;
88-
8985
bool eventFilter(QObject *obj, QEvent *event) override;
9086

9187
private Q_SLOTS:

0 commit comments

Comments
 (0)