diff options
author | Arno <am@disconnect.de> | 2010-06-23 20:27:32 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-06-23 20:31:26 +0200 |
commit | e8f4f398c60060d4edd09065000d977cf38a9bcc (patch) | |
tree | 5860233bf58d484d779169d3cc88a92bc6fb3e1f /smmodelsingleton.cpp | |
parent | f81a83e91b77d41384667eec02409be05e088a06 (diff) | |
download | SheMov-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.
Diffstat (limited to 'smmodelsingleton.cpp')
-rw-r--r-- | smmodelsingleton.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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; +} |