mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
SearchTab: use saveSettings() and loadSettings() to handle header state
This commit is contained in:
parent
5255719661
commit
b2144f7928
@ -1320,14 +1320,22 @@ void Preferences::setRssMainSplitterState(const QByteArray &state)
|
|||||||
#endif
|
#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
|
QStringList Preferences::getSearchEngDisabled() const
|
||||||
|
@ -304,8 +304,8 @@ public:
|
|||||||
void setRssSideSplitterState(const QByteArray &state);
|
void setRssSideSplitterState(const QByteArray &state);
|
||||||
QByteArray getRssMainSplitterState() const;
|
QByteArray getRssMainSplitterState() const;
|
||||||
void setRssMainSplitterState(const QByteArray &state);
|
void setRssMainSplitterState(const QByteArray &state);
|
||||||
QString getSearchColsWidth() const;
|
QByteArray getSearchTabHeaderState() const;
|
||||||
void setSearchColsWidth(const QString &width);
|
void setSearchTabHeaderState(const QByteArray &state);
|
||||||
QStringList getSearchEngDisabled() const;
|
QStringList getSearchEngDisabled() const;
|
||||||
void setSearchEngDisabled(const QStringList &engines);
|
void setSearchEngDisabled(const QStringList &engines);
|
||||||
QString getCreateTorLastAddPath() const;
|
QString getCreateTorLastAddPath() const;
|
||||||
|
@ -74,7 +74,9 @@ SearchTab::SearchTab(SearchWidget *parent)
|
|||||||
m_ui->resultsBrowser->header()->setParent(m_ui->resultsBrowser);
|
m_ui->resultsBrowser->header()->setParent(m_ui->resultsBrowser);
|
||||||
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
||||||
#endif
|
#endif
|
||||||
|
loadSettings();
|
||||||
m_ui->resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
m_ui->resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
header()->setStretchLastSection(false);
|
||||||
|
|
||||||
// Set Search results list model
|
// Set Search results list model
|
||||||
m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this);
|
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 signals to slots (search part)
|
||||||
connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&)));
|
connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&)));
|
||||||
|
|
||||||
// Load last columns width for search results list
|
connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings()));
|
||||||
if (!loadColWidthResultsList())
|
connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings()));
|
||||||
m_ui->resultsBrowser->header()->resizeSection(0, 275);
|
|
||||||
|
|
||||||
// Sort by Seeds
|
// Sort by Seeds
|
||||||
m_ui->resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder);
|
m_ui->resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder);
|
||||||
@ -132,6 +133,7 @@ SearchTab::SearchTab(SearchWidget *parent)
|
|||||||
|
|
||||||
SearchTab::~SearchTab()
|
SearchTab::~SearchTab()
|
||||||
{
|
{
|
||||||
|
saveSettings();
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,21 +150,6 @@ QHeaderView* SearchTab::header() const
|
|||||||
return m_ui->resultsBrowser->header();
|
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
|
QTreeView* SearchTab::getCurrentTreeView() const
|
||||||
{
|
{
|
||||||
return m_ui->resultsBrowser;
|
return m_ui->resultsBrowser;
|
||||||
@ -307,3 +294,13 @@ SearchTab::NameFilteringMode SearchTab::filteringMode() const
|
|||||||
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
|
this->metaObject()->enumerator(this->metaObject()->indexOfEnumerator("NameFilteringMode"));
|
||||||
return static_cast<NameFilteringMode>(metaEnum.keyToValue(m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()).toByteArray()));
|
return static_cast<NameFilteringMode>(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());
|
||||||
|
}
|
||||||
|
@ -75,7 +75,6 @@ public:
|
|||||||
QTreeView* getCurrentTreeView() const;
|
QTreeView* getCurrentTreeView() const;
|
||||||
QHeaderView* header() const;
|
QHeaderView* header() const;
|
||||||
|
|
||||||
bool loadColWidthResultsList();
|
|
||||||
void setRowColor(int row, const QColor &color);
|
void setRowColor(int row, const QColor &color);
|
||||||
|
|
||||||
enum class Status
|
enum class Status
|
||||||
@ -96,6 +95,8 @@ public slots:
|
|||||||
void downloadItem(const QModelIndex &index);
|
void downloadItem(const QModelIndex &index);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void loadSettings();
|
||||||
|
void saveSettings() const;
|
||||||
void updateFilter();
|
void updateFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -267,7 +267,6 @@ void SearchWidget::on_searchButton_clicked()
|
|||||||
// Tab Addition
|
// Tab Addition
|
||||||
m_currentSearchTab = new SearchTab(this);
|
m_currentSearchTab = new SearchTab(this);
|
||||||
m_activeSearchTab = m_currentSearchTab;
|
m_activeSearchTab = m_currentSearchTab;
|
||||||
connect(m_currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth()));
|
|
||||||
m_allTabs.append(m_currentSearchTab);
|
m_allTabs.append(m_currentSearchTab);
|
||||||
QString tabName = pattern;
|
QString tabName = pattern;
|
||||||
tabName.replace(QRegExp("&{1}"), "&&");
|
tabName.replace(QRegExp("&{1}"), "&&");
|
||||||
@ -293,21 +292,6 @@ void SearchWidget::on_searchButton_clicked()
|
|||||||
m_searchEngine->startSearch(pattern, selectedCategory(), plugins);
|
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()
|
void SearchWidget::searchStarted()
|
||||||
{
|
{
|
||||||
// Update SearchEngine widgets
|
// Update SearchEngine widgets
|
||||||
|
@ -74,7 +74,6 @@ private slots:
|
|||||||
|
|
||||||
void addTorrentToSession(const QString &source);
|
void addTorrentToSession(const QString &source);
|
||||||
|
|
||||||
void saveResultsColumnsWidth();
|
|
||||||
void fillCatCombobox();
|
void fillCatCombobox();
|
||||||
void fillPluginComboBox();
|
void fillPluginComboBox();
|
||||||
void searchTextEdited(QString);
|
void searchTextEdited(QString);
|
||||||
|
Loading…
Reference in New Issue
Block a user