2010-06-16 12:53:56 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* 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 <QDir>
|
|
|
|
#include "ccrosspackage.h"
|
|
|
|
#include "cnonogram.h"
|
|
|
|
#include "ccrosspackagelistmodel.h"
|
|
|
|
|
2011-12-21 11:49:33 +00:00
|
|
|
namespace libqnono {
|
2010-06-16 12:53:56 +00:00
|
|
|
//public:
|
2011-12-21 11:49:33 +00:00
|
|
|
CCrossPackageListModel::CCrossPackageListModel(QString dataPath, QString dataFilter, QObject * parent) : QAbstractItemModel(parent),
|
|
|
|
m_DataPath(dataPath), m_DataFilter(dataFilter) {
|
2010-06-16 12:53:56 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCrossPackageListModel::~CCrossPackageListModel() {
|
|
|
|
foreach (CCrossPackage * i, m_PackageList)
|
|
|
|
delete i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCrossPackageListModel::update() {
|
|
|
|
foreach (CCrossPackage * i, m_PackageList)
|
|
|
|
delete i;
|
|
|
|
|
|
|
|
m_PackageList.clear();
|
|
|
|
|
|
|
|
CCrossPackage * newPackage;
|
|
|
|
|
|
|
|
QDir workDir(m_DataPath);
|
2011-12-21 11:49:33 +00:00
|
|
|
QStringList fileNames = workDir.entryList(QStringList(m_DataFilter), QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
|
2010-06-16 12:53:56 +00:00
|
|
|
foreach (QString fileName, fileNames) {
|
2012-04-09 11:39:44 +00:00
|
|
|
newPackage = CCrossPackage::readHeader(workDir.filePath(fileName));
|
|
|
|
if (newPackage) m_PackageList << newPackage;
|
2010-06-16 12:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex CCrossPackageListModel::index(int row, int column, const QModelIndex & /*parent*/) const {
|
|
|
|
return (column > 0) || (row < 0) || (row >= m_PackageList.size()) ?
|
|
|
|
QModelIndex() :
|
|
|
|
createIndex(row, column, static_cast<void *>(m_PackageList[row]));
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CCrossPackageListModel::data(const QModelIndex & index, int role) const {
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
return static_cast<CCrossPackage *>(index.internalPointer())->name();
|
|
|
|
else
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCrossPackageListModel::rowCount(const QModelIndex & /*parent*/) const {
|
|
|
|
return m_PackageList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCrossPackageListModel::columnCount(const QModelIndex & /*parent*/) const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CCrossPackageListModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Qt::ItemFlags CCrossPackageListModel::flags(const QModelIndex & index) const {
|
|
|
|
// return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
// }
|
|
|
|
|
|
|
|
QModelIndex CCrossPackageListModel::parent(const QModelIndex &) const {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCrossPackageListModel::hasChildren(const QModelIndex & parent) const {
|
|
|
|
return !parent.isValid();
|
|
|
|
}
|
|
|
|
}
|