Хранилища Subversion OpenInventory

Редакция

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

Редакция Автор № строки Строка
123 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
 
44
45
    A delegate that allows the user to change integer values from the model
46
 
47
*/
48
49
#include <QtGui>
50
 
51
#include "delegate.h"
52
 
53
54
 
55
 
56
    : QItemDelegate(parent)
57
{
58
}
59
//! [0]
60
61
void SpinBoxDelegate::setInctance(QString newInctance){
62
 
126 pingvin 63
}
64
65
void SpinBoxDelegate::getItems(){
66
 
67
    QSqlQuery q;
68
    QString query_str;
69
    bool ok;
70
71
    if (SpinBoxDelegate::inctance.isEmpty())
72
 
73
        items.clear();
74
        return;
75
    }
76
77
    query_str = tr("select * from `");
78
 
79
    query_str.append( tr("`"));
80
81
    q.prepare(query_str);
82
 
83
84
 
85
 
86
87
 
88
 
89
 
90
 
91
                            QString error_str;
92
                            error_str =  tr("       ");
93
                            error_str.append(inctance);
94
                            QMessageBox::critical( //     .
95
                                                                            this,                      //  .
96
                                                                            QObject::tr("Database Error"),   // .
97
                                                                            q.lastError().text());          //  .
98
                                                                        //    tr("       "));    //  .
99
100
                            */
101
 
102
                            return;
103
                        }
104
105
106
 
107
 
108
    while(q.next()){
129 pingvin 109
126 pingvin 110
                  QString ID;
111
 
112
                  ID = q.value(0).toString(); //  ID
113
                  Name = q.value(1).toString(); //  Name
114
                  items.insert(ID, Name);
115
                }
116
117
118
 
119
 
120
121
122
 
123
 
123 pingvin 124
    const QStyleOptionViewItem &/* option */,
125
    const QModelIndex &/* index */) const
126
{
127
    //QSpinBox *editor = new QSpinBox(parent);
128
    //editor->setMinimum(0);
129
    //editor->setMaximum(100);
130
    QStringList ID_list;
131
    QStringList Name_list;
126 pingvin 132
133
  // getItems();
134
 
135
136
 
137
 
138
 
139
 
140
 
141
142
    QComboBox *editor = new QComboBox(parent);
143
 
123 pingvin 144
/*
126 pingvin 145
 
146
    editor->addItem("1");
123 pingvin 147
    editor->addItem("2");
148
    editor->addItem("3");
149
    editor->addItem("4");
150
    editor->addItem("5");
151
    editor->addItem("6");
152
    editor->addItem("7");
153
    editor->addItem("8");
154
    editor->addItem("9");
155
*/
156
126 pingvin 157
//  editor->addItem("0");
123 pingvin 158
 
126 pingvin 159
    editor->addItems(Name_list);
160
 
161
}
123 pingvin 162
//! [1]
163
164
//! [2]
165
 
166
                                    const QModelIndex &index) const
167
{
168
   // int value = index.model()->data(index, Qt::EditRole).toInt();
169
170
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
171
 
172
QString value = index.model()->data(index, Qt::EditRole).toString();
173
174
QComboBox *comboBox = static_cast<QComboBox*>(editor);
136 pingvin 175
 
123 pingvin 176
QStringList ID_list;
126 pingvin 177
 
178
int curr_index;
179
180
ID_list = items.keys();
181
 
182
183
curr_index = ID_list.indexOf(value);
184
 
185
comboBox->setCurrentIndex(curr_index);
136 pingvin 186
/****************************************************
126 pingvin 187
if (value == "0") comboBox->setCurrentIndex(0);
188
if (value == "1") comboBox->setCurrentIndex(1);
123 pingvin 189
if (value == "2") comboBox->setCurrentIndex(2);
190
if (value == "3") comboBox->setCurrentIndex(3);
191
if (value == "4") comboBox->setCurrentIndex(4);
192
if (value == "5") comboBox->setCurrentIndex(5);
193
if (value == "6") comboBox->setCurrentIndex(6);
194
if (value == "7") comboBox->setCurrentIndex(7);
195
if (value == "8") comboBox->setCurrentIndex(8);
196
if (value == "9") comboBox->setCurrentIndex(9);
197
******************************************************/
198
comboBox->setEditable(true);
126 pingvin 199
123 pingvin 200
201
 
202
 
203
}
204
 
205
206
//! [3]
207
 
208
                                   const QModelIndex &index) const
209
{
210
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
211
  //  spinBox->interpretText();
212
  //  int value = spinBox->value();
213
214
  //  model->setData(index, value, Qt::EditRole);
215
 
216
    QStringList Name_list;
126 pingvin 217
218
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
123 pingvin 219
 
220
    currIndex = comboBox->currentIndex();
221
    if (currIndex==-1) return;
222
  //  QString value = comboBox->itemText(currIndex);
136 pingvin 223
126 pingvin 224
    ID_list = items.keys();
225
 
226
227
    QString value = ID_list.at(currIndex);
228
 
229
}
123 pingvin 230
//! [3]
231
232
//! [4]
233
 
234
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
235
{
236
    editor->setGeometry(option.rect);
237
}
238
//! [4]
239
MyDEDelegate::MyDEDelegate(
240
                       bool calpopup,
241
                       QObject *parent)
242
               : QItemDelegate(parent),
243
                 m_calpopup(calpopup) {
244
   }
245
246
   QWidget *MyDEDelegate::createEditor(
247
 
248
               const QStyleOptionViewItem& /* option */,
249
               const QModelIndex& /* index */) const {
250
       QDateEdit *editor = new QDateEdit(parent);
251
       editor->setCalendarPopup(m_calpopup);
252
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
253
       return editor;
254
   }
255
256
   void MyDEDelegate::setEditorData(
257
 
258
                   const QModelIndex &index) const {
259
       QDate value = index.model()->data(
260
               index, Qt::EditRole).toDate();
261
       QDateEdit *de = static_cast<QDateEdit*>(editor);
262
       de->setDate(value);
263
   }
264
265
   void MyDEDelegate::setModelData(
266
 
267
               QAbstractItemModel *model,
268
               const QModelIndex& index) const {
269
       QDateEdit *de = static_cast<QDateEdit*>(editor);
270
       de->interpretText();
271
       QDate value = de->date();
272
       model->setData(index, value);
273
   }
274
275
   void MyDEDelegate::updateEditorGeometry(
276
 
277
               const QStyleOptionViewItem &option,
278
               const QModelIndex& /* index */) const {
279
       editor->setGeometry(option.rect);
280
   }
281
282
138 pingvin 283
 
284
 
285
 
286
 
287
 
288
   }
289
290
   void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
291
 
292
           m_pxPicture.fill( QColor(Qt::white) );
293
294
           const QAbstractItemModel * model = index.model();
295
 
296
297
           if ( !sFileName.isEmpty() )
298
 
299
           else {
300
               //QItemDelegate::paint(painter, option, index);
301
           return;
302
           }
303
304
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
305
 
306
                                                             QPalette::Disabled;
307
308
            if (option.state & QStyle::State_Selected)
309
 
310
311
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
312
 
313
           painter->drawPixmap( nX, nY, m_pxPicture );
314
315
316
 
317
 
318
           /*
319
 
320
           painter->setPen(option.palette.color(QPalette::Mid));
321
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
322
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
323
           painter->setPen(pen);
324
   */
325
   }
326