예제 #1
0
void MainWindow::setupInsetLayoutTest(QCustomPlot *customPlot)
{
	customPlot->addLayer("insetLayer");
	customPlot->setCurrentLayer("insetLayer");
	QCPAxisRect *insetAxRect = new QCPAxisRect(customPlot);
	insetAxRect->setMinimumSize(300, 250);
	customPlot->axisRect(0)->insetLayout()->addElement(insetAxRect, Qt::AlignRight|Qt::AlignTop);
	insetAxRect->setupFullAxesBox(true);
	insetAxRect->setBackground(QBrush(QColor(240, 240, 240)));
}
예제 #2
0
void MainWindow::setupMultiAxisRectInteractions(QCustomPlot *customPlot)
{
	QCPAxisRect *r1 = new QCPAxisRect(customPlot);
	customPlot->plotLayout()->addElement(1, 0, r1);
	QCPAxisRect *r2 = new QCPAxisRect(customPlot);
	customPlot->plotLayout()->addElement(0, 1, r2);
	QCPAxisRect *r3 = new QCPAxisRect(customPlot);
	customPlot->plotLayout()->addElement(1, 1, r3);

	QCPAxisRect *inset = new QCPAxisRect(customPlot);
	inset->setMinimumSize(170, 120);
	inset->setupFullAxesBox(true);
	foreach (QCPAxis *ax, inset->axes())
		ax->setAutoTickCount(3);
	r3->insetLayout()->addElement(inset, Qt::AlignRight|Qt::AlignTop);

	connect(mCustomPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(setupMultiAxisRectInteractionsMouseMove(QMouseEvent*)));
}
예제 #3
0
void MainWindow::setupItemTracerTest_MyTest_2(QCustomPlot *customPlot)
{
	QCPAxisRect* pAxisRectTop = NULL;
	QCPAxisRect* pAxisRectBottom = NULL;
	QCPLayoutGrid *pLayoutGrid = NULL;
	QCPMarginGroup *pMarginGroup = NULL;
	QCPItemTracerCrossHair *pTracerTop = NULL;
	QCPItemTracerCrossHair *pTracerBottom = NULL;
	CMidSubDrawHelper* m_pMidSubDrawHelper = NULL;
	CHistoryDataManager* pHistoryDataManager = NULL;

	customPlot->clearGraphs();
	customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch

	pAxisRectTop = new QCPAxisRect(customPlot);
	pAxisRectTop->setupFullAxesBox(true);
	pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value"));
	pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time"));
	pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
	pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str());

	pAxisRectBottom = new QCPAxisRect(customPlot);
	pAxisRectBottom->setupFullAxesBox(true);
	pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value"));
	pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time"));
	pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
	pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str());//("yyyy-MM-dd hh-mm-ss");

	customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row
	customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row

	pLayoutGrid = customPlot->plotLayout();
	pMarginGroup = new QCPMarginGroup(customPlot);
	pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup);
	pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup);

	m_pMidSubDrawHelper = new CMidSubDrawHelper();
	pHistoryDataManager = new CHistoryDataManager();

	m_pMidSubDrawHelper->drawHistoryBarData(pHistoryDataManager, customPlot, pAxisRectTop);
	m_pMidSubDrawHelper->drawHistoryVolumeData(pHistoryDataManager, customPlot, pAxisRectBottom);

	//setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectTop);
	//setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectBottom);


	pTracerTop = NULL;
	pTracerTop = new QCPItemTracerCrossHair(customPlot);
	customPlot->addItem(pTracerTop);
	pTracerTop->setTracerAxisRect(pAxisRectTop);
	pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair);
	pTracerTop->setShowLeft(QCPAxis::ltNumber, true, QString(""));
	pTracerTop->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str()));
	m_pQCPItemTracerCrossHairTop = pTracerTop;

	pTracerBottom = NULL;
	pTracerBottom = new QCPItemTracerCrossHair(customPlot);
	customPlot->addItem(pTracerBottom);
	pTracerBottom->setTracerAxisRect(pAxisRectBottom);
	pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair);
	pTracerBottom->setShowLeft(QCPAxis::ltNumber, true, QString(""));
	pTracerBottom->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str()));
	m_pQCPItemTracerCrossHairBottom = pTracerBottom;
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*)));


	//customPlot->rescaleAxes();
	customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
	customPlot->replot();//draw again


	if (NULL != m_pMidSubDrawHelper)
	{
		delete m_pMidSubDrawHelper;
		m_pMidSubDrawHelper = NULL;
	}
	
	if (NULL != pHistoryDataManager)
	{
		delete pHistoryDataManager;
		pHistoryDataManager = NULL;
	}


}
예제 #4
0
void MainWindow::setupItemTracerTest_MyTest_1(QCustomPlot *customPlot)
{
	QCPAxisRect* pAxisRectTop = NULL;
	QCPAxisRect* pAxisRectBottom = NULL;
	QCPLayoutGrid *pLayoutGrid = NULL;
	QCPMarginGroup *pMarginGroup = NULL;
	QCPItemTracerCrossHair *pTracerTop = NULL;
	QCPItemTracerCrossHair *pTracerBottom = NULL;

	customPlot->clearGraphs();
	customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch

	pAxisRectTop = new QCPAxisRect(customPlot);
	pAxisRectTop->setupFullAxesBox(true);
	//pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value"));
	//pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time"));
	//pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
	//pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME

	pAxisRectBottom = new QCPAxisRect(customPlot);
	pAxisRectBottom->setupFullAxesBox(true);
	//pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value"));
	//pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time"));
	//pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
	//pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME

	customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row
	customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row

	pLayoutGrid = customPlot->plotLayout();
	pMarginGroup = new QCPMarginGroup(customPlot);
	pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup);
	pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup);



	QCPGraph *graph = customPlot->addGraph(pAxisRectTop->axis(QCPAxis::atBottom), pAxisRectTop->axis(QCPAxis::atLeft));
	int n = 200;
	QVector<double> x(n), y(n);
	for (int i=0; i<n; ++i)
	{
		x[i] = 0.5+i/(double)n*4;
		y[i] = qSin(x[i])+1.5;
	}
	graph->setData(x, y);


	pTracerTop = NULL;
	pTracerTop = new QCPItemTracerCrossHair(customPlot);
	customPlot->addItem(pTracerTop);
	pTracerTop->setTracerAxisRect(pAxisRectTop);
	pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair);
	m_pQCPItemTracerCrossHairTop = pTracerTop;

	pTracerBottom = NULL;
	pTracerBottom = new QCPItemTracerCrossHair(customPlot);
	customPlot->addItem(pTracerBottom);
	pTracerBottom->setTracerAxisRect(pAxisRectBottom);
	pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair);
	m_pQCPItemTracerCrossHairBottom = pTracerBottom;
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*)));


	customPlot->rescaleAxes();
	customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
	customPlot->replot();//draw again


}