]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filelistmodel.cpp
Removed some cruft and nonstandard int/uint types, added M series BIOS.
[virtualjaguar] / src / gui / filelistmodel.cpp
index 097514c851ca18958bbaa2d40b3b3cad335147f9..36b32b557831653467c1a9450346e97956cb317d 100644 (file)
@@ -1,15 +1,17 @@
 //
 // filelistmodel.cpp - A ROM chooser
 //
-// by James L. Hammons
+// by James Hammons
 // (C) 2010 Underground Software
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // 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
+// JLH  07/07/2011  Added code to help the built-in keyboard based auto-search
+//                  of the QListView class
 //
 
 // Note that we have to put in convenience functions to the model for adding data
 
 #include "filelistmodel.h"
 
+#include "filedb.h"
+
 
 FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent)
 {
 }
 
-int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
+int FileListModel::rowCount(const QModelIndex & /*parent = QModelIndex()*/) const
 {
        return list.size();
 }
@@ -46,6 +50,25 @@ QVariant FileListModel::data(const QModelIndex & index, int role) const
                return (uint)list.at(index.row()).fileType;
        else if (role == FLM_CRC)
                return (uint)list.at(index.row()).crc;
+       else if (role == Qt::DisplayRole)
+       {
+               // The QListView uses this role to do keyboard based searching,
+               // so we help it along by giving it what it needs to do the job. :-)
+               unsigned long dbIndex = list.at(index.row()).dbIndex;
+               QString filename = list.at(index.row()).filename;
+               QString nameToMatch;
+
+               // Pull name from file DB, otherwise, use the filename...
+               if (dbIndex != 0xFFFFFFFF)
+                       nameToMatch = romList[dbIndex].name;
+               else
+               {
+                       int lastSlashPos = filename.lastIndexOf('/');
+                       nameToMatch = filename.mid(lastSlashPos + 1);
+               }
+
+               return nameToMatch;
+       }
 
        return QVariant();
 }