//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()
Exemplo n.º 2
0
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 );
}
Exemplo n.º 3
0
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());
                     }
                 }
             }

         }
     }
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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"));
		}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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());
        }
    }
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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 );
    }
}
Exemplo n.º 10
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++;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
void UIPropertySetters::DefaultSetter(QWidget* editor, SettingsPropertyMapper::WidgetType editorType, SettingsPropertyMapper::PropertyType propertyType, QVariant propertyValue)
{
	switch (editorType)
	{
		case SettingsPropertyMapper::CHECKBOX:
		{
			QCheckBox* pCheckBox = qobject_cast<QCheckBox*>(editor);
			if (pCheckBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pCheckBox->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::RADIOBUTTON:
		{
			QRadioButton* pRadioButton = qobject_cast<QRadioButton*>(editor);
			if (pRadioButton == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pRadioButton->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::CHECKABLE_GROUPBOX:
		{
			QGroupBox* pGroupBox = qobject_cast<QGroupBox*>(editor);
			if (pGroupBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (!pGroupBox->isCheckable())
			{
				qCritical() << "Given QGroupBox is not checkable";
			}
			if (propertyType != SettingsPropertyMapper::BOOL)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pGroupBox->setChecked(propertyValue.toBool());
			break;
		}
		case SettingsPropertyMapper::LINE_EDIT:
		{
			QLineEdit* pLineEdit = qobject_cast<QLineEdit*>(editor);
			if (pLineEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType == SettingsPropertyMapper::STRING || propertyType == SettingsPropertyMapper::INT)
			{
				pLineEdit->setText(propertyValue.toString());
			}
			else
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
			}
			break;
		}
		case SettingsPropertyMapper::TEXT_EDIT:
		{
			QTextEdit* pTextEdit = qobject_cast<QTextEdit*>(editor);
			if (pTextEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::STRING)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pTextEdit->setText(propertyValue.toString());
			break;
		}
		case SettingsPropertyMapper::COMBOBOX:
		{
			QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
			if (pComboBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::INT)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pComboBox->setCurrentIndex(propertyValue.toInt());
			break;
		}
		case SettingsPropertyMapper::SPINBOX:
		{
			QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(editor);
			if (pSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::INT)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pSpinBox->setValue(propertyValue.toInt());
			break;
		}
		case SettingsPropertyMapper::DOUBLE_SPINBOX:
		{
			QDoubleSpinBox* pDoubleSpinBox = qobject_cast<QDoubleSpinBox*>(editor);
			if (pDoubleSpinBox == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::DOUBLE)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pDoubleSpinBox->setValue(propertyValue.toDouble());
			break;
		}
		case SettingsPropertyMapper::TIME_EDIT:
		{
			QTimeEdit* pTimeEdit = qobject_cast<QTimeEdit*>(editor);
			if (pTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::TIME)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pTimeEdit->setTime(propertyValue.toTime());
			break;
		}
		case SettingsPropertyMapper::DATETIME_EDIT:
		{
			QDateTimeEdit* pDateTimeEdit = qobject_cast<QDateTimeEdit*>(editor);
			if (pDateTimeEdit == NULL)
			{
				qCritical() << "Invalid editor given";
				return;
			}
			if (propertyType != SettingsPropertyMapper::DATETIME)
			{
				qCritical() << "Unable to set value with default setter for property using value" << propertyValue;
				return;
			}
			pDateTimeEdit->setDateTime(propertyValue.toDateTime());
			break;
		}
		default: break;
	}
}
Exemplo n.º 13
0
QWidget*  MultiDelegate::createEditor( QWidget* parent,
                                     const QStyleOptionViewItem& option,
                                     const QModelIndex& index)  const
{
    const QAbstractItemModel*  model = index.model();
    QVariant  value = model->data( index, Qt::EditRole);
    switch (value.type()) {
    case QMetaType::QTime:
    {
        QTimeEdit*  editor = new QTimeEdit( parent);
        editor->setMaximumWidth( editor->sizeHint().width());

        //// Get value snapshot into editor
        editor->setTime( value.toTime());
        return editor;
    }
    case QMetaType::QDate:
    {
        QDateEdit*  editor = new QDateEdit( parent);
        setupCalenderWidget( editor);
        editor->setMaximumWidth( editor->sizeHint().width());

        //// Get value snapshot into editor
        editor->setDate( value.toDate());
        return editor;
    }
    case QMetaType::QDateTime:
    {
        QDateTimeEdit*  editor = new QDateTimeEdit( parent);
        setupCalenderWidget( editor);
        editor->setMaximumWidth( editor->sizeHint().width());

        editor->setDateTime( value.toDateTime());
        return editor;
    }
    case QMetaType::QImage:
        // Fall throu
    case QMetaType::QPixmap:
        // Fall throu
    case QMetaType::QIcon:
    {
        PixmapViewer*  editor = new PixmapViewer( parent);
        connect( editor, SIGNAL(finished(int)), this, SLOT(closeEmittingEditor()));
        return editor;
    }
    case QMetaType::QStringList:
    {
        QVariant  varList = index.model()->data( index, ItemDataRole::EnumList);
        if (varList.isNull())  break;  // Not a enum-list, fall to std

        QListWidget*  editor = new QListWidget( parent);
        foreach (const QString& bitItemText, varList.toStringList()) {
            QListWidgetItem* bitItem = new QListWidgetItem( bitItemText, editor);
            bitItem->setFlags(bitItem->flags() | Qt::ItemIsUserCheckable);
            bitItem->setCheckState(Qt::Unchecked);
        }
        int width  = editor->sizeHintForColumn(0) + 25;
        int height = editor->sizeHintForRow(0) * editor->count() + 10;
        editor->setMinimumWidth( width);
        editor->setMaximumWidth( width);
        editor->setMinimumHeight( height);
        editor->setMaximumHeight( height);

        //// Get value snapshot into editor
        QStringList  valList = value.toStringList();
        int  itemCount = editor->count();
        for (int i = 0; i < itemCount; ++i) {
            QListWidgetItem*  bitItem = editor->item(i);
            bool  isActive = valList.contains( bitItem->text());
            bitItem->setCheckState( isActive ? Qt::Checked : Qt::Unchecked);
        }
        return editor;
    }
    case QMetaType::QString:
    {
        QVariant  varList = index.model()->data( index, ItemDataRole::EnumList);
        if (varList.isNull())  break;  // Not a enum-list, fall to std

        QComboBox*  editor = new QComboBox( parent);
        editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
        editor->addItems( varList.toStringList());
        editor->setMaximumWidth( editor->minimumSizeHint().width());

        //// Get value snapshot into editor
        editor->setCurrentIndex( editor->findText( value.toString()));
        return editor;
    }
    default:;
    }

    if (index.column() == 0) {
        emit itemEditTrigged( index);
        return 0;  // No inline editor
    }

    QWidget*  editor = QItemDelegate::createEditor( parent, option, index);

    //// Get value snapshot into editor
    QItemDelegate::setEditorData( editor, index);
    return editor;
}
Exemplo n.º 14
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]);
}
Exemplo n.º 15
0
void protoObject::propertyUpdated(QString propertyName){
    QObject *receiver = mapper->mapping(propertyName);
    QWidget *widget;

    if (receiver) return; //if not binding, just leave

    widget = qobject_cast<QLabel*>(receiver);
    if (widget) {
        QLabel* edit = qobject_cast<QLabel*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setText(edit->text().arg(value));
        edit->blockSignals(false);
    };

    widget = qobject_cast<QLineEdit*>(receiver);
    if (widget) {
        QLineEdit* edit = qobject_cast<QLineEdit*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setText(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QComboBox*>(receiver);
    if (widget) {
        QComboBox* edit = qobject_cast<QComboBox*>(receiver);
        edit->blockSignals(true);
        edit->setCurrentIndex(edit->findData(this->property(propertyName.toLatin1()), Qt::UserRole));
        edit->blockSignals(false);
    };

    widget = qobject_cast<QRadioButton*>(receiver);
    if (widget) {
        QRadioButton* edit = qobject_cast<QRadioButton*>(receiver);
        bool value = this->property(propertyName.toLatin1()).toBool();
        edit->blockSignals(true);
        edit->setChecked(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QCheckBox*>(receiver);
    if (widget) {
        QCheckBox* edit = qobject_cast<QCheckBox*>(receiver);
        bool value = this->property(propertyName.toLatin1()).toBool();
        edit->blockSignals(true);
        edit->setChecked(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QPlainTextEdit*>(receiver);
    if (widget) {
        QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(receiver);
        QString value = this->property(propertyName.toLatin1()).toString();
        edit->blockSignals(true);
        edit->setPlainText(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QSpinBox*>(receiver);
    if (widget) {
        QSpinBox* edit = qobject_cast<QSpinBox*>(receiver);
        int value = this->property(propertyName.toLatin1()).toInt();
        edit->blockSignals(true);
        edit->setValue(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QDoubleSpinBox*>(receiver);
    if (widget) {
        QDoubleSpinBox* edit = qobject_cast<QDoubleSpinBox*>(receiver);
        double value = this->property(propertyName.toLatin1()).toDouble();
        edit->blockSignals(true);
        edit->setValue(value);
        edit->blockSignals(false);
    };

    widget = qobject_cast<QDateTimeEdit*>(receiver);
    if (widget) {
        QDateTimeEdit* edit = qobject_cast<QDateTimeEdit*>(receiver);
        QDateTime value = this->property(propertyName.toLatin1()).toDateTime();
        edit->blockSignals(true);
        edit->setDateTime(value);
        edit->blockSignals(false);
    };
}