Хранилища Subversion OpenInventory

Редакция

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

Редакция 226 Редакция 227
1
1
2
2
3
/****************************************************************************
3
/****************************************************************************
4
**
4
**
5
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
** All rights reserved.
6
** All rights reserved.
7
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
**
8
**
9
** This file is part of the examples of the Qt Toolkit.
9
** This file is part of the examples of the Qt Toolkit.
10
**
10
**
11
** $QT_BEGIN_LICENSE:LGPL$
11
** $QT_BEGIN_LICENSE:LGPL$
12
** Commercial Usage
12
** Commercial Usage
13
** Licensees holding valid Qt Commercial licenses may use this file in
13
** Licensees holding valid Qt Commercial licenses may use this file in
14
** accordance with the Qt Commercial License Agreement provided with the
14
** accordance with the Qt Commercial License Agreement provided with the
15
** Software or, alternatively, in accordance with the terms contained in
15
** Software or, alternatively, in accordance with the terms contained in
16
** a written agreement between you and Nokia.
16
** a written agreement between you and Nokia.
17
**
17
**
18
** GNU Lesser General Public License Usage
18
** GNU Lesser General Public License Usage
19
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** Alternatively, this file may be used under the terms of the GNU Lesser
20
** General Public License version 2.1 as published by the Free Software
20
** General Public License version 2.1 as published by the Free Software
21
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** Foundation and appearing in the file LICENSE.LGPL included in the
22
** packaging of this file.  Please review the following information to
22
** packaging of this file.  Please review the following information to
23
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** ensure the GNU Lesser General Public License version 2.1 requirements
24
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
**
25
**
26
** In addition, as a special exception, Nokia gives you certain additional
26
** In addition, as a special exception, Nokia gives you certain additional
27
** rights.  These rights are described in the Nokia Qt LGPL Exception
27
** rights.  These rights are described in the Nokia Qt LGPL Exception
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
**
29
**
30
** GNU General Public License Usage
30
** GNU General Public License Usage
31
** Alternatively, this file may be used under the terms of the GNU
31
** Alternatively, this file may be used under the terms of the GNU
32
** General Public License version 3.0 as published by the Free Software
32
** General Public License version 3.0 as published by the Free Software
33
** Foundation and appearing in the file LICENSE.GPL included in the
33
** Foundation and appearing in the file LICENSE.GPL included in the
34
** packaging of this file.  Please review the following information to
34
** packaging of this file.  Please review the following information to
35
** ensure the GNU General Public License version 3.0 requirements will be
35
** ensure the GNU General Public License version 3.0 requirements will be
36
** met: http://www.gnu.org/copyleft/gpl.html.
36
** met: http://www.gnu.org/copyleft/gpl.html.
37
**
37
**
38
** If you have questions regarding the use of this file, please contact
38
** If you have questions regarding the use of this file, please contact
39
** Nokia at qt-info@nokia.com.
39
** Nokia at qt-info@nokia.com.
40
** $QT_END_LICENSE$
40
** $QT_END_LICENSE$
41
**
41
**
42
****************************************************************************/
42
****************************************************************************/
43
43
44
/*
44
/*
45
    delegate.cpp
45
    delegate.cpp
46

46

47
    A delegate that allows the user to change integer values from the model
47
    A delegate that allows the user to change integer values from the model
48
    using a spin box widget.
48
    using a spin box widget.
49
*/
49
*/
50
50
51
#include <QtGui>
51
#include <QtGui>
52
52
53
#include "delegate.h"
53
#include "delegate.h"
54
54
55
55
56
//! [0]
56
//! [0]
57
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
57
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
58
    : QItemDelegate(parent)
58
    : QItemDelegate(parent)
59
{
59
{
60
}
60
}
61
//! [0]
61
//! [0]
62
62
63
void SpinBoxDelegate::setInctance(QString newInctance){
63
void SpinBoxDelegate::setInctance(QString newInctance){
64
    inctance = newInctance;
64
    inctance = newInctance;
65
}
65
}
66
66
67
void SpinBoxDelegate::getItems(){
67
void SpinBoxDelegate::getItems(){
68
    QMap <QString, QString> result_map;
68
    QMap <QString, QString> result_map;
69
    QSqlQuery q;
69
    QSqlQuery q;
70
    QString query_str;
70
    QString query_str;
71
    bool ok;
71
    bool ok;
72
72
73
    if (SpinBoxDelegate::inctance.isEmpty())
73
    if (SpinBoxDelegate::inctance.isEmpty())
74
    {
74
    {
75
        items.clear();
75
        items.clear();
76
        return;
76
        return;
77
    }
77
    }
78
78
79
    query_str = tr("select * from `");
79
    query_str = tr("select * from `");
80
    query_str.append(inctance);
80
    query_str.append(inctance);
81
    query_str.append( tr("`"));
81
    query_str.append( tr("`"));
82
82
83
    q.prepare(query_str);
83
    q.prepare(query_str);
84
84
85
85
86
    ok = q.exec();
86
    ok = q.exec();
87
87
88
88
89
89
90
90
91
    if (!ok) {
91
    if (!ok) {
92
                            /*
92
                            /*
93
                            QString error_str;
93
                            QString error_str;
94
                            error_str =  tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
94
                            error_str =  tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
95
                            error_str.append(inctance);
95
                            error_str.append(inctance);
96
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
96
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
97
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
97
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
98
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
98
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
99
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
99
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
100
                                                                        //    tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû "));    // Òåêñò ñîîáùåíèÿ.
100
                                                                        //    tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû "));    // Òåêñò ñîîáùåíèÿ.
101

101

102
                            */
102
                            */
103
                            items.clear();
103
                            items.clear();
104
                            return;
104
                            return;
105
                        }
105
                        }
106
106
107
107
108
 //   field_inctance = q.record().indexOf(tr("TableWhithInstance"));
108
 //   field_inctance = q.record().indexOf(tr("TableWhithInstance"));
109
    items.clear();
109
    items.clear();
110
    while(q.next()){
110
    while(q.next()){
111
111
112
                  QString ID;
112
                  QString ID;
113
                  QString Name;
113
                  QString Name;
114
                  ID = q.value(0).toString(); // îïðåäåëÿåì ID
114
                  ID = q.value(0).toString(); // îïðåäåëÿåì ID
115
                  Name = q.value(1).toString(); // îïðåäåëÿåì Name
115
                  Name = q.value(1).toString(); // îïðåäåëÿåì Name
116
                  items.insert(ID, Name);
116
                  items.insert(ID, Name);
117
                }
117
                }
118
118
119
119
120
 //   return result_map;
120
 //   return result_map;
121
}
121
}
122
122
123
123
124
//! [1]
124
//! [1]
125
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
125
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
126
    const QStyleOptionViewItem &/* option */,
126
    const QStyleOptionViewItem &/* option */,
127
    const QModelIndex &/* index */) const
127
    const QModelIndex &/* index */) const
128
{
128
{
129
    //QSpinBox *editor = new QSpinBox(parent);
129
    //QSpinBox *editor = new QSpinBox(parent);
130
    //editor->setMinimum(0);
130
    //editor->setMinimum(0);
131
    //editor->setMaximum(100);
131
    //editor->setMaximum(100);
132
    QStringList ID_list;
132
    QStringList ID_list;
133
    QStringList Name_list;
133
    QStringList Name_list;
134
134
135
  // getItems();
135
  // getItems();
136
136
137
137
138
138
139
139
140
140
141
    ID_list = items.keys();
141
    ID_list = items.keys();
142
    Name_list = items.values();
142
    Name_list = items.values();
143
143
144
    QComboBox *editor = new QComboBox(parent);
144
    QComboBox *editor = new QComboBox(parent);
145
145
146
/*
146
/*
147
    editor->addItem("0");
147
    editor->addItem("0");
148
    editor->addItem("1");
148
    editor->addItem("1");
149
    editor->addItem("2");
149
    editor->addItem("2");
150
    editor->addItem("3");
150
    editor->addItem("3");
151
    editor->addItem("4");
151
    editor->addItem("4");
152
    editor->addItem("5");
152
    editor->addItem("5");
153
    editor->addItem("6");
153
    editor->addItem("6");
154
    editor->addItem("7");
154
    editor->addItem("7");
155
    editor->addItem("8");
155
    editor->addItem("8");
156
    editor->addItem("9");
156
    editor->addItem("9");
157
*/
157
*/
158
158
159
//  editor->addItem("0");
159
//  editor->addItem("0");
160
160
161
    editor->addItems(Name_list);
161
    editor->addItems(Name_list);
162
//    editor->setEditable(false);
162
//    editor->setEditable(false);
163
    return editor;
163
    return editor;
164
}
164
}
165
//! [1]
165
//! [1]
166
166
167
//! [2]
167
//! [2]
168
void SpinBoxDelegate::setEditorData(QWidget *editor,
168
void SpinBoxDelegate::setEditorData(QWidget *editor,
169
                                    const QModelIndex &index) const
169
                                    const QModelIndex &index) const
