]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filelistmodel.cpp
Preliminary support for alternate file types.
[virtualjaguar] / src / gui / filelistmodel.cpp
index b509957d144a9d10014139735aac24e49a02f8e6..8308c5c946123c3511c1eb07f7b776e8519c1123 100644 (file)
@@ -26,17 +26,51 @@ FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent
 
 int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
 {
-       return pixList.size();
+//     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 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)
+               return (uint)list.at(index.row()).dbIndex;
+       else if (role == FLM_FILENAME)
+               return list.at(index.row()).filename;
+       else if (role == FLM_FILESIZE)
+               return (uint)list.at(index.row()).fileSize;
+       else if (role == FLM_UNIVERSALHDR)
+               return (uint)list.at(index.row()).hasUniversalHeader;
+       else if (role == FLM_FILETYPE)
+               return (uint)list.at(index.row()).fileType;
+       else if (role == FLM_CRC)
+               return (uint)list.at(index.row()).crc;
+
+       return QVariant();
+#endif
 }
 
-QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
+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)
@@ -46,14 +80,74 @@ QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int
                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.
+       FileListData data;
+
+       data.dbIndex = index;
+       data.fileSize = size;
+       data.filename = str;
+       data.label = img;
+
+       list.push_back(data);
+       reset();
+}
+
+void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size, bool univHdr, uint32_t type, uint32_t fileCrc)
+{
+       // Assuming that both QString and QImage have copy constructors, this should work.
+       FileListData data;
+
+       data.dbIndex = index;
+       data.fileSize = size;
+       data.filename = str;
+       data.label = img;
+       data.hasUniversalHeader = univHdr;
+       data.fileType = type;
+       data.crc = fileCrc;
+
+       list.push_back(data);
+       reset();
+}
+
+void FileListModel::ClearData(void)
+{
+       if (list.size() == 0)
+               return;
+
+       beginResetModel();
+       list.clear();
+       endResetModel();
+}
+
+//FileListData FileListModel::GetData(const QModelIndex & index) const
+//{
+//     return list.at(index.row());
+//}
 
 #if 0