X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Ffilelistmodel.cpp;h=36b32b557831653467c1a9450346e97956cb317d;hb=d207b11e613703aff7d00191c4595b7359f29700;hp=c35bd35944ca84ac9a49c30ed0d95e54ff016a8d;hpb=caf1236884015695c52910a75b8420be7c63d574;p=virtualjaguar diff --git a/src/gui/filelistmodel.cpp b/src/gui/filelistmodel.cpp index c35bd35..36b32b5 100644 --- a/src/gui/filelistmodel.cpp +++ b/src/gui/filelistmodel.cpp @@ -1,14 +1,17 @@ // -// filepicker.cpp - A ROM chooser +// filelistmodel.cpp - A ROM chooser // -// by James L. Hammons +// by James Hammons // (C) 2010 Underground Software // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- // JLH 02/01/2010 Created this file +// JLH 07/05/2011 Fixed model to not reset itself with each new row insertion +// JLH 07/07/2011 Added code to help the built-in keyboard based auto-search +// of the QListView class // // Note that we have to put in convenience functions to the model for adding data @@ -19,142 +22,112 @@ #include "filelistmodel.h" +#include "filedb.h" + FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent) { } -int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const +int FileListModel::rowCount(const QModelIndex & /*parent = QModelIndex()*/) const { -// return pixList.size(); -// return dbIndex.size(); return list.size(); } QVariant FileListModel::data(const QModelIndex & index, int role) const { -// return QVariant(); -// return pixList.at(index.row()); -// return (uint)dbIndex.at(index.row()); - if (role == Qt::DecorationRole) + if (role == FLM_LABEL) return list.at(index.row()).label; - else if (role == Qt::DisplayRole) + else if (role == FLM_INDEX) return (uint)list.at(index.row()).dbIndex; - else if (role == Qt::EditRole) + else if (role == FLM_FILENAME) return list.at(index.row()).filename; - else - return QVariant(); + else if (role == FLM_FILESIZE) + return (uint)list.at(index.row()).fileSize; + else if (role == FLM_UNIVERSALHDR) + return (uint)list.at(index.row()).hasUniversalHeader; + else if (role == FLM_FILETYPE) + return (uint)list.at(index.row()).fileType; + else if (role == FLM_CRC) + return (uint)list.at(index.row()).crc; + else if (role == Qt::DisplayRole) + { + // The QListView uses this role to do keyboard based searching, + // so we help it along by giving it what it needs to do the job. :-) + unsigned long dbIndex = list.at(index.row()).dbIndex; + QString filename = list.at(index.row()).filename; + QString nameToMatch; + + // Pull name from file DB, otherwise, use the filename... + if (dbIndex != 0xFFFFFFFF) + nameToMatch = romList[dbIndex].name; + else + { + int lastSlashPos = filename.lastIndexOf('/'); + nameToMatch = filename.mid(lastSlashPos + 1); + } + + return nameToMatch; + } + + return QVariant(); } QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientation*/, int role/*= Qt::DisplayRole*/) const { -#if 0 - // Not sure that this is necessary for our purposes... - // Especially since this model would never make use of this info... - if (role != Qt::DisplayRole) - return QVariant(); - - if (orientation == Qt::Horizontal) - return QString("Column %1").arg(section); - else - return QString("Row %1").arg(section); -#else // This seems more like what we want... if (role == Qt::SizeHintRole) return QSize(1, 1); return QVariant(); -#endif -} - -void FileListModel::AddData(QIcon pix) -{ - pixList.push_back(pix); - reset(); -} - -void FileListModel::AddData(unsigned long index) -{ - dbIndex.push_back(index); - reset(); } -void FileListModel::AddData(unsigned long index, QString str, QImage img) +void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size) { // Assuming that both QString and QImage have copy constructors, this should work. FileListData data; data.dbIndex = index; + data.fileSize = size; data.filename = str; data.label = img; + // Let's try this: + beginInsertRows(QModelIndex(), list.size(), list.size()); list.push_back(data); - reset(); -} - -//FileListData FileListModel::GetData(const QModelIndex & index) const -//{ -// return list.at(index.row()); -//} - -#if 0 - -class StringListModel : public QAbstractListModel -{ - Q_OBJECT - - public: - StringListModel(const QStringList &strings, QObject *parent = 0) - : QAbstractListModel(parent), stringList(strings) {} - - int rowCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - private: - QStringList stringList; -}; - -int StringListModel::rowCount(const QModelIndex &parent) const -{ - return stringList.count(); + endInsertRows(); } -QVariant StringListModel::data(const QModelIndex &index, int role) const +void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size, bool univHdr, uint32_t type, uint32_t fileCrc) { - if (!index.isValid()) - return QVariant(); + // Assuming that both QString and QImage have copy constructors, this should work. + FileListData data; - if (index.row() >= stringList.size()) - return QVariant(); + data.dbIndex = index; + data.fileSize = size; + data.filename = str; + data.label = img; + data.hasUniversalHeader = univHdr; + data.fileType = type; + data.crc = fileCrc; - if (role == Qt::DisplayRole) - return stringList.at(index.row()); - else - return QVariant(); + // Let's try this: + beginInsertRows(QModelIndex(), list.size(), list.size()); + list.push_back(data); + endInsertRows(); } - -QVariant StringListModel::headerData(int section, Qt::Orientation orientation, int role) const +void FileListModel::ClearData(void) { - if (role != Qt::DisplayRole) - return QVariant(); + if (list.size() == 0) + return; - if (orientation == Qt::Horizontal) - return QString("Column %1").arg(section); - else - return QString("Row %1").arg(section); + beginResetModel(); + list.clear(); + endResetModel(); } - - - void ImageModel::setImage(const QImage &image) - { - modelImage = image; - reset(); - } - -The QAbstractItemModel::reset() call tells the view(s) that the model has changed. - -#endif +//FileListData FileListModel::GetData(const QModelIndex & index) const +//{ +// return list.at(index.row()); +//}