Beispiel #1
0
QDate QtopiaInputDialog::getDate(QWidget *parent, const QString &title, const QString &label, const QDate &date,
                                 const QDate &minDate, const QDate &maxDate, bool *ok)
{
#ifdef CALENDAR_FOR_DATE
    QCalendarWidget *cal = new QCalendarWidget();
    cal->setSelectedDate(date);
    cal->setMinimumDate(minDate);
    cal->setMaximumDate(maxDate);
    cal->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
    QTextCharFormat headerFormat = cal->headerTextFormat();
    headerFormat.setBackground(QApplication::palette().window());
    headerFormat.setForeground(QApplication::palette().windowText());
    cal->setHeaderTextFormat(headerFormat);
    QWidget *navBar = cal->findChild<QWidget*>("qt_calendar_navigationbar");
    if (navBar)
        navBar->setBackgroundRole(QPalette::Window);

    QtopiaInputDialog dlg(parent, title, label, cal);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return cal->selectedDate();
#else
    QDateEdit *de = new QDateEdit(date);
    de->setMinimumDate(minDate);
    de->setMaximumDate(maxDate);

    QtopiaInputDialog dlg(parent, title, label, de);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return de->date();
#endif
}
//------------------------------------------------------------------------------
void ConditionValueDelegate::setModelData(QWidget* editor,
	QAbstractItemModel* model, const QModelIndex& index) const
{
	switch (field(index))
	{
	case AssignmentRule::Date:
	{
		QDateEdit* dateEditor = static_cast<QDateEdit*>(editor);
		QDate date = dateEditor->date();
		model->setData(index, date.toString(Qt::ISODate), Qt::EditRole);
	}
		break;

	case AssignmentRule::Amount:
	{
		MoneyEdit* moneyEditor = static_cast<MoneyEdit*>(editor);
		Money amount = moneyEditor->value();
		QString newVal = QString("%1,%2")
			.arg(amount.amount()).arg(amount.currency().code());
		model->setData(index, newVal, Qt::EditRole);
	}
		break;

	default:
	{
		LineEdit* stringEditor = static_cast<LineEdit*>(editor);
		model->setData(index, stringEditor->text(), Qt::EditRole);
	}

	}
}
void PupilSingularActivityDelegate::setModelData ( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
    switch ( index.column() ) {
    case 2: {
        QDateEdit *cal = qobject_cast<QDateEdit *> ( editor );
        if ( !cal ) {
            QItemDelegate::setModelData ( editor, model, index );
            return;
        }
        model -> setData ( index, cal->date().toString("yyyy-MM-dd") );
    }
    break;
    case 3: {
        QComboBox *combo = qobject_cast<QComboBox *> ( editor );
        if ( !combo ) {
            QItemDelegate::setModelData ( editor, model, index );
            return;
        }
        model -> setData ( index, combo->currentIndex() );
    }
    break;
    default: {
        QItemDelegate::setModelData ( editor, model, index );
        return;

    }
    break;
    }
}
Beispiel #4
0
 void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                      const QModelIndex &index) const
 {
     QDateEdit * dateEdit = static_cast<QDateEdit*>(editor);
     QString value = dateEdit->date().toString("yyyy-MM-dd");

     model->setData(index, value, Qt::EditRole);
 }
