Редакция 41 | Редакция 43 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 41 | Редакция 42 | ||
---|---|---|---|
1 | #include "classeditor.h"
|
1 | #include "classeditor.h"
|
2 | #include "ui_classeditor.h"
|
2 | #include "ui_classeditor.h"
|
3 | 3 | ||
4 | ClassEditor::ClassEditor(QWidget *parent) : |
4 | ClassEditor::ClassEditor(QWidget *parent) : |
5 | QMainWindow(parent), |
5 | QMainWindow(parent), |
6 | ui(new Ui::ClassEditor) |
6 | ui(new Ui::ClassEditor) |
7 | {
|
7 | {
|
8 | ui->setupUi(this); |
8 | ui->setupUi(this); |
9 | // settdialog = new SettingsDialog(this);
|
9 | // settdialog = new SettingsDialog(this);
|
10 | settdialog.show(); |
10 | settdialog.show(); |
11 | sql.setDatabaseName(tr("an_db")); |
11 | sql.setDatabaseName(tr("an_db")); |
12 | field = new TableField(tr("Ñîòðóäíèêè"), this); |
12 | field = new TableField(tr("Ñîòðóäíèêè"), this); |
13 | field->setNotNull(true); |
13 | field->setNotNull(true); |
14 | field->setDefaultValue(tr("ñîòðóäíèê")); |
14 | field->setDefaultValue(tr("ñîòðóäíèê")); |
15 | 15 | ||
16 | table = new SqlTable (tr("NewTable"), this); |
16 | table = new SqlTable (tr("NewTable"), this); |
17 | table->setName(tr("NewTable")); |
17 | table->setName(tr("NewTable")); |
18 | table->fields().at(0)->setNotNull(true); |
18 | table->fields().at(0)->setNotNull(true); |
19 | if (!(table->setPrimaryKey(tr("ID")))) { |
19 | if (!(table->setPrimaryKey(tr("ID")))) { |
20 | ui->label_3->setText(table->lastError()); |
20 | ui->label_3->setText(table->lastError()); |
21 | }
|
21 | }
|
22 | else ui->label_3->setText(table->primaryKey()); |
22 | else ui->label_3->setText(table->primaryKey()); |
23 | table->append(field); |
23 | table->append(field); |
24 | 24 | ||
25 | field = new TableField(tr("Êîìïüþòåðû"), this); |
25 | field = new TableField(tr("Êîìïüþòåðû"), this); |
26 | field->setNotNull(true); |
26 | field->setNotNull(true); |
27 | field->setDefaultValue(tr("êîìïüþòåð")); |
27 | field->setDefaultValue(tr("êîìïüþòåð")); |
28 | table->append(field); |
28 | table->append(field); |
29 | 29 | ||
30 | field = new TableField(tr("Ìîíèòîðû"), this); |
30 | field = new TableField(tr("Ìîíèòîðû"), this); |
31 | field->setNotNull(true); |
31 | field->setNotNull(true); |
32 | field->setDefaultValue(tr("ìîíèòîð")); |
32 | field->setDefaultValue(tr("ìîíèòîð")); |
33 | table->append(field); |
33 | table->append(field); |
34 | 34 | ||
35 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this); |
35 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this); |
36 | field->setNotNull(true); |
36 | field->setNotNull(true); |
37 | field->setType(tr("INTEGER")); |
37 | field->setType(tr("INTEGER")); |
38 | field->setDefaultValue(tr("1")); |
38 | field->setDefaultValue(tr("1")); |
39 | table->append(field); |
39 | table->append(field); |
40 | 40 | ||
41 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this); |
41 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this); |
42 | field->setNotNull(false); |
42 | field->setNotNull(false); |
43 | field->setType(tr("DATE")); |
43 | field->setType(tr("DATE")); |
44 | field->setDefaultValue(tr("NULL")); |
44 | field->setDefaultValue(tr("NULL")); |
45 | table->append(field); |
45 | table->append(field); |
46 | 46 | ||
47 | ui->label_2->setText(table->name()); |
47 | ui->label_2->setText(table->name()); |
48 | ui->label->setText(table->fields().at(0)->sqlString()); |
48 | ui->label->setText(table->fields().at(0)->sqlString()); |
49 | ui->label_4->setText(table->sqlString()); |
49 | ui->label_4->setText(table->sqlString()); |
50 | ////// ui->lineEdit->insert(table->sqlString());
|
50 | ////// ui->lineEdit->insert(table->sqlString());
|
51 | 51 | ||
52 | QTextDocument *document; |
52 | QTextDocument *document; |
53 | // = ui->textEdit->document();
|
53 | // = ui->textEdit->document();
|
54 | QTextCursor *cursor; |
54 | QTextCursor *cursor; |
55 | document = ui->textEdit->document(); |
55 | document = ui->textEdit->document(); |
56 | cursor = new QTextCursor(document); |
56 | cursor = new QTextCursor(document); |
57 | cursor->movePosition(QTextCursor::Start); |
57 | cursor->movePosition(QTextCursor::Start); |
58 | QTextCharFormat format(cursor->charFormat()); |
58 | QTextCharFormat format(cursor->charFormat()); |
59 | //format.setFontFamily("Courier");
|
59 | //format.setFontFamily("Courier");
|
60 | format.setFontFamily("Arial"); |
60 | format.setFontFamily("Arial"); |
61 | //format.setFontItalic(false);
|
61 | //format.setFontItalic(false);
|
62 | 62 | ||
63 | format.setFontWeight(QFont::Normal); |
63 | format.setFontWeight(QFont::Normal); |
64 | QTextCharFormat boldFormat = format; |
64 | QTextCharFormat boldFormat = format; |
65 | boldFormat.setFontWeight(QFont::Bold); |
65 | boldFormat.setFontWeight(QFont::Bold); |
66 | 66 | ||
67 | QTextCharFormat italicFormat = format; |
67 | QTextCharFormat italicFormat = format; |
68 | //format.setFontFamily("Courier");
|
68 | //format.setFontFamily("Courier");
|
69 | // format.setFontFamily("Arial");
|
69 | // format.setFontFamily("Arial");
|
70 | italicFormat.setFontItalic(true); |
70 | italicFormat.setFontItalic(true); |
71 | 71 | ||
72 | cursor->insertText(table->sqlString(), format); |
72 | cursor->insertText(table->sqlString(), format); |
73 | 73 | ||
74 | QString errorString;
|
74 | QString errorString;
|
75 | 75 | ||
76 | sql.setDatabaseName(tr("an_db")); |
76 | sql.setDatabaseName(tr("an_db")); |
77 | sql.setHostName(tr("localhost")); |
77 | sql.setHostName(tr("localhost")); |
78 | sql.setUserName(tr("an")); |
78 | sql.setUserName(tr("an")); |
79 | sql.setPassword(tr("393939")); |
79 | sql.setPassword(tr("393939")); |
80 | 80 | ||
81 | bool ok; |
81 | bool ok; |
82 | ok = sql.connect(&errorString); |
82 | ok = sql.connect(&errorString); |
83 | if (!ok) { |
83 | if (!ok) { |
84 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
84 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
85 | this, // Ðîäèòåëüñêèé âèäæåò. |
85 | this, // Ðîäèòåëüñêèé âèäæåò. |
86 | QObject::tr("Database Error"), // Çàãîëîâîê. |
86 | QObject::tr("Database Error"), // Çàãîëîâîê. |
87 | errorString); // Òåêñò ñîîáùåíèÿ. |
87 | errorString); // Òåêñò ñîîáùåíèÿ. |
88 | 88 | ||
89 | }
|
89 | }
|
90 | else { |
90 | else { |
91 | 91 | ||
92 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
92 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
93 | this, // Ðîäèòåëüñêèé âèäæåò. |
93 | this, // Ðîäèòåëüñêèé âèäæåò. |
94 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
94 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
95 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
95 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
96 | 96 | ||
97 | 97 | ||
98 | 98 | ||
99 | 99 | ||
100 | 100 | ||
101 | }
|
101 | }
|
102 | 102 | ||
- | 103 | ||
- | 104 | ok = sql.createTable(table, &errorString); |
|
- | 105 | ok = sql.connect(&errorString); |
|
- | 106 | if (!ok) { |
|
- | 107 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 108 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 109 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 110 | errorString); // Òåêñò ñîîáùåíèÿ. |
|
- | 111 | ||
- | 112 | }
|
|
- | 113 | else { |
|
- | 114 | ||
- | 115 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 116 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 117 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
|
- | 118 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
|
- | 119 | ||
- | 120 | ||
- | 121 | ||
- | 122 | ||
- | 123 | ||
- | 124 | }
|
|
- | 125 | ||
103 | }
|
126 | }
|
104 | 127 | ||
105 | ClassEditor::~ClassEditor() |
128 | ClassEditor::~ClassEditor() |
106 | {
|
129 | {
|
107 | delete ui; |
130 | delete ui; |
108 | // delete field;
|
131 | // delete field;
|
109 | // delete settdialog;
|
132 | // delete settdialog;
|
110 | }
|
133 | }
|
111 | 134 | ||
112 | void ClassEditor::changeEvent(QEvent *e) |
135 | void ClassEditor::changeEvent(QEvent *e) |
113 | {
|
136 | {
|
114 | QMainWindow::changeEvent(e); |
137 | QMainWindow::changeEvent(e); |
115 | switch (e->type()) { |
138 | switch (e->type()) { |
116 | case QEvent::LanguageChange: |
139 | case QEvent::LanguageChange: |
117 | ui->retranslateUi(this); |
140 | ui->retranslateUi(this); |
118 | break; |
141 | break; |
119 | default: |
142 | default: |
120 | break; |
143 | break; |
121 | }
|
144 | }
|
122 | }
|
145 | }
|
123 | 146 |