-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix8log.cpp.brok
642 lines (602 loc) · 26 KB
/
fix8log.cpp.brok
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
//-------------------------------------------------------------------------------------------------
/*
Fix8logviewer is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
Fix8logviewer Open Source FIX Log Viewer.
Copyright (C) 2010-14 David N Boosalis [email protected], David L. Dight <[email protected]>
Fix8logviewer is free software: you can redistribute it and / or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
Fix8logviewer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU Lesser General Public License along with Fix8.
If not, see <http://www.gnu.org/licenses/>.
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
//-------------------------------------------------------------------------------------------------
#include "database.h"
#include "fix8log.h"
#include "fixmimedata.h"
#include "globals.h"
#include "mainwindow.h"
#include "messagefield.h"
#include "schemaeditordialog.h"
#include "worksheetmodel.h"
#include "windowdata.h"
#include <QApplication>
#include <QDebug>
#include <QtWidgets>
#include "worksheetmodel.h"
#include <fix8/f8includes.hpp>
#include "fix8/field.hpp"
#include "fix8/message.hpp"
#include <fix8/f8types.hpp>
#include <Myfix_types.hpp>
#include <Myfix_router.hpp>
#include <Myfix_classes.hpp>
#include <iostream>
#include <string.h>
using namespace GUI;
using namespace FIX8;
using namespace std;
Fix8Log::Fix8Log(QtSingleApplication *qsa) :
QObject(),firstTimeToUse(false),database(0),autoSaveOn(false),
cancelSessionRestore(false),schemaEditorDialog(0),tableSchemaList(0),
defaultTableSchema(0),worldTableSchema(0),applicationInstance(qsa),searchDialog(0),searchFunctionList(0)
{
Globals::Instance()->version = 0.1;
Globals::Instance()->versionStr = "0.1";
connect(qApp,SIGNAL(lastWindowClosed()),this,SLOT(lastWindowClosedSlot()));
defaultHeaderStrs << "MsgSeqNum" << "MsgType" << "SendingTime" << "SenderCompID" << "TargetCompID";
}
/* Clean windows data ->verify schema is good */
void Fix8Log::cleanWindowDataList(QList <WindowData> &windowDataList)
{
WindowData *wd;
TableSchema *ts;
int tsid;
if (windowDataList.count()<1) {
qWarning() << "Error - clean window data list failed, list is empty" << __FILE__ << __LINE__;
return;
}
QListIterator <WindowData> iter(windowDataList);
while(iter.hasNext()) {
wd = (WindowData *)&iter.next();
tsid = wd->tableSchemaID;
if (!tableSchemaList) {
qWarning() << "Table Schema List is NULL " << " so setting to default" << __FILE__ << __LINE__;
wd->tableSchema = defaultTableSchema;
if (!defaultTableSchema) {
qWarning() << "ERROR - DEFAULT TABLE SCHEMA NOT SET" << __FILE__ << __LINE__;
}
else
wd->tableSchemaID = defaultTableSchema->id;
}
else {
wd->tableSchema = tableSchemaList->findByID(tsid);
if (!wd->tableSchema) {
qWarning() << "Could not find table schema for window " << wd->name;
qWarning() << "Resetting to default table schema" << __FILE__ << __LINE__;
wd->tableSchema = defaultTableSchema;
if (!defaultTableSchema) {
qWarning() << "ERROR - DEFAULT TABLE SCHEMA NOT SET" << __FILE__ << __LINE__;
}
else
wd->tableSchemaID = defaultTableSchema->id;
}
}
}
}
void Fix8Log::copyWindowSlot(MainWindow *mw)
{
MainWindow *newMW =new MainWindow(*mw,database,true);
newMW->setSearchFunctions(searchFunctionList);
wireSignalAndSlots(newMW);
newMW->show();
mainWindows.append(newMW);
}
void Fix8Log::wireSignalAndSlots(MainWindow *mw)
{
if (!mw) {
qWarning() << "Error - wire signals and slots, window is null" << __FILE__ << __LINE__;
return;
}
mw->
connect(mw,SIGNAL(toolButtonStyleModified(Qt::ToolButtonStyle)),
this,SLOT(toolButtonStyleModfiedSlot(Qt::ToolButtonStyle)));
connect(mw,SIGNAL(createWindow(MainWindow*)),this,SLOT(createNewWindowSlot(MainWindow*)));
connect(mw,SIGNAL(copyWindow(MainWindow*)),this,SLOT(copyWindowSlot(MainWindow*)));
connect(mw,SIGNAL(deleteWindow(MainWindow*)),this,SLOT(deleteMainWindowSlot(MainWindow*)));
connect(mw,SIGNAL(exitApp()),this,SLOT(exitAppSlot()));
connect(mw,SIGNAL(autoSaveOn(bool)),this,SLOT(autoSaveOnSlot(bool)));
connect(mw,SIGNAL(cancelSessionRestore()),this,SLOT(cancelSessionRestoreSlot()));
connect(mw,SIGNAL(notifyTimeFormatChanged(GUI::Globals::TimeFormat)),
this,SLOT(setTimeFormatSlot(GUI::Globals::TimeFormat)));
connect(this,SIGNAL(notifyTimeFormatChanged(GUI::Globals::TimeFormat)),
mw,SLOT(setTimeFormatSlot(GUI::Globals::TimeFormat)));
connect(mw,SIGNAL(modelDropped(FixMimeData*)),this,SLOT(modelDroppedSlot(FixMimeData*)));
connect(mw,SIGNAL(editSchema(MainWindow*)),this,SLOT(editSchemaSlot(MainWindow *)));
connect(mw,SIGNAL(tableSchemaChanged(TableSchema*)),this,SLOT(tableSchemaSelectedSlot(TableSchema *)));
connect(mw,SIGNAL(showSearchDialog()),this,SLOT(showSearchDialogSlot()));
connect(mw,SIGNAL(showSearchDialogAddMode(QString)),this,SLOT(showSearchDialogAddModeSlot(QString)));
mw->setAutoSaveOn(autoSaveOn);
}
void Fix8Log::displayConsoleMessage(QString str, GUI::ConsoleMessage::ConsoleMessageType mt)
{
GUI::ConsoleMessage m(str,mt);
displayConsoleMessage(m);
}
void Fix8Log::generate_traits(const TraitHelper& tr,QMap <QString, QBaseEntry *> &baseMap,FieldUseList &ful,
MessageField *mf,QList <QBaseEntry *> *qbaseEntryList,int *level)
{
int ii = 0;
for (F8MetaCntx::const_iterator itr(F8MetaCntx::begin(tr)); itr != F8MetaCntx::end(tr); ++itr)
{
QBaseEntry *qbe;
FieldUse *fieldUse = 0;
QString name;
const BaseEntry *be(TEX::ctx().find_be(itr->_fnum)); // lookup the field
if(qbaseEntryList) {
qbe = baseMap.value(be->_name);
if (!qbe) {
qbe = new QBaseEntry(*be);
qbe->ft = new FieldTrait(*itr);
//qDebug () << "Number2 " << qbe->ft->_fnum;
baseMap.insert(qbe->name,qbe);
}
name = qbe->name;
qbaseEntryList->append(qbe);
if (defaultHeaderStrs.contains(name)) {
if (!defaultHeaderItems.findByName(name))
defaultHeaderItems.append(qbe);
}
fieldUse = ful.findByName(name);
if (!fieldUse) {
fieldUse = new FieldUse();
fieldUse->name = name;
fieldUse->field = qbe->ft;
ful.append(fieldUse);
}
fieldUse->messageFieldList.append(mf);
}
else
qWarning() << "\t\tERROR QBASELIST = 0" ;
//MessageBase *header = new Message::Header();
//cout << "Field Type: " << ft._ftype << endl;
//cout << spacer << "\t" << *itr << endl; // use FieldTrait insert operator. g out traits.
if (itr->_field_traits.has(FieldTrait::group)) {// any nested repeating groups?
qbe->baseEntryList = new QList<QBaseEntry *>();
generate_traits(itr->_group,baseMap,ful,mf,qbe->baseEntryList,level); // descend into repeating groups
}
ii++;
}
}
void Fix8Log::generate_traits(const TraitHelper& tr,QMap <QString, QBaseEntry *> &baseMap,FieldUseList &ful,
MessageField *mf,QBaseEntryList *qbaseEntryList,int *level)
{
int ii = 0;
QString name;
for (F8MetaCntx::const_iterator itr(F8MetaCntx::begin(tr)); itr != F8MetaCntx::end(tr); ++itr)
{
QBaseEntry *qbe;
FieldUse *fieldUse = 0;
const BaseEntry *be(TEX::ctx().find_be(itr->_fnum)); // lookup the field
if(qbaseEntryList) {
qbe = baseMap.value(be->_name);
if (!qbe) {
qbe = new QBaseEntry(*be);
qbe->ft = new FieldTrait(*itr);
baseMap.insert(qbe->name,qbe);
}
name = qbe->name;
qbaseEntryList->append(qbe);
fieldUse = ful.findByName(name);
if (!fieldUse) {
fieldUse = new FieldUse();
fieldUse->name = name;
fieldUse->field = qbe->ft;
ful.append(fieldUse);
}
fieldUse->messageFieldList.append(mf);
if (defaultHeaderStrs.contains(name)) {
if (!defaultHeaderItems.findByName(name))
defaultHeaderItems.append(qbe);
}
}
if (itr->_field_traits.has(FieldTrait::group)) {// any nested repeating groups?
qbe->baseEntryList = new QList<QBaseEntry *>();
(*level)++;
generate_traits(itr->_group,baseMap,ful,mf,qbe->baseEntryList,level); // descend into repeating groups
}
ii++;
}
}
bool Fix8Log::init()
{
bool bstatus;
bool fistTimeForDefaultTableSchema = false;
bool createdTable = false;
QString dbFileName = "fix8log.sql";
QString errorStr;
WorkSheetModel *model = 0;
QList <WindowData> windowDataList;
WindowData wd;
QString dbPath = QCoreApplication::applicationDirPath() + QDir::separator() + "share";
QDir dir(dbPath);
readSettings();
if (!dir.exists()) {
bstatus = dir.mkdir(dbPath);
if (!bstatus) {
errorStr = "Failed to create directory\n" + dbPath +
"\nPlease make sure you have write access to this directory";
QMessageBox::warning(0,"Fix8Log Error", errorStr);
qApp->exit();
}
else {
displayConsoleMessage(GUI::ConsoleMessage("Created Database Directory:" + dbPath));
}
}
dbFileName = dbPath + QDir::separator() + dbFileName;
QFile dbFile(dbFileName);
if (!dbFile.exists()) {
firstTimeToUse = true;
GUI::Globals::isFirstTime = true;
displayConsoleMessage(GUI::ConsoleMessage("Creating Database..."));
}
database = new Database(dbFileName,this);
bstatus = database->open();
if (!bstatus) {
errorStr = "Error - open local database: " + dbFileName
+ " failed " + __FILE__;
QMessageBox::warning(0,"Local Database",errorStr);
qApp->exit();
}
bstatus = database->tableIsValid(Database::Windows);
if (!bstatus) {
bstatus = database->createTable(Database::Windows);
if (!bstatus) {
errorStr = "Failed to create windows table.";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
bstatus = database->tableIsValid(Database::WorkSheet);
if (!bstatus) {
bstatus = database->createTable(Database::WorkSheet);
if (!bstatus) {
errorStr = "Failed to create worksheet table.";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
bstatus = database->tableIsValid(Database::SchemaFields);
if (!bstatus) {
bstatus = database->createTable(Database::SchemaFields);
if (!bstatus) {
errorStr = "Failed to create table fields table.";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
bstatus = database->tableIsValid(Database::SearchFunctions);
if (!bstatus) {
qWarning() << "Cerateing Search Table" << __FILE__ << __LINE__;
bstatus = database->createTable(Database::SearchFunctions);
if (!bstatus) {
errorStr = "Failed to create table search table.";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
else
searchFunctionList = database->getSearchFunctions();
bstatus = database->tableIsValid(Database::TableSchemas);
if (!bstatus) {
bstatus = database->createTable(Database::TableSchemas);
if (!bstatus) {
errorStr = "Failed to create table table.";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
else {
// create default schema ...
TableSchema *ts = new TableSchema("Default","Default Table Schema",true);
if (ts) {
bstatus = database->addTableSchema(*ts);
if (!bstatus) {
errorStr = "Failed to create default table schema";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
else {
tableSchemaList = database->getTableSchemas();
defaultTableSchema = tableSchemaList->findByName("Default");
if (!tableSchemaList) {
errorStr = "Error - no table schemas found in database";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
}
}
}
else {
tableSchemaList = database->getTableSchemas();
if (!tableSchemaList) {
errorStr = "Error - no table schemas found in database, creating default....";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::WarningMsg));
//defaultTableSchema = new TableSchema("Default","Default Table Schema",true);
/*
bstatus = database->addTableSchema(*defaultTableSchema);
if (!bstatus) {
errorStr = "Failed to add default table schema to database";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
else {
tableSchemaList = new TableSchemaList();
tableSchemaList->append(defaultTableSchema);
}
*/
}
/*
else { // lets make sure we have default table schema, else create it
defaultTableSchema = tableSchemaList->findByName("Default");
if(!defaultTableSchema) {
errorStr = "Failed to find default table schema, creating it...";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::WarningMsg));
defaultTableSchema = new TableSchema("Default","Default Table Schema",true);
tableSchemaList->append(defaultTableSchema);
bstatus = database->addTableSchema(*defaultTableSchema);
if (!bstatus) {
errorStr = "Failed to add default table schema to database 2";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
MainWindow::defaultTableSchema = defaultTableSchema;
}
*/
}
if (tableSchemaList) {
QListIterator <TableSchema *> tsIter(*tableSchemaList);
while(tsIter.hasNext()) {
TableSchema *ts = tsIter.next();
ts->fieldNames = database->getSchemaFields(ts->id);
}
}
QString key;
QString value;
quint32 ikey;
FieldTrait::FieldType ft;
const BaseMsgEntry *tbme;
//Globals::messagePairs = new QVector<Globals::MessagePair>(TEX::ctx()._bme.size());
//Globals::messagePairs = new QVector<Globals::MessagePair>();
int messageCount = TEX::ctx()._bme.size();
// qDebug() << "SIZE OF MESSAGE TABLE = " << messageCount ;
const BaseEntry *tbe;
messageFieldList = new MessageFieldList();
MessageField *messageField;
fieldTraitV.resize( TEX::ctx()._be.size());
///dnb
QString fieldName;
FIX8::TEX::NewOrderSingle nos;
MessageBase *_header = nos.Header();
for (Fields::const_iterator hiter = _header->fields_begin();
hiter != _header->fields_end();
hiter++) {
}
for(int ii=0;ii < messageCount; ii++)
{
const char *kk = TEX::ctx()._bme.at(ii)->_key;
const TraitHelper tr = TEX::ctx()._bme.at(ii)->_value._create._get_traits();
//cout << ">>>>> " << TEX::ctx()._bme.at(ii)->_value._name << endl;
QBaseEntryList *qbaseEntryList = new QBaseEntryList();
value = QString::fromStdString(TEX::ctx()._bme.at(ii)->_value._name);
key =
QString::fromStdString(TEX::ctx()._bme.at(ii)->_key);
messageField = new MessageField(key,value);
int level = 0;
generate_traits(tr,baseMap,fieldUseList,messageField,qbaseEntryList,&level);
messageField->qbel = qbaseEntryList;
messageFieldList->append(messageField);
}
// created default header items so create default schema
if (tableSchemaList->count () < 1) { // lets make sure we have default table schema, else create it
defaultTableSchema = new TableSchema("Default","Default Table Schema",true);
defaultTableSchema->fieldList = defaultHeaderItems.clone();
defaultTableSchema->fieldNames = defaultHeaderItems.getFieldNames();
tableSchemaList->append(defaultTableSchema);
bstatus = database->addTableSchema(*defaultTableSchema);
if (!bstatus) {
errorStr = "Failed to add default table schema to database 2";
displayConsoleMessage(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg));
}
}
else {
qDebug() << "Find Default By name" << __FILE__ << __LINE__;
defaultTableSchema = tableSchemaList->findByName("Default");
if (defaultTableSchema)
qDebug() << "\t Found IT !!";
else
qDebug() << "\t Not FOUND";
}
MainWindow::defaultTableSchema = defaultTableSchema;
// qbaseEntryList->print();
//Globals::messagePairs->insert(ii,Globals::MessagePair(key,value));
// generate fieldList from names;
if (tableSchemaList) {
QListIterator <TableSchema *> tsIter(*tableSchemaList);
while(tsIter.hasNext()) {
TableSchema *ts = tsIter.next();
ts->fieldList = new QBaseEntryList();
QStringListIterator fieldNameIter(ts->fieldNames);
while(fieldNameIter.hasNext()) {
fieldName = fieldNameIter.next();
QBaseEntry *qbe = baseMap.value(fieldName);
if (qbe) {
ts->fieldList->append(qbe);
}
}
}
}
MainWindow::setTableSchemaList(tableSchemaList);
int sizeofFieldTable = TEX::ctx()._be.size();
// initial screeen
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,10);
// QList <WindowData> windowDataList = database->getWindows();
windowDataList = database->getWindows();
cleanWindowDataList(windowDataList);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,10);
QListIterator <WindowData> iter(windowDataList);
QStringList errorStrList;
MainWindow *newMW;
QMap <QString, QStandardItemModel *>::iterator currentItemIter;
bool haveError = false;
bool isInitial = true;
if (autoSaveOn){
while(iter.hasNext()) {
wd = iter.next();
newMW = new MainWindow(database,true);
newMW->setSearchFunctions(searchFunctionList);
newMW->setWindowData(wd);
wireSignalAndSlots(newMW);
mainWindows.append(newMW);
newMW->setAutoSaveOn(autoSaveOn);
newMW->show();
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,40);
QList <WorkSheetData> wsdList = database->getWorkSheets(wd.id);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,40);
if (wsdList.count() > 0) {
QListIterator <WorkSheetData> iter2(wsdList);
while(iter2.hasNext()) {
WorkSheetData wsd = iter2.next();
//model = 0;
/* Used to share models to speed up time, but now every work sheet has its own model */
currentItemIter = fileNameModelMap.find(wsd.fileName);
/*
if (currentItemIter != fileNameModelMap.end()) {
model = (WorkSheetModel *) currentItemIter.value();
}
else {
// newMW->setLoadMessage("Loading File " + wsd.fileName);
// model = readLogFile(wsd.fileName,errorStr);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,4);
qDebug() << "LATTER RESTORE ABILITY TO CANCEL RESTORE" << __FILE__ << __LINE__;
if (cancelSessionRestore) {
newMW->setLoading(false);
goto done;
}
if (!model)
errorStrList.append(errorStr);
else
fileNameModelMap.insert(wsd.fileName,model);
//}
//if (model) {
//newMW->addWorkSheet(model,wsd);
*/
newMW->addWorkSheet(wsd); // do not create model, have code reuse and redo busy screen for each tab
qDebug() << "FIX THIS HARD CODE ROW SETTING of 2 ?" << __FILE__ << __LINE__;
newMW->setCurrentTabAndSelectedRow(wd.currentTab,2);
//}
}
}
newMW->setLoading(false);
}
displayConsoleMessage("Session restored from autosave");
}
else
qDebug() << "TODO - Display error messages here, and if no work sheets created lets delete main window" << __FILE__ << __LINE__;
// if no main windows lets create one
if (mainWindows.count() < 1) {
newMW = new MainWindow(database);
qDebug() << "************************ SET TABLE SCHEMA TO DEFAULT ************" << __FILE__ << __LINE__;
newMW->setTableSchema(defaultTableSchema);
newMW->setSearchFunctions(searchFunctionList);
if (windowDataList.count() > 0) {
wd = windowDataList.at(0);
if (!wd.tableSchema) {
qWarning() << "No Table schema found for window, setting it to default" << __FILE__ << __LINE__;
wd.tableSchema = defaultTableSchema;
}
newMW->setWindowData(wd);
}
newMW->setTableSchema(defaultTableSchema);
wireSignalAndSlots(newMW);
newMW->show();
newMW->setAutoSaveOn(autoSaveOn);
mainWindows.append(newMW);
}
return bstatus;
}
bool Fix8Log::init(QString fileNameToLoad)
{
WorkSheetModel *model = 0;
MainWindow *newMW =new MainWindow(database,true);
newMW->setSearchFunctions(searchFunctionList);
WindowData wd;
WorkSheetData wsd;
QString errorStr;
wsd.fileName = fileNameToLoad;
wd.isVisible = true;
wd.name = "Fix8LogViewer";
wireSignalAndSlots(newMW);
newMW->setWindowData(wd);
wireSignalAndSlots(newMW);
mainWindows.append(newMW);
newMW->setLoadMessage("Loading File " + wsd.fileName);
model = readLogFile(wsd.fileName,errorStr);
qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,4);
if (model) {
fileNameModelMap.insert(wsd.fileName,model);
newMW->addWorkSheet(model,wsd);
newMW->show();
}
newMW->setLoading(false);
return true;
}
void Fix8Log::saveSession()
{
MainWindow *mw;
WorkSheetData wsd;
bool bstatus;
bstatus = database->deleteAllWindows();
if (!bstatus)
qWarning() << "Delete all windows from database failed" << __FILE__ << __LINE__;
bstatus = database->deleteAllWorkSheets();
if (!bstatus)
qWarning() << "Delete all worksheets from database failed" << __FILE__ << __LINE__;
QListIterator <MainWindow *> iter(mainWindows);
while(iter.hasNext()) {
mw = iter.next();
WindowData wd = mw->getWindowData();
bstatus = database->addWindow(wd);
if (!bstatus) {
displayConsoleMessage("Error failed saving window to database",GUI::ConsoleMessage::ErrorMsg);
}
else {
QList<WorkSheetData> wsdList = mw->getWorksheetData(wd.id);
QListIterator <WorkSheetData> wsdIter(wsdList);
int i = 0;
while(wsdIter.hasNext()) {
wsd = wsdIter.next();
bstatus = database->addWorkSheet(wsd);
i++;
}
}
}
}
void Fix8Log::readSettings()
{
QSettings settings("fix8","logviewer");
autoSaveOn = (bool) settings.value("AutoSave",false).toBool();
GUI::Globals::timeFormat = (GUI::Globals::TimeFormat) settings.value("StartTimeFormat",GUI::Globals::HHMMSS).toInt();
emit notifyTimeFormatChanged(GUI::Globals::timeFormat);
}
void Fix8Log::writeSettings()
{
QSettings settings("fix8","logviewer");
}