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++; }
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; }
QWidget* WidgetStyle::createWidget(const QString& name) { if(name == "CheckBox") { QCheckBox* box = new QCheckBox("CheckBox"); box->setObjectName("CheckBox"); return setLayoutWidget({ box }, { 100, 30 }); } else if(name == "ComboBox") { QComboBox* box = new QComboBox; box->addItem("Item1"); box->addItem("Item3"); box->addItem("Item3"); box->setObjectName("ComboBox"); return setLayoutWidget({ box }, { 70, 30 }); } else if(name == "DateEdit") { QDateEdit* date = new QDateEdit; date->setObjectName("DateEdit"); return setLayoutWidget({ date }, { 110, 40 }); } else if(name == "DateTimeEdit") { QDateTimeEdit* date = new QDateTimeEdit; date->setObjectName("DateTimeEdit"); return setLayoutWidget({ date }, { 160, 30 }); } else if(name == "Dialog") { QDialog* dialog = new QDialog; dialog->setObjectName("Dialog"); return setLayoutWidget({ dialog }, { 160, 110 }); } else if(name == "DockWidget") //? { QDockWidget* widget = new QDockWidget; widget->setObjectName("DockWidget"); widget->resize(61, 22); return widget; } else if(name == "DoubleSpinBox") { QDoubleSpinBox* box = new QDoubleSpinBox; box->setObjectName("DoubleSpinBox"); return setLayoutWidget({ box }, { 90, 40 }); } else if(name == "Frame") //?? { QFrame* frame = new QFrame; frame->setObjectName("Frame"); frame->resize(150, 100); return frame; } else if(name == "GroupBox") { QGroupBox* box = new QGroupBox("GroupBox"); box->setObjectName("GroupBox"); return setLayoutWidget({ box }, { 160, 110 }); } else if(name == "Label") { QLabel* label = new QLabel("Label"); label->setObjectName("Label"); return setLayoutWidget({ label }, { 40, 20}); } else if(name == "LineEdit") { QLineEdit* line = new QLineEdit; line->setObjectName("LineEdit"); return setLayoutWidget({ line }, { 30, 30 }); } else if(name == "ListView") //?? { QListView* view = new QListView; view->setObjectName("ListView"); view->resize(71, 71); return view; } else if(name == "ListWidget") { QListWidget* list = new QListWidget; list->setObjectName("ListWidget"); for(int i = 0; i < 20; i++) list->addItem(QString("Item %1").arg(i)); return setLayoutWidget({ list }, { 80, 80 }); } else if(name == "MainWindow") { QMainWindow* window = new QMainWindow; window->setObjectName("MainWindow"); return setLayoutWidget({ window }, { 160, 110 }); } else if(name == "Menu") { QMenu* parentMenu = new QMenu; parentMenu->setObjectName("Menu"); parentMenu->addMenu("Menu1"); QMenu* menu1 = parentMenu->addMenu("Menu2"); menu1->addMenu("Menu1"); menu1->addMenu("Menu2"); parentMenu->addSeparator(); parentMenu->addMenu("Menu3"); return setLayoutWidget({ parentMenu }, { 160, 110 }); } else if(name == "MenuBar") { QMenuBar* bar = new QMenuBar; bar->setObjectName("QMenuBar"); QMenu* menu1 = bar->addMenu("MenuBar1"); menu1->addMenu("Menu1"); menu1->addSeparator(); menu1->addMenu("Menu2"); QMenu* menu2 = bar->addMenu("MenuBar2"); menu2->addMenu("Menu1"); menu2->addSeparator(); menu2->addMenu("Menu2"); QMenu* menu3 = bar->addMenu("MenuBar3"); menu3->addMenu("Menu1"); menu3->addSeparator(); menu3->addMenu("Menu2"); return setLayoutWidget({ bar }, { 280, 60 }); } else if(name == "ProgressBar") { QProgressBar* bar = new QProgressBar; bar->setObjectName("ProgressBar"); bar->setRange(0, 100); bar->setValue(0); QTimer* timer = new QTimer(bar); this->connect(timer, &QTimer::timeout, this, [bar]() { if(bar->value() == 100) bar->setValue(0); else bar->setValue(bar->value() + 1); }); timer->start(100); return setLayoutWidget({ bar }, { 110, 30 }); } else if(name == "PushButton") { QPushButton* button = new QPushButton("PushButton"); button->setObjectName("PushButton"); return setLayoutWidget({ button }, { 125, 30 }); } else if(name == "RadioButton") { QRadioButton* button = new QRadioButton("RadioButton"); button->setObjectName("RadioButton"); return setLayoutWidget({ button }, { 125, 30 }); } else if(name == "ScrollBar") { QScrollBar* barH = new QScrollBar(Qt::Horizontal); QScrollBar* barV = new QScrollBar(Qt::Vertical); barH->setObjectName("ScrollBarH"); barV->setObjectName("ScrollBarV"); return setLayoutWidget({ barH, barV }, { 200, 100 }); } else if(name == "Slider") { QSlider* sliderH = new QSlider(Qt::Horizontal); QSlider* sliderV = new QSlider(Qt::Vertical); sliderH->setObjectName("SliderH"); sliderV->setObjectName("SliderV"); return setLayoutWidget({ sliderH, sliderV }, { 200, 100 }); } else if(name == "SpinBox") { QSpinBox* spinBox = new QSpinBox; spinBox->setObjectName("SpinBox"); return setLayoutWidget({ spinBox }, { 60, 35 }); } else if(name == "Splitter") { QSplitter* splitterV = new QSplitter(Qt::Vertical); QSplitter* splitterH = new QSplitter(Qt::Horizontal); splitterV->setObjectName("SplitterV"); splitterH->setObjectName("SplitterH"); splitterV->addWidget(new QPushButton("PushButton1")); splitterV->addWidget(new QPushButton("PushButton2")); splitterH->addWidget(splitterV); splitterH->addWidget(new QPushButton("PushButton3")); return setLayoutWidget({ splitterH }, { 250, 110 }); } else if(name == "TabWidget") { QTabWidget* tab = new QTabWidget; tab->addTab(new QWidget, "Widget1"); tab->addTab(new QWidget, "Widget2"); tab->addTab(new QWidget, "Widget3"); tab->setObjectName("TabWidget"); return setLayoutWidget({ tab }, { 210, 110 }); } else if(name == "TableView") //? { QTableView* view = new QTableView; view->setObjectName("TableView"); view->resize(200, 100); return view; } else if(name == "TableWidget") { const int n = 100; QStringList list = { "one", "two", "three" }; QTableWidget* table = new QTableWidget(n, n); table->setObjectName("TableWidget"); table->setHorizontalHeaderLabels(list); table->setVerticalHeaderLabels(list); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) table->setItem(i, j, new QTableWidgetItem(QString("%1, %2").arg(i).arg(j))); return setLayoutWidget({ table }, { 210, 110 }); } else if(name == "TextEdit") { QTextEdit* text = new QTextEdit; text->setObjectName("TextEdit"); return setLayoutWidget({ text }, { 80, 80 }); } else if(name == "TimeEdit") { QTimeEdit* time = new QTimeEdit; time->setObjectName("TimeEdit"); return setLayoutWidget({ time }, { 80, 80 }); } else if(name == "ToolButton") { QToolButton* button = new QToolButton; button->setText("ToolButton"); button->setObjectName("ToolButton"); return setLayoutWidget({ button }, { 95, 25 }); } else if(name == "ToolBox") { QToolBox* box = new QToolBox; box->addItem(new QWidget, "Widget1"); box->addItem(new QWidget, "Widget2"); box->addItem(new QWidget, "Widget3"); box->setObjectName("ToolBox"); return setLayoutWidget({ box }, { 110, 180 }); } else if(name == "TreeView") //? { QTreeView* tree = new QTreeView; tree->setObjectName("TreeView"); tree->resize(200, 100); return tree; } else if(name == "TreeWidget") { QTreeWidget* tree = new QTreeWidget; tree->setObjectName("TreeWidget"); tree->setHeaderLabels({ "Folders", "Used Space" }); QTreeWidgetItem* item = new QTreeWidgetItem(tree); item->setText(0, "Local Disk"); for(int i = 1; i < 20; i++) { QTreeWidgetItem* dir = new QTreeWidgetItem(item); dir->setText(0, "Directory" + QString::number(i)); dir->setText(1, QString::number(i) + "MB"); } tree->setItemExpanded(item, true); return setLayoutWidget({ tree }, { 210, 110 }); } else if(name == "Widget") { QWidget* widget = new QWidget; widget->setObjectName("Widget"); return setLayoutWidget({ widget }, { 210, 110 }); } return nullptr; }
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]); }