From daf33ef8aa39589b2e627535cb47240d22704d46 Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 16 Jun 2016 21:35:00 +0300 Subject: [PATCH 1/8] PeerList: align text to the right in columns that handle numbers --- src/gui/properties/peerlistdelegate.h | 8 ++++++++ src/gui/properties/peerlistwidget.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index 84cb27110..defab38c2 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -52,15 +52,22 @@ public: painter->save(); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); switch(index.column()) { + case PORT: + QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); + break; case TOT_DOWN: case TOT_UP: QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; case DOWN_SPEED: case UP_SPEED:{ QItemDelegate::drawBackground(painter, opt, index); qreal speed = index.data().toDouble(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; if (speed > 0.0) QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); break; @@ -69,6 +76,7 @@ public: case RELEVANCE:{ QItemDelegate::drawBackground(painter, opt, index); qreal progress = index.data().toDouble(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); break; } diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 258fc553e..eb6a49d7c 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -83,6 +83,14 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded")); m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, tr("Relevance", "i.e: How relevant this peer is to us. How many pieces it has that we don't.")); m_listModel->setHeaderData(PeerListDelegate::DOWNLOADING_PIECE, Qt::Horizontal, tr("Files", "i.e. files that are being downloaded right now")); + // Set header text alignment + m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::PROGRESS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::DOWN_SPEED, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); // Proxy model to support sorting without actually altering the underlying model m_proxyModel = new PeerListSortModel(); m_proxyModel->setDynamicSortFilter(true); From 525571966142c36b870f3adaa1f680c7d368fbec Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 16 Jun 2016 21:44:33 +0300 Subject: [PATCH 2/8] SearchTab: align text to the right in columns that handle numbers --- src/gui/search/searchlistdelegate.cpp | 3 +++ src/gui/search/searchtab.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/gui/search/searchlistdelegate.cpp b/src/gui/search/searchlistdelegate.cpp index 646eb8344..dc286f5d9 100644 --- a/src/gui/search/searchlistdelegate.cpp +++ b/src/gui/search/searchlistdelegate.cpp @@ -50,14 +50,17 @@ void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op switch(index.column()) { case SearchSortModel::SIZE: QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; case SearchSortModel::SEEDS: QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown")); break; case SearchSortModel::LEECHES: QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown")); break; default: diff --git a/src/gui/search/searchtab.cpp b/src/gui/search/searchtab.cpp index df86ebb84..819789770 100644 --- a/src/gui/search/searchtab.cpp +++ b/src/gui/search/searchtab.cpp @@ -83,6 +83,10 @@ SearchTab::SearchTab(SearchWidget *parent) m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine")); + // Set columns text alignment + m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); + m_searchListModel->setHeaderData(SearchSortModel::LEECHES, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); m_proxyModel = new SearchSortModel(this); m_proxyModel->setDynamicSortFilter(true); From b2144f7928672d1af1663e5ec784ecf29a61e93d Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 22 Jun 2016 16:34:53 +0300 Subject: [PATCH 3/8] SearchTab: use saveSettings() and loadSettings() to handle header state --- src/base/preferences.cpp | 16 ++++++++++++---- src/base/preferences.h | 4 ++-- src/gui/search/searchtab.cpp | 33 +++++++++++++++------------------ src/gui/search/searchtab.h | 3 ++- src/gui/search/searchwidget.cpp | 16 ---------------- src/gui/search/searchwidget.h | 1 - 6 files changed, 31 insertions(+), 42 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 28184ea95..89e16b8fe 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1320,14 +1320,22 @@ void Preferences::setRssMainSplitterState(const QByteArray &state) #endif } -QString Preferences::getSearchColsWidth() const +QByteArray Preferences::getSearchTabHeaderState() const { - return value("SearchResultsColsWidth").toString(); +#ifdef QBT_USES_QT5 + return value("SearchTab/qt5/SearchTabHeaderState").toByteArray(); +#else + return value("SearchTab/SearchTabHeaderState").toByteArray(); +#endif } -void Preferences::setSearchColsWidth(const QString &width) +void Preferences::setSearchTabHeaderState(const QByteArray &state) { - setValue("SearchResultsColsWidth", width); +#ifdef QBT_USES_QT5 + setValue("SearchTab/qt5/SearchTabHeaderState", state); +#else + setValue("SearchTab/SearchTabHeaderState", state); +#endif } QStringList Preferences::getSearchEngDisabled() const diff --git a/src/base/preferences.h b/src/base/preferences.h index f6ca325a5..ec328f264 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -304,8 +304,8 @@ public: void setRssSideSplitterState(const QByteArray &state); QByteArray getRssMainSplitterState() const; void setRssMainSplitterState(const QByteArray &state); - QString getSearchColsWidth() const; - void setSearchColsWidth(const QString &width); + QByteArray getSearchTabHeaderState() const; + void setSearchTabHeaderState(const QByteArray &state); QStringList getSearchEngDisabled() const; void setSearchEngDisabled(const QStringList &engines); QString getCreateTorLastAddPath() const; diff --git a/src/gui/search/searchtab.cpp b/src/gui/search/searchtab.cpp index 819789770..e7db4eceb 100644 --- a/src/gui/search/searchtab.cpp +++ b/src/gui/search/searchtab.cpp @@ -74,7 +74,9 @@ SearchTab::SearchTab(SearchWidget *parent) m_ui->resultsBrowser->header()->setParent(m_ui->resultsBrowser); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); #endif + loadSettings(); m_ui->resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection); + header()->setStretchLastSection(false); // Set Search results list model m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this); @@ -106,9 +108,8 @@ SearchTab::SearchTab(SearchWidget *parent) // Connect signals to slots (search part) connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&))); - // Load last columns width for search results list - if (!loadColWidthResultsList()) - m_ui->resultsBrowser->header()->resizeSection(0, 275); + connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings())); + connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings())); // Sort by Seeds m_ui->resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); @@ -132,6 +133,7 @@ SearchTab::SearchTab(SearchWidget *parent) SearchTab::~SearchTab() { + saveSettings(); delete m_ui; } @@ -148,21 +150,6 @@ QHeaderView* SearchTab::header() const return m_ui->resultsBrowser->header(); } -bool SearchTab::loadColWidthResultsList() -{ - QString line = Preferences::instance()->getSearchColsWidth(); - if (line.isEmpty()) return false; - - QStringList widthList = line.split(' '); - if (widthList.size() > m_searchListModel->columnCount()) - return false; - - for (int i = 0; i < widthList.size(); ++i) - m_ui->resultsBrowser->header()->resizeSection(i, widthList.at(i).toInt()); - - return true; -} - QTreeView* SearchTab::getCurrentTreeView() const { return m_ui->resultsBrowser; @@ -307,3 +294,13 @@ SearchTab::NameFilteringMode SearchTab::filteringMode() const this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode")); return static_cast(metaEnum.keyToValue(m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()).toByteArray())); } + +void SearchTab::loadSettings() +{ + header()->restoreState(Preferences::instance()->getSearchTabHeaderState()); +} + +void SearchTab::saveSettings() const +{ + Preferences::instance()->setSearchTabHeaderState(header()->saveState()); +} diff --git a/src/gui/search/searchtab.h b/src/gui/search/searchtab.h index ac9da1223..f74c9cfeb 100644 --- a/src/gui/search/searchtab.h +++ b/src/gui/search/searchtab.h @@ -75,7 +75,6 @@ public: QTreeView* getCurrentTreeView() const; QHeaderView* header() const; - bool loadColWidthResultsList(); void setRowColor(int row, const QColor &color); enum class Status @@ -96,6 +95,8 @@ public slots: void downloadItem(const QModelIndex &index); private slots: + void loadSettings(); + void saveSettings() const; void updateFilter(); private: diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 952f1439d..b240e8091 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -267,7 +267,6 @@ void SearchWidget::on_searchButton_clicked() // Tab Addition m_currentSearchTab = new SearchTab(this); m_activeSearchTab = m_currentSearchTab; - connect(m_currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth())); m_allTabs.append(m_currentSearchTab); QString tabName = pattern; tabName.replace(QRegExp("&{1}"), "&&"); @@ -293,21 +292,6 @@ void SearchWidget::on_searchButton_clicked() m_searchEngine->startSearch(pattern, selectedCategory(), plugins); } -void SearchWidget::saveResultsColumnsWidth() -{ - if (m_allTabs.isEmpty()) return; - - QTreeView *treeview = m_allTabs.first()->getCurrentTreeView(); - QStringList newWidthList; - short nbColumns = m_allTabs.first()->getCurrentSearchListModel()->columnCount(); - for (short i = 0; i < nbColumns; ++i) - if (treeview->columnWidth(i) > 0) - newWidthList << QString::number(treeview->columnWidth(i)); - // Don't save the width of the last column (auto column width) - newWidthList.removeLast(); - Preferences::instance()->setSearchColsWidth(newWidthList.join(" ")); -} - void SearchWidget::searchStarted() { // Update SearchEngine widgets diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index b2514daaa..5b8954774 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -74,7 +74,6 @@ private slots: void addTorrentToSession(const QString &source); - void saveResultsColumnsWidth(); void fillCatCombobox(); void fillPluginComboBox(); void searchTextEdited(QString); From c90794878fb7ff08cb060c069774681e61c5152f Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 22 Jun 2016 18:25:53 +0300 Subject: [PATCH 4/8] SearchTab: Allow to toggle columns in searchtab --- src/gui/search/searchtab.cpp | 56 ++++++++++++++++++++++++++++++++++++ src/gui/search/searchtab.h | 1 + 2 files changed, 57 insertions(+) diff --git a/src/gui/search/searchtab.cpp b/src/gui/search/searchtab.cpp index e7db4eceb..84e575fb4 100644 --- a/src/gui/search/searchtab.cpp +++ b/src/gui/search/searchtab.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -105,9 +106,28 @@ SearchTab::SearchTab(SearchWidget *parent) m_ui->resultsBrowser->setAllColumnsShowFocus(true); m_ui->resultsBrowser->setSortingEnabled(true); + //Ensure that at least one column is visible at all times + bool atLeastOne = false; + for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) { + if (!m_ui->resultsBrowser->isColumnHidden(i)) { + atLeastOne = true; + break; + } + } + if (!atLeastOne) + m_ui->resultsBrowser->setColumnHidden(SearchSortModel::NAME, false); + //To also mitigate the above issue, we have to resize each column when + //its size is 0, because explicitly 'showing' the column isn't enough + //in the above scenario. + for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) + if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i)) + m_ui->resultsBrowser->resizeColumnToContents(i); + // Connect signals to slots (search part) connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&))); + header()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &))); connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings())); connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings())); @@ -304,3 +324,39 @@ void SearchTab::saveSettings() const { Preferences::instance()->setSearchTabHeaderState(header()->saveState()); } + +void SearchTab::displayToggleColumnsMenu(const QPoint&) +{ + QMenu hideshowColumn(this); + hideshowColumn.setTitle(tr("Column visibility")); + QList actions; + for (int i = 0; i < SearchSortModel::DL_LINK; ++i) { + QAction *myAct = hideshowColumn.addAction(m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); + myAct->setCheckable(true); + myAct->setChecked(!m_ui->resultsBrowser->isColumnHidden(i)); + actions.append(myAct); + } + int visibleCols = 0; + for (unsigned int i = 0; i < SearchSortModel::DL_LINK; i++) { + if (!m_ui->resultsBrowser->isColumnHidden(i)) + visibleCols++; + + if (visibleCols > 1) + break; + } + + // Call menu + QAction *act = hideshowColumn.exec(QCursor::pos()); + if (act) { + int col = actions.indexOf(act); + Q_ASSERT(col >= 0); + Q_ASSERT(visibleCols > 0); + if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (visibleCols == 1)) + return; + qDebug("Toggling column %d visibility", col); + m_ui->resultsBrowser->setColumnHidden(col, !m_ui->resultsBrowser->isColumnHidden(col)); + if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (m_ui->resultsBrowser->columnWidth(col) <= 5)) + m_ui->resultsBrowser->setColumnWidth(col, 100); + saveSettings(); + } +} diff --git a/src/gui/search/searchtab.h b/src/gui/search/searchtab.h index f74c9cfeb..2322f82da 100644 --- a/src/gui/search/searchtab.h +++ b/src/gui/search/searchtab.h @@ -98,6 +98,7 @@ private slots: void loadSettings(); void saveSettings() const; void updateFilter(); + void displayToggleColumnsMenu(const QPoint&); private: void fillFilterComboBoxes(); From 1652425cee35b65169a08d1b8a6aae8cc296cee7 Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 22 Jun 2016 20:01:02 +0300 Subject: [PATCH 5/8] TransferListWidget: keep columns width even if they are hidden on qBittorrent startup (unless something goes wrong) --- src/gui/transferlistwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index ae193f55c..1d4028ef6 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -141,7 +141,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window) //end up being size 0 when the new version is launched with //a conf file from the previous version. for (unsigned int i = 0; i Date: Wed, 22 Jun 2016 20:53:14 +0300 Subject: [PATCH 6/8] PeerList: allow to hide zero values for the "uploaded" and "downloaded" columns --- src/gui/properties/peerlistdelegate.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index defab38c2..959d6fe7b 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -35,6 +35,7 @@ #include #include "base/utils/misc.h" #include "base/utils/string.h" +#include "base/preferences.h" class PeerListDelegate: public QItemDelegate { Q_OBJECT @@ -50,6 +51,7 @@ public: void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { painter->save(); + const bool hideValues = Preferences::instance()->getHideZeroValues(); QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); switch(index.column()) { case PORT: @@ -58,10 +60,14 @@ public: QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); break; case TOT_DOWN: - case TOT_UP: + case TOT_UP: { + qlonglong size = index.data().toLongLong(); + if (hideValues && (size <= 0)) + break; QItemDelegate::drawBackground(painter, opt, index); opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); + } break; case DOWN_SPEED: case UP_SPEED:{ From f523685414e69556f54a3d3f99374bbdf470a780 Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 22 Jun 2016 21:13:30 +0300 Subject: [PATCH 7/8] PeerListDelegate: fix coding style in whole file --- src/gui/properties/peerlistdelegate.h | 120 +++++++++++++++----------- 1 file changed, 70 insertions(+), 50 deletions(-) diff --git a/src/gui/properties/peerlistdelegate.h b/src/gui/properties/peerlistdelegate.h index 959d6fe7b..1a60ec5e7 100644 --- a/src/gui/properties/peerlistdelegate.h +++ b/src/gui/properties/peerlistdelegate.h @@ -33,69 +33,89 @@ #include #include + +#include "base/preferences.h" #include "base/utils/misc.h" #include "base/utils/string.h" -#include "base/preferences.h" class PeerListDelegate: public QItemDelegate { - Q_OBJECT + Q_OBJECT public: - enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED, - TOT_DOWN, TOT_UP, RELEVANCE, DOWNLOADING_PIECE, IP_HIDDEN, COL_COUNT}; + enum PeerListColumns + { + COUNTRY, + IP, + PORT, + CONNECTION, + FLAGS, + CLIENT, + PROGRESS, + DOWN_SPEED, + UP_SPEED, + TOT_DOWN, + TOT_UP, RELEVANCE, + DOWNLOADING_PIECE, + IP_HIDDEN, + + COL_COUNT + }; public: - PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} + PeerListDelegate(QObject *parent) : QItemDelegate(parent) {} - ~PeerListDelegate() {} + ~PeerListDelegate() {} - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { - painter->save(); - const bool hideValues = Preferences::instance()->getHideZeroValues(); - QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); - switch(index.column()) { - case PORT: - QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); - break; - case TOT_DOWN: - case TOT_UP: { - qlonglong size = index.data().toLongLong(); - if (hideValues && (size <= 0)) + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const + { + painter->save(); + const bool hideValues = Preferences::instance()->getHideZeroValues(); + QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); + switch(index.column()) { + case PORT: { + QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); + } break; - QItemDelegate::drawBackground(painter, opt, index); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); - } - break; - case DOWN_SPEED: - case UP_SPEED:{ - QItemDelegate::drawBackground(painter, opt, index); - qreal speed = index.data().toDouble(); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - if (speed > 0.0) - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); - break; + case TOT_DOWN: + case TOT_UP: { + qlonglong size = index.data().toLongLong(); + if (hideValues && (size <= 0)) + break; + QItemDelegate::drawBackground(painter, opt, index); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); + } + break; + case DOWN_SPEED: + case UP_SPEED:{ + QItemDelegate::drawBackground(painter, opt, index); + qreal speed = index.data().toDouble(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + if (speed > 0.0) + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); + } + break; + case PROGRESS: + case RELEVANCE: { + QItemDelegate::drawBackground(painter, opt, index); + qreal progress = index.data().toDouble(); + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); + } + break; + default: + QItemDelegate::paint(painter, option, index); + } + painter->restore(); } - case PROGRESS: - case RELEVANCE:{ - QItemDelegate::drawBackground(painter, opt, index); - qreal progress = index.data().toDouble(); - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress*100.0, 1)+"%"); - break; - } - default: - QItemDelegate::paint(painter, option, index); - } - painter->restore(); - } - QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { - // No editor here - return 0; - } + QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const + { + // No editor here + return 0; + } }; From 9f06d0d47bb8abb2f22b4e762fe6d36c27145aa6 Mon Sep 17 00:00:00 2001 From: thalieht Date: Tue, 30 Aug 2016 13:23:22 +0300 Subject: [PATCH 8/8] SearchTab: can now save sorting column changes --- src/gui/search/searchtab.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gui/search/searchtab.cpp b/src/gui/search/searchtab.cpp index 84e575fb4..db4c0e2b3 100644 --- a/src/gui/search/searchtab.cpp +++ b/src/gui/search/searchtab.cpp @@ -130,9 +130,7 @@ SearchTab::SearchTab(SearchWidget *parent) connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &))); connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings())); connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings())); - - // Sort by Seeds - m_ui->resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); + connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings())); fillFilterComboBoxes();