170
{
170
{
171
   // int value = index.model()->data(index, Qt::EditRole).toInt();
171
   // int value = index.model()->data(index, Qt::EditRole).toInt();
172
172
173
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
173
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
174
 //   spinBox->setValue(value);
174
 //   spinBox->setValue(value);
175
QString value = index.model()->data(index, Qt::EditRole).toString();
175
QString value = index.model()->data(index, Qt::EditRole).toString();
176
176
177
QComboBox *comboBox = static_cast<QComboBox*>(editor);
177
QComboBox *comboBox = static_cast<QComboBox*>(editor);
178
178
179
QStringList ID_list;
179
QStringList ID_list;
180
QStringList Name_list;
180
QStringList Name_list;
181
int curr_index;
181
int curr_index;
182
182
183
ID_list = items.keys();
183
ID_list = items.keys();
184
Name_list = items.values();
184
Name_list = items.values();
185
185
186
curr_index = ID_list.indexOf(value);
186
curr_index = ID_list.indexOf(value);
187
if (curr_index==-1) return;
187
if (curr_index==-1) return;
188
comboBox->setCurrentIndex(curr_index);
188
comboBox->setCurrentIndex(curr_index);
189
/****************************************************
189
/****************************************************
190
if (value == "0") comboBox->setCurrentIndex(0);
190
if (value == "0") comboBox->setCurrentIndex(0);
191
if (value == "1") comboBox->setCurrentIndex(1);
191
if (value == "1") comboBox->setCurrentIndex(1);
192
if (value == "2") comboBox->setCurrentIndex(2);
192
if (value == "2") comboBox->setCurrentIndex(2);
193
if (value == "3") comboBox->setCurrentIndex(3);
193
if (value == "3") comboBox->setCurrentIndex(3);
194
if (value == "4") comboBox->setCurrentIndex(4);
194
if (value == "4") comboBox->setCurrentIndex(4);
195
if (value == "5") comboBox->setCurrentIndex(5);
195
if (value == "5") comboBox->setCurrentIndex(5);
196
if (value == "6") comboBox->setCurrentIndex(6);
196
if (value == "6") comboBox->setCurrentIndex(6);
197
if (value == "7") comboBox->setCurrentIndex(7);
197
if (value == "7") comboBox->setCurrentIndex(7);
198
if (value == "8") comboBox->setCurrentIndex(8);
198
if (value == "8") comboBox->setCurrentIndex(8);
199
if (value == "9") comboBox->setCurrentIndex(9);
199
if (value == "9") comboBox->setCurrentIndex(9);
200
******************************************************/
200
******************************************************/
201
comboBox->setEditable(false);
201
comboBox->setEditable(false);
202
202
203
203
204
//comboBox->setItemText(0, value);
204
//comboBox->setItemText(0, value);
205
205
206
}
206
}
207
//! [2]
207
//! [2]
208
208
209
//! [3]
209
//! [3]
210
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
210
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
211
                                   const QModelIndex &index) const
211
                                   const QModelIndex &index) const
212
{
212
{
213
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
213
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
214
  //  spinBox->interpretText();
214
  //  spinBox->interpretText();
215
  //  int value = spinBox->value();
215
  //  int value = spinBox->value();
216
216
217
  //  model->setData(index, value, Qt::EditRole);
217
  //  model->setData(index, value, Qt::EditRole);
218
    QStringList ID_list;
218
    QStringList ID_list;
219
    QStringList Name_list;
219
    QStringList Name_list;
220
220
221
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
221
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
222
    int currIndex;
222
    int currIndex;
223
    currIndex = comboBox->currentIndex();
223
    currIndex = comboBox->currentIndex();
224
    if (currIndex==-1) return;
224
    if (currIndex==-1) return;
225
  //  QString value = comboBox->itemText(currIndex);
225
  //  QString value = comboBox->itemText(currIndex);
226
226
227
    ID_list = items.keys();
227
    ID_list = items.keys();
228
    Name_list = items.values();
228
    Name_list = items.values();
229
229
230
    QString value = ID_list.at(currIndex);
230
    QString value = ID_list.at(currIndex);
231
    model->setData(index, value, Qt::EditRole);
231
    model->setData(index, value, Qt::EditRole);
232
}
232
}
233
//! [3]
233
//! [3]
234
234
235
//! [4]
235
//! [4]
236
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
236
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
237
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
237
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
238
{
238
{
239
    editor->setGeometry(option.rect);
239
    editor->setGeometry(option.rect);
240
}
240
}
241
241
242
242
243
243
244
244
245
245
246
246
247
247
248
248
249
249
250
250
251
251
252
//! [0]
252
//! [0]
253
FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent)
253
FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent)
254
    : QItemDelegate(parent)
254
    : QItemDelegate(parent)
255
{
255
{
256
}
256
}
257
//! [0]
257
//! [0]
258
258
259
void FilterSpinBoxDelegate::setClassID(QString newClassID){
259
void FilterSpinBoxDelegate::setClassID(QString newClassID){
260
    class_id = newClassID;
260
    class_id = newClassID;
261
}
261
}
262
262
263
void FilterSpinBoxDelegate::getItems(){
263
void FilterSpinBoxDelegate::getItems(){
264
    QMap <QString, QString> result_map;
264
    QMap <QString, QString> result_map;
265
    QSqlQuery q;
265
    QSqlQuery q;
266
    QString query_str;
266
    QString query_str;
267
    bool ok;
267
    bool ok;
268
268
269
    if (FilterSpinBoxDelegate::class_id.isEmpty())
269
    if (FilterSpinBoxDelegate::class_id.isEmpty())
270
    {
270
    {
271
        items.clear();
271
        items.clear();
272
        return;
272
        return;
273
    }
273
    }
274
274
275
    query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '");
275
    query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '");
276
    query_str.append(class_id);
276
    query_str.append(class_id);
277
    query_str.append( tr("'"));
277
    query_str.append( tr("'"));
278
278
279
    q.prepare(query_str);
279
    q.prepare(query_str);
280
280
281
281
282
    ok = q.exec();
282
    ok = q.exec();
283
283
284
284
285
285
286
286
287
    if (!ok) {
287
    if (!ok) {
288
                            /*
288
                            /*
289
                            QString error_str;
289
                            QString error_str;
290
                            error_str =  tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
290
                            error_str =  tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
291
                            error_str.append(inctance);
291
                            error_str.append(inctance);
292
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
292
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
293
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
293
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
294
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
294
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
295
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
295
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
296
                                                                        //    tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû "));    // Òåêñò ñîîáùåíèÿ.
296
                                                                        //    tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû "));    // Òåêñò ñîîáùåíèÿ.
297

297

298
                            */
298
                            */
299
                            items.clear();
299
                            items.clear();
300
                            return;
300
                            return;
301
                        }
301
                        }
302
302
303
303
304
 //   field_inctance = q.record().indexOf(tr("TableWhithInstance"));
304
 //   field_inctance = q.record().indexOf(tr("TableWhithInstance"));
305
    items.clear();
305
    items.clear();
306
    while(q.next()){
306
    while(q.next()){
307
307
308
                  QString ID;
308
                  QString ID;
309
                  QString Name;
309
                  QString Name;
310
                  ID = q.value(0).toString(); // îïðåäåëÿåì ID
310
                  ID = q.value(0).toString(); // îïðåäåëÿåì ID
311
                  Name = q.value(1).toString(); // îïðåäåëÿåì Name
311
                  Name = q.value(1).toString(); // îïðåäåëÿåì Name
312
                  items.insert(ID, Name);
312
                  items.insert(ID, Name);
313
                }
313
                }
314
314
315
315
316
 //   return result_map;
316
 //   return result_map;
317
}
317
}
318
318
319
319
320
//! [1]
320
//! [1]
321
QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent,
321
QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent,
322
    const QStyleOptionViewItem &/* option */,
322
    const QStyleOptionViewItem &/* option */,
323
    const QModelIndex &/* index */) const
323
    const QModelIndex &/* index */) const
324
{
324
{
325
    //QSpinBox *editor = new QSpinBox(parent);
325
    //QSpinBox *editor = new QSpinBox(parent);
326
    //editor->setMinimum(0);
326
    //editor->setMinimum(0);
327
    //editor->setMaximum(100);
327
    //editor->setMaximum(100);
328
    QStringList ID_list;
328
    QStringList ID_list;
329
    QStringList Name_list;
329
    QStringList Name_list;
330
330
331
  // getItems();
331
  // getItems();
332
332
333
333
334
334
335
335
336
336
337
    ID_list = items.keys();
337
    ID_list = items.keys();
338
    Name_list = items.values();
338
    Name_list = items.values();
339
339
340
    QComboBox *editor = new QComboBox(parent);
340
    QComboBox *editor = new QComboBox(parent);
341
341
342
/*
342
/*
343
    editor->addItem("0");
343
    editor->addItem("0");
344
    editor->addItem("1");
344
    editor->addItem("1");
345
    editor->addItem("2");
345
    editor->addItem("2");
346
    editor->addItem("3");
346
    editor->addItem("3");
347
    editor->addItem("4");
347
    editor->addItem("4");
348
    editor->addItem("5");
348
    editor->addItem("5");
349
    editor->addItem("6");
349
    editor->addItem("6");
350
    editor->addItem("7");
350
    editor->addItem("7");
351
    editor->addItem("8");
351
    editor->addItem("8");
352
    editor->addItem("9");
352
    editor->addItem("9");
353
*/
353
*/
354
354
355
//  editor->addItem("0");
355
//  editor->addItem("0");
356
356
357
    editor->addItems(Name_list);
357
    editor->addItems(Name_list);
358
//    editor->setEditable(false);
358
//    editor->setEditable(false);
359
    return editor;
359
    return editor;
360
}
360
}
361
//! [1]
361
//! [1]
362
362
363
//! [2]
363
//! [2]
364
void FilterSpinBoxDelegate::setEditorData(QWidget *editor,
364
void FilterSpinBoxDelegate::setEditorData(QWidget *editor,
365
                                    const QModelIndex &index) const
365
                                    const QModelIndex &index) const
