Хранилища Subversion OpenInventory

Редакция

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

Редакция 88 Редакция 89
1
#include "mainwindow.h"
1
#include "mainwindow.h"
2
#include "ui_mainwindow.h"
2
#include "ui_mainwindow.h"
3
3
4
MainWindow::MainWindow(QWidget *parent) :
4
MainWindow::MainWindow(QWidget *parent) :
5
    QMainWindow(parent),
5
    QMainWindow(parent),
6
    ui(new Ui::MainWindow)
6
    ui(new Ui::MainWindow)
7
{
7
{
8
    ui->setupUi(this);
8
    ui->setupUi(this);
9
   rootItem1 = new  QTreeWidgetItem(ui->treeWidget);
-
 
10
   rootItem1->setText(0, tr("Óðîâåíü 1"));
-
 
-
 
9
11
   rootItem2 = new  QTreeWidgetItem(rootItem1);
10
   MainWindow::readModel();
12
   rootItem2->setText(0, tr("óðîâåíü 2"));
-
 
13
   rootItem1->setCheckState(0,Qt::Checked);
-
 
14
   rootItem2->setCheckState(0,Qt::Checked);
-
 
15
11
16
}
12
}
17
13
18
MainWindow::~MainWindow()
14
MainWindow::~MainWindow()
19
{
15
{
20
    delete ui;
16
    delete ui;
21
}
17
}
22
18
23
void MainWindow::changeEvent(QEvent *e)
19
void MainWindow::changeEvent(QEvent *e)
24
{
20
{
25
    QMainWindow::changeEvent(e);
21
    QMainWindow::changeEvent(e);
26
    switch (e->type()) {
22
    switch (e->type()) {
27
    case QEvent::LanguageChange:
23
    case QEvent::LanguageChange:
28
        ui->retranslateUi(this);
24
        ui->retranslateUi(this);
29
        break;
25
        break;
30
    default:
26
    default:
31
        break;
27
        break;
32
    }
28
    }
33
}
29
}
-
 
30
-
 
31
-
 
32
bool MainWindow::readModel(){
-
 
33
    bool result;
-
 
34
    QString model_str;
-
 
35
    QFile file(":/model.txt");
-
 
36
    rootItem1 = new  QTreeWidgetItem(ui->treeWidget);
-
 
37
    rootItem1->setText(0, tr("Óðîâåíü 1"));
-
 
38
   // rootItem2 = new  QTreeWidgetItem(rootItem1);
-
 
39
   // rootItem2->setText(0, tr("óðîâåíü 2"));
-
 
40
    rootItem1->setCheckState(0,Qt::Checked);
-
 
41
   // rootItem2->setCheckState(0,Qt::Checked);
-
 
42
-
 
43
-
 
44
-
 
45
    result = file.open(QIODevice::ReadOnly);
-
 
46
    if (result) {
-
 
47
                     model_str = QString(file.readAll());
-
 
48
                }
-
 
49
-
 
50
   setupModelData(model_str.split(QString("\n")), rootItem1);
-
 
51
-
 
52
-
 
53
    return result;
-
 
54
-
 
55
}
-
 
56
-
 
57
-
 
58
void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent)
-
 
59
{
-
 
60
    QList<QTreeWidgetItem*> parents;
-
 
61
    QList<int> indentations;
-
 
62
    parents << parent;
-
 
63
    indentations << 0;
-
 
64
-
 
65
    int number = 0;
-
 
66
-
 
67
    while (number < lines.count()) {
-
 
68
        int position = 0;
-
 
69
        while (position < lines[number].length()) {
-
 
70
            if (lines[number].mid(position, 1) != " ")
-
 
71
                break;
-
 
72
            position++;
-
 
73
        }
-
 
74
-
 
75
        QString lineData = lines[number].mid(position).trimmed();
-
 
76
-
 
77
        if (!lineData.isEmpty()) {
-
 
78
            // Read the column data from the rest of the line.
-
 
79
            QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
-
 
80
            QList<QVariant> columnData;
-
 
81
            for (int column = 0; column < columnStrings.count(); ++column)
-
 
82
                columnData << columnStrings[column];
-
 
83
-
 
84
            if (position > indentations.last()) {
-
 
85
                // The last child of the current parent is now the new parent
-
 
86
                // unless the current parent has no children.
-
 
87
-
 
88
                if (parents.last()->childCount() > 0) {
-
 
89
                    parents << parents.last()->child(parents.last()->childCount()-1);
-
 
90
                    indentations << position;
-
 
91
                }
-
 
92
            } else {
-
 
93
                while (position < indentations.last() && parents.count() > 0) {
-
 
94
                    parents.pop_back(
-
 
95
-
 
96
-
 
97
-
 
98
-
 
99
-
 
100
-
 
101
-
 
102
-
 
103
-
 
104
-
 
105
-
 
106
-
 
107
-
 
108
-
 
109
-
 
110
-
 
111
-
 
112
-
 
113
-
 
114
-
 
115
-
 
116
-
 
117
-
 
118
-
 
119
-
 
120
-
 
121
-
 
122
-
 
123
-
 
124
-
 
125
-
 
126
-
 
127
-
 
128
-
 
129
-
 
130
-
 
131
-
 
132
-
 
133
-
 
134
-
 
135
-
 
136
-
 
137
-
 
138
-
 
139
-
 
140
-
 
141
-
 
142
-
 
143
-
 
144
-
 
145
-
 
146
-
 
147
-
 
148
-
 
149
-
 
150
-
 
151
-
 
152
-
 
153
-
 
154
-
 
155
-
 
156
-
 
157
-
 
158
-
 
159
-
 
160
-
 
161
-
 
162
-
 
163
-
 
164
-
 
165
-
 
166
-
 
167
-
 
168
-
 
169
-
 
170
-
 
171
-
 
172
-
 
173
-
 
174
-
 
175
-
 
176
-
 
177
-
 
178
-
 
179
-
 
180
-
 
181
34
 
-