diff options
author | Max Linke <kain88@mixxx.org> | 2013-07-06 17:56:43 +0200 |
---|---|---|
committer | Max Linke <kain88@mixxx.org> | 2013-07-06 17:56:43 +0200 |
commit | 905ce1bc6bf1f4570d9fa0470be6a46657d6b1d3 (patch) | |
tree | b876c406ae7459b813f322f82d52b80a939ad681 /src/dlganalysis.cpp | |
parent | 4c12988d3715de63f27614047bdbf79ea3b45d17 (diff) |
Rename every occurence of prepare with analysis
If you are new to the code the name prepare for everything that is
related to the analysisview can be confusing. Renaming them will make
it easier to see what the classes are being used for
Diffstat (limited to 'src/dlganalysis.cpp')
-rw-r--r-- | src/dlganalysis.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/dlganalysis.cpp b/src/dlganalysis.cpp new file mode 100644 index 0000000000..6bc10809c2 --- /dev/null +++ b/src/dlganalysis.cpp @@ -0,0 +1,163 @@ +#include <QSqlTableModel> + +#include "widget/wwidget.h" +#include "widget/wskincolor.h" +#include "transposeproxymodel.h" +#include "widget/wanalysislibrarytableview.h" +#include "library/trackcollection.h" +#include "dlganalysis.h" + + +DlgAnalysis::DlgAnalysis(QWidget* parent, + ConfigObject<ConfigValue>* pConfig, + TrackCollection* pTrackCollection) + : QWidget(parent), + m_pConfig(pConfig), + m_pTrackCollection(pTrackCollection), + m_bAnalysisActive(false), + m_tracksInQueue(0), + m_currentTrack(0) { + setupUi(this); + m_songsButtonGroup.addButton(radioButtonRecentlyAdded); + m_songsButtonGroup.addButton(radioButtonAllSongs); + + m_pAnalysisLibraryTableView = new WAnalysisLibraryTableView(this, pConfig, pTrackCollection); + connect(m_pAnalysisLibraryTableView, SIGNAL(loadTrack(TrackPointer)), + this, SIGNAL(loadTrack(TrackPointer))); + connect(m_pAnalysisLibraryTableView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)), + this, SIGNAL(loadTrackToPlayer(TrackPointer, QString))); + + QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout()); + Q_ASSERT(box); //Assumes the form layout is a QVBox/QHBoxLayout! + box->removeWidget(m_pTrackTablePlaceholder); + m_pTrackTablePlaceholder->hide(); + box->insertWidget(1, m_pAnalysisLibraryTableView); + + m_pAnalysisLibraryTableModel = new AnalysisLibraryTableModel(this, + pTrackCollection); + m_pAnalysisLibraryTableView->loadTrackModel(m_pAnalysisLibraryTableModel); + + connect(radioButtonRecentlyAdded, SIGNAL(clicked()), + this, SLOT(showRecentSongs())); + connect(radioButtonAllSongs, SIGNAL(clicked()), + this, SLOT(showAllSongs())); + + radioButtonRecentlyAdded->click(); + + labelProgress->setText(""); + pushButtonAnalyze->setEnabled(false); + connect(pushButtonAnalyze, SIGNAL(clicked()), + this, SLOT(analyze())); + + connect(pushButtonSelectAll, SIGNAL(clicked()), + this, SLOT(selectAll())); + + connect(m_pAnalysisLibraryTableView->selectionModel(), + SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection&)), + this, + SLOT(tableSelectionChanged(const QItemSelection &, const QItemSelection&))); +} + +DlgAnalysis::~DlgAnalysis() { +} + +void DlgAnalysis::onShow() { + // Refresh table + // There might be new tracks dropped to other views + m_pAnalysisLibraryTableModel->select(); +} + +void DlgAnalysis::onSearch(const QString& text) { + m_pAnalysisLibraryTableModel->search(text); +} + +void DlgAnalysis::loadSelectedTrack() { + m_pAnalysisLibraryTableView->loadSelectedTrack(); +} + +void DlgAnalysis::loadSelectedTrackToGroup(QString group, bool play) { + m_pAnalysisLibraryTableView->loadSelectedTrackToGroup(group, play); +} + +void DlgAnalysis::moveSelection(int delta) { + m_pAnalysisLibraryTableView->moveSelection(delta); +} + +void DlgAnalysis::tableSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected) { + Q_UNUSED(selected); + Q_UNUSED(deselected); + bool tracksSelected = m_pAnalysisLibraryTableView->selectionModel()->hasSelection(); + pushButtonAnalyze->setEnabled(tracksSelected || m_bAnalysisActive); +} + +void DlgAnalysis::selectAll() { + m_pAnalysisLibraryTableView->selectAll(); +} + +void DlgAnalysis::analyze() { + //qDebug() << this << "analyze()"; + if (m_bAnalysisActive) { + emit(stopAnalysis()); + } else { + QList<int> trackIds; + + QModelIndexList selectedIndexes = m_pAnalysisLibraryTableView->selectionModel()->selectedRows(); + foreach(QModelIndex selectedIndex, selectedIndexes) { + bool ok; + int trackId = selectedIndex.sibling( + selectedIndex.row(), + m_pAnalysisLibraryTableModel->fieldIndex(LIBRARYTABLE_ID)).data().toInt(&ok); + if (ok) { + trackIds.append(trackId); + } + } + m_tracksInQueue = trackIds.count(); + m_currentTrack = 1; + emit(analyzeTracks(trackIds)); + } +} + +void DlgAnalysis::analysisActive(bool bActive) { + qDebug() << this << "analysisActive" << bActive; + m_bAnalysisActive = bActive; + if (bActive) { + pushButtonAnalyze->setEnabled(true); + pushButtonAnalyze->setText(tr("Stop Analysis")); + } else { + pushButtonAnalyze->setText(tr("Analyze")); + labelProgress->setText(""); + } +} + +// slot +void DlgAnalysis::trackAnalysisFinished(int size) { + qDebug() << "Analysis finished" << size << "tracks left"; + if (size > 0) { + m_currentTrack = m_tracksInQueue - size + 1; + } +} + +// slot +void DlgAnalysis::trackAnalysisProgress(int progress) { + if (m_bAnalysisActive) { + QString text = tr("Analyzing %1/%2 %3%").arg( + QString::number(m_currentTrack), + QString::number(m_tracksInQueue), + QString::number(progress)); + labelProgress->setText(text); + } +} + +void DlgAnalysis::showRecentSongs() { + m_pAnalysisLibraryTableModel->showRecentSongs(); +} + +void DlgAnalysis::showAllSongs() { + m_pAnalysisLibraryTableModel->showAllSongs(); +} + +void DlgAnalysis::installEventFilter(QObject* pFilter) { + QWidget::installEventFilter(pFilter); + m_pAnalysisLibraryTableView->installEventFilter(pFilter); +} |