コード例 #1
0
void SetList::guessSortKeys()
{
    // sort by release date DESC; invalid dates to the bottom.
    QDate distantFuture(2050, 1, 1);
    int aHundredYears = 36500;
    for (int i = 0; i < size(); ++i)
    {
        CardSet *set = at(i);
        QDate date = set->getReleaseDate();
        if(date.isNull())
            set->setSortKey(aHundredYears);
        else
            set->setSortKey(date.daysTo(distantFuture));
    }
}
コード例 #2
0
ファイル: setsmodel.cpp プロジェクト: DINKIN/Cockatrice
QVariant SetsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount()))
        return QVariant();

    CardSet *set = sets[index.row()];

    if ( role == Qt::CheckStateRole && index.column() == EnabledCol )
        return static_cast< int >( enabledSets.contains(set) ? Qt::Checked : Qt::Unchecked );

    if (role != Qt::DisplayRole)
        return QVariant();

    switch (index.column()) {
        case SortKeyCol: return QString("%1").arg(set->getSortKey(), 8, 10, QChar('0'));
        case IsKnownCol: return set->getIsKnown();
        case SetTypeCol: return set->getSetType();
        case ShortNameCol: return set->getShortName();
        case LongNameCol: return set->getLongName();
        case ReleaseDateCol: return set->getReleaseDate().toString(Qt::ISODate);
        default: return QVariant();
    }
}