Хранилища Subversion OpenInventory

Редакция

Редакция 90 | Редакция 92 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 90 Редакция 91
1
1
#include "mainwindow.h"
2
2
#include "ui_mainwindow.h"
3
3
4
4
MainWindow::MainWindow(QWidget *parent) :
5
5
    QMainWindow(parent),
6
6
    ui(new Ui::MainWindow)
7
7
{
8
8
    ui->setupUi(this);
9
9
10
10
   MainWindow::readModel();
11
11
-
 
12
   //QString model_str;
-
 
13
   MainWindow::creatModelString();
-
 
14
   int i;
-
 
15
   i++;
-
 
16
12
17
}
13
18
14
19
MainWindow::~MainWindow()
15
20
{
16
21
    delete ui;
17
22
}
18
23
19
24
void MainWindow::changeEvent(QEvent *e)
20
25
{
21
26
    QMainWindow::changeEvent(e);
22
27
    switch (e->type()) {
23
28
    case QEvent::LanguageChange:
24
29
        ui->retranslateUi(this);
25
30
        break;
26
31
    default:
27
32
        break;
28
33
    }
29
34
}
30
35
31
36
32
37
bool MainWindow::readModel(){
33
38
    bool result;
34
39
    QString model_str;
35
40
    QFile file(":/model.txt");
36
41
   rootItem1 = new  QTreeWidgetItem(ui->treeWidget);
37
42
    rootItem1->setText(0, tr("Óðîâåíü 1"));
38
43
   // rootItem2 = new  QTreeWidgetItem(rootItem1);
39
44
   // rootItem2->setText(0, tr("óðîâåíü 2"));
40
45
    rootItem1->setCheckState(0,Qt::Checked);
41
46
   // rootItem2->setCheckState(0,Qt::Checked);
42
47
43
48
44
49
45
50
    result = file.open(QIODevice::ReadOnly);
46
51
    if (result) {
47
52
                     model_str = QString(tr(file.readAll()));
48
53
                }
49
54
50
55
    setupModelData(model_str.split(QString("\n")), rootItem1);
51
56
52
57
53
58
    return result;
54
59
55
60
}
56
61
57
62
58
63
void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent)
59
64
{
60
65
    QList<QTreeWidgetItem*> parents;
61
66
    QList<int> indentations;
62
67
    parents << parent;
63
68
    indentations << 0;
64
69
65
70
    int number = 0;
66
71
67
72
    while (number < lines.count()) {
68
73
        int position = 0;
69
74
        while (position < lines[number].length()) {
70
75
            if (lines[number].mid(position, 1) != " ")
71
76
                break;
72
77
            position++;
73
78
        }
74
79
75
80
        QString lineData = lines[number].mid(position).trimmed();
76
81
77
82
        if (!lineData.isEmpty()) {
78
83
            // Read the column data from the rest of the line.
79
84
            QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
80
85
            QList<QVariant> columnData;
81
86
            for (int column = 0; column < columnStrings.count(); ++column)
82
87
                columnData << columnStrings[column];
83
88
84
89
            if (position > indentations.last()) {
85
90
                // The last child of the current parent is now the new parent
86
91
                // unless the current parent has no children.
87
92
88
93
                if (parents.last()->childCount() > 0) {
89
94
                    parents << parents.last()->child(parents.last()->childCount()-1);
90
95
                    indentations << position;
91
96
                }
92
97
            } else {
93
98
                while (position < indentations.last() && parents.count() > 0) {
94
99
                    parents.pop_back();
95
100
                    indentations.pop_back();
96
101
                }
97
102
            }
98
103
99
104
            // Append a new item to the current parent's list of children.
100
105
          // // //  parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last()));
101
106
            QTreeWidgetItem* itm_tmp;
102
107
            itm_tmp = new QTreeWidgetItem( parents.last());
103
108
104
109
            itm_tmp->setText(0, QString(columnData.at(0).toString()));
105
110
            if (columnData.at(1).toString() == "true") {
106
111
                                                            itm_tmp->setCheckState(0,Qt::Checked);
107
112
                                                        }
108
113
            else itm_tmp->setCheckState(0,Qt::Unchecked);
109
114
            itm_tmp->setText(1, QString(columnData.at(2).toString()));
110
115
            itm_tmp->setText(2, QVariant(number).toString()); // íîìåð ñòðîêè â ôàéëå-ìîäåëè îòîáðàæåíèÿ
111
116
            itm_tmp->setText(3, QVariant(indentations.size()).toString());
112
117
        }
113
118
114
119
        number++;
115
120
    }
116
121
}
117
122
118
123
119
124
/*
120
125
void MainWindow::openBase()
121
126
{
122
127

123
128
        db = QSqlDatabase::addDatabase("QMYSQL");
124
129
        pdb = &db;
125
130
        raportFrm.pdb = &db;
126
131

127
132
        pdb->setHostName(hostName);
128
133
        pdb->setDatabaseName(baseName);
129
134
        pdb->setUserName(userName);
130
135
        pdb->setPassword(password);
131
136
        bool ok = pdb->open();
132
137
        if (!ok) {
133
138
                                QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
134
139
                                                                                this,                      // Ðîäèòåëüñêèé âèäæåò.
135
140
                                                                                QObject::tr("Database Error"),   // Çàãîëîâîê.
136
141
                                                                                pdb->lastError().text());          // Òåêñò ñîîáùåíèÿ.
137
142
                         }
138
143
        if (ok)
139
144
        {lineEdit-> insert(tr("Áàçà óñïåøíî îòêðûòà"));
140
145
        }
141
146
        else {lineEdit-> insert(tr("Áàçà íåäîñòóïíà. Êîä îøèáêè: "));
142
147
                  lineEdit-> insert(pdb->lastError().text());
143
148
                 }
144
149

145
150

146
151

147
152
        model = new QSqlTableModel(this);
148
153
        model->setTable(tableName);
149
154

150
155
        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
151
156
        model->setSort(0, Qt::AscendingOrder);
152
157

153
158
        model->select();
154
159

155
160

156
161
        QSqlField field(tr("age"), QVariant::Int);
157
162
        field.setValue(QString(tr("123")));
158
163

159
164
        bool okey;
160
165
        int index;
161
166
        QSqlRecord record;
162
167

163
168

164
169
  &
165
170
166
171
167
172
168
173
169
174
170
175
171
176
172
177
173
178
174
179
175
180
176
181
177
182
178
183
179
184
180
185
181
186
182
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