File indexing completed on 2024-05-12 05:39:50

0001 /***************************************************************************
0002  *  Copyright (C) 2009 by Renaud Guezennec                             *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   Rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef DICEALIASMODEL_H
0021 #define DICEALIASMODEL_H
0022 
0023 #include <QAbstractListModel>
0024 
0025 #include "core_global.h"
0026 
0027 #include <memory>
0028 #include <vector>
0029 class DiceAlias;
0030 /**
0031  * @brief The DiceAliasModel class
0032  */
0033 class CORE_EXPORT DiceAliasModel : public QAbstractListModel
0034 {
0035     Q_OBJECT
0036 public:
0037     /**
0038      * @brief The COLUMN_TYPE enum
0039      */
0040     enum COLUMN_TYPE
0041     {
0042         PATTERN,
0043         COMMAND,
0044         METHOD,
0045         DISABLE,
0046         COMMENT
0047     };
0048     /**
0049      * @brief DiceAliasModel
0050      */
0051     explicit DiceAliasModel(QObject* parent= nullptr);
0052     /**
0053      *
0054      * */
0055     ~DiceAliasModel() override;
0056 
0057     /**
0058      * @brief data
0059      * @param index
0060      * @param role
0061      * @return
0062      */
0063     QVariant data(const QModelIndex& index, int role) const override;
0064     /**
0065      * @brief rowCount
0066      * @param parent
0067      * @return
0068      */
0069     int rowCount(const QModelIndex& parent= QModelIndex()) const override;
0070     /**
0071      * @brief columnCount
0072      * @param parent
0073      * @return
0074      */
0075     int columnCount(const QModelIndex& parent) const override;
0076     /**
0077      * @brief headerData
0078      * @param section
0079      * @param orientation
0080      * @param role
0081      * @return
0082      */
0083     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0084     /**
0085      * @brief flags
0086      * @param index
0087      * @return
0088      */
0089     Qt::ItemFlags flags(const QModelIndex& index) const override;
0090     /**
0091      * @brief setData
0092      * @param index
0093      * @param value
0094      * @param role
0095      * @return
0096      */
0097     bool setData(const QModelIndex& index, const QVariant& value, int role) override;
0098 
0099     /// new methods
0100     void appendAlias(DiceAlias&& alias);
0101     void deleteAlias(const QModelIndex& index);
0102 
0103     const std::vector<std::unique_ptr<DiceAlias>>& aliases() const;
0104 
0105     void upAlias(const QModelIndex& index);
0106     void downAlias(const QModelIndex& index);
0107     void topAlias(const QModelIndex& index);
0108     void bottomAlias(const QModelIndex& index);
0109     void clear();
0110 
0111     void setGM(bool);
0112     void setModified(bool);
0113     QString convert(const QString& str);
0114 
0115 signals:
0116     void aliasAdded(DiceAlias* alias, int i);
0117     void aliasRemoved(int i);
0118     void aliasMoved(int, int);
0119     void aliasChanged(DiceAlias* alias, int i);
0120 
0121 private:
0122     std::vector<std::unique_ptr<DiceAlias>> m_diceAliasList;
0123     QStringList m_header;
0124 };
0125 
0126 #endif // DICEALIASMODEL_H