File indexing completed on 2024-05-05 04:48:25

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Daniel Dewald <Daniel.Dewald@time-shift.de>                       *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef AMAROK_LABELLISTMODEL_H
0018 #define AMAROK_LABELLISTMODEL_H
0019 
0020 #include "core/support/Amarok.h"
0021 
0022 #include <QAbstractListModel>
0023 
0024 /**
0025 *   MVC Model Class for displaying a Label List
0026 *   should be used with a QListView
0027 */
0028 
0029 
0030 class LabelListModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033 
0034     public:
0035         explicit LabelListModel( const QStringList &m_labels, QObject *parent = nullptr );
0036 
0037         int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
0038         QVariant data( const QModelIndex &index, int role ) const override;
0039         QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
0040         Qt::ItemFlags flags( const QModelIndex &index ) const override;
0041         bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
0042         bool insertRows( int position, int rows, const QModelIndex &index = QModelIndex() ) override;
0043         bool removeRows( int position, int rows, const QModelIndex &index = QModelIndex() ) override;
0044 
0045         /**
0046         * Adds a label
0047         * @arg label Label that should be added
0048         */
0049         void addLabel( const QString &label );
0050 
0051         /**
0052         * Removes a label
0053         * @arg label Label that should be removed
0054         */
0055         void removeLabel( const QString &label );
0056 
0057         /**
0058         * Removes labels
0059         * @arg labels List of labels that should be removed
0060         */
0061         void removeLabels( const QStringList &labels );
0062 
0063         /**
0064         * Sets the labels
0065         * @arg labels List of new Labels
0066         */
0067         void setLabels( const QStringList& labels );
0068 
0069         /**
0070         * @returns List of labels
0071         */
0072         QStringList labels() const;
0073 
0074     private:
0075         QStringList m_labels;
0076         bool isPresent( const QString &label );
0077 };
0078 
0079 #endif