Files
aliendefender/ADeditor/animationmodel.cpp
blizer 894e55bb41 added morphs, fix some bugs, new images
added onAlienInRadius trigger
but it not work right((
2011-08-21 22:22:02 +04:00

43 lines
1.1 KiB
C++

#include "animationmodel.h"
AnimationModel::AnimationModel(QHash <int,tbAnimation> &manims, QObject *parent) :
QAbstractListModel(parent), anims(manims)
{
// anims = manims;
}
//void AnimationModel::refresh(QList<tbAnimation>manims)
//{
// anims = manims;
//}
int AnimationModel::rowCount(const QModelIndex &) const
{
return anims.count();
}
QVariant AnimationModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (index.row() >= anims.size()) return QVariant();
if (role == Qt::DisplayRole)
return tr("(%1) ").arg(anims.values().at(index.row()).id) + anims[anims.values().at(index.row()).id].name;
if (role == Qt::EditRole)
return anims[anims.values().at(index.row()).id].name;
return QVariant();
}
bool AnimationModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role != Qt::EditRole) return false;
if (!index.isValid()) return false;
if (index.row() >= anims.size()) return false;
anims[anims.values().at(index.row()).id].name = value.toString();
emit dataChanged(index, index);
return true;
}