uint64_t ExprParamElement::getIntValueFromField(QString fieldName, bool isToField,bool *ok)
{
    uint64_t val = 0;
	 if(ok!=NULL)
		 *ok=true ;
    QString suffix = (isToField) ? "2": "1" ;

    // NOTE qFindChild necessary for MSVC 6 compatibility!!
    switch (searchType)
    {
        case DateSearch:
        {
            QDateEdit * dateEdit =  qFindChild<QDateEdit *> (internalframe, (fieldName + suffix));
            QDateTime * time = new QDateTime(dateEdit->date());
            val = (uint64_t)time->toTime_t();
            break;
        }   
        case SizeSearch:
        {
            QLineEdit * lineEditSize =  qFindChild<QLineEdit*>(internalframe, (fieldName + suffix));
            bool ok2 = false;
            val = (lineEditSize->displayText()).toULongLong(&ok2);
            if (ok2) 
				{
                QComboBox * cb = qFindChild<QComboBox*> (internalframe, (QString("unitsCb") + suffix));
                QVariant data = cb->itemData(cb->currentIndex());
                val *= data.toULongLong();
            } 
				else 
					if(ok!=NULL) 
						*ok=false ;
           
            break;
        }
        case PopSearch: // not implemented
/*        {
            QLineEdit * lineEditPop = qFindChild<QLineEdit*>(elem, (fieldName + suffix));
            bool ok = false;
            val = (lineEditPop->displayText()).toInt(&ok);
            if (!ok) {
                val = -1;
            }
            break;
        }*/
        case NameSearch:
        case PathSearch:
        case ExtSearch:
        case HashSearch:
        default:
            // shouldn't be here...val stays at -1
				if(ok!=NULL)
					*ok=false ;
    }
   
    return val;
}
Beispiel #6
0
void tst_QItemDelegate::dateTimeEditor()
{
    QFETCH(QTime, time);
    QFETCH(QDate, date);

    QTableWidgetItem *item1 = new QTableWidgetItem;
    item1->setData(Qt::DisplayRole, time);

    QTableWidgetItem *item2 = new QTableWidgetItem;
    item2->setData(Qt::DisplayRole, date);

    QTableWidgetItem *item3 = new QTableWidgetItem;
    item3->setData(Qt::DisplayRole, QDateTime(date, time));

    QTableWidget widget(1, 3);
    widget.setItem(0, 0, item1);
    widget.setItem(0, 1, item2);
    widget.setItem(0, 2, item3);
    widget.show();

    widget.editItem(item1);

    QTestEventLoop::instance().enterLoop(1);

    QTimeEdit *timeEditor = qFindChild<QTimeEdit *>(widget.viewport());
    QVERIFY(timeEditor);
    QCOMPARE(timeEditor->time(), time);

    widget.clearFocus();
    qApp->setActiveWindow(&widget);
    widget.setFocus();
    widget.editItem(item2);

    QTestEventLoop::instance().enterLoop(1);

    QDateEdit *dateEditor = qFindChild<QDateEdit *>(widget.viewport());
    QVERIFY(dateEditor);
    QCOMPARE(dateEditor->date(), date);

    widget.clearFocus();
    widget.setFocus();
    widget.editItem(item3);

    QTestEventLoop::instance().enterLoop(1);

    QList<QDateTimeEdit *> dateTimeEditors = widget.findChildren<QDateTimeEdit *>();
    QDateTimeEdit *dateTimeEditor = 0;
    foreach(dateTimeEditor, dateTimeEditors)
        if (dateTimeEditor->metaObject()->className() == QLatin1String("QDateTimeEdit"))
            break;
    QVERIFY(dateTimeEditor);
    QCOMPARE(dateTimeEditor->date(), date);
    QCOMPARE(dateTimeEditor->time(), time);
}
Beispiel #7
0
void MultiDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex &index) const
{
    QVariant value;

    QString  className = editor->metaObject()->className();
    if (className == "QTimeEdit") {
        QTimeEdit*  ed = qobject_cast<QTimeEdit*>(editor);
        Q_ASSERT( ed);
        value = QVariant( ed->time());
    }
    else if (className == "QDateEdit") {
        QDateEdit*  ed = qobject_cast<QDateEdit*>(editor);
        Q_ASSERT( ed);
        value = QVariant( ed->date());
    }
    else if (className == "QDateTimeEdit") {
        QDateTimeEdit*  ed = qobject_cast<QDateTimeEdit*>(editor);
        Q_ASSERT( ed);
        value = QVariant( ed->dateTime());
    }
    else if (className == "IconViewer") {
        return;
    }
    else if (className == "QComboBox") {
        QComboBox*  ed = qobject_cast<QComboBox*>(editor);
        Q_ASSERT( ed);
        value = QVariant( ed->currentText());
    }
    else if (className == "QListWidget") {
        QListWidget*  ed = qobject_cast<QListWidget*>(editor);
        Q_ASSERT( ed);
        QStringList  valList;
        int  itemCount = ed->count();
        for (int i = 0; i < itemCount; ++i) {
            QListWidgetItem*  bitItem = ed->item(i);
            bool  isChecked = (bitItem->checkState() == Qt::Checked);
            if (isChecked)
                valList += bitItem->text();
        }
        value = QVariant( valList);
    }
    else if (className == "QCheckBox") {
        QCheckBox*  ed = qobject_cast<QCheckBox*>(editor);
        Q_ASSERT( ed);
        value = QVariant( ed->isChecked());
    }
    else {
        QItemDelegate::setModelData( editor, model, index);
        return;
    }
    model->setData(index, value, Qt::EditRole);
}
void DateTimeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                   const QModelIndex &index) const
{
    QDateEdit *dateEdit = qobject_cast<QDateEdit*>(editor);
    if (dateEdit) {
        model->setData(index, dateEdit->date(), Qt::EditRole);
    } else {
        QDateTimeEdit *dateTimeEdit = qobject_cast<QDateTimeEdit*>(editor);
        if (dateTimeEdit) {
            model->setData(index, dateTimeEdit->dateTime(), Qt::EditRole);
        }
    }
}
// We don't set anything because the data is saved within the view not the model!
void RideDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{

    // stored as text field
    if (index.column() == dateColumn) {
        QDateEdit *dateEdit = qobject_cast<QDateEdit *>(editor);
        QString value = dateEdit->date().toString("dd MMM yyyy");
        // Place in the view
        model->setData(index, value, Qt::DisplayRole);
    } else if (index.column() == dateColumn+1) {
        QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor);
        QString value = timeEdit->time().toString("hh:mm:ss a");
        model->setData(index, value, Qt::DisplayRole);
    }
}
void AlbumDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
	if( index.column() == 1 )
	{
		QDateEdit *dateEdit = qobject_cast<QDateEdit*>(editor);

		QDate editedDate = dateEdit->date();

		model->setData( index, editedDate, Qt::EditRole );
	}
	else
	{
		QItemDelegate::setModelData(editor, model, index);
	}
}
	void BudgetEntityDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
		BudgetEntity entity = qvariant_cast<BudgetEntity>(index.data());
		
		QDateEdit *dateEdit = qobject_cast<QDateEdit *>( editor->layout()->itemAt(0)->widget() );
		QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit *>( editor->layout()->itemAt(1)->widget() );
		QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox *>( editor->layout()->itemAt(2)->widget() );
		
		entity.setDate(dateEdit->date());
		entity.setDescription(textEdit->toPlainText());
		entity.setAmount(spinBox->value());
		
		QVariant val;
		val.setValue<BudgetEntity>(entity);
		model->setData(index, val, Qt::EditRole);
	}
void DBFRedactorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
	QVariant value;
	switch (m_redactor->field(index.column()).type) {
		case DBFRedactor::TYPE_DATE: {
			QDateEdit *edit = qobject_cast<QDateEdit*> (editor);
			value = edit->date();
			break;
		}
		case DBFRedactor::TYPE_FLOAT: case DBFRedactor::TYPE_NUMERIC: {
			QDoubleSpinBox *edit = qobject_cast<QDoubleSpinBox*> (editor);
			value = edit->value();
			break;
		}
		default: {
			QLineEdit *edit = qobject_cast<QLineEdit*> (editor);
			value = edit->text();
		}
	}
	model->setData(index, value, Qt::EditRole);
}
void MySqlRelationDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    if (!index.isValid())
        return;

    QSqlRelationalTableModel *sqlModel = qobject_cast<QSqlRelationalTableModel *>(model);
    QSqlTableModel *childModel = sqlModel ? sqlModel->relationModel(index.column()) : 0;
    QComboBox *combo = qobject_cast<QComboBox *>(editor);
    if (!sqlModel || !childModel || !combo) {
        if (HandbookDialog::m_record.fieldName(index.column()).contains("IS_", Qt::CaseSensitive))
        {
            QCheckBox * checkBox = qobject_cast<QCheckBox *>(editor);
            sqlModel->setData(index, checkBox->isChecked(), Qt::DisplayRole);
            sqlModel->setData(index, checkBox->isChecked(), Qt::EditRole);
            return;
        }
        else if (HandbookDialog::m_record.fieldName(index.column()).contains("DATE_", Qt::CaseSensitive))
        {
            QDateEdit * dateEdit = qobject_cast<QDateEdit *>(editor);
            sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::DisplayRole);
            sqlModel->setData(index, dateEdit->date().toString("yyyy-MM-dd"), Qt::EditRole);
            return;
        }
        else
        {
            QItemDelegate::setModelData(editor, model, index);
            return;
        }
    }

    int currentItem = combo->currentIndex();
    int childColIndex = childModel->fieldIndex(sqlModel->relation(index.column()).displayColumn());
    int childEditIndex = childModel->fieldIndex(sqlModel->relation(index.column()).indexColumn());
    sqlModel->setData(index,
            childModel->data(childModel->index(currentItem, childColIndex), Qt::DisplayRole),
            Qt::DisplayRole);
    sqlModel->setData(index,
            childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole),
            Qt::EditRole);
}
Beispiel #14
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void UKvyt_Delegate::setModelData(QWidget *editor,
                                 QAbstractItemModel *model,
                                 const QModelIndex &index) const
{
    if ((index.column() == durationColumn_2)) {
        QDoubleSpinBox *double_spinbox = qobject_cast<QDoubleSpinBox *>(editor);
		double value= double_spinbox->value();
        model->setData(index, value);
    }
	else if ( (index.column() == durationColumn_3) || (index.column() == durationColumn_4) ){
        QDateEdit * dateEdit = qobject_cast<QDateEdit *>(editor);
        model->setData(index, dateEdit->date());
	}
	else if (index.column() == durationColumn_5)
	{
        QSpinBox *spinbox = qobject_cast<QSpinBox *>(editor);
		int value = spinbox->value();
        model->setData(index, value);
	}
	else {
        QSqlRelationalDelegate::setModelData(editor, model, index);
    }
}
void DateEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{
    QDateEdit *date = static_cast<QDateEdit*>(editor);
   QDate value = date->date();
    model->setData(index,value);
}
void CalendarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const {
    QDateEdit *de = static_cast<QDateEdit*>(editor);
    de->interpretText();
    QDate value = de->date();
    model->setData(index, value);
}
Beispiel #17
0
void tst_QItemDelegate::dateTimeEditor()
{
    QFETCH(QTime, time);
    QFETCH(QDate, date);

    QTableWidgetItem *item1 = new QTableWidgetItem;
    item1->setData(Qt::DisplayRole, time);

    QTableWidgetItem *item2 = new QTableWidgetItem;
    item2->setData(Qt::DisplayRole, date);

    QTableWidgetItem *item3 = new QTableWidgetItem;
    item3->setData(Qt::DisplayRole, QDateTime(date, time));

    QTableWidget widget(1, 3);
    widget.setItem(0, 0, item1);
    widget.setItem(0, 1, item2);
    widget.setItem(0, 2, item3);
    widget.show();

    widget.editItem(item1);

    QTestEventLoop::instance().enterLoop(1);

    QTimeEdit *timeEditor = qFindChild<QTimeEdit *>(widget.viewport());
    QVERIFY(timeEditor);
    QCOMPARE(timeEditor->time(), time);
    // The data must actually be different in order for the model
    // to be updated.
    timeEditor->setTime(time.addSecs(60));

    widget.clearFocus();
    qApp->setActiveWindow(&widget);
    widget.setFocus();
    widget.editItem(item2);

    QTestEventLoop::instance().enterLoop(1);

    QDateEdit *dateEditor = qFindChild<QDateEdit *>(widget.viewport());
    QVERIFY(dateEditor);
    QCOMPARE(dateEditor->date(), date);
    dateEditor->setDate(date.addDays(60));

    widget.clearFocus();
    widget.setFocus();
    widget.editItem(item3);

    QTestEventLoop::instance().enterLoop(1);

    QList<QDateTimeEdit *> dateTimeEditors = widget.findChildren<QDateTimeEdit *>();
    QDateTimeEdit *dateTimeEditor = 0;
    foreach(dateTimeEditor, dateTimeEditors)
        if (dateTimeEditor->metaObject()->className() == QLatin1String("QDateTimeEdit"))
            break;
    QVERIFY(dateTimeEditor);
    QCOMPARE(dateTimeEditor->date(), date);
    QCOMPARE(dateTimeEditor->time(), time);
    dateTimeEditor->setTime(time.addSecs(600));
    widget.clearFocus();

    QVERIFY(item1->data(Qt::EditRole).userType() == QMetaType::QTime);
    QVERIFY(item2->data(Qt::EditRole).userType() == QMetaType::QDate);
    QVERIFY(item3->data(Qt::EditRole).userType() == QMetaType::QDateTime);
}