1 /* 2 * Copyright (C) 2014-2018 Christopho, Solarus - http://www.solarus-games.org 3 * 4 * Solarus Quest Editor is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * Solarus Quest Editor is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef SOLARUSEDITOR_BORDER_SET_MODEL_H 18 #define SOLARUSEDITOR_BORDER_SET_MODEL_H 19 20 #include "border_kind_traits.h" 21 #include <QAbstractItemModel> 22 #include <memory> 23 24 namespace SolarusEditor { 25 26 class TilesetModel; 27 28 /** 29 * @brief Item model used by the border set tree view. 30 */ 31 class BorderSetModel : public QAbstractItemModel { 32 Q_OBJECT 33 34 public: 35 36 explicit BorderSetModel(TilesetModel& tileset, QObject* parent = nullptr); 37 38 // QAbstractItemModel interface. 39 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 40 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 41 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 42 QModelIndex parent(const QModelIndex& index) const override; 43 QVariant data(const QModelIndex& index, int role) const override; 44 Qt::ItemFlags flags(const QModelIndex& index) const override; 45 46 QStringList mimeTypes() const override; 47 QMimeData* mimeData(const QModelIndexList& indexes) const override; 48 Qt::DropActions supportedDropActions() const override; 49 bool canDropMimeData( 50 const QMimeData* data, 51 Qt::DropAction action, 52 int row, 53 int column, 54 const QModelIndex& parent 55 ) const override; 56 bool dropMimeData( 57 const QMimeData* data, 58 Qt::DropAction action, 59 int row, 60 int column, 61 const QModelIndex& parent 62 ) override; 63 64 bool is_border_set_index(const QModelIndex& index) const; 65 bool is_pattern_index(const QModelIndex& index) const; 66 QString get_border_set_id(const QModelIndex& index) const; 67 QString get_pattern_id(const QModelIndex& index) const; 68 BorderKind get_border_kind(const QModelIndex& index) const; 69 QPair<QString, QString> get_pattern_info(const QModelIndex& index) const; 70 QModelIndex get_border_set_index(const QString& border_set_id) const; 71 QModelIndex get_pattern_index(const QString& border_set_id, BorderKind border_kind) const; 72 73 signals: 74 75 void change_border_set_patterns_requested( 76 const QString& border_set_id, 77 const QStringList& pattern_ids 78 ); 79 80 public slots: 81 82 void border_set_created(const QString& border_set_id); 83 void border_set_deleted(const QString& border_set_id); 84 void border_set_id_changed(const QString& old_id, const QString& new_id); 85 void border_set_pattern_changed( 86 const QString& border_set_id, 87 BorderKind border_kind, 88 const QString& pattern_id 89 ); 90 void pattern_id_changed(int old_index, const QString& old_id, 91 int new_index, const QString& new_id); 92 93 private: 94 95 /** 96 * @brief Data of a specific border set. 97 */ 98 struct BorderSetIndex { 99 100 /** 101 * @brief Creates a border set id. 102 * @param id Name of the border set. 103 */ BorderSetIndexBorderSetIndex104 explicit BorderSetIndex(const QString& border_set_id) : 105 border_set_id(new QString(border_set_id)) { 106 } 107 108 std::shared_ptr<QString> border_set_id; 109 }; 110 111 TilesetModel& tileset; /**< The tileset represented by this model. */ 112 QList<BorderSetIndex> border_set_indexes; /**< Ids of the border sets in the model. */ 113 }; 114 115 } 116 117 #endif 118