366
{
366
{
367
   // int value = index.model()->data(index, Qt::EditRole).toInt();
367
   // int value = index.model()->data(index, Qt::EditRole).toInt();
368
368
369
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
369
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
370
 //   spinBox->setValue(value);
370
 //   spinBox->setValue(value);
371
QString value = index.model()->data(index, Qt::EditRole).toString();
371
QString value = index.model()->data(index, Qt::EditRole).toString();
372
372
373
QComboBox *comboBox = static_cast<QComboBox*>(editor);
373
QComboBox *comboBox = static_cast<QComboBox*>(editor);
374
374
375
QStringList ID_list;
375
QStringList ID_list;
376
QStringList Name_list;
376
QStringList Name_list;
377
int curr_index;
377
int curr_index;
378
378
379
ID_list = items.keys();
379
ID_list = items.keys();
380
Name_list = items.values();
380
Name_list = items.values();
381
381
382
curr_index = ID_list.indexOf(value);
382
curr_index = ID_list.indexOf(value);
383
if (curr_index==-1) return;
383
if (curr_index==-1) return;
384
comboBox->setCurrentIndex(curr_index);
384
comboBox->setCurrentIndex(curr_index);
385
/****************************************************
385
/****************************************************
386
if (value == "0") comboBox->setCurrentIndex(0);
386
if (value == "0") comboBox->setCurrentIndex(0);
387
if (value == "1") comboBox->setCurrentIndex(1);
387
if (value == "1") comboBox->setCurrentIndex(1);
388
if (value == "2") comboBox->setCurrentIndex(2);
388
if (value == "2") comboBox->setCurrentIndex(2);
389
if (value == "3") comboBox->setCurrentIndex(3);
389
if (value == "3") comboBox->setCurrentIndex(3);
390
if (value == "4") comboBox->setCurrentIndex(4);
390
if (value == "4") comboBox->setCurrentIndex(4);
391
if (value == "5") comboBox->setCurrentIndex(5);
391
if (value == "5") comboBox->setCurrentIndex(5);
392
if (value == "6") comboBox->setCurrentIndex(6);
392
if (value == "6") comboBox->setCurrentIndex(6);
393
if (value == "7") comboBox->setCurrentIndex(7);
393
if (value == "7") comboBox->setCurrentIndex(7);
394
if (value == "8") comboBox->setCurrentIndex(8);
394
if (value == "8") comboBox->setCurrentIndex(8);
395
if (value == "9") comboBox->setCurrentIndex(9);
395
if (value == "9") comboBox->setCurrentIndex(9);
396
******************************************************/
396
******************************************************/
397
comboBox->setEditable(false);
397
comboBox->setEditable(false);
398
398
399
399
400
//comboBox->setItemText(0, value);
400
//comboBox->setItemText(0, value);
401
401
402
}
402
}
403
//! [2]
403
//! [2]
404
404
405
//! [3]
405
//! [3]
406
void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
406
void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
407
                                   const QModelIndex &index) const
407
                                   const QModelIndex &index) const
408
{
408
{
409
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
409
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
410
  //  spinBox->interpretText();
410
  //  spinBox->interpretText();
411
  //  int value = spinBox->value();
411
  //  int value = spinBox->value();
412
412
413
  //  model->setData(index, value, Qt::EditRole);
413
  //  model->setData(index, value, Qt::EditRole);
414
    QStringList ID_list;
414
    QStringList ID_list;
415
    QStringList Name_list;
415
    QStringList Name_list;
416
416
417
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
417
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
418
    int currIndex;
418
    int currIndex;
419
    currIndex = comboBox->currentIndex();
419
    currIndex = comboBox->currentIndex();
420
    if (currIndex==-1) return;
420
    if (currIndex==-1) return;
421
  //  QString value = comboBox->itemText(currIndex);
421
  //  QString value = comboBox->itemText(currIndex);
422
422
423
    ID_list = items.keys();
423
    ID_list = items.keys();
424
    Name_list = items.values();
424
    Name_list = items.values();
425
425
426
 //   QString value = ID_list.at(currIndex);
426
 //   QString value = ID_list.at(currIndex);
427
    QString value = Name_list.at(currIndex);
427
    QString value = Name_list.at(currIndex);
428
    model->setData(index, value, Qt::EditRole);
428
    model->setData(index, value, Qt::EditRole);
429
}
429
}
430
//! [3]
430
//! [3]
431
431
432
//! [4]
432
//! [4]
433
void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor,
433
void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor,
434
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
434
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
435
{
435
{
436
    editor->setGeometry(option.rect);
436
    editor->setGeometry(option.rect);
437
}
437
}
438
438
439
439
440
440
441
441
442
442
443
443
444
444
445
445
446
446
447
447
448
//! [0]
448
//! [0]
449
FilterConditionDelegate::FilterConditionDelegate(QObject *parent)
449
FilterConditionDelegate::FilterConditionDelegate(QObject *parent)
450
    : QItemDelegate(parent)
450
    : QItemDelegate(parent)
451
{
451
{
452
}
452
}
453
//! [0]
453
//! [0]
454
454
455
void FilterConditionDelegate::setClassID(QString newClassID){
455
void FilterConditionDelegate::setClassID(QString newClassID){
456
    class_id = newClassID;
456
    class_id = newClassID;
457
}
457
}
458
458
459
459
460
460
461
//! [1]
461
//! [1]
462
QWidget *FilterConditionDelegate::createEditor(QWidget *parent,
462
QWidget *FilterConditionDelegate::createEditor(QWidget *parent,
463
    const QStyleOptionViewItem &/* option */,
463
    const QStyleOptionViewItem &/* option */,
464
    const QModelIndex &/* index */) const
464
    const QModelIndex &/* index */) const
465
{
465
{
466
    QStringList Name_list;
466
    QStringList Name_list;
467
467
468
    Name_list = items;
468
    Name_list = items;
469
469
470
    QComboBox *editor = new QComboBox(parent);
470
    QComboBox *editor = new QComboBox(parent);
471
471
472
/*
472
/*
473
    editor->addItem("0");
473
    editor->addItem("0");
474
    editor->addItem("1");
474
    editor->addItem("1");
475
    editor->addItem("2");
475
    editor->addItem("2");
476
    editor->addItem("3");
476
    editor->addItem("3");
477
    editor->addItem("4");
477
    editor->addItem("4");
478
    editor->addItem("5");
478
    editor->addItem("5");
479
    editor->addItem("6");
479
    editor->addItem("6");
480
    editor->addItem("7");
480
    editor->addItem("7");
481
    editor->addItem("8");
481
    editor->addItem("8");
482
    editor->addItem("9");
482
    editor->addItem("9");
483
*/
483
*/
484
484
485
//  editor->addItem("0");
485
//  editor->addItem("0");
486
486
487
    editor->addItems(Name_list);
487
    editor->addItems(Name_list);
488
//    editor->setEditable(false);
488
//    editor->setEditable(false);
489
    return editor;
489
    return editor;
490
}
490
}
491
//! [1]
491
//! [1]
492
492
493
//! [2]
493
//! [2]
494
void FilterConditionDelegate::setEditorData(QWidget *editor,
494
void FilterConditionDelegate::setEditorData(QWidget *editor,
495
                                    const QModelIndex &index) const
495
                                    const QModelIndex &index) const
496
{
496
{
497
   // int value = index.model()->data(index, Qt::EditRole).toInt();
497
   // int value = index.model()->data(index, Qt::EditRole).toInt();
498
498
499
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
499
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
500
 //   spinBox->setValue(value);
500
 //   spinBox->setValue(value);
501
QString value = index.model()->data(index, Qt::EditRole).toString();
501
QString value = index.model()->data(index, Qt::EditRole).toString();
502
502
503
QComboBox *comboBox = static_cast<QComboBox*>(editor);
503
QComboBox *comboBox = static_cast<QComboBox*>(editor);
504
504
505
//QStringList ID_list;
505
//QStringList ID_list;
506
//QStringList Name_list;
506
//QStringList Name_list;
507
int curr_index;
507
int curr_index;
508
508
509
//ID_list = items.keys();
509
//ID_list = items.keys();
510
//Name_list = items.values();
510
//Name_list = items.values();
511
511
512
curr_index = items.indexOf(value);
512
curr_index = items.indexOf(value);
513
if (curr_index==-1) return;
513
if (curr_index==-1) return;
514
comboBox->setCurrentIndex(curr_index);
514
comboBox->setCurrentIndex(curr_index);
515
/****************************************************
515
/****************************************************
516
if (value == "0") comboBox->setCurrentIndex(0);
516
if (value == "0") comboBox->setCurrentIndex(0);
517
if (value == "1") comboBox->setCurrentIndex(1);
517
if (value == "1") comboBox->setCurrentIndex(1);
518
if (value == "2") comboBox->setCurrentIndex(2);
518
if (value == "2") comboBox->setCurrentIndex(2);
519
if (value == "3") comboBox->setCurrentIndex(3);
519
if (value == "3") comboBox->setCurrentIndex(3);
520
if (value == "4") comboBox->setCurrentIndex(4);
520
if (value == "4") comboBox->setCurrentIndex(4);
521
if (value == "5") comboBox->setCurrentIndex(5);
521
if (value == "5") comboBox->setCurrentIndex(5);
522
if (value == "6") comboBox->setCurrentIndex(6);
522
if (value == "6") comboBox->setCurrentIndex(6);
523
if (value == "7") comboBox->setCurrentIndex(7);
523
if (value == "7") comboBox->setCurrentIndex(7);
524
if (value == "8") comboBox->setCurrentIndex(8);
524
if (value == "8") comboBox->setCurrentIndex(8);
525
if (value == "9") comboBox->setCurrentIndex(9);
525
if (value == "9") comboBox->setCurrentIndex(9);
526
******************************************************/
526
******************************************************/
527
comboBox->setEditable(false);
527
comboBox->setEditable(false);
528
528
529
529
530
//comboBox->setItemText(0, value);
530
//comboBox->setItemText(0, value);
531
531
532
}
532
}
533
//! [2]
533
//! [2]
534
534
535
//! [3]
535
//! [3]
536
void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
536
void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
537
                                   const QModelIndex &index) const
