]> Shamusworld >> Repos - schematic/blob - src/notedialog.cpp
Move DB access to NoteDialog class, new AlertDialog class.
[schematic] / src / notedialog.cpp
1 //
2 // notedialog.cpp: Dialog for creating & editing notes
3 //
4 // Part of the SCheMatic Project
5 // (C) 2012 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  12/05/2012  Created this file
12 //
13
14 #include "notedialog.h"
15 #include <QtSql>
16
17
18 NoteDialog::NoteDialog(int uidToUse, QWidget * parent/*= 0*/): QDialog(parent), uid(uidToUse)
19 {
20         note = new QTextEdit;
21         buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
22
23         connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
24         connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
25
26         QVBoxLayout * mainLayout = new QVBoxLayout;
27         mainLayout->addWidget(note);
28         mainLayout->addWidget(buttonBox);
29         setLayout(mainLayout);
30
31         setWindowTitle(tr("Note"));
32 }
33
34
35 NoteDialog::~NoteDialog()
36 {
37 }
38
39
40 void NoteDialog::accept(void)
41 {
42         // Call base class version, so things work right
43         QDialog::accept();
44
45         // Add note to DB for this user
46         QString noteText = note->document()->toPlainText();
47
48         if (noteText.isEmpty())
49                 return;
50
51         QSqlQuery query;
52         query.prepare("INSERT INTO Notes VALUES ('', ?, NULL, ?)");
53         query.addBindValue(uid);
54 //      query.addBindValue(NULL);
55         query.addBindValue(noteText.toAscii());
56         query.exec();
57 }
58