Skip to content

Commit 58b3b4f

Browse files
authored
Drop buggy TableViewLastColumnResizingFixer class (btc#204) (#1036)
backport bitcoin#204 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.
1 parent 82556fb commit 58b3b4f

6 files changed

+3
-186
lines changed

src/qt/guiutil.cpp

-119
Original file line numberDiff line numberDiff line change
@@ -597,125 +597,6 @@ bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt)
597597
return QObject::eventFilter(obj, evt);
598598
}
599599

600-
void TableViewLastColumnResizingFixer::connectViewHeadersSignals()
601-
{
602-
connect(tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(on_sectionResized(int,int,int)));
603-
connect(tableView->horizontalHeader(), SIGNAL(geometriesChanged()), this, SLOT(on_geometriesChanged()));
604-
}
605-
606-
// We need to disconnect these while handling the resize events, otherwise we can enter infinite loops.
607-
void TableViewLastColumnResizingFixer::disconnectViewHeadersSignals()
608-
{
609-
disconnect(tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(on_sectionResized(int,int,int)));
610-
disconnect(tableView->horizontalHeader(), SIGNAL(geometriesChanged()), this, SLOT(on_geometriesChanged()));
611-
}
612-
613-
// Setup the resize mode, handles compatibility for Qt5 and below as the method signatures changed.
614-
// Refactored here for readability.
615-
void TableViewLastColumnResizingFixer::setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode)
616-
{
617-
#if QT_VERSION < 0x050000
618-
tableView->horizontalHeader()->setResizeMode(logicalIndex, resizeMode);
619-
#else
620-
tableView->horizontalHeader()->setSectionResizeMode(logicalIndex, resizeMode);
621-
#endif
622-
}
623-
624-
void TableViewLastColumnResizingFixer::resizeColumn(int nColumnIndex, int width)
625-
{
626-
tableView->setColumnWidth(nColumnIndex, width);
627-
tableView->horizontalHeader()->resizeSection(nColumnIndex, width);
628-
}
629-
630-
int TableViewLastColumnResizingFixer::getColumnsWidth()
631-
{
632-
int nColumnsWidthSum = 0;
633-
for (int i = 0; i < columnCount; i++)
634-
{
635-
nColumnsWidthSum += tableView->horizontalHeader()->sectionSize(i);
636-
}
637-
return nColumnsWidthSum;
638-
}
639-
640-
int TableViewLastColumnResizingFixer::getAvailableWidthForColumn(int column)
641-
{
642-
int nResult = lastColumnMinimumWidth;
643-
int nTableWidth = tableView->horizontalHeader()->width();
644-
645-
if (nTableWidth > 0)
646-
{
647-
int nOtherColsWidth = getColumnsWidth() - tableView->horizontalHeader()->sectionSize(column);
648-
nResult = std::max(nResult, nTableWidth - nOtherColsWidth);
649-
}
650-
651-
return nResult;
652-
}
653-
654-
// Make sure we don't make the columns wider than the table's viewport width.
655-
void TableViewLastColumnResizingFixer::adjustTableColumnsWidth()
656-
{
657-
disconnectViewHeadersSignals();
658-
resizeColumn(lastColumnIndex, getAvailableWidthForColumn(lastColumnIndex));
659-
connectViewHeadersSignals();
660-
661-
int nTableWidth = tableView->horizontalHeader()->width();
662-
int nColsWidth = getColumnsWidth();
663-
if (nColsWidth > nTableWidth)
664-
{
665-
resizeColumn(secondToLastColumnIndex,getAvailableWidthForColumn(secondToLastColumnIndex));
666-
}
667-
}
668-
669-
// Make column use all the space available, useful during window resizing.
670-
void TableViewLastColumnResizingFixer::stretchColumnWidth(int column)
671-
{
672-
disconnectViewHeadersSignals();
673-
resizeColumn(column, getAvailableWidthForColumn(column));
674-
connectViewHeadersSignals();
675-
}
676-
677-
// When a section is resized this is a slot-proxy for ajustAmountColumnWidth().
678-
void TableViewLastColumnResizingFixer::on_sectionResized(int logicalIndex, int oldSize, int newSize)
679-
{
680-
adjustTableColumnsWidth();
681-
int remainingWidth = getAvailableWidthForColumn(logicalIndex);
682-
if (newSize > remainingWidth)
683-
{
684-
resizeColumn(logicalIndex, remainingWidth);
685-
}
686-
}
687-
688-
// When the table's geometry is ready, we manually perform the stretch of the "Message" column,
689-
// as the "Stretch" resize mode does not allow for interactive resizing.
690-
void TableViewLastColumnResizingFixer::on_geometriesChanged()
691-
{
692-
if ((getColumnsWidth() - this->tableView->horizontalHeader()->width()) != 0)
693-
{
694-
disconnectViewHeadersSignals();
695-
resizeColumn(secondToLastColumnIndex, getAvailableWidthForColumn(secondToLastColumnIndex));
696-
connectViewHeadersSignals();
697-
}
698-
}
699-
700-
/**
701-
* Initializes all internal variables and prepares the
702-
* the resize modes of the last 2 columns of the table and
703-
*/
704-
TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent) :
705-
QObject(parent),
706-
tableView(table),
707-
lastColumnMinimumWidth(lastColMinimumWidth),
708-
allColumnsMinimumWidth(allColsMinimumWidth)
709-
{
710-
columnCount = tableView->horizontalHeader()->count();
711-
lastColumnIndex = columnCount - 1;
712-
secondToLastColumnIndex = columnCount - 2;
713-
tableView->horizontalHeader()->setMinimumSectionSize(allColumnsMinimumWidth);
714-
setViewHeaderResizeMode(columnCount - 3, QHeaderView::ResizeToContents);
715-
setViewHeaderResizeMode(secondToLastColumnIndex, QHeaderView::ResizeToContents);
716-
setViewHeaderResizeMode(lastColumnIndex, QHeaderView::Stretch);
717-
}
718-
719600
#ifdef WIN32
720601
fs::path static StartupShortcutPath()
721602
{

src/qt/guiutil.h

-39
Original file line numberDiff line numberDiff line change
@@ -166,45 +166,6 @@ namespace GUIUtil
166166
int size_threshold;
167167
};
168168