537
                                   const QModelIndex &index) const
538
{
538
{
539
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
539
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
540
  //  spinBox->interpretText();
540
  //  spinBox->interpretText();
541
  //  int value = spinBox->value();
541
  //  int value = spinBox->value();
542
542
543
  //  model->setData(index, value, Qt::EditRole);
543
  //  model->setData(index, value, Qt::EditRole);
544
    QStringList ID_list;
544
    QStringList ID_list;
545
    QStringList Name_list;
545
    QStringList Name_list;
546
546
547
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
547
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
548
    int currIndex;
548
    int currIndex;
549
    currIndex = comboBox->currentIndex();
549
    currIndex = comboBox->currentIndex();
550
    if (currIndex==-1) return;
550
    if (currIndex==-1) return;
551
  //  QString value = comboBox->itemText(currIndex);
551
  //  QString value = comboBox->itemText(currIndex);
552
552
553
    // ID_list = items.keys();
553
    // ID_list = items.keys();
554
    // Name_list = items.values();
554
    // Name_list = items.values();
555
555
556
 //   QString value = ID_list.at(currIndex);
556
 //   QString value = ID_list.at(currIndex);
557
    QString value = items.at(currIndex);
557
    QString value = items.at(currIndex);
558
    model->setData(index, value, Qt::EditRole);
558
    model->setData(index, value, Qt::EditRole);
559
}
559
}
560
//! [3]
560
//! [3]
561
561
562
//! [4]
562
//! [4]
563
void FilterConditionDelegate::updateEditorGeometry(QWidget *editor,
563
void FilterConditionDelegate::updateEditorGeometry(QWidget *editor,
564
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
564
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
565
{
565
{
566
    editor->setGeometry(option.rect);
566
    editor->setGeometry(option.rect);
567
}
567
}
568
568
569
569
570
570
571
571
572
572
573
573
574
574
575
575
576
576
577
577
578
FilterValueDelegate::FilterValueDelegate(QObject *parent)
578
FilterValueDelegate::FilterValueDelegate(QObject *parent)
579
    : QItemDelegate(parent)
579
    : QItemDelegate(parent)
580
{
580
{
581
}
581
}
582
//! [0]
582
//! [0]
583
583
584
void FilterValueDelegate::setClassID(QString newClassID){
584
void FilterValueDelegate::setClassID(QString newClassID){
585
    class_id = newClassID;
585
    class_id = newClassID;
586
}
586
}
587
587
588
588
589
589
590
// ïîëó÷àåì èìÿ òàáëèöû - õðàíèëèùà îáúåêòîâ êëàññà
590
// ïîëó÷àåì èìÿ òàáëèöû - õðàíèëèùà îáúåêòîâ êëàññà
591
QString FilterValueDelegate::getClassInctanc(QString class_id){
591
QString FilterValueDelegate::getClassInctanc(QString class_id){
592
592
593
593
594
594
595
595
596
    QSqlQuery q;
596
    QSqlQuery q;
597
    QString sql_str;
597
    QString sql_str;
598
    QString result;
598
    QString result;
599
    QString classInctance;
599
    QString classInctance;
600
    int field_inctance;
600
    int field_inctance;
601
    bool ok;
601
    bool ok;
602
    sql_str = tr("select * "
602
    sql_str = tr("select * "
603
                 " from ListOfClasses where  ListOfClasses.ID = '"       //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
603
                 " from ListOfClasses where  ListOfClasses.ID = '"       //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
604
                 );
604
                 );
605
    sql_str.append(class_id);
605
    sql_str.append(class_id);
606
     sql_str.append(tr("'"));
606
     sql_str.append(tr("'"));
607
    q.prepare(sql_str);
607
    q.prepare(sql_str);
608
608
609
    ok = q.exec();
609
    ok = q.exec();
610
610
611
    if (!ok) return result;
611
    if (!ok) return result;
612
612
613
    /*
613
    /*
614
    if (!ok) {
614
    if (!ok) {
615
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
615
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
616
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
616
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
617
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
617
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
618
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
618
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
619
                                                                            return result;
619
                                                                            return result;
620
                     }
620
                     }
621

621

622
   */
622
   */
623
623
624
624
625
625
626
626
627
    field_inctance = q.record().indexOf(tr("TableWhithInstance"));
627
    field_inctance = q.record().indexOf(tr("TableWhithInstance"));
628
    while(q.next()){
628
    while(q.next()){
629
629
630
                  classInctance = q.value(field_inctance).toString();
630
                  classInctance = q.value(field_inctance).toString();
631
                  result.append(classInctance);
631
                  result.append(classInctance);
632
                  }
632
                  }
633
633
634
  return result;
634
  return result;
635
635
636
636
637
637
638
638
639
639
640
}
640
}
641
641
642
642
643
643
644
 QString FilterValueDelegate::getFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ
644
 QString FilterValueDelegate::getFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ
645
 {
645
 {
646
646
647
 }
647
 }
648
648
-
 
649
 QMap<QString, QString>  FilterValueDelegate::getItems(QString inctance){ // âîçâðàùàåì ñïèñîê âñåõ çíà÷åíèé èç òàáëèöû-õðàíèëèùà
-
 
650
    QSqlQuery q;
-
 
651
    QString sql_str;
-
 
652
    QStringList keys_list;
-
 
653
    QStringList values_list;
-
 
654
    QMap<QString, QString> result_map;
-
 
655
-
 
656
-
 
657
-
 
658
-
 
659
    bool ok;
-
 
660
    sql_str = tr("select * from `");
-
 
661
    sql_str.append(inctance);
-
 
662
    sql_str.append(tr("`"));
-
 
663
    ok = q.prepare(sql_str);
-
 
664
    ok = q.exec();
-
 
665
    if(!ok) return result_map;
-
 
666
    while (q.next()){
-
 
667
        QString key_tmp;
-
 
668
        QString value_tmp;
-
 
669
-
 
670
         key_tmp = q.record().value(0).asString(); //îïðåäåëÿåì id îáúåêòà
-
 
671
         //keys_list.append(tmp_str); // äîáàâèì â ñïèñîê êëþ÷åé
-
 
672
-
 
673
        value_tmp = q.record().value(1).asString(); //îïðåäåëÿåì èìÿ îáúåêòà
-
 
674
-
 
675
        result_map.insert(key_tmp,  value_tmp);
-
 
676
        // values_list.append(tmp_str);
-
 
677
-
 
678
-
 
679
    }
649
680
650
681
651
682
652
683
653
684
-
 
685
    return result_map;
-
 
686
-
 
687
 }
-
 
688
-
 
689
-
 
690
654
691
655
//! [1]
692
//! [1]
656
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
693
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
657
    const QStyleOptionViewItem &/* option */,
694
    const QStyleOptionViewItem &/* option */,
658
    const QModelIndex &/* index */) const
695
    const QModelIndex &/* index */) const
