// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef MAPMODEL_H
#define MAPMODEL_H

#include <QtCore/QAbstractTableModel>
#include <QtCore/QVector>
#include <QtCore/QPoint>

class MapModel : public QAbstractTableModel
{
    Q_OBJECT

    Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)

public:
    explicit MapModel(QObject *parent = 0);

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;

    virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    virtual Qt::ItemFlags flags(const QModelIndex &index) const;

    QString source() const;
    void setSource(const QString &);

    Q_INVOKABLE void newMap(int columns, int rows);

    Q_INVOKABLE void setType(QPoint index, int type);
    Q_INVOKABLE void save(const QString &filename) const;
    Q_INVOKABLE int type(QPoint index) const;

    Q_INVOKABLE void extendUp();
    Q_INVOKABLE void extendDown();
    Q_INVOKABLE void extendLeft();
    Q_INVOKABLE void extendRight();

signals:
    void sourceChanged();

private:
    void read();

    int _columns;
    QVector<int> _data;
    QString _source;
};

#endif // MAPMODEL_H
