Хранилища Subversion OpenInventory

Редакция

Редакция 167 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
53 pingvin 1
 
2
**
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the examples of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Commercial Usage
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Commercial License Agreement provided with the
13
** Software or, alternatively, in accordance with the terms contained in
14
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file.  Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
**
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file.  Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
35
**
36
** If you have questions regarding the use of this file, please contact
37
** Nokia at qt-info@nokia.com.
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
 
43
    delegate.cpp
44
45
 
46
    using a spin box widget.
47
*/
48
49
 
50
51
 
52
53
 
54
 
55
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
56
    : QItemDelegate(parent)
57
{
58
  //  SpinBoxDelegate::getItems();
134 pingvin 59
}
53 pingvin 60
//! [0]
61
62
 
63
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
64
    const QStyleOptionViewItem &/* option */,
65
    const QModelIndex &/* index */) const
66
{
67
    QStringList ID_list;
134 pingvin 68
    QStringList Name_list;
69
70
 
71
72
 
73
 
74
 
75
 
76
 
77
    Name_list = items.values();
78
79
 
53 pingvin 80
134 pingvin 81
 
82
    editor->addItem("0");
53 pingvin 83
    editor->addItem("1");
84
    editor->addItem("2");
85
    editor->addItem("3");
86
    editor->addItem("4");
87
    editor->addItem("5");
88
    editor->addItem("6");
89
    editor->addItem("7");
90
    editor->addItem("8");
91
    editor->addItem("9");
92
*/
134 pingvin 93
53 pingvin 94
 
134 pingvin 95
96
 
97
    return editor;
53 pingvin 98
}
99
//! [1]
100
101
 
102
void SpinBoxDelegate::setEditorData(QWidget *editor,
103
                                    const QModelIndex &index) const
104
{
105
    QString value = index.model()->data(index, Qt::EditRole).toString();
134 pingvin 106
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
107
53 pingvin 108
 
134 pingvin 109
    QStringList Name_list;
110
    int curr_index;
111
53 pingvin 112
 
134 pingvin 113
    Name_list = items.values();
114
53 pingvin 115
 
134 pingvin 116
    comboBox->setCurrentIndex(curr_index);
117
    /****************************************************
118
    if (value == "0") comboBox->setCurrentIndex(0);
119
    if (value == "1") comboBox->setCurrentIndex(1);
120
    if (value == "2") comboBox->setCurrentIndex(2);
121
    if (value == "3") comboBox->setCurrentIndex(3);
122
    if (value == "4") comboBox->setCurrentIndex(4);
123
    if (value == "5") comboBox->setCurrentIndex(5);
124
    if (value == "6") comboBox->setCurrentIndex(6);
125
    if (value == "7") comboBox->setCurrentIndex(7);
126
    if (value == "8") comboBox->setCurrentIndex(8);
127
    if (value == "9") comboBox->setCurrentIndex(9);
128
    ******************************************************/
129
    comboBox->setEditable(true);
130
131
 
132
 
53 pingvin 133
134
 
135
//! [2]
136
137
 
138
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
139
                                   const QModelIndex &index) const
140
{
141
    QStringList ID_list;
134 pingvin 142
    QStringList Name_list;
143
53 pingvin 144
 
145
    int currIndex;
146
    currIndex = comboBox->currentIndex();
147
  //  QString value = comboBox->itemText(currIndex);
134 pingvin 148
149
 
150
    Name_list = items.values();
151
152
 
153
    model->setData(index, value, Qt::EditRole);
53 pingvin 154
134 pingvin 155
 
156
 
53 pingvin 157
//! [3]
158
159
 
160
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
161
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
162
{
163
    editor->setGeometry(option.rect);
164
}
165
//! [4]
166
134 pingvin 167
 
168
    QMap <QString, QString> result_map;
169
    QSqlQuery q;
170
    QString query_str;
171
    bool ok;
172
173
 
174
    q.prepare(query_str);
175
176
 
177
 
178
179
 
180
 
181
 
182
 
183
                            /*
184
                            QString error_str;
185
                            error_str =  tr("       ");
186
                            error_str.append(inctance);
187
                            QMessageBox::critical( //     .
188
                                                                            this,                      //  .
189
                                                                            QObject::tr("Database Error"),   // .
190
                                                                            q.lastError().text());          //  .
191
                                                                        //    tr("       "));    //  .
192
193
 
194
                            items.clear();
195
                            return;
196
                        }
197
198
 
199
 
200
    items.clear();
201
    while(q.next()){
202
203
 
204
                  QString ClassName;
205
                  ID = q.value(0).toString(); //  ID
206
                  ClassName = q.value(1).toString(); //  Name
207
                  items.insert(ID, ClassName);
208
                }
209
210
 
211
 
212
}
213
214
 
215
 
216
 
217
 
218
 
219
 
220
 
221
 
222
 
223
 
224
 
225
 
226
 
227
 
228
 
229
 
230
 
53 pingvin 231
                       bool calpopup,
232
                       QObject *parent)
233
               : QItemDelegate(parent),
234
                 m_calpopup(calpopup) {
235
   }
236
237
 
238
               QWidget *parent,
239
               const QStyleOptionViewItem& /* option */,
240
               const QModelIndex& /* index */) const {
241
       QDateEdit *editor = new QDateEdit(parent);
242
       editor->setCalendarPopup(m_calpopup);
243
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
244
       return editor;
245
   }