659
{
696
{
660
    QStringList Name_list;
697
    QStringList Name_list;
661
698
662
    Name_list = items;
699
    Name_list = items;
663
700
664
    QComboBox *editor = new QComboBox(parent);
701
    QComboBox *editor = new QComboBox(parent);
665
702
666
/*
703
/*
667
    editor->addItem("0");
704
    editor->addItem("0");
668
    editor->addItem("1");
705
    editor->addItem("1");
669
    editor->addItem("2");
706
    editor->addItem("2");
670
    editor->addItem("3");
707
    editor->addItem("3");
671
    editor->addItem("4");
708
    editor->addItem("4");
672
    editor->addItem("5");
709
    editor->addItem("5");
673
    editor->addItem("6");
710
    editor->addItem("6");
674
    editor->addItem("7");
711
    editor->addItem("7");
675
    editor->addItem("8");
712
    editor->addItem("8");
676
    editor->addItem("9");
713
    editor->addItem("9");
677
*/
714
*/
678
715
679
//  editor->addItem("0");
716
//  editor->addItem("0");
680
717
681
// // //    editor->addItems(Name_list);
718
// // //    editor->addItems(Name_list);
682
    editor->setEditable(true);
719
    editor->setEditable(true);
683
    return editor;
720
    return editor;
684
}
721
}
685
//! [1]
722
//! [1]
686
723
687
724
688
725
689
726
690
TField FilterValueDelegate::getField(const QModelIndex &index) // ïî èíäåêñó (â òàáëèöå ôèëüòðîâ) ïîëó÷èì èíôîðìàöèþ î ïîëå
727
TField FilterValueDelegate::getField(const QModelIndex &index) // ïî èíäåêñó (â òàáëèöå ôèëüòðîâ) ïîëó÷èì èíôîðìàöèþ î ïîëå
691
{
728
{
692
    const QAbstractItemModel * model = index.model();
729
    const QAbstractItemModel * model = index.model();
693
730
694
    TField field_result;
731
    TField field_result;
695
    QSqlQuery q;
732
    QSqlQuery q;
696
    QString sql_str;
733
    QString sql_str;
697
    bool ok;
734
    bool ok;
698
735
699
736
700
    // QString fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
737
    // QString fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
701
  //  QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
738
  //  QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
702
    field_result.FieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
739
    field_result.FieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
703
    field_result.ClassIdentifer = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
740
    field_result.ClassIdentifer = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
704
741
705
    sql_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '");
742
    sql_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '");
706
    sql_str.append(field_result.ClassIdentifer);
743
    sql_str.append(field_result.ClassIdentifer);
707
    sql_str.append(tr("' and `FieldName` = '"));
744
    sql_str.append(tr("' and `FieldName` = '"));
708
    sql_str.append(field_result.FieldName);
745
    sql_str.append(field_result.FieldName);
709
    sql_str.append(tr("'"));
746
    sql_str.append(tr("'"));
710
747
711
    ok = q.prepare(sql_str);
748
    ok = q.prepare(sql_str);
712
749
713
    if(!ok)  return field_result;
750
    if(!ok)  return field_result;
714
751
715
    ok = q.exec();
752
    ok = q.exec();
716
753
717
    if(!ok)  return field_result;
754
    if(!ok)  return field_result;
718
755
719
    int ID_index = q.record().indexOf(tr("ID"));
756
    int ID_index = q.record().indexOf(tr("ID"));
720
757
721
    int FieldAlias_index = q.record().indexOf(tr("FieldAlias"));
758
    int FieldAlias_index = q.record().indexOf(tr("FieldAlias"));
722
759
723
    int FieldType_index = q.record().indexOf(tr("FieldType"));
760
    int FieldType_index = q.record().indexOf(tr("FieldType"));
724
761
725
    int DefaultValue_index = q.record().indexOf(tr("DefaultValue"));
762
    int DefaultValue_index = q.record().indexOf(tr("DefaultValue"));
726
763
727
    int Comment_index = q.record().indexOf(tr("Comment"));
764
    int Comment_index = q.record().indexOf(tr("Comment"));
728
765
729
766
730
767
731
    while(q.next()){
768
    while(q.next()){
732
    field_result.ID = q.value(ID_index).asString();
769
    field_result.ID = q.value(ID_index).asString();
733
    field_result.FieldAlias = q.value(FieldAlias_index).asString();
770
    field_result.FieldAlias = q.value(FieldAlias_index).asString();
734
    field_result.FieldType = q.value(FieldType_index).asString();
771
    field_result.FieldType = q.value(FieldType_index).asString();
735
    field_result.DefaultValue = q.value(DefaultValue_index).asString();
772
    field_result.DefaultValue = q.value(DefaultValue_index).asString();
736
    field_result.Comment = q.value(Comment_index).asString();
773
    field_result.Comment = q.value(Comment_index).asString();
737
    }
774
    }
738
775
739
    return field_result;
776
    return field_result;
740
777
741
778
742
779
743
}
780
}
744
781
745
782
746
783
747
784
748
785
749
//! [2]
786
//! [2]
750
void FilterValueDelegate::setEditorData(QWidget *editor,
787
void FilterValueDelegate::setEditorData(QWidget *editor,
751
                                    const QModelIndex &index) const
788
                                    const QModelIndex &index) const
752
{
789
{
753
   // int value = index.model()->data(index, Qt::EditRole).toInt();
790
   // int value = index.model()->data(index, Qt::EditRole).toInt();
754
791
755
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
792
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
756
 //   spinBox->setValue(value);
793
 //   spinBox->setValue(value);
757
794
758
795
759
const QAbstractItemModel * model = index.model();
796
const QAbstractItemModel * model = index.model();
760
797
761
798
762
QString value = index.model()->data(index, Qt::EditRole).toString();
799
QString value = index.model()->data(index, Qt::EditRole).toString();
763
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
800
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
764
QComboBox *comboBox = static_cast<QComboBox*>(editor);
801
QComboBox *comboBox = static_cast<QComboBox*>(editor);
765
QString inctance; //õðàíèëèùå îáúåêòîâ êëàññà
802
QString inctance; //õðàíèëèùå îáúåêòîâ êëàññà
766
QString fieldName;//èìÿ ïîëÿ
803
QString fieldName;//èìÿ ïîëÿ
767
QSqlQuery q;
804
QSqlQuery q;
768
QString sql_str;
805
QString sql_str;
769
QStringList itemsList;
806
QStringList itemsList;
770
bool ok;
807
bool ok;
771
TField Field;
808
TField Field;
772
809
773
Field = getField(index);
810
Field = getField(index);
774
811
775
812
-
 
813
if (Field.FieldType == tr("pointer")){ // åñëè äàííîå ïîëå õðàíèò óêàçàòåëè íà êëàññ-êîíòåéíåð
-
 
814
    QString parent_inctance;
-
 
815
    QMap<QString, QString> items_map;
-
 
816
    QStringList items_list;
-
 
817
-
 
818
    parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà
-
 
819
    items_map = getItems(parent_inctance);
-
 
820
    items_list = items_map.values();
-
 
821
-
 
822
    comboBox->addItems(items_list);
-
 
823
    if (items_list.indexOf(value)!=-1) comboBox->setCurrentIndex(items_list.indexOf(value));
-
 
824
    return;
776
825
777
826
778
827
-
 
828
}
-
 
829
-
 
830
779
831
780
fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
832
fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
781
833
782
834
783
inctance = FilterValueDelegate::getClassInctanc(class_id);
835
inctance = FilterValueDelegate::getClassInctanc(class_id);
784
if (!inctance.isEmpty() && !fieldName.isEmpty()){
836
if (!inctance.isEmpty() && !fieldName.isEmpty()){
785
sql_str = tr("select `");
837
sql_str = tr("select `");
786
sql_str.append(fieldName);
838
sql_str.append(fieldName);
787
sql_str.append(tr("` from `"));
839
sql_str.append(tr("` from `"));
788
sql_str.append(inctance);
840
sql_str.append(inctance);
789
sql_str.append(tr("`"));
841
sql_str.append(tr("`"));
790
ok = q.prepare(sql_str);
842
ok = q.prepare(sql_str);
791
ok = q.exec();
843
ok = q.exec();
792
844
793
while(q.next()){
845
while(q.next()){
794
QString tmp_str;
846
QString tmp_str;
795
tmp_str = q.record().value(fieldName).asString();
847
tmp_str = q.record().value(fieldName).asString();
796
itemsList.append(tmp_str);
848
itemsList.append(tmp_str);
797
FilterValueDelegate::items.append(tmp_str);
849
FilterValueDelegate::items.append(tmp_str);
798
        }
850
        }
799
if(!itemsList.isEmpty()) {
851
if(!itemsList.isEmpty()) {
800
                            comboBox->addItems(itemsList);
852
                            comboBox->addItems(itemsList);
801
                            items = itemsList; // ãëîáàëüãàÿ ïåðåìåííàÿ
853
                            items = itemsList; // ãëîáàëüãàÿ ïåðåìåííàÿ
802
                         }
854
                         }
803
855
804
}
856
}
805
857
806
858
807
859
808
860
809
861
810
//QStringList ID_list;
862
//QStringList ID_list;
811
//QStringList Name_list;
863
//QStringList Name_list;
812
int curr_index;
864
int curr_index;
813
865
814
//ID_list = items.keys();
866
//ID_list = items.keys();
815
//Name_list = items.values();
867
//Name_list = items.values();
816
868
817
curr_index = itemsList.indexOf(value);
869
curr_index = itemsList.indexOf(value);
818
if (curr_index==-1) return;
870
if (curr_index==-1) return;
819
comboBox->setCurrentIndex(curr_index);
871
comboBox->setCurrentIndex(curr_index);
820
/****************************************************
872
/****************************************************
821
if (value == "0") comboBox->setCurrentIndex(0);
873
if (value == "0") comboBox->setCurrentIndex(0);
822
if (value == "1") comboBox->setCurrentIndex(1);
874
if (value == "1") comboBox->setCurrentIndex(1);
823
if (value == "2") comboBox->setCurrentIndex(2);
875
if (value == "2") comboBox->setCurrentIndex(2);
824
if (value == "3") comboBox->setCurrentIndex(3);
876
if (value == "3") comboBox->setCurrentIndex(3);
825
if (value == "4") comboBox->setCurrentIndex(4);
877
if (value == "4") comboBox->setCurrentIndex(4);
826
if (value == "5") comboBox->setCurrentIndex(5);
878
if (value == "5") comboBox->setCurrentIndex(5);
827
if (value == "6") comboBox->setCurrentIndex(6);
879
if (value == "6") comboBox->setCurrentIndex(6);
828
if (value == "7") comboBox->setCurrentIndex(7);
880
if (value == "7") comboBox->setCurrentIndex(7);
829
if (value == "8") comboBox->setCurrentIndex(8);
881
if (value == "8") comboBox->setCurrentIndex(8);
830
if (value == "9") comboBox->setCurrentIndex(9);
882
if (value == "9") comboBox->setCurrentIndex(9);
831
******************************************************/
883
******************************************************/
832
comboBox->setEditable(true);
884
comboBox->setEditable(true);
833
885
834
886
835
//comboBox->setItemText(0, value);
887
//comboBox->setItemText(0, value);
836
888
837
}
889
}
838
//! [2]
890
//! [2]
839
891
840
//! [3]
892
//! [3]
841
void FilterValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
893
void FilterValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
842
                                   const QModelIndex &index) const
894
                                   const QModelIndex &index) const
843
{
895
{
844
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
896
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
845
  //  spinBox->interpretText();
897
  //  spinBox->interpretText();
846
  //  int value = spinBox->value();
898
  //  int value = spinBox->value();
847
899
848
  //  model->setData(index, value, Qt::EditRole);
900
  //  model->setData(index, value, Qt::EditRole);
849
901
850
    QStringList ID_list;
-
 
851
    QStringList Name_list;
-
 
852
-
 
853
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
902
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
854
    int currIndex;
903
     int currIndex;
855
    currIndex = comboBox->currentIndex();
904
    currIndex = comboBox->currentIndex();
-
 
905
856
    if (currIndex==-1) return;
906
    if (currIndex==-1) return;
-
 
907
-
 
908
    QString new_value = comboBox->itemText(currIndex);
-
 
909
-
 
910
    QString curr_value = model->data(index, Qt::EditRole).toString();//òåêóùåå çíà÷åíèå â ìîäåëè
-
 
911
-
 
912
-
 
913
-
 
914
    QString class_id = model->data(model->index(index.row(),2), Qt::EditRole).toString();//îïðåäåëèì êëàññ, ê êîòîðîìó ïðåíàäëåæèò ïîëå
-
 
915
-
 
916
-
 
917
    QStringList ID_list;
-
 
918
    QStringList Name_list;
-
 
919
-
 
920
-
 
921
    TField Field;
-
 
922
-
 
923
    Field = getField(index);
-
 
924
-
 
925
    if(Field.FieldType==tr("pointer")){
-
 
926
        QString parent_inctance;
-
 
927
        QMap<QString, QString> items_map;
-
 
928
        QStringList keys_list; // ñïèñîê ID îáúåêòîâ ðîäèòåëüñêîãî êëàññà
-
 
929
        QStringList values_list; //ñïèñîê èìåí îáúåêòîâ ðîäèòåëüñêîãî êëàññà
-
 
930
-
 
931
-
 
932
-
 
933
        parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà
-
 
934
        items_map = getItems(parent_inctance); //
-
 
935
        keys_list = items_map.keys();
-
 
936
        values_list = items_map.values();
-
 
937
-
 
938
        if( values_list.indexOf(new_value)!=-1){ //
-
 
939
-
 
940
            QString new_key =  keys_list.at(values_list.indexOf(new_value)); // îïðåäåëÿåì íîâîå ØÂ
-
 
941
            if (new_key != curr_value) model->setData(index, new_key, Qt::EditRole);
-
 
942
            return;
-
 
943
        }
-
 
944
-
 
945
-
 
946
-
 
947
-
 
948
    }
-
 
949
-
 
950
-
 
951
-
 
952
-
 
953
-
 
954
-
 
955
857
  //  QString value = comboBox->itemText(currIndex);
956
 //   QString new_value = comboBox->itemText(currIndex);
-
 
957
-
 
958
-
 
959
858
960
859
    // ID_list = items.keys();
961
    // ID_list = items.keys();
860
    // Name_list = items.values();
962
    // Name_list = items.values();
861
963
862
 //   QString value = ID_list.at(currIndex);
964
 //   QString value = ID_list.at(currIndex);
863
    QString value = items.at(currIndex);
965
  //  QString value = items.at(currIndex);
864
    model->setData(index, value, Qt::EditRole);
966
     model->setData(index, new_value, Qt::EditRole);
865
967
866
968
867
}
969
}
868
970
869
971
870
972
871
973
872
974
873
975
874
976
875
977
876
//! [3]
978
//! [3]
877
979
878
//! [4]
980
//! [4]
879
void FilterValueDelegate::updateEditorGeometry(QWidget *editor,
981
void FilterValueDelegate::updateEditorGeometry(QWidget *editor,
880
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
982
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
881
{
983
{
882
    editor->setGeometry(option.rect);
984
    editor->setGeometry(option.rect);
883
}
985
}
884
986
885
987
886
988
887
989
888
990
889
991
890
992
891
993
892
994
893
995
894
996
895
997
896
998
897
999
898
1000
899
//! [4]
1001
//! [4]
900
MyDEDelegate::MyDEDelegate(
1002
MyDEDelegate::MyDEDelegate(
901
                       bool calpopup,
1003
                       bool calpopup,
902
                       QObject *parent)
1004
                       QObject *parent)
903
               : QItemDelegate(parent),
1005
               : QItemDelegate(parent),
904
                 m_calpopup(calpopup) {
1006
                 m_calpopup(calpopup) {
905
   }
1007
   }
906
1008
907
   QWidget *MyDEDelegate::createEditor(
1009
   QWidget *MyDEDelegate::createEditor(
908
               QWidget *parent,
1010
               QWidget *parent,
909
               const QStyleOptionViewItem& /* option */,
1011
               const QStyleOptionViewItem& /* option */,
910
               const QModelIndex& /* index */) const {
1012
               const QModelIndex& /* index */) const {
911
       QDateEdit *editor = new QDateEdit(parent);
1013
       QDateEdit *editor = new QDateEdit(parent);
912
       editor->setCalendarPopup(m_calpopup);
1014
       editor->setCalendarPopup(m_calpopup);
913
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
1015
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
914
       return editor;
1016
       return editor;
915
   }
1017
   }
916
1018
917
   void MyDEDelegate::setEditorData(
1019
   void MyDEDelegate::setEditorData(
918
                   QWidget *editor,
1020
                   QWidget *editor,
919
                   const QModelIndex &index) const {
1021
                   const QModelIndex &index) const {
920
       QDate value = index.model()->data(
1022
       QDate value = index.model()->data(
921
               index, Qt::EditRole).toDate();
1023
               index, Qt::EditRole).toDate();
922
       QDateEdit *de = static_cast<QDateEdit*>(editor);
1024
       QDateEdit *de = static_cast<QDateEdit*>(editor);
923
       de->setDate(value);
1025
       de->setDate(value);
924
   }
1026
   }
925
1027
926
   void MyDEDelegate::setModelData(
1028
   void MyDEDelegate::setModelData(
927
               QWidget *editor,
1029
               QWidget *editor,
928
               QAbstractItemModel *model,
1030
               QAbstractItemModel *model,
929
               const QModelIndex& index) const {
1031
               const QModelIndex& index) const {
930
       QDateEdit *de = static_cast<QDateEdit*>(editor);
1032
       QDateEdit *de = static_cast<QDateEdit*>(editor);
931
       de->interpretText();
1033
       de->interpretText();
932
       QDate value = de->date();
1034
       QDate value = de->date();
933
       model->setData(index, value);
1035
       model->setData(index, value);
934
   }
1036
   }
935
1037
936
   void MyDEDelegate::updateEditorGeometry(
1038
   void MyDEDelegate::updateEditorGeometry(
937
               QWidget *editor,
1039
               QWidget *editor,
938
               const QStyleOptionViewItem &option,
1040
               const QStyleOptionViewItem &option,
939
               const QModelIndex& /* index */) const {
1041
               const QModelIndex& /* index */) const {
940
1042
941
1043
942
1044
943
       editor->setGeometry(option.rect);
1045
       editor->setGeometry(option.rect);
944
   }
1046
   }
945
1047
946
1048
947
1049
948
1050
949
1051
950
   CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent)
1052
   CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent)
951
   {
1053
   {
952
   }
1054
   }
953
1055
954
   void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
1056
   void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
955
   {
1057
   {
956
           m_pxPicture.fill( QColor(Qt::white) );
1058
           m_pxPicture.fill( QColor(Qt::white) );
957
1059
958
           const QAbstractItemModel * model = index.model();
1060
           const QAbstractItemModel * model = index.model();
959
           QString sFileName = model->data( index, Qt::DisplayRole ).toString();
1061
           QString sFileName = model->data( index, Qt::DisplayRole ).toString();
960
1062
961
           if ( !sFileName.isEmpty() )
1063
           if ( !sFileName.isEmpty() )
962
                   m_pxPicture.load( sFileName );
1064
                   m_pxPicture.load( sFileName );
963
           else {
1065
           else {
964
               //QItemDelegate::paint(painter, option, index);
1066
               //QItemDelegate::paint(painter, option, index);
965
           return;
1067
           return;
966
           }
1068
           }
967
1069
968
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
1070
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
969
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
1071
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
970
                                                             QPalette::Disabled;
1072
                                                             QPalette::Disabled;
971
1073
972
            if (option.state & QStyle::State_Selected)
1074
            if (option.state & QStyle::State_Selected)
973
                    painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
1075
                    painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
974
1076
975
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
1077
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
976
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
1078
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
977
           painter->drawPixmap( nX, nY, m_pxPicture );
1079
           painter->drawPixmap( nX, nY, m_pxPicture );
978
1080
979
1081
980
       ////    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
1082
       ////    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
981
1083
982
           /*
1084
           /*
983
           QPen pen = painter->pen();
1085
           QPen pen = painter->pen();
984
           painter->setPen(option.palette.color(QPalette::Mid));
1086
           painter->setPen(option.palette.color(QPalette::Mid));
985
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
1087
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
986
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
1088
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
987
           painter->setPen(pen);
1089
           painter->setPen(pen);
988
   */
1090
   */
989
   }
1091
   }
