void DateTimeCalendarDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    QDateTime value = index.model()->data(index, Qt::EditRole).toDateTime();

    QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
    e->setDateTime( value );
}
Example #2
0
QWidget * ExtArgTimestamp::createEditor(QWidget * parent)
{
    QDateTimeEdit * tsBox;
    QString text = defaultValue();

    if ( _argument->pref_valptr && *_argument->pref_valptr)
    {
        QString storeValue(*_argument->pref_valptr);

        if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
            text = storeValue.trimmed();
    }

    ts = QDateTime::fromTime_t(text.toInt());
    tsBox = new QDateTimeEdit(ts, parent);
    tsBox->setDisplayFormat(QLocale::system().dateTimeFormat());
    tsBox->setCalendarPopup(true);

    if ( _argument->tooltip != NULL )
        tsBox->setToolTip(QString().fromUtf8(_argument->tooltip));

    connect(tsBox, SIGNAL(dateTimeChanged(QDateTime)), SLOT(onDateTimeChanged(QDateTime)));

    return tsBox;
}
void QFRDRTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {

     QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
     if (dateEditor) {
         dateEditor->setDateTime(index.model()->data(index, Qt::EditRole).toDateTime());
     } else {
         QFDoubleEdit *dEditor = qobject_cast<QFDoubleEdit *>(editor);
         if (dEditor) {
             dEditor->setValue(index.model()->data(index, Qt::EditRole).toDouble());
         } else {
             QSpinBox *sEditor = qobject_cast<QSpinBox *>(editor);
             if (sEditor) {
                 sEditor->setValue(index.model()->data(index, Qt::EditRole).toLongLong());
             } else {
                 QCheckBox *check = qobject_cast<QCheckBox *>(editor);
                 if (check) {
                     check->setChecked(index.model()->data(index, Qt::EditRole).toBool());
                 } else {
                     QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
                     if (edit) {
                         edit->setText(index.model()->data(index, Qt::EditRole).toString());
                     }
                 }
             }

         }
     }
}
void QFRDRTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
    QFDoubleEdit *dEditor = qobject_cast<QFDoubleEdit *>(editor);
    if (dEditor) {
        QVariant v( dEditor->value());
        v.convert(QVariant::Double);
        //qDebug()<<v;
        model->setData(index, v);
    } else {
         QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
         if (dateEditor) {
             model->setData(index, dateEditor->dateTime());
         } else {
            QSpinBox *sEditor = qobject_cast<QSpinBox *>(editor);
             if (sEditor) {
                 model->setData(index, sEditor->value());
             } else {
                 QCheckBox *check = qobject_cast<QCheckBox *>(editor);
                 if (check) {
                      model->setData(index, check->isChecked());
                 } else {
                     QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
                     if (edit) {
                         model->setData(index, edit->text());
                    }
                 }
             }
         }
    }
}
QWidget *DateTimeCalendarDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
    QDateTimeEdit *editor = new QDateTimeEdit(parent);
    editor->setCalendarPopup( true );
    editor->installEventFilter(const_cast<DateTimeCalendarDelegate*>(this));
    return editor;
}
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
                                          const QStyleOptionViewItem &,
                                          const QModelIndex &index) const
{
    if (index.column() == 1) {
        QDateTimeEdit *editor = new QDateTimeEdit(parent);
        editor->setDisplayFormat("dd/M/yyyy");
        editor->setCalendarPopup(true);
        return editor;
    }

    QLineEdit *editor = new QLineEdit(parent);

    // create a completer with the strings in the column as model
    QStringList allStrings;
    for (int i = 1; i<index.model()->rowCount(); i++) {
        QString strItem(index.model()->data(index.sibling(i, index.column()),
            Qt::EditRole).toString());

        if (!allStrings.contains(strItem))
            allStrings.append(strItem);
    }

    QCompleter *autoComplete = new QCompleter(allStrings);
    editor->setCompleter(autoComplete);
    connect(editor, &QLineEdit::editingFinished, this, &SpreadSheetDelegate::commitAndCloseEditor);
    return editor;
}
Example #7
0
void PosService::on_btSetTime_clicked()
{
    int button_width  = data->getVariables()->value(_S("standart_button_width")).toInt();
    int button_height = data->getVariables()->value(_S("standart_button_height")).toInt();
    int button_margin = data->getVariables()->value(_S("standart_margins")).toInt();

    QDialog dlg;

    QVBoxLayout* mainLayout = new QVBoxLayout();
    dlg.setLayout(mainLayout);

    dlg.setWindowTitle(_T("Установка времени"));

    QDateTimeEdit* edit = new QDateTimeEdit(QDateTime::currentDateTime());
    edit->setMaximumHeight(button_height);
    edit->setMinimumHeight(button_height);
    mainLayout->addWidget(edit);

    QHBoxLayout *btLayout = new QHBoxLayout();
    mainLayout->addLayout(btLayout);

    QPushButton* bt;

    bt = new QPushButton(_T("OK"), this);
    bt->setMaximumSize(button_width * 2 + button_margin, button_height);
    bt->setMinimumSize(button_width * 2 + button_margin, button_height);
    btLayout->addWidget(bt);
    connect(bt, SIGNAL(clicked()), &dlg, SLOT(accept()));

    bt = new QPushButton(_T("Отмена"), this);
    bt->setMaximumSize(button_width * 2 + button_margin, button_height);
    bt->setMinimumSize(button_width * 2 + button_margin, button_height);
    btLayout->addWidget(bt);
    connect(bt, SIGNAL(clicked()), &dlg, SLOT(reject()));

    int result = dlg.exec();
    if(result==QDialog::Accepted)
    {
        QString dt = edit->dateTime().toString(data->getSettings()->value("posservice/command_setdatetime_format").toString());
        QString command = data->getSettings()->value("posservice/command_setdatetime").toString().arg(dt);
        if (loglevel > 0)
            qDebug() << _T("%1 Устанавливаем новое время: %2 (было: %3)")
                        .arg(posForLog)
                        .arg(edit->dateTime().toString(Qt::ISODate))
                        .arg(QDateTime::currentDateTime().toString(Qt::ISODate));

        int result = QProcess::execute(command);
        if(result<0)
        {
            qDebug() << _T("%1 Ошибка установки нового времени. Код ошибки: %2")
                        .arg(posForLog)
                        .arg(result);

            QMessageBox message;
            message.setText(_T("Ошибка установки нового времени.\nКод ошибки: %1").arg(result));
            message.exec();
        }
    }
}
void ContactDialog::readAnniversary(int num, DateItem &ann)
{
    QDateTimeEdit* editor = findChild<QDateTimeEdit*>
        (QString("dteAnn%1Date").arg(num));
    if (!editor) return;
    anniversaryDetails[num-1].value = editor->dateTime();
    ann = anniversaryDetails[num-1];
}
Example #9
0
void MyDateItemDelegate::setEditorData(QWidget *editor,
                                       const QModelIndex &index) const
{
    const QDateTime& value = index.model()->data(index, Qt::DisplayRole).toDateTime();

    QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
    e->setDateTime(value);
}
void DocumentPropertiesWidget::addTimePropertyRow(
    const char *rowTitle, const QString &propertyName)
{
    QDateTimeEdit *propertyValue = new QDateTimeEdit;
    propertyValue->setReadOnly(true);
    addRowWithTitleAndValue(rowTitle, propertyValue);
    new MetaDataBinding(propertyValue, "dateTime", resultSet, propertyName, this);
}
Example #11
0
//! [0]
MainWindow::MainWindow()
{
    selectedDate = QDate::currentDate();
    fontSize = 10;

    QWidget *centralWidget = new QWidget;
//! [0]

//! [1]
    QLabel *dateLabel = new QLabel(tr("Date:"));
    QComboBox *monthCombo = new QComboBox;

    for (int month = 1; month <= 12; ++month)
        monthCombo->addItem(QDate::longMonthName(month));

    QDateTimeEdit *yearEdit = new QDateTimeEdit;
    yearEdit->setDisplayFormat("yyyy");
    yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
//! [1]

    monthCombo->setCurrentIndex(selectedDate.month() - 1);
    yearEdit->setDate(selectedDate);

//! [2]
    QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
    QSpinBox *fontSizeSpinBox = new QSpinBox;
    fontSizeSpinBox->setRange(1, 64);
    fontSizeSpinBox->setValue(10);

    editor = new QTextBrowser;
    insertCalendar();
//! [2]

//! [3]
    connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
    connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate)));
    connect(fontSizeSpinBox, SIGNAL(valueChanged(int)),
            this, SLOT(setFontSize(int)));
