Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/library/proxytrackmodel.cpp

Go to the documentation of this file.
00001 // proxytrackmodel.cpp
00002 // Created 10/22/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #include <QtCore>
00005 #include <QVariant>
00006 
00007 #include "library/proxytrackmodel.h"
00008 
00009 ProxyTrackModel::ProxyTrackModel(QAbstractItemModel* pTrackModel,
00010                                  bool bHandleSearches)
00011         // ProxyTrackModel proxies settings requests to the composed TrackModel,
00012         // don't initialize its TrackModel with valid parameters.
00013         : TrackModel(QSqlDatabase(), ""),
00014           m_bHandleSearches(bHandleSearches) {
00015     m_pTrackModel = dynamic_cast<TrackModel*>(pTrackModel);
00016     Q_ASSERT(m_pTrackModel && pTrackModel);
00017     setSourceModel(pTrackModel);
00018 }
00019 
00020 ProxyTrackModel::~ProxyTrackModel() {
00021 }
00022 
00023 int ProxyTrackModel::getTrackId(const QModelIndex& index) const {
00024     QModelIndex indexSource = mapToSource(index);
00025     return m_pTrackModel->getTrackId(indexSource);
00026 }
00027 
00028 const QLinkedList<int> ProxyTrackModel::getTrackRows(int trackId) const {
00029     return m_pTrackModel->getTrackRows(trackId);
00030 }
00031 
00032 TrackPointer ProxyTrackModel::getTrack(const QModelIndex& index) const {
00033     QModelIndex indexSource = mapToSource(index);
00034     return m_pTrackModel->getTrack(indexSource);
00035 }
00036 
00037 QString ProxyTrackModel::getTrackLocation(const QModelIndex& index) const {
00038     QModelIndex indexSource = mapToSource(index);
00039     return m_pTrackModel->getTrackLocation(indexSource);
00040 }
00041 
00042 void ProxyTrackModel::search(const QString& searchText) {
00043     if (m_bHandleSearches) {
00044         m_currentSearch = searchText;
00045         setFilterFixedString(searchText);
00046     } else {
00047         m_pTrackModel->search(searchText);
00048     }
00049 }
00050 
00051 const QString ProxyTrackModel::currentSearch() const {
00052     if (m_bHandleSearches) {
00053         return m_currentSearch;
00054     }
00055     return m_pTrackModel->currentSearch();
00056 }
00057 
00058 bool ProxyTrackModel::isColumnInternal(int column) {
00059     return m_pTrackModel->isColumnInternal(column);
00060 }
00061 
00062 bool ProxyTrackModel::isColumnHiddenByDefault(int column) {
00063     return m_pTrackModel->isColumnHiddenByDefault(column);
00064 }
00065 
00066 void ProxyTrackModel::removeTrack(const QModelIndex& index) {
00067     QModelIndex indexSource = mapToSource(index);
00068     m_pTrackModel->removeTrack(indexSource);
00069 }
00070 
00071 void ProxyTrackModel::removeTracks(const QModelIndexList& indices) {
00072     QModelIndexList translatedList;
00073     foreach (QModelIndex index, indices) {
00074         QModelIndex indexSource = mapToSource(index);
00075         translatedList.append(indexSource);
00076     }
00077     m_pTrackModel->removeTracks(translatedList);
00078 }
00079 
00080 bool ProxyTrackModel::addTrack(const QModelIndex& index, QString location) {
00081     QModelIndex indexSource = mapToSource(index);
00082     return m_pTrackModel->addTrack(indexSource, location);
00083 }
00084 
00085 void ProxyTrackModel::moveTrack(const QModelIndex& sourceIndex,
00086                                 const QModelIndex& destIndex) {
00087     QModelIndex sourceIndexSource = mapToSource(sourceIndex);
00088     QModelIndex destIndexSource = mapToSource(destIndex);
00089     m_pTrackModel->moveTrack(sourceIndexSource, destIndexSource);
00090 }
00091 
00092 QItemDelegate* ProxyTrackModel::delegateForColumn(const int i) {
00093     return m_pTrackModel->delegateForColumn(i);
00094 }
00095 
00096 TrackModel::CapabilitiesFlags ProxyTrackModel::getCapabilities() const {
00097     return m_pTrackModel->getCapabilities();
00098 }
00099 
00100 bool ProxyTrackModel::filterAcceptsRow(int sourceRow,
00101                                        const QModelIndex& sourceParent) const {
00102     if (!m_bHandleSearches)
00103         return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
00104 
00105     const QList<int>& filterColumns = m_pTrackModel->searchColumns();
00106     QAbstractItemModel* itemModel =
00107             dynamic_cast<QAbstractItemModel*>(m_pTrackModel);
00108     bool rowMatches = false;
00109 
00110     QRegExp filter = filterRegExp();
00111     QListIterator<int> iter(filterColumns);
00112 
00113     while (!rowMatches && iter.hasNext()) {
00114         int i = iter.next();
00115         QModelIndex index = itemModel->index(sourceRow, i, sourceParent);
00116         QVariant data = itemModel->data(index);
00117         if (qVariantCanConvert<QString>(data)) {
00118             QString strData = qVariantValue<QString>(data);
00119             if (strData.contains(filter))
00120                 rowMatches = true;
00121         }
00122     }
00123 
00124     return rowMatches;
00125 }
00126 
00127 QString ProxyTrackModel::getModelSetting(QString name) {
00128     if (!m_pTrackModel)
00129         return QString();
00130     return m_pTrackModel->getModelSetting(name);
00131 }
00132 
00133 bool ProxyTrackModel::setModelSetting(QString name, QVariant value) {
00134     if (!m_pTrackModel)
00135         return false;
00136     return m_pTrackModel->setModelSetting(name, value);
00137 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines