Редакция 50 | Редакция 54 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 50 | Редакция 51 | ||
---|---|---|---|
1 | #include "classeditor.h"
|
1 | #include "classeditor.h"
|
2 | #include "ui_classeditor.h"
|
2 | #include "ui_classeditor.h"
|
3 | 3 | ||
4 | 4 | ||
5 | ClassEditor::ClassEditor(QWidget *parent) : |
5 | ClassEditor::ClassEditor(QWidget *parent) : |
6 | QMainWindow(parent), |
6 | QMainWindow(parent), |
7 | ui(new Ui::ClassEditor) |
7 | ui(new Ui::ClassEditor) |
8 | {
|
8 | {
|
9 | ui->setupUi(this); |
9 | ui->setupUi(this); |
10 | // settdialog = new SettingsDialog(this);
|
10 | // settdialog = new SettingsDialog(this);
|
11 | settdialog.show(); |
11 | settdialog.show(); |
12 | sql.setDatabaseName(tr("an_db")); |
12 | sql.setDatabaseName(tr("an_db")); |
13 | field = new TableField(tr("Ñîòðóäíèêè"), this); |
13 | field = new TableField(tr("Ñîòðóäíèêè"), this); |
14 | field->setNotNull(true); |
14 | field->setNotNull(true); |
15 | field->setDefaultValue(tr("ñîòðóäíèê")); |
15 | field->setDefaultValue(tr("ñîòðóäíèê")); |
16 | 16 | ||
17 | table = new SqlTable (tr("NewTable"), this); |
17 | table = new SqlTable (tr("NewTable"), this); |
18 | table->setName(tr("NewTable")); |
18 | table->setName(tr("NewTable")); |
19 | table->fields().at(0)->setNotNull(true); |
19 | table->fields().at(0)->setNotNull(true); |
20 | if (!(table->setPrimaryKey(tr("ID")))) { |
20 | if (!(table->setPrimaryKey(tr("ID")))) { |
21 | ui->label_3->setText(table->lastError()); |
21 | ui->label_3->setText(table->lastError()); |
22 | }
|
22 | }
|
23 | else ui->label_3->setText(table->primaryKey()); |
23 | else ui->label_3->setText(table->primaryKey()); |
24 | table->append(field); |
24 | table->append(field); |
25 | 25 | ||
26 | field = new TableField(tr("Êîìïüþòåðû"), this); |
26 | field = new TableField(tr("Êîìïüþòåðû"), this); |
27 | field->setNotNull(true); |
27 | field->setNotNull(true); |
28 | field->setDefaultValue(tr("êîìïüþòåð")); |
28 | field->setDefaultValue(tr("êîìïüþòåð")); |
29 | table->append(field); |
29 | table->append(field); |
30 | 30 | ||
31 | field = new TableField(tr("Ìîíèòîðû"), this); |
31 | field = new TableField(tr("Ìîíèòîðû"), this); |
32 | field->setNotNull(true); |
32 | field->setNotNull(true); |
33 | field->setDefaultValue(tr("ìîíèòîð")); |
33 | field->setDefaultValue(tr("ìîíèòîð")); |
34 | table->append(field); |
34 | table->append(field); |
35 | 35 | ||
36 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this); |
36 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this); |
37 | field->setNotNull(true); |
37 | field->setNotNull(true); |
38 | field->setType(tr("INTEGER")); |
38 | field->setType(tr("INTEGER")); |
39 | field->setDefaultValue(tr("1")); |
39 | field->setDefaultValue(tr("1")); |
40 | table->append(field); |
40 | table->append(field); |
41 | 41 | ||
42 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this); |
42 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this); |
43 | field->setNotNull(false); |
43 | field->setNotNull(false); |
44 | field->setType(tr("DATE")); |
44 | field->setType(tr("DATE")); |
45 | field->setDefaultValue(tr("NULL")); |
45 | field->setDefaultValue(tr("NULL")); |
46 | table->append(field); |
46 | table->append(field); |
47 | 47 | ||
48 | ui->label_2->setText(table->name()); |
48 | ui->label_2->setText(table->name()); |
49 | ui->label->setText(table->fields().at(0)->sqlString()); |
49 | ui->label->setText(table->fields().at(0)->sqlString()); |
50 | ui->label_4->setText(table->sqlString()); |
50 | ui->label_4->setText(table->sqlString()); |
51 | ////// ui->lineEdit->insert(table->sqlString());
|
51 | ////// ui->lineEdit->insert(table->sqlString());
|
52 | 52 | ||
53 | 53 | ||
54 | /**********************************************
|
54 | /**********************************************
|
55 | 55 | ||
56 | QTextDocument *document;
|
56 | QTextDocument *document;
|
57 | // = ui->textEdit->document();
|
57 | // = ui->textEdit->document();
|
58 | QTextCursor *cursor;
|
58 | QTextCursor *cursor;
|
59 | 59 | ||
60 | document = ui->textEdit->document();
|
60 | document = ui->textEdit->document();
|
61 | cursor = new QTextCursor(document);
|
61 | cursor = new QTextCursor(document);
|
62 | cursor->movePosition(QTextCursor::Start);
|
62 | cursor->movePosition(QTextCursor::Start);
|
63 | QTextCharFormat format(cursor->charFormat());
|
63 | QTextCharFormat format(cursor->charFormat());
|
64 | //format.setFontFamily("Courier");
|
64 | //format.setFontFamily("Courier");
|
65 | format.setFontFamily("Arial");
|
65 | format.setFontFamily("Arial");
|
66 | //format.setFontItalic(false);
|
66 | //format.setFontItalic(false);
|
67 | 67 | ||
68 | format.setFontWeight(QFont::Normal);
|
68 | format.setFontWeight(QFont::Normal);
|
69 | QTextCharFormat boldFormat = format;
|
69 | QTextCharFormat boldFormat = format;
|
70 | boldFormat.setFontWeight(QFont::Bold);
|
70 | boldFormat.setFontWeight(QFont::Bold);
|
71 | 71 | ||
72 | QTextCharFormat italicFormat = format;
|
72 | QTextCharFormat italicFormat = format;
|
73 | //format.setFontFamily("Courier");
|
73 | //format.setFontFamily("Courier");
|
74 | // format.setFontFamily("Arial");
|
74 | // format.setFontFamily("Arial");
|
75 | italicFormat.setFontItalic(true);
|
75 | italicFormat.setFontItalic(true);
|
76 | 76 | ||
77 | cursor->insertText(table->sqlString(), format);
|
77 | cursor->insertText(table->sqlString(), format);
|
78 | 78 | ||
79 | ****************************************************/
|
79 | ****************************************************/
|
80 | 80 | ||
81 | QString errorString;
|
81 | QString errorString;
|
82 | 82 | ||
83 | sql.setDatabaseName(tr("an_db")); |
83 | sql.setDatabaseName(tr("an_db")); |
84 | sql.setHostName(tr("localhost")); |
84 | sql.setHostName(tr("localhost")); |
85 | sql.setUserName(tr("an")); |
85 | sql.setUserName(tr("an")); |
86 | sql.setPassword(tr("393939")); |
86 | sql.setPassword(tr("393939")); |
87 | 87 | ||
88 | bool ok; |
88 | bool ok; |
89 | ok = sql.connect(); |
89 | ok = sql.connect(); |
90 | if (!ok) { |
90 | if (!ok) { |
91 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
91 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
92 | this, // Ðîäèòåëüñêèé âèäæåò. |
92 | this, // Ðîäèòåëüñêèé âèäæåò. |
93 | QObject::tr("Database Error"), // Çàãîëîâîê. |
93 | QObject::tr("Database Error"), // Çàãîëîâîê. |
94 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
94 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
95 | 95 | ||
96 | }
|
96 | }
|
97 | else { |
97 | else { |
98 | 98 | ||
99 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
99 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
100 | this, // Ðîäèòåëüñêèé âèäæåò. |
100 | this, // Ðîäèòåëüñêèé âèäæåò. |
101 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
101 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
102 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
102 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
103 | 103 | ||
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | 107 | ||
108 | }
|
108 | }
|
109 | 109 | ||
110 | 110 | ||
111 | ok = sql.createTable(table); |
111 | ok = sql.createTable(table); |
112 | if (!ok) { |
112 | if (!ok) { |
113 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
113 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
114 | this, // Ðîäèòåëüñêèé âèäæåò. |
114 | this, // Ðîäèòåëüñêèé âèäæåò. |
115 | QObject::tr("Database Error"), // Çàãîëîâîê. |
115 | QObject::tr("Database Error"), // Çàãîëîâîê. |
116 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
116 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
117 | }
|
117 | }
|
118 | else { |
118 | else { |
119 | 119 | ||
120 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
120 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
121 | this, // Ðîäèòåëüñêèé âèäæåò. |
121 | this, // Ðîäèòåëüñêèé âèäæåò. |
122 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
122 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
123 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
123 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
124 | }
|
124 | }
|
125 | 125 | ||
126 | 126 | ||
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | ok = sql.createDataBase(); |
130 | ok = sql.createDataBase(); |
131 | 131 | ||
132 | if (!ok) { |
132 | if (!ok) { |
133 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
133 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
134 | this, // Ðîäèòåëüñêèé âèäæåò. |
134 | this, // Ðîäèòåëüñêèé âèäæåò. |
135 | QObject::tr("Database Error"), // Çàãîëîâîê. |
135 | QObject::tr("Database Error"), // Çàãîëîâîê. |
136 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
136 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
137 | 137 | ||
138 | }
|
138 | }
|
139 | else { |
139 | else { |
140 | 140 | ||
141 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
141 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
142 | this, // Ðîäèòåëüñêèé âèäæåò. |
142 | this, // Ðîäèòåëüñêèé âèäæåò. |
143 | QObject::tr("Database Create"), // Çàãîëîâîê. |
143 | QObject::tr("Database Create"), // Çàãîëîâîê. |
144 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
144 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
145 | }
|
145 | }
|
146 | 146 | ||
147 | 147 | ||
148 | model = new QSqlTableModel(this); |
148 | model = new QSqlTableModel(this); |
149 | mymodel = new MyModel(this); |
149 | mymodel = new MyModel(this); |
150 | 150 | ||
151 | 151 | ||
152 | model->setTable(tr("ListOfClasses")); |
152 | model->setTable(tr("ListOfClasses")); |
153 | mymodel->setTable(tr("ListOfClasses")); |
153 | mymodel->setTable(tr("ListOfClasses")); |
154 | 154 | ||
155 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
155 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
156 | 156 | ||
157 | /*
|
157 | /*
|
158 | model->setEditStrategy(QSqlTableModel::OnFieldChange);
|
158 | model->setEditStrategy(QSqlTableModel::OnFieldChange);
|
159 | mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
159 | mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
160 | */
|
160 | */
|
161 | 161 | ||
162 | 162 | ||
163 | model->setSort(0, Qt::AscendingOrder); |
163 | model->setSort(0, Qt::AscendingOrder); |
164 | mymodel->setSort(0, Qt::AscendingOrder); |
164 | mymodel->setSort(0, Qt::AscendingOrder); |
165 | 165 | ||
166 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
166 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
167 | model->select(); |
167 | model->select(); |
168 | mymodel->select(); |
168 | mymodel->select(); |
169 | 169 | ||
170 | model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
170 | model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
171 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
171 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
175 | model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
176 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
176 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
177 | 177 | ||
178 | //ui->tableView->setModel(model);
|
178 | //ui->tableView->setModel(model);
|
179 | ui->tableView->setModel(mymodel); |
179 | ui->tableView->setModel(mymodel); |
180 | 180 | ||
181 | 181 | ||
182 | 182 | ||
183 | 183 | ||
184 | ui->tableView->setAlternatingRowColors(true); |
184 | ui->tableView->setAlternatingRowColors(true); |
185 | ui->tableView->resizeColumnsToContents(); |
185 | ui->tableView->resizeColumnsToContents(); |
186 | ui->tableView->hideColumn(0); |
186 | //ui->tableView->hideColumn(0);
|
- | 187 | ||
187 | 188 | ||
188 | int row = model->rowCount(); |
- | |
189 | model->insertRows(row, 1); |
- | |
190 | model->setData(model->index(row, 0), row+1); |
- | |
191 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
- | |
192 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
- | |
193 | 189 | ||
194 | model->submitAll(); |
- | |
195 | }
|
190 | }
|
196 | 191 | ||
197 | 192 | ||
198 | 193 | ||
199 | 194 | ||
200 | 195 | ||
201 | 196 | ||
202 | 197 | ||
203 | 198 | ||
204 | 199 | ||
205 | 200 | ||
206 | 201 | ||
207 | ClassEditor::~ClassEditor() |
202 | ClassEditor::~ClassEditor() |
208 | {
|
203 | {
|
209 | delete ui; |
204 | delete ui; |
210 | // delete field;
|
205 | // delete field;
|
211 | // delete settdialog;
|
206 | // delete settdialog;
|
212 | }
|
207 | }
|
213 | 208 | ||
214 | void ClassEditor::changeEvent(QEvent *e) |
209 | void ClassEditor::changeEvent(QEvent *e) |
215 | {
|
210 | {
|
216 | QMainWindow::changeEvent(e); |
211 | QMainWindow::changeEvent(e); |
217 | switch (e->type()) { |
212 | switch (e->type()) { |
218 | case QEvent::LanguageChange: |
213 | case QEvent::LanguageChange: |
219 | ui->retranslateUi(this); |
214 | ui->retranslateUi(this); |
220 | break; |
215 | break; |
221 | default: |
216 | default: |
222 | break; |
217 | break; |
223 | }
|
218 | }
|
224 | }
|
219 | }
|
- | 220 | ||
- | 221 | ||
- | 222 | ||
- | 223 | void ClassEditor::addNewClass(){ |
|
- | 224 | ||
- | 225 | int row = model->rowCount(); |
|
- | 226 | ||
- | 227 | model->insertRows(row, 1); |
|
- | 228 | model->setData(model->index(row, 1), tr("New classû")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
|
- | 229 | ||
- | 230 | ||
- | 231 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
|
- | 232 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
|
- | 233 | ||
- | 234 | ||
- | 235 | model->submitAll(); |
|
- | 236 | ||
- | 237 | row = model->rowCount(); |
|
- | 238 | QString tmp_str;
|
|
- | 239 | int i_tmp; |
|
- | 240 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
|
- | 241 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
|
- | 242 | ||
- | 243 | tmp_str.append(tr("_Inctance")); |
|
- | 244 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó |
|
- | 245 | ||
- | 246 | model->submitAll(); |
|
- | 247 | mymodel->select(); |
|
- | 248 | ||
- | 249 | ||
- | 250 | }
|
|
- | 251 | ||
- | 252 | ||
- | 253 | void ClassEditor::on_pushButton_clicked(){ |
|
- | 254 | int i; |
|
- | 255 | i++; |
|
- | 256 | ClassEditor::addNewClass(); |
|
- | 257 | mymodel->select(); |
|
- | 258 | ui->tableView->setModel(mymodel); |
|
- | 259 | }
|
|
225 | 260 |