]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filelistmodel.cpp
Fixed 24BPP mode (used R twice instead of B), fixed problem with Object
[virtualjaguar] / src / gui / filelistmodel.cpp
index 626b296d9b637af178649f089da61cb4d164e421..097514c851ca18958bbaa2d40b3b3cad335147f9 100644 (file)
@@ -1,5 +1,5 @@
 //
-// filepicker.cpp - A ROM chooser
+// filelistmodel.cpp - A ROM chooser
 //
 // by James L. Hammons
 // (C) 2010 Underground Software
@@ -9,6 +9,7 @@
 // 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
 //
 
 // Note that we have to put in convenience functions to the model for adding data
@@ -26,29 +27,11 @@ FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent
 
 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());
-//It could be that this is fucking things up...
-#if 0
-       if (role == Qt::DecorationRole)
-               return list.at(index.row()).label;
-       else if (role == Qt::DisplayRole)
-               return (uint)list.at(index.row()).dbIndex;
-       else if (role == Qt::EditRole)
-               return list.at(index.row()).filename;
-       else if (role == Qt::WhatsThisRole)
-               return (uint)list.at(index.row()).fileSize;
-       else
-               return QVariant();
-#else
        if (role == FLM_LABEL)
                return list.at(index.row()).label;
        else if (role == FLM_INDEX)
@@ -65,44 +48,17 @@ QVariant FileListModel::data(const QModelIndex & index, int role) const
                return (uint)list.at(index.row()).crc;
 
        return QVariant();
-#endif
 }
 
 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, unsigned long size)
 {
        // Assuming that both QString and QImage have copy constructors, this should work.
@@ -113,8 +69,10 @@ void FileListModel::AddData(unsigned long index, QString str, QImage img, unsign
        data.filename = str;
        data.label = img;
 
+       // Let's try this:
+       beginInsertRows(QModelIndex(), list.size(), list.size());
        list.push_back(data);
-       reset();
+       endInsertRows();
 }
 
 void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size, bool univHdr, uint32_t type, uint32_t fileCrc)
@@ -130,11 +88,10 @@ void FileListModel::AddData(unsigned long index, QString str, QImage img, unsign
        data.fileType = type;
        data.crc = fileCrc;
 
+       // Let's try this:
+       beginInsertRows(QModelIndex(), list.size(), list.size());
        list.push_back(data);
-//This is probably not the best way to do this, it prevents the user from using the
-//list while it populates.
-#warning "!!! AddData calls reset() for every addition, this is bad !!!"
-       reset();
+       endInsertRows();
 }
 
 void FileListModel::ClearData(void)
@@ -151,65 +108,3 @@ void FileListModel::ClearData(void)
 //{
 //     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();
-}
-
-QVariant StringListModel::data(const QModelIndex &index, int role) const
-{
-       if (!index.isValid())
-               return QVariant();
-
-       if (index.row() >= stringList.size())
-               return QVariant();
-
-       if (role == Qt::DisplayRole)
-               return stringList.at(index.row());
-       else
-               return QVariant();
-}
-
-
-QVariant StringListModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
-       if (role != Qt::DisplayRole)
-               return QVariant();
-
-       if (orientation == Qt::Horizontal)
-               return QString("Column %1").arg(section);
-       else
-               return QString("Row %1").arg(section);
-}
-
-
-
- void ImageModel::setImage(const QImage &image)
- {
-     modelImage = image;
-     reset();
- }
-
-The QAbstractItemModel::reset() call tells the view(s) that the model has changed.
-
-#endif