169-
/**
170-
* Makes a QTableView last column feel as if it was being resized from its left border.
171-
* Also makes sure the column widths are never larger than the table's viewport.
172-
* In Qt, all columns are resizable from the right, but it's not intuitive resizing the last column from the right.
173-
* Usually our second to last columns behave as if stretched, and when on strech mode, columns aren't resizable
174-
* interactively or programmatically.
175-
*
176-
* This helper object takes care of this issue.
177-
*
178-
*/
179-
class TableViewLastColumnResizingFixer: public QObject
180-
{
181-
Q_OBJECT
182-
183-
public:
184-
TableViewLastColumnResizingFixer(QTableView* table, int lastColMinimumWidth, int allColsMinimumWidth, QObject *parent);
185-
void stretchColumnWidth(int column);
186-
187-
private:
188-
QTableView* tableView;
189-
int lastColumnMinimumWidth;
190-
int allColumnsMinimumWidth;
191-
int lastColumnIndex;
192-
int columnCount;
193-
int secondToLastColumnIndex;
194-
195-
void adjustTableColumnsWidth();
196-
int getAvailableWidthForColumn(int column);
197-
int getColumnsWidth();
198-
void connectViewHeadersSignals();
199-
void disconnectViewHeadersSignals();
200-
void setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode);
201-
void resizeColumn(int nColumnIndex, int width);
202-
203-
private Q_SLOTS:
204-
void on_sectionResized(int logicalIndex, int oldSize, int newSize);
205-
void on_geometriesChanged();
206-
};
207-
208169
bool GetStartOnSystemStartup();
209170
bool SetStartOnSystemStartup(bool fAutoStart);
210171

