2 // filepicker.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
14 // Note that we have to put in convenience functions to the model for adding data
15 // and calling reset() to tell the view(s) that the model has changed. So that much
16 // should be simple. According to the docs, we have to reimplement flags() in the
17 // QAbstractListModel subclass, but in the example given below they don't. Not sure
18 // if it's necessary or not.
20 #include "filelistmodel.h"
23 FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent)
27 int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
29 // return pixList.size();
30 return dbIndex.size();
33 QVariant FileListModel::data(const QModelIndex & index, int role) const
36 // return pixList.at(index.row());
37 return (uint)dbIndex.at(index.row());
40 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
43 // Not sure that this is necessary for our purposes...
44 // Especially since this model would never make use of this info...
45 if (role != Qt::DisplayRole)
48 if (orientation == Qt::Horizontal)
49 return QString("Column %1").arg(section);
51 return QString("Row %1").arg(section);
53 // This seems more like what we want...
54 if (role == Qt::SizeHintRole)
61 void FileListModel::AddData(QIcon pix)
63 pixList.push_back(pix);
67 void FileListModel::AddData(unsigned long index)
69 dbIndex.push_back(index);
76 class StringListModel : public QAbstractListModel
81 StringListModel(const QStringList &strings, QObject *parent = 0)
82 : QAbstractListModel(parent), stringList(strings) {}
84 int rowCount(const QModelIndex &parent = QModelIndex()) const;
85 QVariant data(const QModelIndex &index, int role) const;
86 QVariant headerData(int section, Qt::Orientation orientation,
87 int role = Qt::DisplayRole) const;
90 QStringList stringList;
93 int StringListModel::rowCount(const QModelIndex &parent) const
95 return stringList.count();
98 QVariant StringListModel::data(const QModelIndex &index, int role) const
100 if (!index.isValid())
103 if (index.row() >= stringList.size())
106 if (role == Qt::DisplayRole)
107 return stringList.at(index.row());
113 QVariant StringListModel::headerData(int section, Qt::Orientation orientation, int role) const
115 if (role != Qt::DisplayRole)
118 if (orientation == Qt::Horizontal)
119 return QString("Column %1").arg(section);
121 return QString("Row %1").arg(section);
126 void ImageModel::setImage(const QImage &image)
132 The QAbstractItemModel::reset() call tells the view(s) that the model has changed.