//! [3]

//! [4]
    QHBoxLayout *controlsLayout = new QHBoxLayout;
    controlsLayout->addWidget(dateLabel);
    controlsLayout->addWidget(monthCombo);
    controlsLayout->addWidget(yearEdit);
    controlsLayout->addSpacing(24);
    controlsLayout->addWidget(fontSizeLabel);
    controlsLayout->addWidget(fontSizeSpinBox);
    controlsLayout->addStretch(1);

    QVBoxLayout *centralLayout = new QVBoxLayout;
    centralLayout->addLayout(controlsLayout);
    centralLayout->addWidget(editor, 1);
    centralWidget->setLayout(centralLayout);

    setCentralWidget(centralWidget);
//! [4]
}
Example #12
0
		void setEditorData(QWidget *editor, const QModelIndex &index) const {
			QDateTimeEdit *edit = qobject_cast<QDateTimeEdit *>(editor);
			if (!edit) {
				QItemDelegate::setEditorData(editor, index);
				return;
			}
			QString time = index.model()->data(index,Qt::EditRole).toString();
			edit->setDateTime(QDateTime::fromString(time, "yyyy-MM-dd hh:mm"));
		}
Example #13
0
void MyDateItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                      const QModelIndex &index) const
{
    QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
    e->interpretText();
    const QDateTime& value = e->dateTime();

    model->setData(index, value.toString(DATETIMEFORMAT), Qt::EditRole);
}
Example #14
0
QWidget *MyDateItemDelegate::createEditor(QWidget *parent,
                                          const QStyleOptionViewItem &/* option */,
                                          const QModelIndex & index ) const
{
    QDateTimeEdit *editor = new QDateTimeEdit(parent);
    editor->setCalendarPopup(true);
    editor->setDisplayFormat(DATETIMEFORMAT);
    editor->setDateTime(QDateTime::fromString(index.data().toString(), DATETIMEFORMAT));
    return editor;
}
Example #15
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);
}
Example #16
0
		QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
			if (index.column() == 2) {
				QDateTimeEdit *editor = new QDateTimeEdit(parent);
				editor->setCalendarPopup(true);
				editor->setDisplayFormat("yyyy-MM-dd hh:mm");
				return editor;
			}
			else {
				return QItemDelegate::createEditor(parent, option, index);
			}
		}