src/qt/receivecoinsdialog.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
2929
QDialog(parent),
3030
ui(new Ui::ReceiveCoinsDialog),
31-
columnResizingFixer(0),
3231
model(0),
3332
platformStyle(_platformStyle)
3433
{
@@ -97,8 +96,6 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
9796
connect(tableView->selectionModel(),
9897
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
9998
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
100-
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
101-
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
10299

103100
tableView->show();
104101
}
@@ -269,14 +266,6 @@ void ReceiveCoinsDialog::on_removeRequestButton_clicked()
269266
model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent());
270267
}
271268

272-
// We override the virtual resizeEvent of the QWidget to adjust tables column
273-
// sizes as the tables width is proportional to the dialogs width.
274-
void ReceiveCoinsDialog::resizeEvent(QResizeEvent *event)
275-
{
276-
QWidget::resizeEvent(event);
277-
columnResizingFixer->stretchColumnWidth(RecentRequestsTableModel::Message);
278-
}
279-
280269
void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event)
281270
{
282271
if (event->key() == Qt::Key_Return)

src/qt/receivecoinsdialog.h

-2
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ public Q_SLOTS:
5757

5858
private:
5959
Ui::ReceiveCoinsDialog *ui;
60-
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
6160
WalletModel *model;
6261
QMenu *contextMenu;
6362
const PlatformStyle *platformStyle;
6463

6564
QModelIndex selectedRow();
6665
void copyColumnToClipboard(int column);
67-
virtual void resizeEvent(QResizeEvent *event);
6866

6967
private Q_SLOTS:
7068
void on_receiveButton_clicked();

src/qt/transactionview.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *parent) :
4545
QWidget(parent), model(0), transactionProxyModel(0),
46-
transactionView(0), abandonAction(0), bumpFeeAction(0), columnResizingFixer(0)
46+
transactionView(0), abandonAction(0), bumpFeeAction(0)
4747
{
4848
// Build filter row
4949
setContentsMargins(0,0,0,0);
@@ -253,7 +253,6 @@ void TransactionView::setModel(WalletModel *_model)
253253

254254
transactionProxyModel->setSortRole(Qt::EditRole);
255255

256-
transactionView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
257256
transactionView->setModel(transactionProxyModel);
258257
transactionView->setAlternatingRowColors(true);
259258
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
@@ -268,8 +267,9 @@ void TransactionView::setModel(WalletModel *_model)
268267
transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH);
269268
transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
270269
transactionView->setColumnWidth(TransactionTableModel::AssetName, AMOUNT_MINIMUM_COLUMN_WIDTH);
270+
transactionView->horizontalHeader()->setMinimumSectionSize(MINIMUM_COLUMN_WIDTH);
271+
transactionView->horizontalHeader()->setStretchLastSection(true);
271272

272-
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(transactionView, AMOUNT_MINIMUM_COLUMN_WIDTH, MINIMUM_COLUMN_WIDTH, this);
273273

274274
if (_model->getOptionsModel())
275275
{
@@ -667,14 +667,6 @@ void TransactionView::focusTransaction(const QModelIndex &idx)
667667
transactionView->setFocus();
668668
}
669669

670-
// We override the virtual resizeEvent of the QWidget to adjust tables column
671-
// sizes as the tables width is proportional to the dialogs width.
672-
void TransactionView::resizeEvent(QResizeEvent* event)
673-
{
674-
QWidget::resizeEvent(event);
675-
columnResizingFixer->stretchColumnWidth(TransactionTableModel::ToAddress);
676-
}
677-
678670
// Need to override default Ctrl+C action for amount as default behaviour is just to copy DisplayRole text
679671
bool TransactionView::eventFilter(QObject *obj, QEvent *event)
680672
{

src/qt/transactionview.h

-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ class TransactionView : public QWidget
8686

8787
QWidget *createDateRangeWidget();
8888

89-
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
90-
91-
virtual void resizeEvent(QResizeEvent* event);
92-
9389
bool eventFilter(QObject *obj, QEvent *event);
9490

9591
private Q_SLOTS:

0 commit comments

Comments
 (0)