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
40 // Not sure that this is necessary for our purposes...
41 // Especially since this model would never make use of this info...
42 if (role != Qt::DisplayRole)
45 if (orientation == Qt::Horizontal)
46 return QString("Column %1").arg(section);
48 return QString("Row %1").arg(section);
51 void FileListModel::AddData(QIcon pix)
53 pixList.push_back(pix);
60 class StringListModel : public QAbstractListModel
65 StringListModel(const QStringList &strings, QObject *parent = 0)
66 : QAbstractListModel(parent), stringList(strings) {}
68 int rowCount(const QModelIndex &parent = QModelIndex()) const;
69 QVariant data(const QModelIndex &index, int role) const;
70 QVariant headerData(int section, Qt::Orientation orientation,
71 int role = Qt::DisplayRole) const;
74 QStringList stringList;
77 int StringListModel::rowCount(const QModelIndex &parent) const
79 return stringList.count();
82 QVariant StringListModel::data(const QModelIndex &index, int role) const
87 if (index.row() >= stringList.size())
90 if (role == Qt::DisplayRole)
91 return stringList.at(index.row());
97 QVariant StringListModel::headerData(int section, Qt::Orientation orientation, int role) const
99 if (role != Qt::DisplayRole)
102 if (orientation == Qt::Horizontal)
103 return QString("Column %1").arg(section);
105 return QString("Row %1").arg(section);
110 void ImageModel::setImage(const QImage &image)
116 The QAbstractItemModel::reset() call tells the view(s) that the model has changed.