-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmanager.cpp
1141 lines (1113 loc) · 39.8 KB
/
dmanager.cpp
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "globals.h"
#include "dmanager.h"
#include "ui_dmanager.h"
#include "dialog.h"
#include <QWidget>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlDriver>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
#include <QFileDialog>
#include <QDebug>
#include <QVariant>
/* Constructor & Destructor */
dmanager::dmanager(QWidget *parent) :QMainWindow(parent), ui(new Ui::dmanager)
{
ui->setupUi(this);
connect(ui->sa_campaign, &QAction::triggered,this, &dmanager::setSaveFileName);
connect(ui->o_campaign, &QAction::triggered,this, &dmanager::setOpenFileName);
connect(ui->n_campaign, &QAction::triggered,this, &dmanager::setNewFileName);
connect(ui->exportJSON, &QAction::triggered,this, &dmanager::export_JSON);
connect(ui->athl_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->acro_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->slha_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->stlh_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->arca_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->hist_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->inve_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->natr_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->rlgn_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->anha_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->insi_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->medi_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->prcp_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->srvl_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->dcep_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->intm_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->perf_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
connect(ui->pers_chk, &QCheckBox::clicked,this, &dmanager::profToggle);
openDB(":memory:",true);
}
dmanager::~dmanager()
{
if(true) // possibly filter double inputs, in fututre
{
for (int i = 0; i < ui->charList->count(); ++i)
{
currentChar = ui->charList->item(i)->text();
QSqlDatabase::database();
QSqlQuery updateIndex;
updateIndex.prepare("UPDATE GameData SET RowID = :index WHERE Character = :charName" );
updateIndex.bindValue(":charName",currentChar);
updateIndex.bindValue(":index",i);
if(!updateIndex.exec()){
debugMsg("Error updateing index: " , updateIndex.lastError().text(),2);
}
else
{
debugMsg("Indexes set","",1);
}
}
}
delete ui;
QSqlDatabase::database().commit();
QSqlDatabase::database().close();
}
/* Menubar slots */
void dmanager::setNewFileName()
{
QSqlDatabase::database().close();
QString newFileName = QFileDialog::getSaveFileName(this,tr("Save Campaign As - DManager"));
if (newFileName == "")
{
newFileName = ":memory:";
currentFile = newFileName;
}
else
{
currentFile = newFileName;
openDB(newFileName,true);
}
}
void dmanager::setOpenFileName()
{
QString openFileName = QFileDialog::getOpenFileName(this,tr("Open Campaign - DManager"));
if (openFileName == "")
{
openFileName = ":memory:";
currentFile = openFileName;
}
else
{
/*if(a database is currently connected)
{
close database
}*/
currentFile = openFileName;
openDB(openFileName, false);
updateFields();
}
}
void dmanager::setSaveFileName()
{
QString saveFileName = QFileDialog::getSaveFileName(this,tr("Save Campaign As - DManager"));
}
void dmanager::export_JSON()
{
debugMsg("Export triggered"," NOT YET IMPLEMENTED :)",1);
}
/* General purpose slots */
void dmanager::updateFields()
{
currentChar = ui->charList->currentItem()->text();
ui->charName->setText(currentChar);
QSqlQuery update;
update.prepare("SELECT Player, Class_Subclass, Race FROM GameData WHERE Character = :charName");
update.bindValue(":charName",currentChar);
if(!update.exec())
{
debugMsg("Error updating: " , update.lastError().text(),2);
}
while(update.next())
{
ui->playerName->setText(update.value(0).toString());
ui->class_subclass->setText(update.value(1).toString());
ui->race->setText(update.value(2).toString());
}
switch (ui->tabWidget->currentIndex())
{
case 0: //stats_and_saves tab active
{
ui->athl_chk->setCheckState(Qt::Unchecked);
ui->acro_chk->setCheckState(Qt::Unchecked);
ui->slha_chk->setCheckState(Qt::Unchecked);
ui->stlh_chk->setCheckState(Qt::Unchecked);
ui->arca_chk->setCheckState(Qt::Unchecked);
ui->hist_chk->setCheckState(Qt::Unchecked);
ui->inve_chk->setCheckState(Qt::Unchecked);
ui->natr_chk->setCheckState(Qt::Unchecked);
ui->rlgn_chk->setCheckState(Qt::Unchecked);
ui->anha_chk->setCheckState(Qt::Unchecked);
ui->insi_chk->setCheckState(Qt::Unchecked);
ui->medi_chk->setCheckState(Qt::Unchecked);
ui->prcp_chk->setCheckState(Qt::Unchecked);
ui->srvl_chk->setCheckState(Qt::Unchecked);
ui->dcep_chk->setCheckState(Qt::Unchecked);
ui->intm_chk->setCheckState(Qt::Unchecked);
ui->perf_chk->setCheckState(Qt::Unchecked);
ui->pers_chk->setCheckState(Qt::Unchecked);
QSqlQuery update;
update.prepare("SELECT StrBase,DexBase,ConBase,IntBase,WisBase,ChaBase,StrMod,DexMod,ConMod,IntMod,WisMod,ChaMod,Profs "
"FROM GameData WHERE Character = :charName");
update.bindValue(":charName",currentChar);
if(!update.exec())
{
debugMsg("Error updating stats: " , update.lastError().text(),2);
}
while(update.next())
{
ui->strBaseSpin->setValue(update.value(0).toInt());
ui->dexBaseSpin->setValue(update.value(1).toInt());
ui->conBaseSpin->setValue(update.value(2).toInt());
ui->intBaseSpin->setValue(update.value(3).toInt());
ui->wisBaseSpin->setValue(update.value(4).toInt());
ui->chaBaseSpin->setValue(update.value(5).toInt());
ui->strMod->setValue(update.value(6).toInt());
int currentStrMod = update.value(6).toInt();
ui->dexMod->setValue(update.value(7).toInt());
int currentDexMod = update.value(7).toInt();
ui->conMod->setValue(update.value(8).toInt());
int currentConMod = update.value(8).toInt();
ui->intMod->setValue(update.value(9).toInt());
int currentIntMod = update.value(9).toInt();
ui->wisMod->setValue(update.value(10).toInt());
int currentWisMod = update.value(10).toInt();
ui->chaMod->setValue(update.value(11).toInt());
int currentChaMod = update.value(11).toInt();
/* Update proficiencies */
QString profs = update.value(12).toString();
int levelProfMod = 0;
if(ui->lvl_spin->value()<5)
{
levelProfMod +=2;
}
else if(ui->lvl_spin->value()>=5 && ui->lvl_spin->value()<9)
{
levelProfMod +=3;
}
else if(ui->lvl_spin->value()>=9 && ui->lvl_spin->value()<12)
{
levelProfMod +=4;
}
else if(ui->lvl_spin->value()>=12 && ui->lvl_spin->value()<16)
{
levelProfMod +=5;
}
else if(ui->lvl_spin->value()>=16)
{
levelProfMod +=6;
}
if(true)
{
ui->athl_val->setText(QString::number(currentStrMod));
ui->acro_val->setText(QString::number(currentDexMod));
ui->slha_val->setText(QString::number(currentDexMod));
ui->stlh_val->setText(QString::number(currentDexMod));
ui->arca_val->setText(QString::number(currentIntMod));
ui->hist_val->setText(QString::number(currentIntMod));
ui->inve_val->setText(QString::number(currentIntMod));
ui->natr_val->setText(QString::number(currentIntMod));
ui->rlgn_val->setText(QString::number(currentIntMod));
ui->anha_val->setText(QString::number(currentWisMod));
ui->insi_val->setText(QString::number(currentWisMod));
ui->medi_val->setText(QString::number(currentWisMod));
ui->prcp_val->setText(QString::number(currentWisMod));
ui->srvl_val->setText(QString::number(currentWisMod));
ui->dcep_val->setText(QString::number(currentChaMod));
ui->intm_val->setText(QString::number(currentChaMod));
ui->perf_val->setText(QString::number(currentChaMod));
ui->pers_val->setText(QString::number(currentChaMod));
}
else
{
}
QStringList profsList = profs.split(',');
for(int i = 0; i < profsList.count(); i++) //Switch case not possible with strings, makes this messier than I'd like
{
if(profsList[i] == "athl")
{
debugMsg("Proficiency in athletcs, ", QString::number(currentStrMod + levelProfMod),1);
ui->athl_chk->setCheckState(Qt::PartiallyChecked);
ui->athl_val->setText(QString::number(currentStrMod + levelProfMod));
}
else if(profsList[i] == "acro")
{
debugMsg("Proficiency in acrobatics, ", QString::number(currentDexMod + levelProfMod),1);
ui->acro_chk->setCheckState(Qt::PartiallyChecked);
ui->acro_val->setText(QString::number(currentDexMod + levelProfMod));
}
else if(profsList[i] == "slha")
{
debugMsg("Proficiency in ", "sleight of hand",1);
ui->slha_chk->setCheckState(Qt::PartiallyChecked);
ui->slha_val->setText(QString::number(currentDexMod + levelProfMod));
}
else if(profsList[i] == "stlh")
{
debugMsg("Proficiency in ", "stealth",1);
ui->stlh_chk->setCheckState(Qt::PartiallyChecked);
ui->stlh_val->setText(QString::number(currentDexMod + levelProfMod));
}
else if(profsList[i] == "arca")
{
debugMsg("Proficiency in ", "arcana",1);
ui->arca_chk->setCheckState(Qt::PartiallyChecked);
ui->arca_val->setText(QString::number(currentIntMod + levelProfMod));
}
else if(profsList[i] == "hist")
{
debugMsg("Proficiency in ", "history",1);
ui->hist_chk->setCheckState(Qt::PartiallyChecked);
ui->hist_val->setText(QString::number(currentIntMod + levelProfMod));
}
else if(profsList[i] == "inve")
{
debugMsg("Proficiency in ", "investigation",1);
ui->inve_chk->setCheckState(Qt::PartiallyChecked);
ui->inve_val->setText(QString::number(currentIntMod + levelProfMod));
}
else if(profsList[i] == "natr")
{
debugMsg("Proficiency in ", "nature",1);
ui->natr_chk->setCheckState(Qt::PartiallyChecked);
ui->natr_val->setText(QString::number(currentIntMod + levelProfMod));
}
else if(profsList[i] == "rlgn")
{
debugMsg("Proficiency in ", "religion",1);
ui->rlgn_chk->setCheckState(Qt::PartiallyChecked);
ui->rlgn_val->setText(QString::number(currentIntMod + levelProfMod));
}
else if(profsList[i] == "anha")
{
debugMsg("Proficiency in ", "animal handling",1);
ui->anha_chk->setCheckState(Qt::PartiallyChecked);
ui->anha_val->setText(QString::number(currentWisMod + levelProfMod));
}
else if(profsList[i] == "insi")
{
debugMsg("Proficiency in ", "insight",1);
ui->insi_chk->setCheckState(Qt::PartiallyChecked);
ui->insi_val->setText(QString::number(currentWisMod + levelProfMod));
}
else if(profsList[i] == "medi")
{
debugMsg("Proficiency in ", "medicine",1);
ui->medi_chk->setCheckState(Qt::PartiallyChecked);
ui->medi_val->setText(QString::number(currentWisMod + levelProfMod));
}
else if(profsList[i] == "prcp")
{
debugMsg("Proficiency in ", "perception",1);
ui->prcp_chk->setCheckState(Qt::PartiallyChecked);
ui->prcp_val->setText(QString::number(currentWisMod + levelProfMod));
}
else if(profsList[i] == "srvl")
{
debugMsg("Proficiency in ", "survival",1);
ui->srvl_chk->setCheckState(Qt::PartiallyChecked);
ui->srvl_val->setText(QString::number(currentWisMod + levelProfMod));
}
else if(profsList[i] == "dcep")
{
debugMsg("Proficiency in ", "deception",1);
ui->dcep_chk->setCheckState(Qt::PartiallyChecked);
ui->dcep_val->setText(QString::number(currentChaMod + levelProfMod));
}
else if(profsList[i] == "intm")
{
debugMsg("Proficiency in ", "intimidation",1);
ui->intm_chk->setCheckState(Qt::PartiallyChecked);
ui->intm_val->setText(QString::number(currentChaMod + levelProfMod));
}
else if(profsList[i] == "perf")
{
debugMsg("Proficiency in ", "performance",1);
ui->perf_chk->setCheckState(Qt::PartiallyChecked);
ui->perf_val->setText(QString::number(currentChaMod + levelProfMod));
}
else if(profsList[i] == "pers")
{
debugMsg("Proficiency in ", "persuasion",1);
ui->pers_chk->setCheckState(Qt::PartiallyChecked);
ui->pers_val->setText(QString::number(currentChaMod + levelProfMod));
}
}
}
break;
}
case 1: //spells and abilities tab active
{
QSqlQuery update1;
update1.prepare("SELECT Spells,Abilities "
"FROM GameData WHERE Character = :charName");
update1.bindValue(":charName",currentChar);
if(!update1.exec())
{
debugMsg("Error updating spells: " , update1.lastError().text(),2);
}
while(update1.next())
{
ui->spellsText->setHtml(update1.value(0).toString());
ui->abilitiesText->setHtml(update1.value(1).toString());
}
break;
}
case 2: //inventory tab active
{
QSqlQuery update2;
update2.prepare("SELECT Inventory "
"FROM GameData WHERE Character = :charName");
update2.bindValue(":charName",currentChar);
if(!update2.exec())
{
debugMsg("Error updating inventory: " , update2.lastError().text(),2);
}
while(update2.next())
{
ui->inventoryText->setHtml(update2.value(0).toString());
}
break;
}
case 3: //lore and notes tab active
{
QSqlQuery update3;
update3.prepare("SELECT Lore,Notes "
"FROM GameData WHERE Character = :charName");
update3.bindValue(":charName",currentChar);
if(!update3.exec())
{
debugMsg("Error updating notes: " , update3.lastError().text(),2);
}
while(update3.next())
{
ui->loreText->setHtml(update3.value(0).toString());
ui->notesText->setHtml(update3.value(1).toString());
}
break;
}
}
}
void dmanager::openDB(QString filename, bool newdb) //true to wipe existing data
{
const QString DRIVER("QSQLITE");
if(QSqlDatabase::isDriverAvailable(DRIVER)){
QSqlDatabase database = QSqlDatabase::addDatabase(DRIVER);
database.setDatabaseName(filename);
database.open();
QSqlQuery query;
if(newdb == true)
{
query.exec("DROP TABLE IF EXISTS CampaignData");
query.exec("DROP TABLE IF EXISTS GameData");
query.exec("CREATE TABLE CampaignData "
"(Param TEXT PRIMARY KEY, Value TEXT)");
query.exec("CREATE TABLE GameData "
"(Character TEXT PRIMARY KEY, RowID INTEGER, Player TEXT, Level INTEGER, "
"Class_Subclass TEXT, Race TEXT, "
"StrBase INTEGER, DexBase INTEGER, ConBase INTEGER, IntBase INTEGER, WisBase INTEGER, ChaBase INTEGER,"
"StrMod INTEGER, DexMod INTEGER, ConMod INTEGER, IntMod INTEGER, WisMod INTEGER, ChaMod INTEGER, "
"Profs TEXT, Xprt TEXT, Spells TEXT, Abilities TEXT, Inventory TEXT, Lore TEXT, Notes TEXT)");
debugMsg("Created database file: ", filename,1);
}
else //opening existing db
{
if(!query.exec("SELECT Character, RowID FROM GameData ORDER BY RowID ")) // fetch campaign metadata
{
debugMsg("Error opening database file: " , query.lastError().text(),2);
}
while(query.next())
{
ui->charList->addItem(query.value(0).toString());
debugMsg(query.value(0).toString(),query.value(1).toString(),1);
ui->charList->setCurrentRow(0);
QApplication::processEvents();
}
query.exec("CREATE TABLE CampaignData "
"(Param TEXT PRIMARY KEY, Value TEXT)");
query.exec("CREATE TABLE GameData "
"(Character TEXT PRIMARY KEY, RowID INTEGER, Player TEXT, Level INTEGER, "
"Class_Subclass TEXT, Race TEXT, "
"StrBase INTEGER, DexBase INTEGER, ConBase INTEGER, IntBase INTEGER, WisBase INTEGER, ChaBase INTEGER,"
"StrMod INTEGER, DexMod INTEGER, ConMod INTEGER, IntMod INTEGER, WisMod INTEGER, ChaMod INTEGER, "
"Profs TEXT, Xprt TEXT, Spells TEXT, Abilities TEXT, Inventory TEXT, Lore TEXT, Notes TEXT)");
query.prepare("SELECT Value FROM CampaignData WHERE Param = 'CampaignName'"); // fetch campaign metadata
if(!query.exec())
{
debugMsg("Error selecting campaign metadata: " , query.lastError().text(),2);
}
while(query.next())
{
debugMsg("Fetched CampaignName: ", query.value(0).toString(),1);
ui->campaignName->setText(query.value(0).toString()); // add fields as necessary
}
debugMsg("Opened database file: ", filename,2);
updateFields();
}
}
}
void dmanager::debugMsg(QString message, QString error, int level)
{
/* Debugging Levels - maybe crash logging, etc here
* 2 - qWarning
* 1 - qDebug + statusBar
* 0 - statusBar
*/
if(debugmode == 1)
{
switch (level)
{
case 0:
ui->statusbar->showMessage(message + error);
break;
case 1:
qDebug() << message << error;
ui->statusbar->showMessage(message + error);
break;
case 2:
qWarning() << message << error;
break;
}
}
}
/* Data manipulation slots */
void dmanager::on_tabWidget_currentChanged(int index)
{
updateFields();
}
void dmanager::on_charList_itemSelectionChanged()
{
updateFields();
debugMsg("Current character is: ",currentChar,1);
}
void dmanager::on_addCharButton_clicked()
{
QSqlDatabase::database();
ui->charList->addItem("New Character");
debugMsg("New char row: ", QString::number(ui->charList->currentRow()),1);
QSqlQuery newChar;
newChar.prepare("INSERT into GameData (Character, RowID) VALUES ('New Character', :rowID)");
newChar.bindValue(":rowID", ui->charList->currentRow());
if(!newChar.exec())
{
debugMsg("Error adding character: " , newChar.lastError().text(),2);
}
}
void dmanager::on_killCharButton_clicked()
{
QSqlDatabase::database();
QSqlQuery deleteCharacter;
deleteCharacter.prepare("DELETE FROM GameData WHERE Character = :charName" );
deleteCharacter.bindValue(":charName",currentChar);
ui->charList->takeItem(ui->charList->currentRow());
if(!deleteCharacter.exec()){
debugMsg("Error deleting character: " , deleteCharacter.lastError().text(),2);
}
else
{
debugMsg("Character killed","",1);
}
QList<QListWidgetItem*> items = ui->charList->selectedItems();
if(items.length() > 0)
{
updateFields();
}
else
{
debugMsg("No characters left","",1);
}
}
void dmanager::on_campaignName_editingFinished()
{
QSqlDatabase::database();
QSqlQuery setCampaignName;
setCampaignName.prepare("INSERT INTO CampaignData (Param,Value) "
"VALUES ('CampaignName',:camName) "
"ON CONFLICT (Param) DO UPDATE SET Value=excluded.Value" );
setCampaignName.bindValue(":camName",ui->campaignName->text());
if(!setCampaignName.exec()){
debugMsg("Error setting campaign name: " , setCampaignName.lastError().text(),2);
}
else
{
debugMsg("Campaign name is: ", ui->campaignName->text(),1);
}
}
void dmanager::on_charName_editingFinished()
{
QString oldChar = ui->charList->currentItem()->text();
if(oldChar != ui->charName->text())
{
debugMsg("Old character name is: ", oldChar,1);
ui->charList->currentItem()->setText(ui->charName->text());
currentChar = ui->charList->currentItem()->text();
QSqlDatabase::database();
QSqlQuery setName;
setName.prepare("UPDATE GameData SET Character = :newName WHERE Character = :oldName" );
setName.bindValue(":oldName",oldChar);
setName.bindValue(":newName",ui->charName->text());
if(!setName.exec()){
debugMsg("Error setting character name: " , setName.lastError().text(),2);
}
else
{
debugMsg("Current character name is: ",currentChar,1);
}
}
}
void dmanager::on_playerName_editingFinished()
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setPlayer;
setPlayer.prepare("UPDATE GameData SET Player = :playerName WHERE Character = :charName" );
setPlayer.bindValue(":charName",currentChar);
setPlayer.bindValue(":playerName",ui->playerName->text());
if(!setPlayer.exec()){
debugMsg("Error setting player name: " , setPlayer.lastError().text(),2);
}
else
{
debugMsg("Player name is: ",ui->playerName->text(),1);
}
}
}
void dmanager::on_race_editingFinished()
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setRace;
setRace.prepare("UPDATE GameData SET Race = :race WHERE Character = :charName" );
setRace.bindValue(":charName",currentChar);
setRace.bindValue(":race",ui->race->text());
if(!setRace.exec()){
debugMsg("Error setting race: " , setRace.lastError().text(),2);
}
else
{
debugMsg("Character race is: ",ui->race->text(),1);
}
}
}
void dmanager::on_class_subclass_editingFinished()
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setClass;
setClass.prepare("UPDATE GameData SET Class_Subclass = :class WHERE Character = :charName" );
setClass.bindValue(":charName",currentChar);
setClass.bindValue(":class",ui->class_subclass->text());
if(!setClass.exec()){
debugMsg("Error setting class: " , setClass.lastError().text(),2);
}
else
{
debugMsg("Character class is: ",ui->class_subclass->text(),1);
}
}
}
/* Stats & Profs */
/* TODO: Convert individual
* slots into general slots
* and connect to signals, once
* I get that working */
void dmanager::on_strBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET StrBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting strength: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character strength is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_strMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET StrMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting strength: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character strength mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::on_dexBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET DexBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting dexterity: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character dexterity is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_dexMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET DexMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting dexterity: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character dexterity mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::on_conBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET ConBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting constitution: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character constitution is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_conMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET ConMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting constitution: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character constitution mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::on_intBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET IntBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting intelligence: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character intelligence is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_intMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET IntMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting intelligence: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character intelligence mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::on_wisBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET WisBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting wisdom: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character wisdom is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_wisMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET WisMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting wisdom: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character wisdom mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::on_chaBaseSpin_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET ChaBase = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting charisma: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character charisma is: ",QString::number(arg1),1);
}
}
}
void dmanager::on_chaMod_valueChanged(int arg1)
{
if(true) // possibly filter double inputs, in fututre
{
QSqlDatabase::database();
QSqlQuery setStat;
setStat.prepare("UPDATE GameData SET ChaMod = :stat WHERE Character = :charName" );
setStat.bindValue(":charName",currentChar);
setStat.bindValue(":stat",arg1);
if(!setStat.exec()){
debugMsg("Error setting charisma: " , setStat.lastError().text(),2);
}
else
{
debugMsg("Character charisma mod is: ",QString::number(arg1),1);
}
updateFields();
}
}
void dmanager::profToggle()
{
debugMsg(sender()->objectName(), " toggled", 1);
QString profsList;
QString xprtList;
if(true) //proficiency - for folding purposes
{
if(ui->athl_chk->checkState()==1)
{
profsList += "athl,";
}
if(ui->acro_chk->checkState()==1)
{
profsList += "acro,";
}
if(ui->slha_chk->checkState()==1)
{
profsList += "slha,";
}
if(ui->stlh_chk->checkState()==1)
{
profsList += "stlh,";
}
if(ui->arca_chk->checkState()==1)
{
profsList += "arca,";
}
if(ui->hist_chk->checkState()==1)
{
profsList += "hist,";
}
if(ui->inve_chk->checkState()==1)
{
profsList += "inve,";
}
if(ui->natr_chk->checkState()==1)
{
profsList += "natr,";
}
if(ui->rlgn_chk->checkState()==1)
{
profsList += "rlgn,";
}
if(ui->anha_chk->checkState()==1)
{
profsList += "anha,";
}
if(ui->insi_chk->checkState()==1)
{
profsList += "insi,";
}
if(ui->medi_chk->checkState()==1)
{
profsList += "medi,";
}
if(ui->prcp_chk->checkState()==1)
{
profsList += "prcp,";
}
if(ui->srvl_chk->checkState()==1)
{
profsList += "srvl,";
}
if(ui->dcep_chk->checkState()==1)
{
profsList += "dcep,";
}
if(ui->intm_chk->checkState()==1)
{
profsList += "intm,";
}
if(ui->perf_chk->checkState()==1)
{
profsList += "perf,";
}
if(ui->pers_chk->checkState()==1)
{
profsList += "pers,";
}
}
/*if(true) //expertise - for folding purposes
{
if(ui->athl_chk->checkState()==2)
{
xprtList += "athl,";
}
if(ui->acro_chk->checkState()==2)
{
xprtList += "acro,";
}
if(ui->slha_chk->checkState()==2)
{
xprtList += "slha,";
}
if(ui->stlh_chk->checkState()==2)
{
xprtList += "stlh,";
}
if(ui->arca_chk->checkState()==2)
{
xprtList += "arca,";
}
if(ui->hist_chk->checkState()==2)
{
xprtList += "hist,";
}
if(ui->inve_chk->checkState()==2)
{
xprtList += "inve,";
}
if(ui->natr_chk->checkState()==2)
{
xprtList += "natr,";
}
if(ui->rlgn_chk->checkState()==2)
{
xprtList += "rlgn,";
}
if(ui->anha_chk->checkState()==2)
{
xprtList += "anha,";
}
if(ui->insi_chk->checkState()==2)
{
xprtList += "insi,";
}
if(ui->medi_chk->checkState()==2)
{
xprtList += "medi,";
}
if(ui->prcp_chk->checkState()==2)
{
xprtList += "prcp,";
}
if(ui->srvl_chk->checkState()==2)
{
xprtList += "srvl,";
}
if(ui->dcep_chk->checkState()==2)
{
xprtList += "dcep,";
}
if(ui->intm_chk->checkState()==2)
{