mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Deck editor
This commit is contained in:
parent
bb30012fbb
commit
3ae865178b
10 changed files with 175 additions and 43 deletions
|
|
@ -6,34 +6,39 @@
|
|||
DeckListModel::DeckListModel(CardDatabase *_db, QObject *parent)
|
||||
: QAbstractListModel(parent), db(_db)
|
||||
{
|
||||
deckList = new DeckList(db);
|
||||
deckList = new DeckList(db, this);
|
||||
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(resetModel()));
|
||||
}
|
||||
|
||||
DeckListModel::~DeckListModel()
|
||||
{
|
||||
delete deckList;
|
||||
}
|
||||
|
||||
int DeckListModel::rowCount(const QModelIndex &parent) const
|
||||
void DeckListModel::resetModel()
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
reset();
|
||||
}
|
||||
|
||||
int DeckListModel::rowCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
// qDebug(QString("rowCount = %1").arg(deckList->size()).toLatin1());
|
||||
return deckList->size();
|
||||
}
|
||||
|
||||
int DeckListModel::columnCount(const QModelIndex &parent) const
|
||||
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// qDebug(QString("data() called: index.row = %1, column = %2, role = %3").arg(index.row()).arg(index.column()).arg(role).toLatin1());
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
if ((index.row() >= deckList->size()) || (index.column() >= 2))
|
||||
return QVariant();
|
||||
|
||||
if (role != Qt::DisplayRole)
|
||||
if ((role != Qt::DisplayRole) && (role != Qt::EditRole))
|
||||
return QVariant();
|
||||
|
||||
DecklistRow *r = deckList->at(index.row());
|
||||
|
|
@ -46,6 +51,7 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
// qDebug(QString("headerData() called: section = %1, orientation = %2, role = %3").arg(section).arg(orientation).arg(role).toLatin1());
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
if (orientation != Qt::Horizontal)
|
||||
|
|
@ -57,15 +63,52 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
|
|||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() == 0)
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
else
|
||||
return QAbstractItemModel::flags(index);
|
||||
}
|
||||
|
||||
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || role != Qt::EditRole)
|
||||
return false;
|
||||
|
||||
switch (index.column()) {
|
||||
case 0: deckList->at(index.row())->setNumber(value.toInt()); break;
|
||||
case 1: deckList->at(index.row())->setCard(value.toString()); break;
|
||||
default: return false;
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
deckList->removeAt(row);
|
||||
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeckListModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
deckList->insert(row, new DecklistRow);
|
||||
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeckListModel::cleanList()
|
||||
{
|
||||
deckList->cleanList();
|
||||
reset();
|
||||
}
|
||||
|
||||
DecklistRow *DeckListModel::getRow(int row) const
|
||||
{
|
||||
if (row >= deckList->size())
|
||||
return 0;
|
||||
return deckList->at(row);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue