2 // filelistmodel.cpp - A ROM chooser
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 02/01/2010 Created this file
12 // JLH 07/05/2011 Fixed model to not reset itself with each new row insertion
15 // Note that we have to put in convenience functions to the model for adding data
16 // and calling reset() to tell the view(s) that the model has changed. So that much
17 // should be simple. According to the docs, we have to reimplement flags() in the
18 // QAbstractListModel subclass, but in the example given below they don't. Not sure
19 // if it's necessary or not.
21 #include "filelistmodel.h"
24 FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent)
28 int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
33 QVariant FileListModel::data(const QModelIndex & index, int role) const
35 if (role == FLM_LABEL)
36 return list.at(index.row()).label;
37 else if (role == FLM_INDEX)
38 return (uint)list.at(index.row()).dbIndex;
39 else if (role == FLM_FILENAME)
40 return list.at(index.row()).filename;
41 else if (role == FLM_FILESIZE)
42 return (uint)list.at(index.row()).fileSize;
43 else if (role == FLM_UNIVERSALHDR)
44 return (uint)list.at(index.row()).hasUniversalHeader;
45 else if (role == FLM_FILETYPE)
46 return (uint)list.at(index.row()).fileType;
47 else if (role == FLM_CRC)
48 return (uint)list.at(index.row()).crc;
53 QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientation*/, int role/*= Qt::DisplayRole*/) const
55 // This seems more like what we want...
56 if (role == Qt::SizeHintRole)
62 void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size)
64 // Assuming that both QString and QImage have copy constructors, this should work.
73 beginInsertRows(QModelIndex(), list.size(), list.size());
78 void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size, bool univHdr, uint32_t type, uint32_t fileCrc)
80 // Assuming that both QString and QImage have copy constructors, this should work.
87 data.hasUniversalHeader = univHdr;
92 beginInsertRows(QModelIndex(), list.size(), list.size());
97 void FileListModel::ClearData(void)
107 //FileListData FileListModel::GetData(const QModelIndex & index) const
109 // return list.at(index.row());