Files
aliendefender/ADeditor/wavemodel.h
2020-06-15 22:22:46 +03:00

79 lines
3.0 KiB
C++

#ifndef WAVEMODEL_H
#define WAVEMODEL_H
#include <QAbstractTableModel>
#include <QMultiHash>
#include "../loader.h"
class WavePartModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit WavePartModel(QHash <int,tbWave> &waves, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent) const {return 2;}
//bool insertRows(int row, int count, const QModelIndex &parent);
bool removeRows(int row, int count, const QModelIndex &parent);
QVariant data(const QModelIndex &index, int role) const;
// void refresh(QList <tbAnimation> &anims);
Qt::ItemFlags flags(const QModelIndex &index) const {Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (index.column()==1) f = f | Qt::ItemIsEditable;
return f;}
bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
// QStringList waveList();
public slots:
//void setLevel(int level) {this->level = level; dataChanged(index(0,0),index(rowCount()-1,1));}
void setCurrentWave(QModelIndex = QModelIndex(), QModelIndex b = QModelIndex());
void insertAlien(int alId);
void removeAlien(QModelIndex index);
void clearAliens();
void addWave() {int i=0; while(waves.contains(i)) i++;
tbWave w; w.id=i; w.prise=0; w.timeout=10; waves.insert(w.id,w);
setCurrentWave(index(waves.size()-1,0));}
void updateIndex();
private:
QHash <int,tbWave> &waves;
int curWave;
//int level;
};
class WaveModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit WaveModel(QHash <int,tbWave> &waves, QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const {return waves.size();}
int columnCount(const QModelIndex &parent = QModelIndex()) const {return 4;}
//bool insertRows(int row, int count, const QModelIndex &parent);
//bool removeRows(int row, int count, const QModelIndex &parent);
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const {Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
if (index.column()==1||index.column()==2) f = f | Qt::ItemIsEditable;
return f;}
bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
public slots:
void addWave(QModelIndex a);
void copyWave(QModelIndex a);
void removeWave(QModelIndex a);
void upWave(QModelIndex a);
void downWave(QModelIndex a);
void refreshData(bool inverse = false);
private:
QHash <int,tbWave> &waves;
QList<tbWave> values;
signals:
void needUpdateIndex();
};
#endif // WAVEMODEL_H