1 /* 2 * wangsetmodel.h 3 * Copyright 2017, Benjamin Trotter <bdtrotte@ucsc.edu> 4 * 5 * This file is part of Tiled. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #pragma once 22 23 #include <QAbstractItemModel> 24 #include <tileset.h> 25 26 namespace Tiled { 27 28 class Tileset; 29 class WangSet; 30 31 class ChangeEvent; 32 class TilesetDocument; 33 34 /** 35 * This model displays the Wang sets in a given list of tilesets, which are 36 * provided by another model. 37 */ 38 class WangSetModel : public QAbstractItemModel 39 { 40 Q_OBJECT 41 42 public: 43 // Synchronized with TilesetWangSetModel 44 enum UserRoles { 45 WangSetRole = Qt::UserRole, 46 TilesetDocumentRole, 47 }; 48 49 WangSetModel(QAbstractItemModel *tilesetDocumentModel, 50 QObject *parent = nullptr); 51 ~WangSetModel(); 52 53 QModelIndex index(int row, int column, 54 const QModelIndex &parent = QModelIndex()) const override; 55 56 QModelIndex index(Tileset *tileset) const; 57 QModelIndex index(WangSet *wangSet) const; 58 59 QModelIndex parent(const QModelIndex &child) const override; 60 61 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 62 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 63 64 QVariant data(const QModelIndex &index, 65 int role = Qt::DisplayRole) const override; 66 67 Qt::ItemFlags flags(const QModelIndex &index) const override; 68 69 Tileset *tilesetAt(const QModelIndex &index) const; 70 WangSet *wangSetAt(const QModelIndex &index) const; 71 72 private: 73 void onTilesetRowsInserted(const QModelIndex &parent, int first, int last); 74 void onTilesetRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last); 75 void onTilesetRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); 76 void onTilesetLayoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint); 77 void onTilesetDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 78 79 void onDocumentChanged(const ChangeEvent &change); 80 81 QAbstractItemModel *mTilesetDocumentsModel; 82 QList<TilesetDocument*> mTilesetDocuments; 83 }; 84 85 } // namespace Tiled 86