Редакция 46 | Редакция 51 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 46 | Редакция 50 | ||
---|---|---|---|
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); |
|
- | 150 | ||
- | 151 | ||
149 | model->setTable(tr("ListOfClasses")); |
152 | model->setTable(tr("ListOfClasses")); |
- | 153 | mymodel->setTable(tr("ListOfClasses")); |
|
- | 154 | ||
150 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
155 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
- | 156 | ||
- | 157 | /*
|
|
151 | model->setEditStrategy(QSqlTableModel::OnFieldChange); |
158 | model->setEditStrategy(QSqlTableModel::OnFieldChange);
|
- | 159 | mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
|
- | 160 | */
|
|
- | 161 | ||
- | 162 | ||
152 | model->setSort(0, Qt::AscendingOrder); |
163 | model->setSort(0, Qt::AscendingOrder); |
- | 164 | mymodel->setSort(0, Qt::AscendingOrder); |
|
- | 165 | ||
153 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
166 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
154 | model->select(); |
167 | model->select(); |
- | 168 | mymodel->select(); |
|
- | 169 | ||
155 | model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
170 | model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
- | 171 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
|
- | 172 | ||
- | 173 | ||
- | 174 | ||
156 | model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
175 | model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
- | 176 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
|
- | 177 | ||
157 | ui->tableView->setModel(model); |
178 | //ui->tableView->setModel(model);
|
- | 179 | ui->tableView->setModel(mymodel); |
|
- | 180 | ||
- | 181 | ||
- | 182 | ||
- | 183 | ||
158 | ui->tableView->setAlternatingRowColors(true); |
184 | ui->tableView->setAlternatingRowColors(true); |
159 | ui->tableView->resizeColumnsToContents(); |
185 | ui->tableView->resizeColumnsToContents(); |
160 | ui->tableView->hideColumn(0); |
186 | ui->tableView->hideColumn(0); |
161 | 187 | ||
162 | int row = model->rowCount(); |
188 | int row = model->rowCount(); |
163 | model->insertRows(row, 1); |
189 | model->insertRows(row, 1); |
164 | model->setData(model->index(row, 0), row+1); |
190 | model->setData(model->index(row, 0), row+1); |
165 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
191 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
166 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
192 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
167 | 193 | ||
168 | model->submitAll(); |
194 | model->submitAll(); |
169 | }
|
195 | }
|
170 | 196 | ||
171 | 197 | ||
172 | 198 | ||
173 | 199 | ||
174 | 200 | ||
175 | 201 | ||
176 | 202 | ||
177 | 203 | ||
178 | 204 | ||
179 | 205 | ||
180 | 206 | ||
181 | ClassEditor::~ClassEditor() |
207 | ClassEditor::~ClassEditor() |
182 | {
|
208 | {
|
183 | delete ui; |
209 | delete ui; |
184 | // delete field;
|
210 | // delete field;
|
185 | // delete settdialog;
|
211 | // delete settdialog;
|
186 | }
|
212 | }
|
187 | 213 | ||
188 | void ClassEditor::changeEvent(QEvent *e) |
214 | void ClassEditor::changeEvent(QEvent *e) |
189 | {
|
215 | {
|
190 | QMainWindow::changeEvent(e); |
216 | QMainWindow::changeEvent(e); |
191 | switch (e->type()) { |
217 | switch (e->type()) { |
192 | case QEvent::LanguageChange: |
218 | case QEvent::LanguageChange: |
193 | ui->retranslateUi(this); |
219 | ui->retranslateUi(this); |
194 | break; |
220 | break; |
195 | default: |
221 | default: |
196 | break; |
222 | break; |
197 | }
|
223 | }
|
198 | }
|
224 | }
|
199 | 225 |