From 4baa6dde52c201e38b258e454f2948851edacc02 Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 11 May 2016 15:05:51 +0300 Subject: [PATCH] resize column to contents only when they're visible refactor updatePeerCountryResolutionState deprecate m_resolveCountries var --- src/gui/properties/peerlistwidget.cpp | 13 +++++-------- src/gui/properties/peerlistwidget.h | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 2fd1bb103..975c4b340 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -57,7 +57,6 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) : QTreeView(parent) , m_properties(parent) - , m_resolveCountries(false) { // Load settings loadSettings(); @@ -91,9 +90,9 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) setModel(m_proxyModel); hideColumn(PeerListDelegate::IP_HIDDEN); hideColumn(PeerListDelegate::COL_COUNT); - if (!Preferences::instance()->resolvePeerCountries()) + m_resolveCountries = Preferences::instance()->resolvePeerCountries(); + if (!m_resolveCountries) hideColumn(PeerListDelegate::COUNTRY); - m_wasCountryColHidden = isColumnHidden(PeerListDelegate::COUNTRY); //Ensure that at least one column is visible at all times bool atLeastOne = false; for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { @@ -108,7 +107,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) //its size is 0, because explicitly 'showing' the column isn't enough //in the above scenario. for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) - if (!columnWidth(i)) + if ((columnWidth(i) <= 0) && !isColumnHidden(i)) resizeColumnToContents(i); // Context menu setContextMenuPolicy(Qt::CustomContextMenu); @@ -208,14 +207,12 @@ void PeerListWidget::updatePeerCountryResolutionState() m_resolveCountries = !m_resolveCountries; if (m_resolveCountries) { loadPeers(m_properties->getCurrentTorrent()); - if (!m_wasCountryColHidden) { - showColumn(PeerListDelegate::COUNTRY); + showColumn(PeerListDelegate::COUNTRY); + if (columnWidth(PeerListDelegate::COUNTRY) <= 0) resizeColumnToContents(PeerListDelegate::COUNTRY); - } } else { hideColumn(PeerListDelegate::COUNTRY); - m_wasCountryColHidden = false; // to forcefully enable that column if the user decides to resolve countries again } } } diff --git a/src/gui/properties/peerlistwidget.h b/src/gui/properties/peerlistwidget.h index 51f2d3dbe..7b4ca50ef 100644 --- a/src/gui/properties/peerlistwidget.h +++ b/src/gui/properties/peerlistwidget.h @@ -94,7 +94,6 @@ private: QPointer m_resolver; PropertiesWidget *m_properties; bool m_resolveCountries; - bool m_wasCountryColHidden; QShortcut *m_copyHotkey; };