File indexing completed on 2024-05-19 04:56:00

0001 /**
0002  * \file checkablestringlistmodel.h
0003  * String list model with checkable items.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 29 Dec 2012
0008  *
0009  * Copyright (C) 2012-2024  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <QStringListModel>
0030 #include "kid3api.h"
0031 
0032 /**
0033  * String list model with checkable items.
0034  * Up to 64 items can be stored in such a model because the check states are
0035  * stored in a 64 bit member variable.
0036  */
0037 class KID3_CORE_EXPORT CheckableStringListModel : public QStringListModel {
0038 public:
0039   /**
0040    * Constructor.
0041    * @param parent parent widget
0042    */
0043   explicit CheckableStringListModel(QObject* parent = nullptr);
0044 
0045   /**
0046    * Destructor.
0047    */
0048   ~CheckableStringListModel() override = default;
0049 
0050   /**
0051    * Get item flags for index.
0052    * @param index model index
0053    * @return item flags
0054    */
0055   Qt::ItemFlags flags(const QModelIndex& index) const override;
0056 
0057   /**
0058    * Get data for a given role.
0059    * @param index model index
0060    * @param role item data role
0061    * @return data for role
0062    */
0063   QVariant data(const QModelIndex& index,
0064                 int role = Qt::DisplayRole) const override;
0065   /**
0066    * Set data for a given role.
0067    * @param index model index
0068    * @param value data value
0069    * @param role item data role
0070    * @return true if successful
0071    */
0072   bool setData(const QModelIndex& index, const QVariant& value,
0073                int role = Qt::EditRole) override;
0074 
0075 
0076   /**
0077    * Insert rows.
0078    * @param row first row
0079    * @param count number of rows to insert
0080    * @param parent parent model index
0081    * @return true if rows were successfully inserted.
0082    */
0083   bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
0084 
0085   /**
0086    * Remove rows.
0087    * @param row first row
0088    * @param count number of rows to remove
0089    * @param parent parent model index
0090    * @return true if rows were successfully removed.
0091    */
0092   bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
0093 
0094   /**
0095    * Set mask with checked state for the items in the model.
0096    * @param mask bit mask containing check states, bit 0 is set if the first
0097    * item is checked, etc.
0098    */
0099   void setBitMask(quint64 mask) { m_bitMask = mask; }
0100 
0101   /**
0102    * Get mask with checked state for the items in the model.
0103    * @return bit mask containing check states, bit 0 is set if the first
0104    * item is checked, etc.
0105    */
0106   quint64 getBitMask() const { return m_bitMask; }
0107 
0108 private:
0109   quint64 m_bitMask;
0110 };