Example #17
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);
}
Example #18
0
	void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
		if (!index.isValid())
			return;

		QDateTimeEdit *edit = qobject_cast<QDateTimeEdit *>(editor);
		if (!edit) {
			QItemDelegate::setModelData(editor, model, index);
			return;
		}

		model->setData(index, edit->dateTime().toString("yyyy-MM-dd hh:mm"), Qt::EditRole);
	}
Example #19
0
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);
        }
    }
}
Example #20
0
void DateTimeDelegate::setEditorData(QWidget *editor,
                                    const QModelIndex &index) const
{
    QDateEdit *dateEdit = qobject_cast<QDateEdit*>(editor);
    if (dateEdit) {
        dateEdit->setDate(index.data(Qt::EditRole).toDate());
    } else {
        QDateTimeEdit *dateTimeEdit = qobject_cast<QDateTimeEdit*>(editor);
        if (dateTimeEdit) {
            dateTimeEdit->setDateTime(index.data(Qt::EditRole).toDateTime());
        }
    }
}
void SpreadSheetDelegate::setModelData(QWidget *editor,
    QAbstractItemModel *model, const QModelIndex &index) const
{
    QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
    if (edit) {
        model->setData(index, edit->text());
        return;
    }

    QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
    if (dateEditor)
        model->setData(index, dateEditor->date().toString("dd/M/yyyy"));
}
Example #22
0
void SpreadSheetDelegate::setEditorData(QWidget *editor,
    const QModelIndex &index) const
{
    QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
    if (edit) {
        edit->setText(index.model()->data(index, Qt::EditRole).toString());
    } else {
        QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
        if (dateEditor) {
            dateEditor->setDate(QDate::fromString(
            index.model()->data(index, Qt::EditRole).toString(),
            "d/M/yyyy"));
        }
    }
}
Example #23
0
void CDlgBulkRegister::OnBulkMonth( int nMonth )
{
    QDateTimeEdit* pDt = NULL;
    QDateTime dtStart;

    for ( int nRow = 0; nRow < ui->tabRecord->rowCount( ); nRow++ ) {
        pDt = ( QDateTimeEdit* ) ui->tabRecord->cellWidget( nRow, 5 );
        dtStart = pDt->dateTime( );

        pDt = ( QDateTimeEdit* ) ui->tabRecord->cellWidget( nRow, 6 );
        dtStart = dtStart.addMonths( nMonth );
        //qDebug( ) << dtStart.toString( ) << endl;
        pDt->setDateTime( dtStart );
    }
}
Example #24
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{


    QString strNumber = "k";
    int nNumber = strNumber.toInt( );
    strNumber = "";
    nNumber = strNumber.toInt( );
    QString strDateTime = "2011-01-06 01:02:03";
    QString strFormat = "yyyy-M-d H:m:s";
    QDateTime dt = QDateTime::fromString( strDateTime, strFormat );
    strDateTime = "";
    strDateTime = dt.toString( "yyyy-MM-dd HH:mm:ss" );
    ui->setupUi(this);
    //QPalette pal;
    //QPixmap map( "D:/WinParkUI/debug/Image/NewIcon/CommonBG-normal.jpg");
    //QBrush br( map );
    //pal.setBrush( backgroundRole( ), br );
    //setPalette( pal );
    //setAutoFillBackground( true );

    //mysql.DbConnect( "192.168.1.51", "test", "test", "parkadmin", 3306 );

    //QSplitter *splitter = new QSplitter(this);
    //splitter->setGeometry( this->geometry( ) );
    //splitter->addWidget( ui->pushButton );
    //splitter->addWidget( ui->tableWidget );
    //splitter->addWidget( ui->pushButton_3 );

    QWidgetAction* act = new QWidgetAction( ui->menuTest );
    QComboBox* cbx = new QComboBox( ui->menuTest );
    QStringList lst;
    lst << "1" << "2" << "3";
    cbx->addItems( lst );
    act->setDefaultWidget( cbx );
    //ui->toolBar->addAction( act );

    act->setText( "Hello" );
    ui->menuTest->addAction( act );

    act = new QWidgetAction( ui->menuTest );
    QDateTimeEdit* edit = new QDateTimeEdit( ui->menuTest );
    edit->setCalendarPopup( true );
    act->setDefaultWidget( edit );
    ui->menuTest->addAction( act );
}
QWidget *reDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const
{
	switch (type) {
	case QVariant::Bool: {
		QBooleanComboBox *cb = new QBooleanComboBox(parent);
		return cb; }
	case QVariant::UInt: {
		QSpinBox *sb = new QSpinBox(parent);
		sb->setFrame(false);
		sb->setMaximum(INT_MAX);
		return sb; }
	case QVariant::Int: {
		QSpinBox *sb = new QSpinBox(parent);
		sb->setFrame(false);
		sb->setMinimum(INT_MIN);
		sb->setMaximum(INT_MAX);
		return sb; }
	case QVariant::Date: {
		QDateTimeEdit *ed = new QDateEdit(parent);
		ed->setFrame(false);
		return ed; }
	case QVariant::Time: {
		QDateTimeEdit *ed = new QTimeEdit(parent);
		ed->setFrame(false);
		return ed; }
	case QVariant::DateTime: {
		QDateTimeEdit *ed = new QDateTimeEdit(parent);
		ed->setFrame(false);
		return ed; }
	case QVariant::Pixmap:
		return new QLabel(parent);
	case QVariant::Double: {
		QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
		sb->setFrame(false);
		sb->setMinimum(-DBL_MAX);
		sb->setMaximum(DBL_MAX);
		return sb; }
	case QVariant::String:
	default: {
		// the default editor is a lineedit
		QLineEdit *le = new QLineEdit(parent);
		//le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le));
		//if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le))
			//le->setWidgetOwnsGeometry(true);
		return le; }
	}
	return 0;
}
void ContactDialog::addAnniversary(const DateItem &ann)
{
    anniversaryDetails.push_back(ann);
    // Value
    QDateTimeEdit* dte = new QDateTimeEdit(this);
    dte->setObjectName(QString("dteAnn%1Date").arg(anniversaryCount+1));
    dte->setDateTime(ann.value);
    DateDetailsDialog::setDateFormat(dte, ann.hasTime);
    dte->setCalendarPopup(true);
    layAnniversaries->addWidget(dte, anniversaryCount, 0);
    // Details button
    QPushButton* btnDet = new QPushButton(this);
    btnDet->setObjectName(QString("btnAnn%1Details").arg(anniversaryCount+1));
    btnDet->setText(ui->btnBDayDetails->text());
    connect(btnDet, SIGNAL(clicked()), this, SLOT(slotAnnDetails()));
    layAnniversaries->addWidget(btnDet, anniversaryCount, 1);
    // Delete button
    QToolButton* btnD = addDelButton(anniversaryCount, "Ann", SLOT(slotDelAnniversary()));
    layAnniversaries->addWidget(btnD, anniversaryCount, 2);
    anniversaryCount++;
}
Example #27
0
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;
}
Example #28
0
QWidget*
Dynamic::WeeklyTopBias::widget( QWidget* parent )
{
    QWidget *widget = new QWidget( parent );
    QVBoxLayout *layout = new QVBoxLayout( widget );

    QLabel *label = new QLabel( i18nc( "in WeeklyTopBias. Label for the date widget", "from:" ) );
    QDateTimeEdit *fromEdit = new QDateTimeEdit( QDate::currentDate().addDays( -7 ) );
    fromEdit->setMinimumDate( QDateTime::fromTime_t( 1111320001 ).date() ); // That's the first week in last fm
    fromEdit->setMaximumDate( QDate::currentDate() );
    fromEdit->setCalendarPopup( true );
    if( m_range.from.isValid() )
        fromEdit->setDateTime( m_range.from );

    connect( fromEdit, SIGNAL( dateTimeChanged( const QDateTime& ) ),
             this, SLOT( fromDateChanged( const QDateTime& ) ) );
    label->setBuddy( fromEdit );
    layout->addWidget( label );
    layout->addWidget( fromEdit );

    label = new QLabel( i18nc( "in WeeklyTopBias. Label for the date widget", "to:" ) );
    QDateTimeEdit *toEdit = new QDateTimeEdit( QDate::currentDate().addDays( -7 ) );
    toEdit->setMinimumDate( QDateTime::fromTime_t( 1111320001 ).date() ); // That's the first week in last fm
    toEdit->setMaximumDate( QDate::currentDate() );
    toEdit->setCalendarPopup( true );
    if( m_range.to.isValid() )
        toEdit->setDateTime( m_range.to );

    connect( toEdit, SIGNAL( dateTimeChanged( const QDateTime& ) ),
             this, SLOT( toDateChanged( const QDateTime& ) ) );
    label->setBuddy( toEdit );
    layout->addWidget( label );
    layout->addWidget( toEdit );

    return widget;
}
//Check to make sure display time comes before end display time
void NLSimpleGuiWindow::checkDisplayTimeLimitsConsistency()
{
  QDateTimeEdit *endEntry = ui->endDisplayTime;
  QDateTimeEdit *startEntry = ui->startDisplayTime;

  if( startEntry->dateTime() <= endEntry->dateTime() )
    return;
  if( posixTimeToQTime(kGenericT0) == endEntry->dateTime() )
    return;
  if( posixTimeToQTime(kGenericT0) == startEntry->dateTime() )
    return;

  QObject *caller = QObject::sender();
  if( caller == dynamic_cast<QObject *>(endEntry) )
  {
    endEntry->setDateTime( startEntry->dateTime() );
  }else if( caller == dynamic_cast<QObject *>(startEntry) )
  {
    startEntry->setDateTime( endEntry->dateTime() );
  }else
  {
    cout << "void NLSimpleGuiWindow::checkDisplayTimeLimitsConsistency()"
         << " error in caller logic" << endl;
    endEntry->setDateTime( startEntry->dateTime() );
  }//
}//void NLSimpleGuiWindow::checkDisplayTimeLimitsConsistency()
Example #30
0
QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const
{
    switch (type) {
#ifndef QT_NO_COMBOBOX
    case QVariant::Bool: {
        QBooleanComboBox *cb = new QBooleanComboBox(parent);
        cb->setFrame(false);
        return cb;
    }
#endif
#ifndef QT_NO_SPINBOX
    case QVariant::UInt: {
        QSpinBox *sb = new QSpinBox(parent);
        sb->setFrame(false);
        sb->setMaximum(INT_MAX);
        return sb;
    }
    case QVariant::Int: {
        QSpinBox *sb = new QSpinBox(parent);
        sb->setFrame(false);
        sb->setMinimum(INT_MIN);
        sb->setMaximum(INT_MAX);
        return sb;
    }
#endif
#ifndef QT_NO_DATETIMEEDIT
    case QVariant::Date: {
        QDateTimeEdit *ed = new QDateEdit(parent);
        ed->setFrame(false);
        return ed;
    }
    case QVariant::Time: {
        QDateTimeEdit *ed = new QTimeEdit(parent);
        ed->setFrame(false);
        return ed;
    }
    case QVariant::DateTime: {
        QDateTimeEdit *ed = new QDateTimeEdit(parent);
        ed->setFrame(false);
        return ed;
    }
#endif
    case QVariant::Pixmap:
        return new QLabel(parent);
#ifndef QT_NO_SPINBOX
    case QVariant::Double: {
        QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
        sb->setFrame(false);
        sb->setMinimum(-DBL_MAX);
        sb->setMaximum(DBL_MAX);
        return sb;
    }
#endif
#ifndef QT_NO_LINEEDIT
    case QVariant::String:
    default: {
        // the default editor is a lineedit
        QExpandingLineEdit *le = new QExpandingLineEdit(parent);
        le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le));
        if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le))
            le->setWidgetOwnsGeometry(true);
        return le;
    }
#else
    default:
        break;
#endif
    }
    return 0;
}