summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2017-06-28 15:29:56 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-06 08:37:24 (GMT)
commitba67437900cfabb1ce9e115c0ec5029c76696b8b (patch)
tree91a4422c214bb4453f6fdf9e2ea0dbdee031bbde /Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
parent1f69a24bc609ce40bab2bcb40b29438b63c9bc73 (diff)
downloadswift-ba67437900cfabb1ce9e115c0ec5029c76696b8b.zip
swift-ba67437900cfabb1ce9e115c0ec5029c76696b8b.tar.bz2
Fix a crash that occurs when resizing chat layout
This patch fixes a client crash that was caused when the chat layout was resized to a size that would make some of the chat window out of range. Test-Information: Tested on Ubuntu 16.04 LTS (Qt5.5.1) and Windows 10 (Qt5.7.1) Change-Id: I900c1efcf3c9ae3c416fb4e2d19bd47bf27bbaee
Diffstat (limited to 'Swift/QtUI/Trellis/QtDynamicGridLayout.cpp')
-rw-r--r--Swift/QtUI/Trellis/QtDynamicGridLayout.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
index 5600cc8..b753ffa 100644
--- a/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
+++ b/Swift/QtUI/Trellis/QtDynamicGridLayout.cpp
@@ -263,61 +263,66 @@ void QtDynamicGridLayout::setDimensions(const QSize& dim) {
int oldHeight = oldLayout->rowCount();
int maxCol = qMax(oldWidth, dim.width());
int minCol = qMin(oldWidth, dim.width());
int maxRow = qMax(oldHeight, dim.height());
int minRow = qMin(oldHeight, dim.height());
for (int row = 0; row < maxRow; row++) {
for (int col = 0; col < maxCol; col++) {
QLayoutItem* oldItem = oldLayout->itemAtPosition(row, col);
QLayoutItem* newItem = newLayout->itemAtPosition(row, col);
bool removeRow = !(row < dim.height());
bool removeCol = !(col < dim.width());
if (removeCol || removeRow) {
if (oldItem) {
int squeezeRow = removeRow ? (minRow - 1) : row;
int squeezeCol = removeCol ? (minCol - 1) : col;
newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
if (!newItem) {
newLayout->addWidget(createDNDTabWidget(this), squeezeRow, squeezeCol);
newItem = newLayout->itemAtPosition(squeezeRow, squeezeCol);
}
QtTabWidget* oldTabWidget = dynamic_cast<QtTabWidget*>(oldItem->widget());
QtTabWidget* newTabWidget = dynamic_cast<QtTabWidget*>(newItem->widget());
assert(oldTabWidget && newTabWidget);
oldTabWidget->hide();
while(oldTabWidget->count()) {
QIcon icon = oldTabWidget->tabIcon(0);
QString text = oldTabWidget->tabText(0);
- newTabWidget->addTab(oldTabWidget->widget(0), icon, text);
+ QWidget* movingTab = oldTabWidget->widget(0);
+ //If handling was allowed, QtChatTabs::handleWidgetShown() would be triggered when newTabWidget has no tabs.
+ //That would access indices of the gridLayout_ that are null because they have been migrated to the newLayout.
+ movingTab->blockSignals(true);
+ newTabWidget->addTab(movingTab, icon, text);
+ movingTab->blockSignals(false);
}
delete oldTabWidget;
}
} else {
if (oldItem) {
newLayout->addWidget(oldItem->widget(), row, col);
newItem = newLayout->itemAtPosition(row, col);
} else {
newLayout->addWidget(createDNDTabWidget(this), row, col);
}
}
}
}
for (int col = 0; col < dim.width(); col++) {
newLayout->setColumnStretch(col, 1);
}
for (int row = 0; row < dim.height(); row++) {
newLayout->setRowStretch(row, 1);
}
setUpdatesEnabled(true);
delete layout();
setLayout(newLayout);
gridLayout_ = newLayout;
resizing_ = false;
setCurrentWidget(restoredWidget);
updateEmphasiseFocusOnTabs();