990
1092
991
1093
992
1094
993
1095
994
   void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
1096
   void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
995
                            const QModelIndex &index) const
1097
                            const QModelIndex &index) const
996
   {
1098
   {
997
       int datetime = index.model()->data(index, Qt::DisplayRole).toInt();
1099
       int datetime = index.model()->data(index, Qt::DisplayRole).toInt();
998
1100
999
       QString indexvalue = "";
1101
       QString indexvalue = "";
1000
1102
1001
       if (datetime > 0)
1103
       if (datetime > 0)
1002
       {
1104
       {
1003
           QDateTime dateTime2 = QDateTime();
1105
           QDateTime dateTime2 = QDateTime();
1004
           dateTime2.setTime_t(datetime);
1106
           dateTime2.setTime_t(datetime);
1005
           indexvalue = dateTime2.toString(this->timeformat);
1107
           indexvalue = dateTime2.toString(this->timeformat);
1006
       }
1108
       }
1007
       else
1109
       else
1008
       {
1110
       {
1009
           indexvalue = tr("Date not set");
1111
           indexvalue = tr("Date not set");
1010
       }
1112
       }
1011
1113
1012
       Q_ASSERT(index.isValid());
1114
       Q_ASSERT(index.isValid());
1013
1115
1014
       QStyleOptionViewItemV3 opt = setOptions(index, option);
1116
       QStyleOptionViewItemV3 opt = setOptions(index, option);
1015
1117
1016
       const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
1118
       const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
1017
       opt.features = v2 ? v2->features
1119
       opt.features = v2 ? v2->features
1018
                       : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
1120
                       : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
1019
       const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
1121
       const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
1020
       opt.locale = v3 ? v3->locale : QLocale();
1122
       opt.locale = v3 ? v3->locale : QLocale();
1021
       opt.widget = v3 ? v3->widget : 0;
1123
       opt.widget = v3 ? v3->widget : 0;
1022
1124
1023
       // prepare
1125
       // prepare
1024
       painter->save();
1126
       painter->save();
1025
1127
1026
       painter->setClipRect(opt.rect);
1128
       painter->setClipRect(opt.rect);
1027
1129
1028
       // get the data and the rectangles
1130
       // get the data and the rectangles
1029
       QVariant value;
1131
       QVariant value;
1030
1132
1031
       QPixmap pixmap;
1133
       QPixmap pixmap;
1032
       QRect decorationRect;
1134
       QRect decorationRect;
1033
       value = index.data(Qt::DecorationRole);
1135
       value = index.data(Qt::DecorationRole);
1034
1136
1035
       QString text;
1137
       QString text;
1036
       QRect displayRect;
1138
       QRect displayRect;
1037
       value = index.data(Qt::DisplayRole);
1139
       value = index.data(Qt::DisplayRole);
1038
       if (value.isValid()) {
1140
       if (value.isValid()) {
1039
           text = indexvalue;
1141
           text = indexvalue;
1040
           displayRect = textRectangle(painter, option.rect, opt.font, text);
1142
           displayRect = textRectangle(painter, option.rect, opt.font, text);
1041
       }
1143
       }
1042
1144
1043
       QRect checkRect;
1145
       QRect checkRect;
1044
       Qt::CheckState checkState = Qt::Unchecked;
1146
       Qt::CheckState checkState = Qt::Unchecked;
1045
       value = index.data(Qt::CheckStateRole);
1147
       value = index.data(Qt::CheckStateRole);
1046
       if (value.isValid()) {
1148
       if (value.isValid()) {
1047
           checkState = static_cast<Qt::CheckState>(value.toInt());
1149
           checkState = static_cast<Qt::CheckState>(value.toInt());
1048
           checkRect = check(opt, opt.rect, value);
1150
           checkRect = check(opt, opt.rect, value);
1049
       }
1151
       }
1050
1152
1051
       // do the layout
1153
       // do the layout
1052
       doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
1154
       doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
1053
       // draw the item
1155
       // draw the item
1054
1156
1055
       drawBackground(painter, opt, index);
1157
       drawBackground(painter, opt, index);
1056
       drawCheck(painter, opt, checkRect, checkState);
1158
       drawCheck(painter, opt, checkRect, checkState);
1057
       drawDecoration(painter, opt, decorationRect, pixmap);
1159
       drawDecoration(painter, opt, decorationRect, pixmap);
1058
       drawDisplay(painter, opt, displayRect, text);
1160
       drawDisplay(painter, opt, displayRect, text);
1059
       drawFocus(painter, opt, displayRect);
1161
       drawFocus(painter, opt, displayRect);
1060
1162
1061
       // done
1163
       // done
1062
       painter->restore();
1164
       painter->restore();
1063
   }
1165
   }
1064
1166
1065
1167
1066
1168
1067
1169
1068
1170
1069
1171
1070
   IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent)
1172
   IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent)
1071
   {
1173
   {
1072
   }
1174
   }
1073
1175
1074
1176
1075
1177
1076
1178
1077
1179
1078
   QWidget *IconDelegate::createEditor(QWidget *parent,
1180
   QWidget *IconDelegate::createEditor(QWidget *parent,
1079
       const QStyleOptionViewItem &/* option */,
1181
       const QStyleOptionViewItem &/* option */,
1080
       const QModelIndex & /* index */) const
1182
       const QModelIndex & /* index */) const
1081
   {
1183
   {
1082
1184
1083
       IconForm *editor = new IconForm(parent);
1185
       IconForm *editor = new IconForm(parent);
1084
1186
1085
       return editor;
1187
       return editor;
1086
1188
1087
   }
1189
   }
1088
1190
1089
1191
1090
1192
1091
1193
1092
   void IconDelegate::setEditorData(QWidget *editor,
1194
   void IconDelegate::setEditorData(QWidget *editor,
1093
                                       const QModelIndex &index) const
1195
                                       const QModelIndex &index) const
1094
   {
1196
   {
1095
1197
1096
1198
1097
       const QAbstractItemModel * model = index.model();
1199
       const QAbstractItemModel * model = index.model();
1098
       IconForm *icnFrm = static_cast<IconForm*>(editor);
1200
       IconForm *icnFrm = static_cast<IconForm*>(editor);
1099
       QVariant currentImage = model->data(index,0);
1201
       QVariant currentImage = model->data(index,0);
1100
       QByteArray bytes = currentImage.toByteArray();
1202
       QByteArray bytes = currentImage.toByteArray();
1101
       if (currentImage.isValid()) {
1203
       if (currentImage.isValid()) {
1102
            m_pxPicture.loadFromData(bytes);
1204
            m_pxPicture.loadFromData(bytes);
1103
       }
1205
       }
1104
       else {
1206
       else {
1105
           //QItemDelegate::paint(painter, option, index);
1207
           //QItemDelegate::paint(painter, option, index);
1106
1208
1107
1209
1108
           return;
1210
           return;
1109
       }
1211
       }
1110
       icnFrm->setPixmap(m_pxPicture);
1212
       icnFrm->setPixmap(m_pxPicture);
1111
     //  tblView->setRowHeight(index.row(), icnFrm->geometry().height());
1213
     //  tblView->setRowHeight(index.row(), icnFrm->geometry().height());
1112
   }
1214
   }
1113
1215
1114
1216
1115
1217
1116
1218
1117
   void IconDelegate::setModelData(
1219
   void IconDelegate::setModelData(
1118
               QWidget *editor,
1220
               QWidget *editor,
1119
               QAbstractItemModel *model,
1221
               QAbstractItemModel *model,
1120
               const QModelIndex& index) const {
1222
               const QModelIndex& index) const {
1121
       IconForm *icnFrm = static_cast<IconForm*>(editor);
1223
       IconForm *icnFrm = static_cast<IconForm*>(editor);
1122
       if (!(icnFrm->dataIsChanged())) return;
1224
       if (!(icnFrm->dataIsChanged())) return;
1123
1225
1124
       m_pxPicture = icnFrm->pixmap();
1226
       m_pxPicture = icnFrm->pixmap();
1125
       QImage currentImage = m_pxPicture.toImage();
1227
       QImage currentImage = m_pxPicture.toImage();
1126
          QByteArray bytes;
1228
          QByteArray bytes;
1127
          QBuffer buffer(&bytes);
1229
          QBuffer buffer(&bytes);
1128
          buffer.open(QIODevice::WriteOnly);
1230
          buffer.open(QIODevice::WriteOnly);
1129
          currentImage.save(&buffer, "PNG");
1231
          currentImage.save(&buffer, "PNG");
1130
1232
1131
1233
1132
1234
1133
1235
1134
         model->setData(index, QVariant (bytes), Qt::EditRole);
1236
         model->setData(index, QVariant (bytes), Qt::EditRole);
1135
1237
1136
     //    int widht = m_pxPicture.width();
1238
     //    int widht = m_pxPicture.width();
1137
     //    int heigh =  m_pxPicture.height();
1239
     //    int heigh =  m_pxPicture.height();
1138
     //    tblView->setRowHeight(index.row(), heigh + 10);
1240
     //    tblView->setRowHeight(index.row(), heigh + 10);
1139
         // model->submitAll();
1241
         // model->submitAll();
1140
1242
1141
1243
1142
1244
1143
1245
1144
      // model->setData(index, value);
1246
      // model->setData(index, value);
1145
   }
1247
   }
