From 8549cdb01f45764f69a6483285dc0771ea66c007 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 3 Feb 2010 04:39:13 +0000 Subject: [PATCH] Start of model/view class implementation, since QListViewWidget ultimately just doesn't have what we need. --- Makefile | 1 + src/gui/filelistmodel.cpp | 118 ++++++++++++++++++++++++++++++++++++++ src/gui/filelistmodel.h | 29 ++++++++++ src/gui/filepicker.cpp | 13 ++++- src/gui/filepicker.h | 2 +- src/gui/filethread.cpp | 15 ++++- src/unzip.c | 2 +- 7 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 src/gui/filelistmodel.cpp create mode 100644 src/gui/filelistmodel.h diff --git a/Makefile b/Makefile index 2c3d82e..f0ae69e 100644 --- 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 index 0000000..b509957 --- /dev/null +++ b/src/gui/filelistmodel.cpp @@ -0,0 +1,118 @@ +// +// filepicker.cpp - A ROM chooser +// +// by James L. Hammons +// (C) 2010 Underground Software +// +// JLH = James L. Hammons +// +// 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 index 0000000..4828d38 --- /dev/null +++ b/src/gui/filelistmodel.h @@ -0,0 +1,29 @@ +// +// filelistmodel.h: Class definition +// +// by James L. Hammons +// (C) 2010 Underground Software +// + +#ifndef __FILELISTMODEL_H__ +#define __FILELISTMODEL_H__ + +#include +#include + +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 pixList; +}; + +#endif // __FILELISTMODEL_H__ diff --git a/src/gui/filepicker.cpp b/src/gui/filepicker.cpp index 13cc4d1..a221d03 100644 --- a/src/gui/filepicker.cpp +++ b/src/gui/filepicker.cpp @@ -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; } } - +*/ diff --git a/src/gui/filepicker.h b/src/gui/filepicker.h index 2978248..a476a50 100644 --- a/src/gui/filepicker.h +++ b/src/gui/filepicker.h @@ -14,7 +14,7 @@ class FilePickerWindow: public QWidget FilePickerWindow(QWidget * parent = 0); protected: - void PopulateList(void); +// void PopulateList(void); private: QListWidget * fileList; diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index 1f5a5aa..55d9e42 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -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