Example #1
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;
}
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 #3
0
QWidget *DateDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &/*option*/,const QModelIndex &/*index*/) const
{
    QDateTimeEdit *editor = new QDateTimeEdit(parent);
    editor->setDisplayFormat("yyyy-MM-dd");
    editor->setCalendarPopup(true);
    editor->installEventFilter(const_cast<DateDelegate*>(this));
    return editor;
}
Example #4
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 #5
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 #6
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);
			}
		}
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 #8
0
QWidget * Q3EditorFactory::createEditor(QWidget * parent, const QVariant & v)
{
    QWidget * w = 0;
    switch(v.type()){
        case QVariant::Invalid:
            w = 0;
            break;
        case QVariant::Bool:
            w = new QComboBox(parent, "qt_editor_bool");
            ((QComboBox *) w)->insertItem(QLatin1String("False"));
            ((QComboBox *) w)->insertItem(QLatin1String("True"));
            break;
        case QVariant::UInt:
            w = new QSpinBox(0, 999999, 1, parent, "qt_editor_spinbox");
            break;
        case QVariant::Int:
            w = new QSpinBox(-999999, 999999, 1, parent, "qt_editor_int");
            break;
        case QVariant::String:
        case QVariant::Double:
            w = new QLineEdit(parent, "qt_editor_double");
            ((QLineEdit*)w)->setFrame(false);
            break;
        case QVariant::Date: {
            QDateTimeEdit *edit = new QDateTimeEdit(parent);
            edit->setDisplayFormat(QLatin1String("yyyy/MM/dd"));
            edit->setObjectName(QLatin1String("qt_editor_date"));
            w = edit; }
            break;
        case QVariant::Time: {
            QDateTimeEdit *edit = new QDateTimeEdit(parent);
            edit->setDisplayFormat(QLatin1String("hh:mm"));
            edit->setObjectName(QLatin1String("qt_editor_time"));
            w = edit; }
            break;
        case QVariant::DateTime:
            w = new QDateTimeEdit(parent);
            w->setObjectName(QLatin1String("qt_editor_datetime"));
            break;
#ifndef QT_NO_LABEL
        case QVariant::Pixmap:
            w = new QLabel(parent, QLatin1String("qt_editor_pixmap"));
            break;
#endif
        case QVariant::Palette:
        case QVariant::Color:
        case QVariant::Font:
        case QVariant::Brush:
        case QVariant::Bitmap:
        case QVariant::Cursor:
        case QVariant::Map:
        case QVariant::StringList:
        case QVariant::Rect:
        case QVariant::Size:
        case QVariant::IconSet:
        case QVariant::Point:
        case QVariant::PointArray:
        case QVariant::Region:
        case QVariant::SizePolicy:
        case QVariant::ByteArray:
        default:
            w = new QWidget(parent, "qt_editor_default");
            break;
    }
    return w;
}
Example #9
0
HistoryWidget::HistoryWidget(QWidget *parent)
    : QDialog(parent)
{
    setObjectName("HistoryWidget");
    setWindowTitle(tr("History Data View"));

    // layout - top
    QHBoxLayout *horiLayoutTop = new QHBoxLayout();

    QPushButton *buttonQuit = new QPushButton(this);
    buttonQuit->setObjectName("buttonQuit");
    horiLayoutTop->addSpacing(25);
    horiLayoutTop->addWidget(buttonQuit, 0, Qt::AlignLeft);
    horiLayoutTop->addStretch();

    // button-export
    QPushButton *buttonExport = new QPushButton(this);
    buttonExport->setObjectName("buttonExport");
    horiLayoutTop->addWidget(buttonExport);
    horiLayoutTop->addStretch();

    // button-open
    QPushButton *buttonOpen = new QPushButton(this);
    buttonOpen->setObjectName("buttonOpen");
    horiLayoutTop->addWidget(buttonOpen);
    horiLayoutTop->addStretch();

    QFormLayout *formLayoutTime = new QFormLayout();
    formLayoutTime->setFormAlignment(Qt::AlignVCenter);
    horiLayoutTop->addLayout(formLayoutTime);
    horiLayoutTop->addStretch();

    QDateTimeEdit *dateTimeEditStart = new QDateTimeEdit(this);
    dateTimeEditStart->setObjectName("dateTimeEditStart");
    dateTimeEditStart->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
    formLayoutTime->addRow(tr("Start Time:"), dateTimeEditStart);

    QDateTimeEdit *dateTimeEditEnd = new QDateTimeEdit(this);
    dateTimeEditEnd->setObjectName("dateTimeEditEnd");
    dateTimeEditEnd->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
    formLayoutTime->addRow(tr("End Time:"), dateTimeEditEnd);

    //LBP
    QFormLayout *formLayoutLBP = new QFormLayout();
    formLayoutLBP->setFormAlignment(Qt::AlignVCenter);
    formLayoutLBP->setLabelAlignment(Qt::AlignRight);
    horiLayoutTop->addLayout(formLayoutLBP);
    horiLayoutTop->addStretch();
    QCheckBox *checkBoxLBPMajor = new QCheckBox(tr("Major"), this);
    checkBoxLBPMajor->setProperty("curveColor", "#101010");
    QCheckBox *checkBoxLBPMinor = new QCheckBox(tr("Minor"), this);
    checkBoxLBPMinor->setProperty("curveColor", "#101010");
    formLayoutLBP->addRow(tr("LBP:"), checkBoxLBPMajor);
    formLayoutLBP->addRow("", checkBoxLBPMinor);

    //RBP
    QFormLayout *formLayoutRBP = new QFormLayout();
    formLayoutRBP->setFormAlignment(Qt::AlignVCenter);
    formLayoutRBP->setLabelAlignment(Qt::AlignRight);
    horiLayoutTop->addLayout(formLayoutRBP);
    horiLayoutTop->addStretch();
    QCheckBox *checkBoxRBPMajor = new QCheckBox(tr("Major"), this);
    checkBoxRBPMajor->setProperty("curveColor", "#101010");
    QCheckBox *checkBoxRBPMinor = new QCheckBox(tr("Minor"), this);
    checkBoxRBPMinor->setProperty("curveColor", "#101010");
    formLayoutRBP->addRow(tr("RBP:"), checkBoxRBPMajor);
    formLayoutRBP->addRow("", checkBoxRBPMinor);

    //LRP
    QFormLayout *formLayoutLRP = new QFormLayout();
    formLayoutLRP->setFormAlignment(Qt::AlignVCenter);
    formLayoutLRP->setLabelAlignment(Qt::AlignRight);
    horiLayoutTop->addLayout(formLayoutLRP);
    horiLayoutTop->addStretch();
    QCheckBox *checkBoxLRPTheory = new QCheckBox(tr("Theory"), this);
    checkBoxLRPTheory->setProperty("curveColor", "#101010");
    QCheckBox *checkBoxLRPReal = new QCheckBox(tr("Real"), this);
    checkBoxLRPReal->setProperty("curveColor", "#101010");
    formLayoutLRP->addRow(tr("LRP:"), checkBoxLRPTheory);
    formLayoutLRP->addRow("", checkBoxLRPReal);

    //RRP
    QFormLayout *formLayoutRRP = new QFormLayout();
    formLayoutRRP->setFormAlignment(Qt::AlignVCenter);
    formLayoutRRP->setLabelAlignment(Qt::AlignRight);
    horiLayoutTop->addLayout(formLayoutRRP);
    horiLayoutTop->addStretch();
    QCheckBox *checkBoxRRPTheory = new QCheckBox(tr("Theory"), this);
    checkBoxRRPTheory->setProperty("curveColor", "#101010");
    QCheckBox *checkBoxRRPReal = new QCheckBox(tr("Real"), this);
    checkBoxRRPReal->setProperty("curveColor", "#101010");
    formLayoutRRP->addRow(tr("RRP:"), checkBoxRRPTheory);
    formLayoutRRP->addRow("", checkBoxRRPReal);

    // button-update
    QPushButton *buttonUpdate = new QPushButton(this);
    buttonUpdate->setObjectName("buttonUpdate");
    horiLayoutTop->addWidget(buttonUpdate);
    horiLayoutTop->addStretch();
/*
    // button-undo
    QPushButton *buttonUndo = new QPushButton(this);
    buttonUndo->setObjectName("buttonUndo");
    horiLayoutTop->addWidget(buttonUndo);
    horiLayoutTop->addStretch();
*/
    // middle - curves
    CurveWidget* curveHistory = new CurveWidget(tr("History Data View"), this, true);
    curveHistory->setMaximumWidth(10000000);
    curveHistory->setScaleLabelFormat("yyyy/MM/dd\n  HH:mm:ss");
    curveHistory->clear();

    QVBoxLayout *vertLayoutMain = new QVBoxLayout(this);
    vertLayoutMain->addLayout(horiLayoutTop);
    vertLayoutMain->addWidget(curveHistory);

    connect(buttonQuit, &QPushButton::clicked, this, [=](){
        this->accept();
    });

    connect(buttonOpen, &QPushButton::clicked, this, [=](){
        QFileDialog fileDialog(this,
                               tr("Open history database files"),
                               QApplication::applicationDirPath().append("/../data"),
                               tr("Data Base File (*.db *.mdb)"));
        if (fileDialog.exec() == QDialog::Rejected) {
            return;
        }

        // clear curve
        curveHistory->clear();

        //
        QStringList filePaths = fileDialog.selectedFiles();
        if (filePaths.isEmpty()) {
            return;
        }

        QString filePath = filePaths.first();
        if (filePath.isEmpty()) {
            return;
        }

        // open database
        if (!DataBaseMgr::instance().open(filePath)) {
            Q_ASSERT(false);
            return;
        }

        //
        QDateTime startTime = QDateTime::fromMSecsSinceEpoch(DataBaseMgr::instance().startTime());
        QDateTime endTime = QDateTime::fromMSecsSinceEpoch(DataBaseMgr::instance().endTime());
        dateTimeEditStart->setDateTimeRange(startTime, endTime);
        dateTimeEditEnd->setDateTimeRange(startTime, endTime);
        dateTimeEditEnd->setDateTime(endTime);
        dateTimeEditStart->setDateTime(startTime);

        // curve title
        curveHistory->setTitle(tr("History Data View")
                               .append(" (")
                               .append(QFileInfo(filePath).fileName())
                               .append(")"));
    });
    connect(buttonExport, &QPushButton::clicked, this, [=](){
        QStringList filePaths = QFileDialog::getOpenFileNames(this,
                                                              tr("Convert data base files to txt format and save..."),
                                                              QApplication::applicationDirPath().append("/../data"),
                                                              tr("Data Base File (*.db *.mdb)"));
        if (filePaths.isEmpty()) {
            return;
        }

        //
        if (DataBaseMgr::instance().convertToText(filePaths)) {
            QMessageBox::information(this, tr("Convert Database file"), tr("Convert successfully!"));
        } else {
            QMessageBox::information(this, tr("Convert Database file"), tr("Convert failed!"));
        }
    });

    connect(dateTimeEditStart, &QDateTimeEdit::dateTimeChanged, this, [=](const QDateTime &dateTime){
        QDateTime endDateTime = dateTimeEditEnd->dateTime();
        if (dateTime > endDateTime) {
            dateTimeEditStart->setDateTime(endDateTime);
        }
    });

    connect(dateTimeEditEnd, &QDateTimeEdit::dateTimeChanged, this, [=](const QDateTime &dateTime){
        QDateTime startDateTime = dateTimeEditStart->dateTime();
        if (dateTime < startDateTime) {
            dateTimeEditEnd->setDateTime(startDateTime);
        }
    });

    connect(checkBoxLBPMajor, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[0] = checked;
    });
    connect(checkBoxLBPMinor, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[1] = checked;
    });
    connect(checkBoxRBPMajor, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[2] = checked;
    });
    connect(checkBoxRBPMinor, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[3] = checked;
    });
    connect(checkBoxLRPTheory, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[4] = checked;
    });
    connect(checkBoxLRPReal, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[5] = checked;
    });
    connect(checkBoxRRPTheory, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[6] = checked;
    });
    connect(checkBoxRRPReal, &QCheckBox::toggled, this, [=](bool checked){
        _v_curve_checked[7] = checked;
    });

    connect(buttonUpdate, &QPushButton::clicked, this, [=](){
        // clear curve
        curveHistory->clear();

        QVector<QPointF> points;
        quint64 startTime = dateTimeEditStart->dateTime().toMSecsSinceEpoch();
        quint64 endTime = dateTimeEditEnd->dateTime().toMSecsSinceEpoch();

        // LBP-Major
        if (checkBoxLBPMajor->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("lMBrakeP", points, startTime, endTime)) {
                curveHistory->addCurve(tr("LBP-Major"), QPen(randomColor(0)), points);
            }
        }

        //QApplication::processEvents();

        // LBP-Minor
        if (checkBoxLBPMinor->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("lABrakeP", points, startTime, endTime)) {
                curveHistory->addCurve(tr("LBP-Minor"), QPen(randomColor(1)), points);
            }
        }

        //QApplication::processEvents();

        // RBP-Major
        if (checkBoxRBPMajor->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("rMBrakeP", points, startTime, endTime)) {
                curveHistory->addCurve(tr("RBP-Major"), QPen(randomColor(2)), points);
            }
        }

        //QApplication::processEvents();

        // RBP-Minor
        if (checkBoxRBPMinor->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("rABrakeP", points, startTime, endTime)) {
                curveHistory->addCurve(tr("RBP-Minor"), QPen(randomColor(3)), points);
            }
        }

        //QApplication::processEvents();

        // LRP-Theory
        if (checkBoxLRPTheory->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("lTheorySpd", points, startTime, endTime)) {
                curveHistory->addCurve(tr("LRP-Theory"), QPen(randomColor(4)), points);
            }
        }

        //QApplication::processEvents();

        // LRP-Real
        if (checkBoxLRPReal->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("lWheelSpd", points, startTime, endTime)) {
                curveHistory->addCurve(tr("LRP-Real"), QPen(randomColor(5)), points);
            }
        }

        //QApplication::processEvents();

        // RRP-Theory
        if (checkBoxRRPTheory->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("rTheorySpd", points, startTime, endTime)) {
                curveHistory->addCurve(tr("RRP-Theory"), QPen(randomColor(6)), points);
            }
        }

        //QApplication::processEvents();

        // RRP-Real
        if (checkBoxRRPReal->isChecked()) {
            // read
            points.clear();
            if (DataBaseMgr::instance().read("rWheelSpd", points, startTime, endTime)) {
                curveHistory->addCurve(tr("RRP-Real"), QPen(randomColor(7)), points);
            }
        }
    });
/*
    connect(buttonUndo, &QPushButton::clicked, this, [=](){
        curveHistory->setNormalScale();
    });
*/
    // finaly initialize
    checkBoxLBPMajor->setChecked(_v_curve_checked[0]);
    checkBoxLBPMinor->setChecked(_v_curve_checked[1]);
    checkBoxRBPMajor->setChecked(_v_curve_checked[2]);
    checkBoxRBPMinor->setChecked(_v_curve_checked[3]);
    checkBoxLRPTheory->setChecked(_v_curve_checked[4]);
    checkBoxLRPReal->setChecked(_v_curve_checked[5]);
    checkBoxRRPTheory->setChecked(_v_curve_checked[6]);
    checkBoxRRPReal->setChecked(_v_curve_checked[7]);
}