1146
1248
1147
1249
1148
1250
1149
   void IconDelegate::updateEditorGeometry(
1251
   void IconDelegate::updateEditorGeometry(
1150
               QWidget *editor,
1252
               QWidget *editor,
1151
               const QStyleOptionViewItem &option,
1253
               const QStyleOptionViewItem &option,
1152
               const QModelIndex& /* index */) const {
1254
               const QModelIndex& /* index */) const {
1153
1255
1154
1256
1155
   //    QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
1257
   //    QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
1156
     //      editor->setGeometry(r);
1258
     //      editor->setGeometry(r);
1157
1259
1158
        editor->setGeometry(option.rect);
1260
        editor->setGeometry(option.rect);
1159
   }
1261
   }
1160
1262
1161
1263
1162
1264
1163
1265
1164
   void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
1266
   void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
1165
   {
1267
   {
1166
1268
1167
1269
1168
          m_pxPicture.fill( QColor(Qt::white) );
1270
          m_pxPicture.fill( QColor(Qt::white) );
1169
1271
1170
          const QAbstractItemModel * model = index.model();
1272
          const QAbstractItemModel * model = index.model();
1171
          QString sFileName = model->data( index, Qt::DisplayRole ).toString();
1273
          QString sFileName = model->data( index, Qt::DisplayRole ).toString();
1172
1274
1173
          QVariant currentImage = model->data(index,0);
1275
          QVariant currentImage = model->data(index,0);
1174
1276
1175
1277
1176
           QByteArray bytes = currentImage.toByteArray();
1278
           QByteArray bytes = currentImage.toByteArray();
1177
     //       QImage image;
1279
     //       QImage image;
1178
     //       image.loadFromData(bytes);
1280
     //       image.loadFromData(bytes);
1179
1281
1180
1282
1181
           if (currentImage.isValid()) {
1283
           if (currentImage.isValid()) {
1182
                m_pxPicture.loadFromData(bytes);
1284
                m_pxPicture.loadFromData(bytes);
1183
1285
1184
           }
1286
           }
1185
           else {
1287
           else {
1186
               //QItemDelegate::paint(painter, option, index);
1288
               //QItemDelegate::paint(painter, option, index);
1187
           return;
1289
           return;
1188
           }
1290
           }
1189
1291
1190
1292
1191
1293
1192
1294
1193
1295
1194
           /*
1296
           /*
1195

1297

1196
           if ( !sFileName.isEmpty() )
1298
           if ( !sFileName.isEmpty() )
1197
                   m_pxPicture.load( sFileName );
1299
                   m_pxPicture.load( sFileName );
1198
           else {
1300
           else {
1199
               //QItemDelegate::paint(painter, option, index);
1301
               //QItemDelegate::paint(painter, option, index);
1200
           return;
1302
           return;
1201
           }
1303
           }
1202
*/
1304
*/
1203
1305
1204
1306
1205
1307
1206
1308
1207
1309
1208
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
1310
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
1209
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
1311
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
1210
                                                             QPalette::Disabled;
1312
                                                             QPalette::Disabled;
1211
1313
1212
            if (option.state & QStyle::State_Selected)
1314
            if (option.state & QStyle::State_Selected)
1213
1315
1214
1316
1215
                painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
1317
                painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
1216
1318
1217
1319
1218
1320
1219
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
1321
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
1220
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
1322
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
1221
   //        painter->setRenderHint(QPainter::Antialiasing);
1323
   //        painter->setRenderHint(QPainter::Antialiasing);
1222
           painter->drawPixmap( nX, nY, m_pxPicture );
1324
           painter->drawPixmap( nX, nY, m_pxPicture );
1223
1325
1224
       //    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
1326
       //    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
1225
1327
1226
           /*
1328
           /*
1227
           QPen pen = painter->pen();
1329
           QPen pen = painter->pen();
1228
           painter->setPen(option.palette.color(QPalette::Mid));
1330
           painter->setPen(option.palette.color(QPalette::Mid));
1229
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
1331
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
1230
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
1332
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
1231
           painter->setPen(pen);
1333
           painter->setPen(pen);
1232
   */
1334
   */
1233
}
1335
}
1234
1336
1235
1337
1236
   void IconDelegate::setTableView(QTableView* table){
1338
   void IconDelegate::setTableView(QTableView* table){
1237
       tblView = table;
1339
       tblView = table;
1238
   }
1340
   }
1239
1341
1240
1342
1241
1343
1242
1344
1243
1345
1244
1346
1245
1347
1246
1348
1247
   FileDelegate::FileDelegate( QObject * parent ) : QItemDelegate(parent)
1349
   FileDelegate::FileDelegate( QObject * parent ) : QItemDelegate(parent)
1248
   {
1350
   {
1249
   }
1351
   }
1250
1352
1251
1353
1252
1354
1253
1355
1254
1356
1255
   QWidget *FileDelegate::createEditor(QWidget *parent,
1357
   QWidget *FileDelegate::createEditor(QWidget *parent,
1256
       const QStyleOptionViewItem &/* option */,
1358
       const QStyleOptionViewItem &/* option */,
1257
       const QModelIndex & /* index */) const
1359
       const QModelIndex & /* index */) const
1258
   {
1360
   {
1259
1361
1260
       FileForm *editor = new FileForm(parent);
1362
       FileForm *editor = new FileForm(parent);
1261
1363
1262
       return editor;
1364
       return editor;
1263
1365
1264
   }
1366
   }
1265
1367
1266
1368
1267
1369
1268
1370
1269
   void FileDelegate::setEditorData(QWidget *editor,
1371
   void FileDelegate::setEditorData(QWidget *editor,
1270
                                       const QModelIndex &index) const
1372
                                       const QModelIndex &index) const
1271
   {
1373
   {
1272
1374
1273
1375
1274
       const QAbstractItemModel * model = index.model();
1376
       const QAbstractItemModel * model = index.model();
1275
       FileForm *flFrm = static_cast<FileForm*>(editor);
1377
       FileForm *flFrm = static_cast<FileForm*>(editor);
1276
       QVariant currentData = model->data(index,Qt::EditRole);
1378
       QVariant currentData = model->data(index,Qt::EditRole);
1277
1379
1278
      // QVariant currentData = QSqlTableModel::data(index, 0);
1380
      // QVariant currentData = QSqlTableModel::data(index, 0);
1279
       QByteArray bytes = currentData.toByteArray();
1381
       QByteArray bytes = currentData.toByteArray();
1280
       if (currentData.isValid()) flFrm->setData(bytes);
1382
       if (currentData.isValid()) flFrm->setData(bytes);
1281
       else return;
1383
       else return;
1282
1384
1283
   }
1385
   }
1284
1386
1285
1387
1286
1388
1287
1389
1288
void FileDelegate::setModelData(
1390
void FileDelegate::setModelData(
1289
               QWidget *editor,
1391
               QWidget *editor,
1290
               QAbstractItemModel *model,
1392
               QAbstractItemModel *model,
1291
               const QModelIndex& index) const {
1393
               const QModelIndex& index) const {
1292
       FileForm *flFrm = static_cast<FileForm*>(editor);
1394
       FileForm *flFrm = static_cast<FileForm*>(editor);
1293
       if (!(flFrm->dataIsChanged())) return;
1395
       if (!(flFrm->dataIsChanged())) return;
1294
1396
1295
       m_Data = flFrm->data();
1397
       m_Data = flFrm->data();
1296
       if (!m_Data.isEmpty()) { // åñëè ìàññèâ íå ïóñòîé
1398
       if (!m_Data.isEmpty()) { // åñëè ìàññèâ íå ïóñòîé
1297
                                   model->setData(index, QVariant (m_Data), Qt::EditRole);
1399
                                   model->setData(index, QVariant (m_Data), Qt::EditRole);
1298
1400
1299
                              }
1401
                              }
1300
       else {       // åñëè ìàññèâ ïóñòîé (ôàéë óäàëèëè)
1402
       else {       // åñëè ìàññèâ ïóñòîé (ôàéë óäàëèëè)
1301
           QVariant val_null;
1403
           QVariant val_null;
1302
           model->setData(index, val_null, Qt::EditRole);
1404
           model->setData(index, val_null, Qt::EditRole);
1303
1405
1304
            }
1406
            }
1305
1407
1306
1408
1307
1409
1308
   }
1410
   }
1309
1411
1310
1412
1311
1413
1312
   void FileDelegate::updateEditorGeometry(
1414
   void FileDelegate::updateEditorGeometry(
1313
               QWidget *editor,
1415
               QWidget *editor,
1314
               const QStyleOptionViewItem &option,
1416
               const QStyleOptionViewItem &option,
1315
               const QModelIndex& /* index */) const {
1417
               const QModelIndex& /* index */) const {
1316
1418
1317
1419
1318
   //    QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
1420
   //    QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
1319
     //      editor->setGeometry(r);
1421
     //      editor->setGeometry(r);
1320
1422
1321
        editor->setGeometry(option.rect);
1423
        editor->setGeometry(option.rect);
1322
   }
1424
   }
1323
1425
1324
1426
1325
1427
1326
1428
1327
 
1429