Rev 228 | Rev 232 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
178 | werner | 2 | /** @class OutputManager |
3 | Global container that handles data output. |
||
4 | |||
5 | */ |
||
6 | |||
173 | werner | 7 | #include "global.h" |
8 | #include "outputmanager.h" |
||
223 | werner | 9 | #include "helper.h" |
173 | werner | 10 | #include <QtCore> |
11 | |||
12 | // tree outputs |
||
13 | #include "treeout.h" |
||
179 | werner | 14 | #include "standout.h" |
184 | werner | 15 | #include "dynamicstandout.h" |
228 | werner | 16 | #include "productionout.h" |
173 | werner | 17 | |
178 | werner | 18 | |
19 | |||
173 | werner | 20 | OutputManager::OutputManager() |
21 | { |
||
231 | werner | 22 | mTransactionOpen = false; |
173 | werner | 23 | // add all the outputs |
24 | mOutputs.append(new TreeOut); |
||
179 | werner | 25 | mOutputs.append(new StandOut); |
184 | werner | 26 | mOutputs.append(new DynamicStandOut); |
228 | werner | 27 | mOutputs.append(new ProductionOut); |
184 | werner | 28 | |
173 | werner | 29 | } |
30 | |||
31 | OutputManager::~OutputManager() |
||
32 | { |
||
33 | qDeleteAll(mOutputs); |
||
34 | } |
||
35 | |||
36 | void OutputManager::setup() |
||
37 | { |
||
38 | XmlHelper &xml = const_cast<XmlHelper&>(GlobalSettings::instance()->settings()); |
||
39 | QString nodepath; |
||
40 | foreach(Output *o, mOutputs) { |
||
176 | werner | 41 | nodepath = QString("output.%1").arg(o->tableName()); |
173 | werner | 42 | xml.setCurrentNode(nodepath); |
43 | qDebug() << "setup of output" << o->name(); |
||
44 | o->setup(); |
||
181 | werner | 45 | bool enabled = xml.valueBool(".enabled", false); |
46 | o->setEnabled(enabled); |
||
47 | if (enabled) |
||
48 | o->open(); |
||
173 | werner | 49 | } |
231 | werner | 50 | endTransaction(); // just to be sur |
173 | werner | 51 | } |
176 | werner | 52 | |
53 | Output *OutputManager::find(const QString& tableName) |
||
54 | { |
||
55 | foreach(Output* p,mOutputs) |
||
56 | if (p->tableName()==tableName) |
||
57 | return p; |
||
58 | return NULL; |
||
59 | } |
||
60 | |||
222 | werner | 61 | void OutputManager::save() |
62 | { |
||
231 | werner | 63 | endTransaction(); |
222 | werner | 64 | } |
65 | |||
231 | werner | 66 | void OutputManager::startTransaction() |
67 | { |
||
68 | if (!mTransactionOpen && GlobalSettings::instance()->dbout().isValid()) { |
||
69 | GlobalSettings::instance()->dbout().transaction(); |
||
70 | qDebug() << "opening transaction"; |
||
71 | mTransactionOpen = true; |
||
72 | } |
||
73 | } |
||
74 | void OutputManager::endTransaction() |
||
75 | { |
||
76 | if (mTransactionOpen && GlobalSettings::instance()->dbout().isValid()) { |
||
77 | GlobalSettings::instance()->dbout().commit(); |
||
78 | mTransactionOpen = false; |
||
79 | qDebug() << "database transaction commited"; |
||
80 | } |
||
81 | } |
||
82 | |||
176 | werner | 83 | bool OutputManager::execute(const QString& tableName) |
84 | { |
||
223 | werner | 85 | DebugTimer t("OutputManager::execute()"); |
225 | werner | 86 | t.setSilent(); |
176 | werner | 87 | Output *p = find(tableName); |
88 | if (p) { |
||
182 | werner | 89 | if (!p->isEnabled()) |
90 | return false; |
||
91 | if(!p->isOpen()) |
||
92 | return false; |
||
207 | werner | 93 | if (!p->onNewRow()) { |
94 | qWarning() << "Output" << p->name() << "invalid (not at new row)!!!"; |
||
95 | return false; |
||
96 | } |
||
97 | |||
231 | werner | 98 | startTransaction(); // just assure a transaction is open.... nothing happens if already inside a transaction |
176 | werner | 99 | p->exec(); |
222 | werner | 100 | |
176 | werner | 101 | return true; |
102 | } |
||
103 | qDebug() << "output" << tableName << "not found!"; |
||
104 | return false; // no output found |
||
105 | } |