Rev 205 | Rev 224 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 205 | Rev 219 | ||
---|---|---|---|
Line 236... | Line 236... | ||
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 | ||
- | 242 | ||
- | 243 | ||
- | 244 | ||
- | 245 | ||
- | 246 | ||
- | 247 | ||
- | 248 | ||
- | 249 | ||
- | 250 | ||
- | 251 | ||
- | 252 | //! [0]
|
|
- | 253 | FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent) |
|
- | 254 | : QItemDelegate(parent) |
|
- | 255 | {
|
|
- | 256 | }
|
|
- | 257 | //! [0]
|
|
- | 258 | ||
- | 259 | void FilterSpinBoxDelegate::setClassID(QString newClassID){ |
|
- | 260 | class_id = newClassID; |
|
- | 261 | }
|
|
- | 262 | ||
- | 263 | void FilterSpinBoxDelegate::getItems(){ |
|
- | 264 | QMap <QString, QString> result_map; |
|
- | 265 | QSqlQuery q;
|
|
- | 266 | QString query_str;
|
|
- | 267 | bool ok; |
|
- | 268 | ||
- | 269 | if (FilterSpinBoxDelegate::class_id.isEmpty()) |
|
- | 270 | {
|
|
- | 271 | items.clear(); |
|
- | 272 | return; |
|
- | 273 | }
|
|
- | 274 | ||
- | 275 | query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
|
- | 276 | query_str.append(class_id); |
|
- | 277 | query_str.append( tr("'")); |
|
- | 278 | ||
- | 279 | q.prepare(query_str); |
|
- | 280 | ||
- | 281 | ||
- | 282 | ok = q.exec(); |
|
- | 283 | ||
- | 284 | ||
- | 285 | ||
- | 286 | ||
- | 287 | if (!ok) { |
|
- | 288 | /*
|
|
- | 289 | QString error_str;
|
|
- | 290 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
|
- | 291 | error_str.append(inctance);
|
|
- | 292 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
|
- | 293 | this, // Ðîäèòåëüñêèé âèäæåò.
|
|
- | 294 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
|
- | 295 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
|
- | 296 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
|
- | 297 | ||
- | 298 | */
|
|
- | 299 | items.clear(); |
|
- | 300 | return; |
|
- | 301 | }
|
|
- | 302 | ||
- | 303 | ||
- | 304 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
|
- | 305 | items.clear(); |
|
- | 306 | while(q.next()){ |
|
- | 307 | ||
- | 308 | QString ID;
|
|
- | 309 | QString Name;
|
|
- | 310 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
|
- | 311 | Name = q.value(1).toString(); // îïðåäåëÿåì Name |
|
- | 312 | items.insert(ID, Name); |
|
- | 313 | }
|
|
- | 314 | ||
- | 315 | ||
- | 316 | // return result_map;
|
|
- | 317 | }
|
|
- | 318 | ||
- | 319 | ||
- | 320 | //! [1]
|
|
- | 321 | QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent, |
|
- | 322 | const QStyleOptionViewItem &/* option */, |
|
- | 323 | const QModelIndex &/* index */) const |
|
- | 324 | {
|
|
- | 325 | //QSpinBox *editor = new QSpinBox(parent);
|
|
- | 326 | //editor->setMinimum(0);
|
|
- | 327 | //editor->setMaximum(100);
|
|
- | 328 | QStringList ID_list;
|
|
- | 329 | QStringList Name_list;
|
|
- | 330 | ||
- | 331 | // getItems();
|
|
- | 332 | ||
- | 333 | ||
- | 334 | ||
- | 335 | ||
- | 336 | ||
- | 337 | ID_list = items.keys(); |
|
- | 338 | Name_list = items.values(); |
|
- | 339 | ||
- | 340 | QComboBox *editor = new QComboBox(parent); |
|
- | 341 | ||
- | 342 | /*
|
|
- | 343 | editor->addItem("0");
|
|
- | 344 | editor->addItem("1");
|
|
- | 345 | editor->addItem("2");
|
|
- | 346 | editor->addItem("3");
|
|
- | 347 | editor->addItem("4");
|
|
- | 348 | editor->addItem("5");
|
|
- | 349 | editor->addItem("6");
|
|
- | 350 | editor->addItem("7");
|
|
- | 351 | editor->addItem("8");
|
|
- | 352 | editor->addItem("9");
|
|
- | 353 | */
|
|
- | 354 | ||
- | 355 | // editor->addItem("0");
|
|
- | 356 | ||
- | 357 | editor->addItems(Name_list); |
|
- | 358 | // editor->setEditable(false);
|
|
- | 359 | return editor; |
|
- | 360 | }
|
|
- | 361 | //! [1]
|
|
- | 362 | ||
- | 363 | //! [2]
|
|
- | 364 | void FilterSpinBoxDelegate::setEditorData(QWidget *editor, |
|
- | 365 | const QModelIndex &index) const |
|
- | 366 | {
|
|
- | 367 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
|
- | 368 | ||
- | 369 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 370 | // spinBox->setValue(value);
|
|
- | 371 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
|
- | 372 | ||
- | 373 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 374 | ||
- | 375 | QStringList ID_list;
|
|
- | 376 | QStringList Name_list;
|
|
- | 377 | int curr_index; |
|
- | 378 | ||
- | 379 | ID_list = items.keys(); |
|
- | 380 | Name_list = items.values(); |
|
- | 381 | ||
- | 382 | curr_index = ID_list.indexOf(value); |
|
- | 383 | if (curr_index==-1) return; |
|
- | 384 | comboBox->setCurrentIndex(curr_index); |
|
- | 385 | /****************************************************
|
|
- | 386 | if (value == "0") comboBox->setCurrentIndex(0);
|
|
- | 387 | if (value == "1") comboBox->setCurrentIndex(1);
|
|
- | 388 | if (value == "2") comboBox->setCurrentIndex(2);
|
|
- | 389 | if (value == "3") comboBox->setCurrentIndex(3);
|
|
- | 390 | if (value == "4") comboBox->setCurrentIndex(4);
|
|
- | 391 | if (value == "5") comboBox->setCurrentIndex(5);
|
|
- | 392 | if (value == "6") comboBox->setCurrentIndex(6);
|
|
- | 393 | if (value == "7") comboBox->setCurrentIndex(7);
|
|
- | 394 | if (value == "8") comboBox->setCurrentIndex(8);
|
|
- | 395 | if (value == "9") comboBox->setCurrentIndex(9);
|
|
- | 396 | ******************************************************/
|
|
- | 397 | comboBox->setEditable(false); |
|
- | 398 | ||
- | 399 | ||
- | 400 | //comboBox->setItemText(0, value);
|
|
- | 401 | ||
- | 402 | }
|
|
- | 403 | //! [2]
|
|
- | 404 | ||
- | 405 | //! [3]
|
|
- | 406 | void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
|
- | 407 | const QModelIndex &index) const |
|
- | 408 | {
|
|
- | 409 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 410 | // spinBox->interpretText();
|
|
- | 411 | // int value = spinBox->value();
|
|
- | 412 | ||
- | 413 | // model->setData(index, value, Qt::EditRole);
|
|
- | 414 | QStringList ID_list;
|
|
- | 415 | QStringList Name_list;
|
|
- | 416 | ||
- | 417 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 418 | int currIndex; |
|
- | 419 | currIndex = comboBox->currentIndex(); |
|
- | 420 | if (currIndex==-1) return; |
|
- | 421 | // QString value = comboBox->itemText(currIndex);
|
|
- | 422 | ||
- | 423 | ID_list = items.keys(); |
|
- | 424 | Name_list = items.values(); |
|
- | 425 | ||
- | 426 | // QString value = ID_list.at(currIndex);
|
|
- | 427 | QString value = Name_list.at(currIndex); |
|
- | 428 | model->setData(index, value, Qt::EditRole); |
|
- | 429 | }
|
|
- | 430 | //! [3]
|
|
- | 431 | ||
- | 432 | //! [4]
|
|
- | 433 | void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
|
- | 434 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
|
- | 435 | {
|
|
- | 436 | editor->setGeometry(option.rect); |
|
- | 437 | }
|
|
- | 438 | ||
- | 439 | ||
- | 440 | ||
- | 441 | ||
- | 442 | ||
- | 443 | ||
- | 444 | ||
- | 445 | ||
- | 446 | ||
- | 447 | ||
- | 448 | //! [0]
|
|
- | 449 | FilterConditionDelegate::FilterConditionDelegate(QObject *parent) |
|
- | 450 | : QItemDelegate(parent) |
|
- | 451 | {
|
|
- | 452 | }
|
|
- | 453 | //! [0]
|
|
- | 454 | ||
- | 455 | void FilterConditionDelegate::setClassID(QString newClassID){ |
|
- | 456 | class_id = newClassID; |
|
- | 457 | }
|
|
- | 458 | ||
- | 459 | ||
- | 460 | ||
- | 461 | //! [1]
|
|
- | 462 | QWidget *FilterConditionDelegate::createEditor(QWidget *parent, |
|
- | 463 | const QStyleOptionViewItem &/* option */, |
|
- | 464 | const QModelIndex &/* index */) const |
|
- | 465 | {
|
|
- | 466 | QStringList Name_list;
|
|
- | 467 | ||
- | 468 | Name_list = items; |
|
- | 469 | ||
- | 470 | QComboBox *editor = new QComboBox(parent); |
|
- | 471 | ||
- | 472 | /*
|
|
- | 473 | editor->addItem("0");
|
|
- | 474 | editor->addItem("1");
|
|
- | 475 | editor->addItem("2");
|
|
- | 476 | editor->addItem("3");
|
|
- | 477 | editor->addItem("4");
|
|
- | 478 | editor->addItem("5");
|
|
- | 479 | editor->addItem("6");
|
|
- | 480 | editor->addItem("7");
|
|
- | 481 | editor->addItem("8");
|
|
- | 482 | editor->addItem("9");
|
|
- | 483 | */
|
|
- | 484 | ||
- | 485 | // editor->addItem("0");
|
|
- | 486 | ||
- | 487 | editor->addItems(Name_list); |
|
- | 488 | // editor->setEditable(false);
|
|
- | 489 | return editor; |
|
- | 490 | }
|
|
- | 491 | //! [1]
|
|
- | 492 | ||
- | 493 | //! [2]
|
|
- | 494 | void FilterConditionDelegate::setEditorData(QWidget *editor, |
|
- | 495 | const QModelIndex &index) const |
|
- | 496 | {
|
|
- | 497 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
|
- | 498 | ||
- | 499 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 500 | // spinBox->setValue(value);
|
|
- | 501 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
|
- | 502 | ||
- | 503 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 504 | ||
- | 505 | //QStringList ID_list;
|
|
- | 506 | //QStringList Name_list;
|
|
- | 507 | int curr_index; |
|
- | 508 | ||
- | 509 | //ID_list = items.keys();
|
|
- | 510 | //Name_list = items.values();
|
|
- | 511 | ||
- | 512 | curr_index = items.indexOf(value); |
|
- | 513 | if (curr_index==-1) return; |
|
- | 514 | comboBox->setCurrentIndex(curr_index); |
|
- | 515 | /****************************************************
|
|
- | 516 | if (value == "0") comboBox->setCurrentIndex(0);
|
|
- | 517 | if (value == "1") comboBox->setCurrentIndex(1);
|
|
- | 518 | if (value == "2") comboBox->setCurrentIndex(2);
|
|
- | 519 | if (value == "3") comboBox->setCurrentIndex(3);
|
|
- | 520 | if (value == "4") comboBox->setCurrentIndex(4);
|
|
- | 521 | if (value == "5") comboBox->setCurrentIndex(5);
|
|
- | 522 | if (value == "6") comboBox->setCurrentIndex(6);
|
|
- | 523 | if (value == "7") comboBox->setCurrentIndex(7);
|
|
- | 524 | if (value == "8") comboBox->setCurrentIndex(8);
|
|
- | 525 | if (value == "9") comboBox->setCurrentIndex(9);
|
|
- | 526 | ******************************************************/
|
|
- | 527 | comboBox->setEditable(false); |
|
- | 528 | ||
- | 529 | ||
- | 530 | //comboBox->setItemText(0, value);
|
|
- | 531 | ||
- | 532 | }
|
|
- | 533 | //! [2]
|
|
- | 534 | ||
- | 535 | //! [3]
|
|
- | 536 | void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
|
- | 537 | const QModelIndex &index) const |
|
- | 538 | {
|
|
- | 539 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 540 | // spinBox->interpretText();
|
|
- | 541 | // int value = spinBox->value();
|
|
- | 542 | ||
- | 543 | // model->setData(index, value, Qt::EditRole);
|
|
- | 544 | QStringList ID_list;
|
|
- | 545 | QStringList Name_list;
|
|
- | 546 | ||
- | 547 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 548 | int currIndex; |
|
- | 549 | currIndex = comboBox->currentIndex(); |
|
- | 550 | if (currIndex==-1) return; |
|
- | 551 | // QString value = comboBox->itemText(currIndex);
|
|
- | 552 | ||
- | 553 | // ID_list = items.keys();
|
|
- | 554 | // Name_list = items.values();
|
|
- | 555 | ||
- | 556 | // QString value = ID_list.at(currIndex);
|
|
- | 557 | QString value = items.at(currIndex); |
|
- | 558 | model->setData(index, value, Qt::EditRole); |
|
- | 559 | }
|
|
- | 560 | //! [3]
|
|
- | 561 | ||
- | 562 | //! [4]
|
|
- | 563 | void FilterConditionDelegate::updateEditorGeometry(QWidget *editor, |
|
- | 564 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
|
- | 565 | {
|
|
- | 566 | editor->setGeometry(option.rect); |
|
- | 567 | }
|
|
- | 568 | ||
- | 569 | ||
- | 570 | ||
- | 571 | ||
- | 572 | ||
- | 573 | ||
- | 574 | ||
- | 575 | ||
- | 576 | ||
- | 577 | ||
241 | //! [4]
|
578 | //! [4]
|
242 | MyDEDelegate::MyDEDelegate( |
579 | MyDEDelegate::MyDEDelegate( |
243 | bool calpopup,
|
580 | bool calpopup,
|
244 | QObject *parent) |
581 | QObject *parent) |
245 | : QItemDelegate(parent), |
582 | : QItemDelegate(parent), |