summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-06-23 20:27:32 +0200
committerArno <am@disconnect.de>2010-06-23 20:31:26 +0200
commite8f4f398c60060d4edd09065000d977cf38a9bcc (patch)
tree5860233bf58d484d779169d3cc88a92bc6fb3e1f
parentf81a83e91b77d41384667eec02409be05e088a06 (diff)
downloadSheMov-e8f4f398c60060d4edd09065000d977cf38a9bcc.tar.gz
SheMov-e8f4f398c60060d4edd09065000d977cf38a9bcc.tar.bz2
SheMov-e8f4f398c60060d4edd09065000d977cf38a9bcc.zip
Singleton cleanup
The SmUberModel class wasn't needed at all, so I removed it. Instead I renamed SmUmberModelSingleton into a real singleton for all QAbstractItemModel*, though right now it only supports the SeriesTreeModel and FileTreeModel. But it should eventually evolve into a singleton for all QAbstractItemModel *. For this I renamed the class SmUberModelSingleton to SmModelSingleton.
-rw-r--r--archivetreeview.cpp8
-rw-r--r--archivetreeview.h2
-rw-r--r--seriestreemodel.h3
-rw-r--r--seriestreewidget.cpp5
-rw-r--r--shemov.cpp5
-rw-r--r--shemov.pro6
-rw-r--r--smmodelsingleton.cpp55
-rw-r--r--smmodelsingleton.h30
-rw-r--r--smubermodel.cpp61
-rw-r--r--smubermodel.h40
-rw-r--r--smubermodelsingleton.cpp18
-rw-r--r--smubermodelsingleton.h24
12 files changed, 96 insertions, 161 deletions
diff --git a/archivetreeview.cpp b/archivetreeview.cpp
index 4131218..fbc9254 100644
--- a/archivetreeview.cpp
+++ b/archivetreeview.cpp
@@ -11,15 +11,11 @@
#include <QVBoxLayout>
#include "archivetreeview.h"
-#include "smubermodel.h"
-#include "smubermodelsingleton.h"
+#include "smmodelsingleton.h"
#include "smtreemodel.h"
#include "seriestreewidget.h"
-ArchiveTreeView::ArchiveTreeView(QWidget *parent) : QWidget(parent), mUberModel(0){
- // get model
- mUberModel = SmUberModelSingleton::instance();
-
+ArchiveTreeView::ArchiveTreeView(QWidget *parent) : QWidget(parent){
// series view
mSeriesWidget = new SeriesTreeWidget;
diff --git a/archivetreeview.h b/archivetreeview.h
index fc3e2fe..2f07d2f 100644
--- a/archivetreeview.h
+++ b/archivetreeview.h
@@ -26,8 +26,6 @@ class ArchiveTreeView : public QWidget
SeriesTreeWidget *mSeriesWidget;
QTreeView *mFilesView;
- //models
- SmUberModel *mUberModel;
};
#endif
diff --git a/seriestreemodel.h b/seriestreemodel.h
index 7933310..a0c5a23 100644
--- a/seriestreemodel.h
+++ b/seriestreemodel.h
@@ -24,6 +24,9 @@ class SeriesTreeModel : public SmTreeModel {
explicit SeriesTreeModel(QStringList &headers, QObject *parent = 0);
~SeriesTreeModel();
+ //numColumns
+ int numColumns() const { return 5; }
+
//data + flags
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role) const;
diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp
index e919c20..5415655 100644
--- a/seriestreewidget.cpp
+++ b/seriestreewidget.cpp
@@ -19,9 +19,8 @@
#include <QSettings>
#include "seriestreewidget.h"
-#include "smubermodel.h"
#include "smtreemodel.h"
-#include "smubermodelsingleton.h"
+#include "smmodelsingleton.h"
#include "seriestreemodel.h"
SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){
@@ -40,7 +39,7 @@ SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){
//the view
mView = new SeriesTreeView;
mProxy = new SeriesTreeSortModel(this);
- mModel = SmUberModelSingleton::instance()->seriesModel();
+ mModel = static_cast<SeriesTreeModel*>(SmModelSingleton::instance()->model("SeriesModel"));
mProxy->setSourceModel(mModel);
mView->setModel(mProxy);
mView->setSortingEnabled(true);
diff --git a/shemov.cpp b/shemov.cpp
index 223e6fa..a33c172 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -45,8 +45,7 @@
#include "listmodelsingleton.h"
#include "pictureviewer.h"
#include "archivetreeview.h"
-#include "smubermodelsingleton.h"
-#include "smubermodel.h"
+#include "smmodelsingleton.h"
#include "seriestreewidget.h"
SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), mOpenWithGroupFS(0), mOpenWithGroupAV(0) {
@@ -121,7 +120,7 @@ void SheMov::closeEvent(QCloseEvent *event){
mFSWidget->writeSettings();
mFSWidget->pictureViewer()->close();
mATree->seriesWidget()->writeSettings();
- delete SmUberModelSingleton::instance();
+ delete SmModelSingleton::instance();
writeSettings();
event->accept();
}
diff --git a/shemov.pro b/shemov.pro
index dab8541..585a7b1 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -48,8 +48,7 @@ SOURCES = main.cpp \
archiveitemeditdialog.cpp \
smtreeitem.cpp \
smtreemodel.cpp \
- smubermodel.cpp \
- smubermodelsingleton.cpp \
+ smmodelsingleton.cpp \
archivetreeview.cpp \
seriestreewidget.cpp \
seriestreemodel.cpp \
@@ -97,8 +96,7 @@ HEADERS = listitem.h \
archiveitemeditdialog.h \
smtreeitem.h \
smtreemodel.h \
- smubermodel.h \
- smubermodelsingleton.h \
+ smmodelsingleton.h \
archivetreeview.h \
seriestreewidget.h \
seriestreemodel.h \
diff --git a/smmodelsingleton.cpp b/smmodelsingleton.cpp
new file mode 100644
index 0000000..d850c9d
--- /dev/null
+++ b/smmodelsingleton.cpp
@@ -0,0 +1,55 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#include <QSqlDatabase>
+#include <QAbstractItemModel>
+#include <QStringList>
+
+#include "smmodelsingleton.h"
+#include "seriestreemodel.h"
+#include "filestreemodel.h"
+
+SmModelSingleton *SmModelSingleton::mInstance = 0;
+
+SmModelSingleton::~SmModelSingleton(){
+ foreach(QAbstractItemModel *model, mModels.values()){
+ delete model;
+ }
+ QSqlDatabase::removeDatabase("treedb");
+}
+
+SmModelSingleton *SmModelSingleton::instance(){
+ if(!mInstance){
+ mInstance = new SmModelSingleton;
+ if(!QSqlDatabase::contains("treedb")){
+ QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", "treedb");
+ db.setHostName("hadante");
+ db.setUserName("shemov");
+ db.setPassword("shemov");
+ db.setDatabaseName("shemov2");
+ db.open();
+ }
+ }
+ return mInstance;
+}
+
+QAbstractItemModel *SmModelSingleton::model(const QString &which){
+ if(which == "SeriesModel"){
+ if(!mModels.contains(which)){
+ QStringList headers = QStringList() << tr("Series") << tr("Series ID") << tr("Series part ID") << tr("Part") << tr("Type");
+ SeriesTreeModel *model = new SeriesTreeModel(headers);
+ mModels.insert(which, model);
+ }
+ }else if(which == "FilesModel"){
+ if(!mModels.contains(which)){
+ QStringList headers = QStringList() << tr("Name") << tr("P") << tr("Size") << tr("Q") << tr("DvdNo") << tr("Full Path") << tr("Size") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID");
+ FilesTreeModel *model = new FilesTreeModel(headers);
+ mModels.insert(which, model);
+ }
+ }
+ return mModels.contains(which) ? mModels.value(which ) : 0;
+}
diff --git a/smmodelsingleton.h b/smmodelsingleton.h
new file mode 100644
index 0000000..e8a3eaf
--- /dev/null
+++ b/smmodelsingleton.h
@@ -0,0 +1,30 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#ifndef SMUBERMODELSINGLETON_H
+#define SMUBERMODELSINGLETON_H
+
+#include <QHash>
+
+class QAbstractItemModel;
+
+class SmModelSingleton : public QObject {
+ Q_OBJECT
+ public:
+ ~SmModelSingleton();
+ static SmModelSingleton *instance();
+ QAbstractItemModel *model(const QString &which);
+
+ private:
+ SmModelSingleton() {}
+ SmModelSingleton(const SmModelSingleton &other);
+ SmModelSingleton &operator=(const SmModelSingleton &other);
+ static SmModelSingleton *mInstance;
+ QHash<QString, QAbstractItemModel*> mModels;
+};
+
+#endif
diff --git a/smubermodel.cpp b/smubermodel.cpp
deleted file mode 100644
index 2e7ae42..0000000
--- a/smubermodel.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#include <QSqlQuery>
-#include <QList>
-#include <QVariant>
-
-#include <QDebug>
-
-#include "smubermodel.h"
-#include "smtreemodel.h"
-#include "seriestreemodel.h"
-#include "smtreeitem.h"
-#include "actormodel.h"
-
-SmUberModel::SmUberModel(QObject *parent) : QObject(parent), mSeriesModel(0), mFileModel(0), mActorModel(0){
- //db setup
- mDb = QSqlDatabase::addDatabase("QPSQL", "treedb");
- mDb.setHostName("hadante");
- mDb.setUserName("shemov");
- mDb.setPassword("shemov");
- mDb.setDatabaseName("shemov2");
- mDb.open();
- mSeriesPartsQuery = new QSqlQuery(mDb);
- //mSeriesPartsQuery->prepare("SELECT iseriesparts_id, iseriespart, iseries_id, iquality FROM seriesparts WHERE iseries_id = :id ORDER BY iseriespart");
-
- //series model
- QStringList seriesHeaders = QStringList() << tr("Series") << QString() << QString() << QString() << QString();
- mSeriesModel = new SeriesTreeModel(seriesHeaders, this);
- //populateSeriesmodel();
-}
-
-SmUberModel::~SmUberModel(){
- delete mSeriesModel;
- mDb = QSqlDatabase();
- QSqlDatabase::removeDatabase("treedb");
-}
-
-/*void SmUberModel::populateSeriesmodel(){
- QSqlQuery seriesQuery("SELECT iseries_id, tseries_name FROM series ORDER BY tseries_name", mDb);
- SmTreeItem *root = new SmTreeItem(3);
- while(seriesQuery.next()){
- QList<QVariant> seriesData;
- seriesData << seriesQuery.value(1) << QVariant() << seriesQuery.value(0);
- SmTreeItem *seriesItem = new SmTreeItem(seriesData, root);
- root->appendChild(seriesItem);
- mSeriesPartsQuery->bindValue(":id", seriesQuery.value(0));
- mSeriesPartsQuery->exec();
- while(mSeriesPartsQuery->next()){
- QList<QVariant> partsData;
- QString title = QString("%1 %2").arg(seriesData.at(0).toString()).arg(mSeriesPartsQuery->value(1).toInt());
- partsData << title << mSeriesPartsQuery->value(3) << mSeriesPartsQuery->value(0);
- seriesItem->appendChild(new SmTreeItem(partsData, seriesItem));
- }
- }
- mSeriesModel->setRoot(root);
-}*/
diff --git a/smubermodel.h b/smubermodel.h
deleted file mode 100644
index 8d82a47..0000000
--- a/smubermodel.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#ifndef SMUBERMODEL_H
-#define SMUBERMODEL_H
-
-#include <QObject>
-#include <QSqlDatabase>
-
-#include "seriestreemodel.h"
-
-class SmTreeModel;
-class ActorModel;
-class QSqlQuery;
-
-class SmUberModel : public QObject {
- Q_OBJECT
- public:
- explicit SmUberModel(QObject *parent = 0);
- SeriesTreeModel *seriesModel() { return mSeriesModel; }
- ~SmUberModel();
-
- private:
- //void populateSeriesmodel();
- //database
- QSqlDatabase mDb;
- QSqlQuery *mSeriesPartsQuery;
-
- //models
- SeriesTreeModel *mSeriesModel;
- SmTreeModel *mFileModel;
- ActorModel *mActorModel;
-
-};
-
-#endif
diff --git a/smubermodelsingleton.cpp b/smubermodelsingleton.cpp
deleted file mode 100644
index ef3d1e3..0000000
--- a/smubermodelsingleton.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#include "smubermodelsingleton.h"
-#include "smubermodel.h"
-
-SmUberModel *SmUberModelSingleton::mInstance = 0;
-
-SmUberModel *SmUberModelSingleton::instance(){
- if(!mInstance){
- mInstance = new SmUberModel;
- }
- return mInstance;
-}
diff --git a/smubermodelsingleton.h b/smubermodelsingleton.h
deleted file mode 100644
index 80b2313..0000000
--- a/smubermodelsingleton.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version
- 2 of the License, or (at your option) any later version.
-*/
-
-#ifndef SMUBERMODELSINGLETON_H
-#define SMUBERMODELSINGLETON_H
-
-class SmUberModel;
-
-class SmUberModelSingleton {
- public:
- static SmUberModel *instance();
-
- private:
- SmUberModelSingleton() {}
- SmUberModelSingleton(const SmUberModelSingleton &other);
- SmUberModelSingleton &operator=(const SmUberModelSingleton &other);
- static SmUberModel *mInstance;
-};
-
-#endif