]> Shamusworld >> Repos - virtualjaguar/commitdiff
Start of model/view class implementation, since QListViewWidget ultimately
authorShamus Hammons <jlhamm@acm.org>
Wed, 3 Feb 2010 04:39:13 +0000 (04:39 +0000)
committerShamus Hammons <jlhamm@acm.org>
Wed, 3 Feb 2010 04:39:13 +0000 (04:39 +0000)
just doesn't have what we need.

Makefile
src/gui/filelistmodel.cpp [new file with mode: 0644]
src/gui/filelistmodel.h [new file with mode: 0644]
src/gui/filepicker.cpp
src/gui/filepicker.h
src/gui/filethread.cpp
src/unzip.c

index 2c3d82eaa6c21276ca4604e3c9565ed7ad5f315a..f0ae69e7a65f878cc199520d692d37799f9a0e36 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -76,6 +76,7 @@ OBJS = \
        obj/app.o           \
        obj/configwin.o     \
        obj/filepicker.o    \
+       obj/filelistmodel.o \
        obj/filethread.o    \
        obj/mainwin.o       \
        obj/moc_mainwin.o   \
diff --git a/src/gui/filelistmodel.cpp b/src/gui/filelistmodel.cpp
new file mode 100644 (file)
index 0000000..b509957
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// filepicker.cpp - A ROM chooser
+//
+// by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -------------------------------------------------------------
+// JLH  02/01/2010  Created this file
+//
+
+// Note that we have to put in convenience functions to the model for adding data
+// and calling reset() to tell the view(s) that the model has changed. So that much
+// should be simple. According to the docs, we have to reimplement flags() in the
+// QAbstractListModel subclass, but in the example given below they don't. Not sure
+// if it's necessary or not.
+
+#include "filelistmodel.h"
+
+
+FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent)
+{
+}
+
+int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const
+{
+       return pixList.size();
+}
+
+QVariant FileListModel::data(const QModelIndex & index, int role) const
+{
+//     return QVariant();
+       return pixList.at(index.row());
+}
+
+QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const
+{
+       // 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);
+}
+
+void FileListModel::AddData(QIcon pix)
+{
+       pixList.push_back(pix);
+       reset();
+}
+
+
+#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
diff --git a/src/gui/filelistmodel.h b/src/gui/filelistmodel.h
new file mode 100644 (file)
index 0000000..4828d38
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// filelistmodel.h: Class definition
+//
+// by James L. Hammons
+// (C) 2010 Underground Software
+//
+
+#ifndef __FILELISTMODEL_H__
+#define __FILELISTMODEL_H__
+
+#include <QtGui>
+#include <vector>
+
+class FileListModel: public QAbstractListModel
+{
+       public:
+               FileListModel(QObject * parent = 0);
+
+               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;
+
+               void AddData(QIcon pix);
+
+       private:
+               std::vector<QIcon> pixList;
+};
+
+#endif // __FILELISTMODEL_H__
index 13cc4d1ad11b08863b36e8dd42616dbfd78d9bde..a221d03a2fbd3f030dd6a99b95a09b8e556b2202 100644 (file)
@@ -112,6 +112,7 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt:
 {
        setWindowTitle("Insert Cartridge...");
 
+#if 1
        fileList = new QListWidget(this);
 //     addWidget(fileList);
 
@@ -124,8 +125,18 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt:
 //     PopulateList();
        fileThread = new FileThread(this);
        fileThread->Go(fileList);
+#else
+QStringList numbers;
+numbers << "One" << "Two" << "Three" << "Four" << "Five";
+
+QAbstractItemModel * model = new StringListModel(numbers);
+QListView * view = new QListView;
+view->setModel(model);
+
+#endif
 }
 
+/*
 void FilePickerWindow::PopulateList(void)
 {
        QDir romDir(vjs.ROMPath);
@@ -161,4 +172,4 @@ printf("FilePickerWindow: Found match [%s]...\n", romList2[j].name);
                delete[] buffer;
        }
 }
-
+*/
index 2978248521ba5ebe1e8318934983dee201e51210..a476a50c8817a619064ec9dedc43da5e4b370a61 100644 (file)
@@ -14,7 +14,7 @@ class FilePickerWindow: public QWidget
                FilePickerWindow(QWidget * parent = 0);
 
        protected:
-               void PopulateList(void);
+//             void PopulateList(void);
 
        private:
                QListWidget * fileList;
index 1f5a5aab51223e50e6d11af57d6a4f6b4c8d3214..55d9e4223a8a93b93615e8ae7923c944f869eb81 100644 (file)
@@ -133,10 +133,22 @@ void FileThread::run(void)
        QDir romDir(vjs.ROMPath);
        QFileInfoList list = romDir.entryInfoList();
 
+/*
+Another thing we'll probably have to do here is check for compressed files and
+decompress/fish around in them to find what we need. :-P
+*/
+
        for(int i=0; i<list.size(); i++)
        {
                if (abort)
+#if 1
+{
+printf("FileThread: Aborting!!!\n");
+#endif
                        return;
+#if 1
+}
+#endif
 
                QFileInfo fileInfo = list.at(i);
                QFile file(romDir.filePath(fileInfo.fileName()));
@@ -164,7 +176,8 @@ printf("FileThread: Found match [%s]...\n", romList[index].name);
 }
 
 //
-// Find a CRC in the ROM list. If it's there, return the index, otherwise return $FFFFFFFF
+// Find a CRC in the ROM list (simple brute force algorithm).
+// If it's there, return the index, otherwise return $FFFFFFFF
 //
 uint32 FileThread::FindCRCIndexInFileList(uint32 crc)
 {
index 9e6c4a319da084861358dded1b59c20423bb5324..5c3d119f9eacc201719a631a5891a794825ae080 100644 (file)
@@ -833,7 +833,7 @@ static int equal_filename(const char * zipfile, const char * file)
 
 //
 // Pass the path to the zipfile and the name of the file within the zipfile.
-// buf will be set to point to the uncompressed image of that zipped file.
+// buf is set to point to the uncompressed image of that zipped file (preallocated by user!).
 // length will be set to the length of the uncompressed data.
 //
 int load_zipped_file(int pathtype, int pathindex, const char * zipfile, const char * filename, unsigned char ** buf, uint32_t * length)