246
247
 
248
                   QWidget *editor,
249
                   const QModelIndex &index) const {
250
       QDate value = index.model()->data(
251
               index, Qt::EditRole).toDate();
252
       QDateEdit *de = static_cast<QDateEdit*>(editor);
253
       de->setDate(value);
254
   }
255
256
 
257
               QWidget *editor,
258
               QAbstractItemModel *model,
259
               const QModelIndex& index) const {
260
       QDateEdit *de = static_cast<QDateEdit*>(editor);
261
       de->interpretText();
262
       QDate value = de->date();
263
       model->setData(index, value);
264
   }
265
266
 
267
               QWidget *editor,
268
               const QStyleOptionViewItem &option,
269
               const QModelIndex& /* index */) const {
270
       editor->setGeometry(option.rect);
271
   }
272
134 pingvin 273
 
274
 
161 pingvin 275
 
276
   {
277
   }
278
279
 
165 pingvin 280
 
281
 
282
 
283
 
284
       const QStyleOptionViewItem &/* option */,
285
       const QModelIndex &/* index */) const
286
   {
287
288
 
289
       return editor;
290
291
 
292
293
 
294
 
295
 
296
 
297
                                       const QModelIndex &index) const
298
   {
299
300
 
301
 
302
       IconForm *icnFrm = static_cast<IconForm*>(editor);
303
       QVariant currentImage = model->data(index,0);
304
       QByteArray bytes = currentImage.toByteArray();
305
       if (currentImage.isValid()) {
306
            m_pxPicture.loadFromData(bytes);
307
       }
308
       else {
309
           //QItemDelegate::paint(painter, option, index);
310
167 pingvin 311
 
312
 
313
       }
165 pingvin 314
       icnFrm->setPixmap(m_pxPicture);
315
   }
316
317
 
318
 
319
 
320
 
321
               QWidget *editor,
322
               QAbstractItemModel *model,
323
               const QModelIndex& index) const {
324
       IconForm *icnFrm = static_cast<IconForm*>(editor);
325
       if (!(icnFrm->dataIsChanged())) return;
167 pingvin 326
327
 
182 pingvin 328
       m_pxPicture = icnFrm->pixmap();
165 pingvin 329
       QImage currentImage = m_pxPicture.toImage();
330
          QByteArray bytes;
331
          QBuffer buffer(&bytes);
332
          buffer.open(QIODevice::WriteOnly);
333
          currentImage.save(&buffer, "PNG");
334
335
 
336
 
337
 
338
 
339
340
 
341
     //    int heigh =  m_pxPicture.height();
342
     //    tblView->setRowHeight(index.row(), heigh + 10);
343
         // model->submitAll();
344
     }
182 pingvin 345
       else { //  
346
           QVariant val_null;
347
           model->setData(index, val_null, Qt::EditRole);
348
       }
349
165 pingvin 350
 
351
 
352
   }
353
354
 
355
 
356
 
357
               QWidget *editor,
358
               const QStyleOptionViewItem &option,
359
               const QModelIndex& /* index */) const {
360
361
 
362
 
363
     //      editor->setGeometry(r);
364
365
 
366
   }
367
368
 
369
 
370
 
371
 
161 pingvin 372
   {
373
374
 
375
 
165 pingvin 376
161 pingvin 377
 
165 pingvin 378
          QString sFileName = model->data( index, Qt::DisplayRole ).toString();
379
161 pingvin 380
 
165 pingvin 381
382
 
161 pingvin 383
     //       QImage image;
384
     //       image.loadFromData(bytes);
385
386
 
387
 
388
                m_pxPicture.loadFromData(bytes);
389
165 pingvin 390
 
161 pingvin 391
           else {
392
           int i;
182 pingvin 393
           i++;
394
               //QItemDelegate::paint(painter, option, index);
161 pingvin 395
           return;
396
           }
397
398
 
399
 
165 pingvin 400
 
401
 
402
 
161 pingvin 403
404
 
405
                   m_pxPicture.load( sFileName );
406
           else {
407
               //QItemDelegate::paint(painter, option, index);
408
           return;
409
           }
410
*/
411
412
 
413
 
414
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
415
                                                             QPalette::Disabled;
416
417
 
418
419
 
165 pingvin 420
 
421
422
 
161 pingvin 423
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
424
           painter->drawPixmap( nX, nY, m_pxPicture );
425
426
 
427
 
165 pingvin 428
161 pingvin 429
 
430
           QPen pen = painter->pen();
431
           painter->setPen(option.palette.color(QPalette::Mid));
432
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
433
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
434
           painter->setPen(pen);
435
   */
436
}
165 pingvin 437
161 pingvin 438
 
439
 
165 pingvin 440
       tblView = table;
441
   }
442