DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
dbhelper.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 /* --------------------------------------------------------------------------
22  * DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
23  * AND EFFORT DISPLACEMENT
24  * Copyright (c) 2012, 2013, 2014 Francois Bastardie <fba@aqua.dtu.dk>
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License along
37  * with this program; if not, write to the Free Software Foundation, Inc.,
38  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39  * --------------------------------------------------------------------------
40  */
41 #ifndef DBHELPER_H
42 #define DBHELPER_H
43 
44 #include <QObject>
45 #include <QSqlDatabase>
46 #include <QThread>
47 #include <QMutex>
48 
49 #include <memory>
50 
52 
53 class DisplaceModel;
54 class NodeData;
55 class HarbourData;
56 class VesselData;
57 class VesselStats;
58 class PopulationData;
59 class NationStats;
60 class HarbourStats;
61 class DbHelper;
62 class Config;
63 class Scenario;
64 class FishfarmData;
65 
66 class DbHelper : public QObject
67 {
68  struct Impl;
69  std::unique_ptr<Impl> p;
70 
71  Q_OBJECT
72 
73 public:
74  DbHelper();
75  ~DbHelper() noexcept;
76 
77  bool attachDb(std::shared_ptr<SQLiteOutputStorage> storage);
78  QString lastDbError() const;
79 
80  bool Q_DECL_DEPRECATED loadConfig(Config &);
81  bool Q_DECL_DEPRECATED saveConfig (const Config &);
82  bool Q_DECL_DEPRECATED loadScenario (Scenario &);
83  bool Q_DECL_DEPRECATED saveScenario (const Scenario &);
84 
85  bool loadNodes(QList<std::shared_ptr<NodeData> > &nodes, QList<std::shared_ptr<HarbourData> > &harbours, DisplaceModel *model);
86  bool loadVessels(const QList<std::shared_ptr<NodeData> > &nodes, QList<std::shared_ptr<VesselData> > &vessels);
87  bool loadFishFarms (const QList<std::shared_ptr<NodeData> > &nodes,QList<std::shared_ptr<FishfarmData>> &fishfarms);
88 
89  /* Update datas for step */
90  bool updateVesselsToStep(int steps, QList<std::shared_ptr<VesselData> > &vessels);
91  bool updateStatsForNodesToStep(int step, QList<std::shared_ptr<NodeData> > &nodes);
92  bool updatePopValuesForNodesToStep (int step, QList<std::shared_ptr<NodeData> > &nodes);
93 
94  HarbourStats getHarbourStatsAtStep(int idx, int step);
95 
96  /* Metadata */
97 
98  void setMetadata (QString key, QString value);
99  QString getMetadata (QString key);
100 
101  int getLastKnownStep();
102 
103 private:
104  QMutex mMutex;
105 };
106 
107 #endif // DBHELPER_H
bool Q_DECL_DEPRECATED saveScenario(const Scenario &)
Definition: dbhelper.cpp:196
Definition: dbhelper.cpp:55
bool Q_DECL_DEPRECATED loadScenario(Scenario &)
Definition: dbhelper.cpp:177
vector< Vessel * > vessels
Definition: main.cpp:199
bool Q_DECL_DEPRECATED loadConfig(Config &)
Definition: dbhelper.cpp:88
Definition: harbourdata.h:29
QString lastDbError() const
Definition: dbhelper.cpp:83
HarbourStats getHarbourStatsAtStep(int idx, int step)
Definition: dbhelper.cpp:349
vector< Fishfarm * > fishfarms
Definition: main.cpp:203
vector< Node * > nodes
Definition: main.cpp:270
bool loadFishFarms(const QList< std::shared_ptr< NodeData > > &nodes, QList< std::shared_ptr< FishfarmData >> &fishfarms)
Definition: dbhelper.cpp:256
bool loadVessels(const QList< std::shared_ptr< NodeData > > &nodes, QList< std::shared_ptr< VesselData > > &vessels)
Definition: dbhelper.cpp:237
Definition: vesseldata.h:152
bool updatePopValuesForNodesToStep(int step, QList< std::shared_ptr< NodeData > > &nodes)
Definition: dbhelper.cpp:296
QString getMetadata(QString key)
Definition: dbhelper.cpp:413
bool loadNodes(QList< std::shared_ptr< NodeData > > &nodes, QList< std::shared_ptr< HarbourData > > &harbours, DisplaceModel *model)
Definition: dbhelper.cpp:215
Definition: config.h:49
Definition: nationdata.h:38
bool Q_DECL_DEPRECATED saveConfig(const Config &)
Definition: dbhelper.cpp:139
Definition: harbourdata.h:46
void setMetadata(QString key, QString value)
Definition: dbhelper.cpp:404
Definition: displacemodel.h:71
std::pair< box, unsigned > value
Definition: diffusion.cpp:30
an extension class for Node
Definition: nodedata.h:43
int getLastKnownStep()
Definition: dbhelper.cpp:424
Definition: fishfarmdata.h:31
DbHelper()
Definition: dbhelper.cpp:67
bool updateVesselsToStep(int steps, QList< std::shared_ptr< VesselData > > &vessels)
Definition: dbhelper.cpp:267
bool attachDb(std::shared_ptr< SQLiteOutputStorage > storage)
Definition: dbhelper.cpp:73
Definition: populationdata.h:26
Definition: vesseldata.h:31
Definition: sqliteoutputstorage.h:37
Definition: dbhelper.h:66
Definition: scenario.h:51
bool updateStatsForNodesToStep(int step, QList< std::shared_ptr< NodeData > > &nodes)
Definition: dbhelper.cpp:317
~DbHelper() noexcept