Хранилища Subversion OpenInventory

Редакция

Редакция 123 | Редакция 129 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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
109
                  QString ID;
110
 
111
                  ID = q.value(0).toString(); //  ID
112
                  Name = q.value(1).toString(); //  Name
113
                  items.insert(ID, Name);
114
                }
115
116
117
 
118
 
119
120
121
 
122
 
123 pingvin 123
    const QStyleOptionViewItem &/* option */,
124
    const QModelIndex &/* index */) const
125
{
126
    //QSpinBox *editor = new QSpinBox(parent);
127
    //editor->setMinimum(0);
128
    //editor->setMaximum(100);
129
    QStringList ID_list;
130
    QStringList Name_list;
126 pingvin 131
132
  // getItems();
133
 
134
135
 
136
 
137
 
138
 
139
 
140
141
    QComboBox *editor = new QComboBox(parent);
142
 
123 pingvin 143
/*
126 pingvin 144
 
145
    editor->addItem("1");
123 pingvin 146
    editor->addItem("2");
147
    editor->addItem("3");
148
    editor->addItem("4");
149
    editor->addItem("5");
150
    editor->addItem("6");
151
    editor->addItem("7");
152
    editor->addItem("8");
153
    editor->addItem("9");
154
*/
155
126 pingvin 156
//  editor->addItem("0");
123 pingvin 157
 
126 pingvin 158
    editor->addItems(Name_list);
159
 
160
}
123 pingvin 161
//! [1]
162
163
//! [2]
164
 
165
                                    const QModelIndex &index) const
166
{
167
   // int value = index.model()->data(index, Qt::EditRole).toInt();
168
169
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
170
 
171
QString value = index.model()->data(index, Qt::EditRole).toString();
172
QComboBox *comboBox = static_cast<QComboBox*>(editor);
173
174
QStringList ID_list;
126 pingvin 175
 
176
int curr_index;
177
178
ID_list = items.keys();
179
 
180
181
curr_index = ID_list.indexOf(value);
182
 
183
/****************************************************
184
if (value == "0") comboBox->setCurrentIndex(0);
185
if (value == "1") comboBox->setCurrentIndex(1);
123 pingvin 186
if (value == "2") comboBox->setCurrentIndex(2);
187
if (value == "3") comboBox->setCurrentIndex(3);
188
if (value == "4") comboBox->setCurrentIndex(4);
189
if (value == "5") comboBox->setCurrentIndex(5);
190
if (value == "6") comboBox->setCurrentIndex(6);
191
if (value == "7") comboBox->setCurrentIndex(7);
192
if (value == "8") comboBox->setCurrentIndex(8);
193
if (value == "9") comboBox->setCurrentIndex(9);
194
******************************************************/
195
comboBox->setEditable(true);
126 pingvin 196
123 pingvin 197
198
 
199
 
200
}
201
 
202
203
//! [3]
204
 
205
                                   const QModelIndex &index) const
206
{
207
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
208
  //  spinBox->interpretText();
209
  //  int value = spinBox->value();
210
211
  //  model->setData(index, value, Qt::EditRole);
212
 
213
    QStringList Name_list;
126 pingvin 214
215
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
123 pingvin 216
 
217
    currIndex = comboBox->currentIndex();
218
  //  QString value = comboBox->itemText(currIndex);
219
126 pingvin 220
    ID_list = items.keys();
221
 
222
223
    QString value = ID_list.at(currIndex);
224
 
225
}
123 pingvin 226
//! [3]
227
228
//! [4]
229
 
230
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
231
{
232
    editor->setGeometry(option.rect);
233
}
234
//! [4]
235
MyDEDelegate::MyDEDelegate(
236
                       bool calpopup,
237
                       QObject *parent)
238
               : QItemDelegate(parent),
239
                 m_calpopup(calpopup) {
240
   }
241
242
   QWidget *MyDEDelegate::createEditor(
243
 
244
               const QStyleOptionViewItem& /* option */,
245
               const QModelIndex& /* index */) const {
246
       QDateEdit *editor = new QDateEdit(parent);
247
       editor->setCalendarPopup(m_calpopup);
248
       editor->installEventFilter(const_cast<MyDEDelegate*>(this));
249
       return editor;
250
   }
251
252
   void MyDEDelegate::setEditorData(
253
 
254
                   const QModelIndex &index) const {
255
       QDate value = index.model()->data(
256
               index, Qt::EditRole).toDate();
257
       QDateEdit *de = static_cast<QDateEdit*>(editor);
258
       de->setDate(value);
259
   }
260
261
   void MyDEDelegate::setModelData(
262
 
263
               QAbstractItemModel *model,
264
               const QModelIndex& index) const {
265
       QDateEdit *de = static_cast<QDateEdit*>(editor);
266
       de->interpretText();
267
       QDate value = de->date();
268
       model->setData(index, value);
269
   }
270
271
   void MyDEDelegate::updateEditorGeometry(
272
 
273
               const QStyleOptionViewItem &option,
274
               const QModelIndex& /* index */) const {
275
       editor->setGeometry(option.rect);
276
   }
277