diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-10-27 15:06:22 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-10-27 15:06:22 +0000 |
| commit | e7cbfaf4e7b7573c25e440fbd17057dabe6e1b47 (patch) | |
| tree | 4524436bb2f0b478817920244cded35f4e7ed318 | |
| parent | 5b1b1b669c23519f72b62a6f36a20ffbd3fb30e5 (diff) | |
| download | qmmp-e7cbfaf4e7b7573c25e440fbd17057dabe6e1b47.tar.gz qmmp-e7cbfaf4e7b7573c25e440fbd17057dabe6e1b47.tar.bz2 qmmp-e7cbfaf4e7b7573c25e440fbd17057dabe6e1b47.zip | |
history: added sorting by time
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8411 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/General/history/historywindow.cpp | 36 | ||||
| -rw-r--r-- | src/plugins/General/history/historywindow.h | 4 |
2 files changed, 35 insertions, 5 deletions
diff --git a/src/plugins/General/history/historywindow.cpp b/src/plugins/General/history/historywindow.cpp index e586da74d..34de9b5bc 100644 --- a/src/plugins/General/history/historywindow.cpp +++ b/src/plugins/General/history/historywindow.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Ilya Kotov * + * Copyright (C) 2017-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -40,7 +40,6 @@ HistoryWindow::HistoryWindow(QSqlDatabase db, QWidget *parent) : setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_QuitOnClose, false); m_db = db; - readSettings(); QDateTime t = QDateTime::currentDateTime(); t.setTime(QTime(23, 59, 0 ,0)); @@ -52,6 +51,13 @@ HistoryWindow::HistoryWindow(QSqlDatabase db, QWidget *parent) : m_ui->topArtistsTreeWidget->setItemDelegate(new ProgressBarItemDelegate(this)); m_ui->topSongsTreeWidget->setItemDelegate(new ProgressBarItemDelegate(this)); m_ui->topGenresTreeWidget->setItemDelegate(new ProgressBarItemDelegate(this)); + m_ui->historyTreeWidget->header()->setSortIndicator(0, Qt::AscendingOrder); + m_ui->historyTreeWidget->header()->setSortIndicatorShown(true); + m_ui->historyTreeWidget->header()->setSectionsClickable(true); + readSettings(); + connect(m_ui->historyTreeWidget->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), + SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); + m_order = m_ui->historyTreeWidget->header()->sortIndicatorOrder(); on_executeButton_clicked(); } @@ -70,8 +76,16 @@ void HistoryWindow::loadHistory() QSqlQuery query(m_db); - query.prepare("SELECT Timestamp,Title,Artist,AlbumArtist,Album,Comment,Genre,Composer,Track,Year,Duration,URL " - "FROM track_history WHERE Timestamp BETWEEN :from and :to"); + if(m_ui->historyTreeWidget->header()->sortIndicatorOrder() == Qt::DescendingOrder) + { + query.prepare("SELECT Timestamp,Title,Artist,AlbumArtist,Album,Comment,Genre,Composer,Track,Year,Duration,URL " + "FROM track_history WHERE Timestamp BETWEEN :from and :to ORDER BY id DESC"); + } + else + { + query.prepare("SELECT Timestamp,Title,Artist,AlbumArtist,Album,Comment,Genre,Composer,Track,Year,Duration,URL " + "FROM track_history WHERE Timestamp BETWEEN :from and :to"); + } query.bindValue(":from", m_ui->fromDateEdit->dateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss")); query.bindValue(":to", m_ui->toDateEdit->dateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss")); @@ -414,3 +428,17 @@ void HistoryWindow::on_toButton_clicked() if(d.exec() == QDialog::Accepted) m_ui->toDateEdit->setDate(d.selectedDate()); } + +void HistoryWindow::onSortIndicatorChanged(int index, Qt::SortOrder order) +{ + if(index == 0) + { + m_order = order; + loadHistory(); + } + else //ignore sorting for second section + { + //restore sort indicator order + m_ui->historyTreeWidget->header()->setSortIndicator(0, m_order); + } +} diff --git a/src/plugins/General/history/historywindow.h b/src/plugins/General/history/historywindow.h index 754cbef8e..7736b5e7d 100644 --- a/src/plugins/General/history/historywindow.h +++ b/src/plugins/General/history/historywindow.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2017 by Ilya Kotov * + * Copyright (C) 2017-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -44,6 +44,7 @@ private slots: void on_lastMonthButton_clicked(); void on_fromButton_clicked(); void on_toButton_clicked(); + void onSortIndicatorChanged(int index, Qt::SortOrder order); private: void loadHistory(); @@ -57,6 +58,7 @@ private: Ui::HistoryWindow *m_ui; QSqlDatabase m_db; MetaDataFormatter m_formatter; + Qt::SortOrder m_order; }; #endif // HISTORYWINDOW_H |
