Fixed two cases of memory loss (parenting was missing).
[emufront] / src / db / dbfilepath.cpp
index f8bb72a..13b5778 100644 (file)
@@ -5,9 +5,9 @@
 //
 //
 // EmuFront 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 3 of the License, or
-// (at your option) any later version.
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
 //
 // EmuFront is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "dbfilepath.h"
 #include "dbsetup.h"
 
+
 DbFilePath::DbFilePath(QObject *parent) : DbQueryModelManager(parent)
 {
+    tableName = DbFilePath::DB_TABLE_NAME_FILEPATH;
     dbSetup = new DbSetup(this);
 }
 
@@ -78,11 +80,6 @@ int DbFilePath::insertDataObjectToModel(const EmuFrontObject *ob)
     return id;
 }
 
-int DbFilePath::countDataObjectRefs(int id) const
-{
-    return 0;
-}
-
 // WARNING: this will delete also all the databindings to selected media image path
 bool DbFilePath::deleteDataObjectFromModel(QModelIndex *index)
 {
@@ -102,9 +99,6 @@ bool DbFilePath::deleteDataObject(int id) const
 
 QString DbFilePath::constructSelect(QString where) const
 {
-    /*QString where = whereClause.isEmpty()
-        ? "" : QString("WHERE ").append(whereClause);*/
-
     return QString("SELECT filepath.id AS FilePathId, "
             "filepath.name AS Name, "
             "filepath.lastscanned AS LastScanned, "
@@ -131,7 +125,7 @@ QString DbFilePath::constructSelectById(int id) const
 
 QSqlQueryModel* DbFilePath::getData()
 {
-    QSqlQueryModel *model = new QSqlQueryModel;
+    QSqlQueryModel *model = new QSqlQueryModel(this);
     model->setQuery(constructSelect());
     model->setHeaderData(FilePath_Id, Qt::Horizontal, tr("Id"));
     model->setHeaderData(FilePath_Name, Qt::Horizontal, tr("Name"));
@@ -140,3 +134,12 @@ QSqlQueryModel* DbFilePath::getData()
     model->setHeaderData(FilePath_SetupName, Qt::Horizontal, tr("Set up"));
     return model;
 }
+
+QString DbFilePath::getCountRefsSelect(int id) const
+{
+    /* filepath is referenced from mediaimagecontainer */
+    return QString("SELECT count(*) FROM filepath"
+              "INNER JOIN mediaimagecontainer "
+              "ON filepath.id=mediaimagecontainer.filepathid"
+              "WHERE filepath.id=%1").arg(id);
+}