103 lines
3.7 KiB
C++
103 lines
3.7 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2008 by Oliver Groß *
|
|
* z.o.gross@gmx.de *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include <libqnono/ccrosspackage.h>
|
|
#include <libqnono/cnonogram.h>
|
|
|
|
#include "cmaskedcrosspackagemodel.h"
|
|
#include "chighscore.h"
|
|
#include "common.h"
|
|
|
|
#define COL_NAME 0
|
|
#define COL_TIME 1
|
|
|
|
namespace qcross {
|
|
using namespace libqnono;
|
|
//public:
|
|
CMaskedCrossPackageModel::CMaskedCrossPackageModel(QObject * parent) :
|
|
CCrossPackageModel(parent), m_Highscore(NULL) {}
|
|
|
|
CMaskedCrossPackageModel::~CMaskedCrossPackageModel() {}
|
|
|
|
void CMaskedCrossPackageModel::setHighscore(CHighscore * highscore) {
|
|
m_Highscore = highscore;
|
|
reset();
|
|
}
|
|
|
|
// QVariant CMaskedCrossPackageModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
|
// if (role == Qt::DisplayRole) {
|
|
// switch (section) {
|
|
// case COL_NAME:
|
|
// return tr("Nonogram");
|
|
// case COL_TIME:
|
|
// return tr("Time");
|
|
// default:
|
|
// break;
|
|
// }
|
|
// }
|
|
//
|
|
// return CCrossPackageModel::headerData(section, orientation, role);
|
|
// }
|
|
|
|
int CMaskedCrossPackageModel::columnCount(const QModelIndex & /*parent*/) const {
|
|
return 2;
|
|
}
|
|
|
|
QVariant CMaskedCrossPackageModel::data(const QModelIndex & index, int role) const {
|
|
if (role == Qt::DisplayRole && m_Highscore) {
|
|
switch (index.column()) {
|
|
case COL_NAME:
|
|
if ((*m_Highscore)[index.row()])
|
|
break;
|
|
else
|
|
return tr("#%1").arg(index.row());
|
|
case COL_TIME:
|
|
if ((*m_Highscore)[index.row()])
|
|
return formatedTime((*m_Highscore)[index.row()]) + (m_Package->pictures()[index.row()].timeout() ?
|
|
" (time out)" : "");
|
|
else
|
|
return QVariant();
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return CCrossPackageModel::data(index, role);
|
|
}
|
|
|
|
Qt::ItemFlags CMaskedCrossPackageModel::flags(const QModelIndex & index) const {
|
|
return CCrossPackageModel::flags(index) & (~Qt::ItemIsEditable);
|
|
}
|
|
|
|
CMaskedCrossPackageProxyModel::CMaskedCrossPackageProxyModel(QObject * parent)
|
|
: QSortFilterProxyModel(parent), m_UnfinishedFilter(false) {}
|
|
|
|
void CMaskedCrossPackageProxyModel::setUnfinishedFilter(bool value) {
|
|
m_UnfinishedFilter = value;
|
|
reset();
|
|
}
|
|
|
|
bool CMaskedCrossPackageProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const {
|
|
QModelIndex index = sourceModel()->index(sourceRow, COL_TIME, sourceParent);
|
|
|
|
return !m_UnfinishedFilter || sourceModel()->data(index).isNull();
|
|
}
|
|
|
|
}
|