void MainWindow::setupColorMapTest(QCustomPlot *customPlot) { customPlot->legend->setVisible(true); presetInteractive(customPlot); QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(colorMap); colorMap->setName("Color Map"); customPlot->addLayer("maplayer", customPlot->layer("grid"), QCustomPlot::limBelow); colorMap->setLayer("maplayer"); int nx = 400; int ny = 400; colorMap->data()->setSize(nx, ny); colorMap->data()->setRange(QCPRange(0, 10), QCPRange(0, 10)); colorMap->setInterpolate(true); colorMap->setTightBoundary(false); for (int x=0; x<nx; ++x) { for (int y=0; y<ny; ++y) { colorMap->data()->setCell(x, y, qExp(-qSqrt((x-310)*(x-310)+(y-260)*(y-260))/200.0)+ qExp(-qSqrt((x-200)*(x-200)+(y-290)*(y-290))/80.0)-qExp(-qSqrt((x-180)*(x-180)+(y-140)*(y-140))/200.0)); } } /* manual test of coordinate to cell transformations (and vice versa): connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(colorMapMouseMove(QMouseEvent*))); colorMap->data()->setRange(QCPRange(0, 1), QCPRange(0, 1)); colorMap->data()->setSize(2,2); colorMap->data()->setCell(0, 0, 0); colorMap->data()->setCell(0, 1, 0); colorMap->data()->setCell(1, 0, 2); colorMap->data()->setCell(1, 1, 4); */ //customPlot->xAxis->setRangeReversed(true); //customPlot->yAxis->setRangeReversed(true); colorMap->setInterpolate(false); QCPColorScale *colorScale = new QCPColorScale(customPlot); customPlot->plotLayout()->addElement(0, 1, colorScale); colorMap->setColorScale(colorScale); colorScale->setLabel("test"); QCPMarginGroup *group = new QCPMarginGroup(customPlot); colorScale->setMarginGroup(QCP::msTop|QCP::msBottom, group); customPlot->axisRect()->setMarginGroup(QCP::msTop|QCP::msBottom, group); QCPColorGradient gradient = colorMap->gradient(); gradient.loadPreset(QCPColorGradient::gpJet); gradient.setPeriodic(false); colorMap->setGradient(gradient); colorMap->rescaleDataRange(true); connect(customPlot, SIGNAL(beforeReplot()), colorMap, SLOT(updateLegendIcon())); customPlot->rescaleAxes(); customPlot->replot(); }
Layout2D::Layout2D(const QString &label, QWidget *parent, const QString name, Qt::WFlags f) : MyWidget(label, parent, name, f), plot2dCanvas_(new Plot2D(this)), layout_(new LayoutGrid2D()), buttionlist_(QList<LayoutButton2D *>()), currentAxisRect_(nullptr), draggingLegend(false) { if (name.isEmpty()) setObjectName("multilayout2d plot"); QDateTime birthday = QDateTime::currentDateTime(); setBirthDate(birthday.toString(Qt::LocalDate)); QPalette pal = palette(); pal.setColor(QPalette::Active, QPalette::Window, QColor(Qt::white)); pal.setColor(QPalette::Inactive, QPalette::Window, QColor(Qt::white)); pal.setColor(QPalette::Disabled, QPalette::Window, QColor(Qt::white)); setPalette(pal); layoutManagebuttonsBox_ = new QHBoxLayout(); addLayoutButton_ = new QPushButton(); addLayoutButton_->setToolTip(tr("Add layer")); addLayoutButton_->setIcon( IconLoader::load("list-add", IconLoader::LightDark)); addLayoutButton_->setMaximumWidth(LayoutButton2D::btnSize()); addLayoutButton_->setMaximumHeight(LayoutButton2D::btnSize()); connect(addLayoutButton_, SIGNAL(clicked()), this, SLOT(addAxisRectItem())); layoutManagebuttonsBox_->addWidget(addLayoutButton_); removeLayoutButton_ = new QPushButton(); removeLayoutButton_->setToolTip(tr("Remove active layer")); removeLayoutButton_->setIcon( IconLoader::load("list-remove", IconLoader::General)); removeLayoutButton_->setMaximumWidth(LayoutButton2D::btnSize()); removeLayoutButton_->setMaximumHeight(LayoutButton2D::btnSize()); connect(removeLayoutButton_, SIGNAL(clicked()), this, SLOT(removeAxisRectItem())); layoutManagebuttonsBox_->addWidget(removeLayoutButton_); layoutButtonsBox_ = new QHBoxLayout(); QHBoxLayout *hbox = new QHBoxLayout(); hbox->addLayout(layoutButtonsBox_); streachLabel_ = new QLabel(this); hbox->addWidget(streachLabel_); setBackground(plot2dCanvas_->getBackgroundColor()); hbox->addLayout(layoutManagebuttonsBox_); QVBoxLayout *layout = new QVBoxLayout(this); layout->addLayout(hbox); layout->addWidget(plot2dCanvas_, 1); layout->setMargin(0); layout->setSpacing(0); setGeometry(QRect(0, 0, 500, 400)); setMinimumSize(QSize(100, 100)); setFocusPolicy(Qt::StrongFocus); plot2dCanvas_->plotLayout()->addElement(0, 0, layout_); // connections connect(plot2dCanvas_, SIGNAL(axisDoubleClick(QCPAxis *, QCPAxis::SelectablePart, QMouseEvent *)), this, SLOT(axisDoubleClicked(QCPAxis *, QCPAxis::SelectablePart))); connect(plot2dCanvas_, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(mouseMoveSignal(QMouseEvent *))); connect(plot2dCanvas_, SIGNAL(mousePress(QMouseEvent *)), this, SLOT(mousePressSignal(QMouseEvent *))); connect(plot2dCanvas_, SIGNAL(mouseRelease(QMouseEvent *)), this, SLOT(mouseReleaseSignal(QMouseEvent *))); connect(plot2dCanvas_, SIGNAL(beforeReplot()), this, SLOT(beforeReplot())); connect(plot2dCanvas_, SIGNAL(mouseWheel(QWheelEvent *)), this, SLOT(mouseWheel())); connect(plot2dCanvas_, SIGNAL(legendDoubleClick(QCPLegend *, QCPAbstractLegendItem *, QMouseEvent *)), this, SLOT(legendDoubleClick(QCPLegend *, QCPAbstractLegendItem *))); }
void ProfilePlotView::createLayout() { m_pltDepth = new QCustomPlot; m_pltDepth->setInteraction(QCustomPlot::iSelectItems, true); m_pltDepth->setInteraction(QCustomPlot::iMultiSelect, false); /* * Calculate Left-hand Margin (identical for both plots) */ QFontMetrics fm(m_pltDepth->xAxis->labelFont()); int lMargin = fm.width('0') * 4 + fm.width('.') + fm.height() * 5 / 2; int bMargin = fm.height() * 7 / 2; /* * Setup Depth Plot Margins */ m_pltDepth->setAutoMargin(false); m_pltDepth->setMargin(lMargin, 8, 8, bMargin); /* * Setup Depth Plot Axes */ m_pltDepth->xAxis->setAutoTicks(false); m_pltDepth->xAxis->setBasePen(QColor(192, 192, 192, 255)); m_pltDepth->xAxis->setLabel("Time (minutes)"); m_pltDepth->xAxis->setSubTickPen(Qt::NoPen); m_pltDepth->xAxis->setTickLength(0, 4); m_pltDepth->xAxis->setTickPen(QColor(192, 192, 192, 255)); m_pltDepth->yAxis->setAutoTicks(false); m_pltDepth->yAxis->setBasePen(QColor(192, 192, 192, 255)); m_pltDepth->yAxis->setRangeReversed(true); m_pltDepth->yAxis->setSubTickPen(Qt::NoPen); m_pltDepth->yAxis->setTickLength(0, 4); m_pltDepth->yAxis->setTickPen(QColor(192, 192, 192, 255)); m_pltDepth->xAxis2->setBasePen(QColor(192, 192, 192, 255)); m_pltDepth->xAxis2->setSubTickPen(Qt::NoPen); m_pltDepth->xAxis2->setTickLabels(false); m_pltDepth->xAxis2->setTickPen(Qt::NoPen); m_pltDepth->xAxis2->setVisible(true); m_pltDepth->yAxis2->setBasePen(QColor(192, 192, 192, 255)); m_pltDepth->yAxis2->setSubTickPen(Qt::NoPen); m_pltDepth->yAxis2->setTickLabels(false); m_pltDepth->yAxis2->setTickPen(Qt::NoPen); m_pltDepth->yAxis2->setVisible(true); connect(m_pltDepth, SIGNAL(beforeReplot()), this, SLOT(pltDepthBeforeReplot())); /* * Setup Aux Plot Margins */ m_pltAux = new QCustomPlot; m_pltAux->setAutoMargin(false); m_pltAux->setMinimumSize(400, 80); m_pltAux->setMargin(lMargin, 8, 8, 8); /* * Setup Aux Plot Axes */ m_pltAux->xAxis->setAutoTicks(false); m_pltAux->xAxis->setBasePen(QColor(192, 192, 192, 255)); m_pltAux->xAxis->setSubTickPen(Qt::NoPen); m_pltAux->xAxis->setTickLabels(false); m_pltAux->xAxis->setTickPen(Qt::NoPen); m_pltAux->yAxis->setAutoTicks(false); m_pltAux->yAxis->setBasePen(QColor(192, 192, 192, 255)); m_pltAux->yAxis->setSubTickPen(Qt::NoPen); m_pltAux->yAxis->setTickLength(0, 4); m_pltAux->yAxis->setTickPen(QColor(192, 192, 192, 255)); m_pltAux->xAxis2->setBasePen(QColor(192, 192, 192, 255)); m_pltAux->xAxis2->setSubTickPen(Qt::NoPen); m_pltAux->xAxis2->setTickLabels(false); m_pltAux->xAxis2->setTickPen(Qt::NoPen); m_pltAux->xAxis2->setVisible(true); m_pltAux->yAxis2->setBasePen(QColor(192, 192, 192, 255)); m_pltAux->yAxis2->setSubTickPen(Qt::NoPen); m_pltAux->yAxis2->setTickLabels(false); m_pltAux->yAxis2->setTickPen(Qt::NoPen); m_pltAux->yAxis2->setVisible(true); /* * Setup Combo Boxes */ m_cbxAuxKeys = new QComboBox; m_cbxProfile = new QComboBox; m_lblProfile = new QLabel(tr("Select &Profile:")); m_lblProfile->setBuddy(m_cbxProfile); m_lblProfile->setVisible(false); m_cbxProfile->setVisible(false); connect(m_cbxAuxKeys, SIGNAL(currentIndexChanged(int)), this, SLOT(cbxAuxKeysIndexChanged(int))); connect(m_cbxProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(cbxProfileIndexChanged(int))); /* * Setup Layout */ QHBoxLayout * hbox1 = new QHBoxLayout; hbox1->addWidget(m_lblProfile); hbox1->addWidget(m_cbxProfile); QHBoxLayout * hbox2 = new QHBoxLayout; hbox2->setContentsMargins(0, 0, 0, 0); hbox2->addSpacing(lMargin * 3 / 4); hbox2->addWidget(m_cbxAuxKeys); hbox2->addStretch(); QVBoxLayout * vbox = new QVBoxLayout; vbox->setContentsMargins(0, 0, 0, 0); vbox->addLayout(hbox1); vbox->addWidget(m_pltDepth, 1); vbox->addLayout(hbox2); vbox->addWidget(m_pltAux); setLayout(vbox); }
void MainWindow::setupSelectTest(QCustomPlot *customPlot) { customPlot->xAxis->setRange(-10, 10); customPlot->yAxis->setRange(-10, 10); QBrush defaultBrush(QColor(255,255,255,30)); //defaultBrush = Qt::NoBrush; /* // QCPItemPixmap QCPItemPixmap *pixmapItem = new QCPItemPixmap(customPlot); customPlot->addItem(pixmapItem); pixmapItem->setPixmap(QPixmap("./gnu.png")); pixmapItem->setScaled(true, Qt::IgnoreAspectRatio); pixmapItem->topLeft->setCoords(-0.2, 1); pixmapItem->bottomRight->setCoords(0.3, 0); QCPItemPixmap *pixmapItem2 = new QCPItemPixmap(customPlot); customPlot->addItem(pixmapItem2); pixmapItem2->setPixmap(QPixmap("./gnu.png")); pixmapItem2->setScaled(true, Qt::IgnoreAspectRatio); pixmapItem2->topLeft->setCoords(1.2, 0); pixmapItem2->bottomRight->setCoords(0.7, 1); // QCPItemRect QCPItemRect *rect = new QCPItemRect(customPlot); customPlot->addItem(rect); rect->setBrush(defaultBrush); rect->topLeft->setCoords(0, 1); rect->bottomRight->setCoords(1, 0); // QCPItemEllipse QCPItemEllipse *ellipse = new QCPItemEllipse(customPlot); customPlot->addItem(ellipse); ellipse->setBrush(defaultBrush); ellipse->topLeft->setCoords(-0.15, 1.1); ellipse->bottomRight->setCoords(1.15, 0); // QCPItemLine QCPItemLine *line = new QCPItemLine(customPlot); customPlot->addItem(line); line->start->setCoords(-0.1, 0.8); line->end->setCoords(1.1, 0.2); line->setHead(QCPLineEnding::esSpikeArrow); // QCPItemStraightLine QCPItemStraightLine *straightLine = new QCPItemStraightLine(customPlot); customPlot->addItem(straightLine); straightLine->point1->setCoords(0, 0.4); straightLine->point2->setCoords(1, 0.6); */ // QCPItemCurve QCPItemCurve *curve = new QCPItemCurve(customPlot); customPlot->addItem(curve); curve->start->setCoords(0, 1); curve->startDir->setCoords(0.5, 1); curve->endDir->setCoords(0.7, 0.2); curve->end->setCoords(1, 0); curve->setHead(QCPLineEnding::esSpikeArrow); curve->setTail(QCPLineEnding::esLineArrow); /* // QCPItemBracket QCPItemBracket *bracket = new QCPItemBracket(customPlot); customPlot->addItem(bracket); bracket->left->setCoords(-0.2, 0.35); bracket->right->setCoords(1.2, 0.65); bracket->setLength(22); */ connect(customPlot, SIGNAL(beforeReplot()), this, SLOT(selectTestColorMapRefresh())); }