Warning, file /games/arkade/src/minesweepermodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-or-later
0004 
0005 #pragma once
0006 
0007 #include <QAbstractTableModel>
0008 
0009 struct Field {
0010     bool isMine;
0011     bool isDiscovered;
0012     bool hasFlag;
0013 };
0014 
0015 /**
0016  * Model for a minesweeper.
0017  */
0018 class MinesweeperModel : public QAbstractTableModel
0019 {
0020     Q_OBJECT
0021     
0022     Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged)
0023     Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged)
0024 
0025 public:
0026     MinesweeperModel(QObject *parent = nullptr);
0027     virtual ~MinesweeperModel() override = default;
0028     
0029     enum FieldType {
0030         MINES,
0031         NO_MINES,
0032     };
0033     Q_ENUM(FieldType)
0034     
0035     enum AdditionalRoles {
0036         MinesNearRole = Qt::UserRole + 1,
0037         HasFlagRole,
0038         HasBeenDiscoveredRole,
0039         FieldRole,
0040     };
0041     Q_ENUM(AdditionalRoles)
0042     
0043     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0044     virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0045     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0046     QHash<int, QByteArray> roleNames() const override;
0047     
0048     int row() const;
0049     void setRow(int row);
0050     int column() const;
0051     void setColumn(int column);
0052     
0053 Q_SIGNALS:
0054     void rowChanged();
0055     void columnChanged();
0056     
0057 private:
0058     int m_row;
0059     int m_column;
0060     QList<Field> m_fields;
0061 };