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();
32 QVariant FileListModel::data(const QModelIndex & index, int role) const
35 return pixList.at(index.row());
38 QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
41 // Not sure that this is necessary for our purposes...
42 // Especially since this model would never make use of this info...
43 if (role != Qt::DisplayRole)
46 if (orientation == Qt::Horizontal)
47 return QString("Column %1").arg(section);
49 return QString("Row %1").arg(section);
51 // This seems more like what we want...
52 if (role == Qt::SizeHintRole)
59 void FileListModel::AddData(QIcon pix)
61 pixList.push_back(pix);
68 class StringListModel : public QAbstractListModel
73 StringListModel(const QStringList &strings, QObject *parent = 0)
74 : QAbstractListModel(parent), stringList(strings) {}
76 int rowCount(const QModelIndex &parent = QModelIndex()) const;
77 QVariant data(const QModelIndex &index, int role) const;
78 QVariant headerData(int section, Qt::Orientation orientation,
79 int role = Qt::DisplayRole) const;
82 QStringList stringList;
85 int StringListModel::rowCount(const QModelIndex &parent) const
87 return stringList.count();
90 QVariant StringListModel::data(const QModelIndex &index, int role) const
95 if (index.row() >= stringList.size())
98 if (role == Qt::DisplayRole)
99 return stringList.at(index.row());
105 QVariant StringListModel::headerData(int section, Qt::Orientation orientation, int role) const
107 if (role != Qt::DisplayRole)
110 if (orientation == Qt::Horizontal)
111 return QString("Column %1").arg(section);
113 return QString("Row %1").arg(section);
118 void ImageModel::setImage(const QImage &image)
124 The QAbstractItemModel::reset() call tells the view(s) that the model has changed.