void QWidgetBusinessTrip::doToolBar() { toolBar_ = new QToolBar(this); QList<QAction*> listActions; QAction *act; act = new QAction(this); act->setIcon(QIcon(":/CTRL/refresh")); act->setToolTip("Обновить"); listActions.push_back(act); connect(act, SIGNAL(triggered(bool)), SLOT(slotRefresh())); toolBar_->addActions(listActions); QWidget *widget; QDateEdit *dateEdit; widget = new QWidget(toolBar_); widget->setLayout(new QVBoxLayout()); widget->layout()->addWidget(new QLabel("Дата с")); dateEdit = new QDateEdit(this); dateEdit->setCalendarPopup(true); dateEdit->setDate(dateStart_); connect(dateEdit, SIGNAL(dateChanged(QDate)), SLOT(slotChangeDateStart(QDate))); widget->layout()->addWidget(dateEdit); toolBar_->addWidget(widget); widget = new QWidget(toolBar_); widget->setLayout(new QVBoxLayout()); widget->layout()->addWidget(new QLabel("Дата по")); dateEdit = new QDateEdit(this); dateEdit->setCalendarPopup(true); dateEdit->setDate(dateEnd_); connect(dateEdit, SIGNAL(dateChanged(QDate)), SLOT(slotChangeDateEnd(QDate))); widget->layout()->addWidget(dateEdit); toolBar_->addWidget(widget); widget = new QWidget(toolBar_); widget->setLayout(new QVBoxLayout()); widget->layout()->addWidget(new QLabel("Сотрудник")); editEmployee_ = new QLineEdit(toolBar_); connect(editEmployee_, SIGNAL(editingFinished()), SLOT(slotRefresh())); widget->layout()->addWidget(editEmployee_); toolBar_->addWidget(widget); toolBar_->setIconSize(QSize(40,40)); layout_->addWidget(toolBar_); }
QWidget *DBFRedactorDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { const DBFRedactor::Field& field = m_redactor->field(index.column()); switch (field.type) { case DBFRedactor::TYPE_DATE: { QDateEdit *edit = new QDateEdit(parent); edit->setCalendarPopup(true); return edit; break; } case DBFRedactor::TYPE_FLOAT: case DBFRedactor::TYPE_NUMERIC: { QDoubleSpinBox *edit = new QDoubleSpinBox(parent); edit->setDecimals(field.secondLenght); QString tempString; tempString.fill('9', field.firstLenght - 1); edit->setMinimum(tempString.toDouble() * (-1)); tempString.fill('9', field.firstLenght); edit->setMaximum(tempString.toDouble()); return edit; break; } default: { QLineEdit *edit = new QLineEdit(parent); edit->setMaxLength(field.firstLenght); return edit; } } return 0; }
QWidget *PupilSingularActivityDelegate::createEditor ( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { switch ( index.column() ) { case 2: { QDateEdit *cal = new QDateEdit ( parent ); cal->setCalendarPopup ( true ); connect ( cal, SIGNAL ( dateChanged ( const QDate ) ), this, SLOT ( emitCommitData() ) ); return cal; } break; case 3: { QComboBox *combo = new QComboBox ( parent ); QStringList myTypeList; myTypeList << "Solo-Vortrag" << "Ensemble-Mitwirkung" << "sonstiges"; combo->insertItems ( 0, myTypeList ); connect ( combo, SIGNAL ( activated ( int ) ), this, SLOT ( emitCommitData() ) ); return combo; } break; default: return QItemDelegate::createEditor ( parent, option, index ); break; } }
QWidget *CalendarDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const { QDateEdit *editor = new QDateEdit(parent); editor->setCalendarPopup(m_calpopup); editor->installEventFilter(const_cast<CalendarDelegate*>(this)); connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return editor; }
QWidget* DateEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const{ QDateEdit *date = new QDateEdit(parent); date->setCalendarPopup(true); date->setDisplayFormat("yyyy-MM-dd"); date->setDate(QDate::currentDate()); date->setMinimumDate(QDate(2014,3,1)); date->setMaximumDate(QDate(2050,12,31)); return date; }
QWidget *PupilContActivityDelegate::createEditor ( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { switch ( index.column() ) { case 2: { QStringList typeList; typeList << tr("Ensemble") << tr("Theorieunterricht") << tr("Korrepetition") << tr("Sonstiges"); QComboBox *combo = new QComboBox ( parent ); combo->insertItems ( 0, typeList ); connect ( combo, SIGNAL ( activated ( int ) ), this, SLOT ( emitCommitData() ) ); return combo; } break; case 3: { QStringList dayList; dayList << tr("Montag") << tr("Dienstag") << tr("Mittwoch") << tr("Donnerstag") << tr("Freitag") << tr("Samstag") << tr("Sonntag") << QString::fromUtf8(tr("unregelmäßig").toStdString().c_str()); QComboBox *combo = new QComboBox ( parent ); combo->insertItems ( 0, dayList ); connect ( combo, SIGNAL ( activated ( int ) ), this, SLOT ( emitCommitData() ) ); return combo; } break; case 4: { QTimeEdit *time = new QTimeEdit ( parent ); connect ( time, SIGNAL ( dateChanged ( const QDate ) ), this, SLOT ( emitCommitData() ) ); return time; } break; case 5: { QDateEdit *cal = new QDateEdit ( parent ); cal->setCalendarPopup ( true ); connect ( cal, SIGNAL ( dateChanged ( const QDate ) ), this, SLOT ( emitCommitData() ) ); return cal; } break; case 6: { QDateEdit *cal1 = new QDateEdit ( parent ); cal1->setCalendarPopup ( true ); connect ( cal1, SIGNAL ( dateChanged ( const QDate ) ), this, SLOT ( emitCommitData() ) ); return cal1; } break; default: return QItemDelegate::createEditor ( parent, option, index ); break; } }
void EventsWindow::createDateFilter(QBoxLayout *layout) { m_dateLabel = new QLabel; m_dateLabel->setStyleSheet(QLatin1String("font-weight:bold;")); layout->addWidget(m_dateLabel); QDateEdit *dateEdit = new QDateEdit(QDate::currentDate()); dateEdit->setCalendarPopup(true); dateEdit->setMaximumDate(QDate::currentDate()); dateEdit->setDisplayFormat(QLatin1String("ddd, MMM dd, yyyy")); dateEdit->setTime(QTime(23, 59, 59, 999)); dateEdit->setFixedWidth(m_sourcesView->width()); layout->addWidget(dateEdit); setFilterDay(dateEdit->dateTime()); connect(dateEdit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setFilterDay(QDateTime))); }
//------------------------------------------------------------------------------ QWidget* ConditionValueDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { switch (field(index)) { case AssignmentRule::Date: { QDateEdit* dateEditor = new QDateEdit(parent); dateEditor = new QDateEdit(parent); dateEditor->installEventFilter(new IgnoreUndoRedo(parent, parent)); dateEditor->setCalendarPopup(true); dateEditor->setSpecialValueText(tr("None")); return dateEditor; } case AssignmentRule::Amount: return new MoneyEdit(parent); default: return new LineEdit("", parent); } }
QWidget *BudgetEntityDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const { QLocale locale; QWidget *editor = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; QDateEdit *dateEdit = new QDateEdit(QDate::currentDate()); QPlainTextEdit *textEdit = new QPlainTextEdit("Textedig"); QDoubleSpinBox *spinBox = new QDoubleSpinBox; dateEdit->setDisplayFormat("yyyy-MM-dd"); dateEdit->setCalendarPopup(true); spinBox->setMaximum(1e+08); spinBox->setMinimum(-1e+07); spinBox->setPrefix(locale.currencySymbol(QLocale::CurrencySymbol)); spinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight); editor->setLayout(lay); lay->addWidget(dateEdit); lay->addWidget(textEdit); lay->addWidget(spinBox); return editor; }
QWidget *DateTimeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const { // TODO: use the ModernDateEditor editor if (m_IsDateOnly) { QDateEdit *editor = new QDateEdit(parent); editor->setMinimumDate(m_MinDate); editor->setMaximumDate(m_MaxDate); editor->setCalendarPopup(true); editor->setDisplayFormat(tkTr(Trans::Constants::DATEFORMAT_FOR_EDITOR)); editor->setDate(index.data(Qt::EditRole).toDate()); return editor; } else { QDateTimeEdit *editor = new QDateTimeEdit(parent); editor->setMinimumDateTime(QDateTime(m_MinDate, m_MinTime)); editor->setMaximumDateTime(QDateTime(m_MaxDate, m_MaxTime)); editor->setDisplayFormat(tkTr(Trans::Constants::DATETIMEFORMAT_FOR_EDITOR)); editor->setDateTime(index.data().toDateTime()); return editor; } return 0; }
// Предоставление редактора QWidget* ComboBoxFileldDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { if (index.column()>2){ // QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString()); QString pole = index.model()->data(index.sibling(index.row(),0)).toString(); int j; for(int i=0;i<fieldName.count();i++){ QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString(); s.replace("\n"," "); if (s==pole){ j=fieldName.at(i); break; } } //QMessageBox::critical(0,"",QString("%1").arg(j)); QSqlRelation rel = model->relation(j); if (rel.indexColumn()!=QString("")){ //QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName()); QComboBox * pRes = new QComboBox(parent); QSqlTableModel* relModel = new QSqlTableModel; relModel->setTable(rel.tableName()); relModel->select(); pRes->setModel(relModel); pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn())); return pRes; } if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Date){ QDateEdit* pRes = new QDateEdit(parent); pRes->setCalendarPopup(true); pRes->setDisplayFormat("dd.MM.yyyy"); return pRes; } if (model->data(model->index(0,j), Qt::EditRole).type() == QVariant::Bool){ QComboBox * pRes = new QComboBox(parent); pRes->addItem(tr("Нет")); pRes->addItem(tr("Да")); return pRes; } return QItemDelegate::createEditor(parent,option,index); } QComboBox * pRes = new QComboBox(parent); switch (index.column()) { case 0: { QStringList field; for(int i=0;i<fieldName.count();i++){ QString s = model->headerData( fieldName.at(i) , Qt::Horizontal).toString(); s.replace("\n"," "); field<<s; } pRes->addItems(field); break; } case 1: { pRes->addItem(tr(" ")); pRes->addItem(tr("не")); break; } case 2: { pRes->addItem(tr("равно")); pRes->addItem(tr("похоже на")); pRes->addItem(tr("больше")); pRes->addItem(tr("меньше")); break; } } // это строка нужна для того чтобы по enter и esc завершалось редактирование итд pRes->installEventFilter(const_cast<ComboBoxFileldDelegate*>(this)); return pRes; };
// Предоставление редактора QWidget* ComboBoxMailDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { if (index.column() == 1) { // QMessageBox::critical(0,"",index.model()->data(index.sibling(index.row(),0)).toString()); QString pole = index.model()->data(index.sibling(index.row(), 0)).toString(); int j; for (int i = 0; i < fieldName.count(); i++) { QString s = model->headerData(fieldName.at(i) , Qt::Horizontal).toString(); s.replace("\n", " "); if (s == pole) { j = fieldName.at(i); break; } } //QMessageBox::critical(0,"",QString("%1").arg(j)); QSqlRelation rel = model->relation(j); if (rel.indexColumn() != QString("")) { //QMessageBox::critical(0,"",rel.indexColumn()+" "+rel.displayColumn()+" "+rel.tableName()); QComboBox* pRes = new QComboBox(parent); QSqlTableModel* relModel = new QSqlTableModel; relModel->setTable(rel.tableName()); /* Удаление выбранных значений в кому */ if (pole == tr("Кому")) { QString relFilter = QString("user_id != '00000000-0000-0000-0000-000000000000'"); for (int i = 0; i < index.model()->rowCount(); i++) { QString pole = index.model()->data(index.sibling(i, 0)).toString(); if (pole == tr("Кому") && index.row() != i) { QString val = index.model()->data(index.sibling(i, 1)).toString(); if ( val != QString("")) relFilter = QString("%1 and not user_id = '%2'").arg(relFilter).arg(val); } //QMessageBox::critical(0,"",index.model()->data(index.sibling(i,1)).toString()); } //QMessageBox::critical(0,"","-"+relFilter+"-"); relModel->setFilter(relFilter); } relModel->select(); pRes->setModel(relModel); pRes->setModelColumn(relModel->fieldIndex(rel.displayColumn())); return pRes; } if (model->data(model->index(0, j)).type() == QVariant::Date) { QDateEdit* pRes = new QDateEdit(parent); pRes->setCalendarPopup(true); pRes->setDisplayFormat("dd.MM.yyyy"); return pRes; } if (model->data(model->index(0, j)).type() == QVariant::Bool) { QComboBox* pRes = new QComboBox(parent); pRes->addItem(tr("Нет")); pRes->addItem(tr("Да")); return pRes; } return QItemDelegate::createEditor(parent, option, index); } if (index.column() == 0) { QComboBox* pRes = new QComboBox(parent); bool typeflag = true; bool priorflag = true; bool recipientflag = true; bool beginflag = true; bool endflag = true; for (int i = 0; i < index.model()->rowCount(); i++) { QString pole = index.model()->data(index.sibling(i, 0)).toString(); if (pole == tr("Тип") && index.row() != i) typeflag = false; if (pole == tr("Приоритет") && index.row() != i) priorflag = false; if (pole == tr("Начало") && index.row() != i) beginflag = false; if (pole == tr("Конец") && index.row() != i) endflag = false; } //if (recipientflag) pRes->addItem(tr("Кому")); if (typeflag) pRes->addItem(tr("Тип")); if (priorflag) pRes->addItem(tr("Приоритет")); if (beginflag) pRes->addItem(tr("Начало")); if (endflag) pRes->addItem(tr("Конец")); //pRes->addItem(tr("Копия")); // это строка нужна для того чтобы по enter и esc завершалось редактирование итд pRes->installEventFilter(const_cast<ComboBoxMailDelegate*>(this)); return pRes; } return QItemDelegate::createEditor(parent, option, index); };