void MainWindow::setupLegendTest(QCustomPlot *customPlot)
{
	customPlot->legend->setVisible(true);
	//customPlot->legend->setMinimumSize(300, 150);
	//customPlot->axisRect()->setMinimumMargins(QMargins(15, 0, 15, 15));

	customPlot->addGraph()->setName("first graph");
	customPlot->addGraph()->setName("second longer graph");
	customPlot->addGraph()->setName("some stupid text\nthat has a line break\nand some more text");
	customPlot->addGraph()->setName("yadayada");
	//customPlot->legend->addElement(0, 1, customPlot->legend->element(3, 0));
	//customPlot->legend->addElement(1, 1, customPlot->legend->element(2, 0));
	customPlot->addGraph()->setName("yadayaasdda");
	customPlot->graph(3)->removeFromLegend();
	customPlot->graph(3)->addToLegend();

	QCPLayoutGrid *grid = customPlot->plotLayout();
	grid->addElement(1, 0, grid->element(0, 0));

	QCPPlotTitle *title = new QCPPlotTitle(customPlot);
	title->setText("This is a Plot Title");
	title->setSelectable(true);
	grid->addElement(0, 0, title);

	customPlot->graph(0)->addData(QVector<double>() << 1 << 2, QVector<double>() << 1 << 1.2);
}
void MainWindow::setupMarginGroupTest(QCustomPlot *customPlot)
{
	QCPLayoutGrid *topLayout =customPlot->plotLayout();

	QCPAxisRect *r = new QCPAxisRect(customPlot);
	topLayout->addElement(1, 0, r);
	r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop);
	r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop);

	QCPMarginGroup *group = new QCPMarginGroup(customPlot);
	topLayout->element(0, 0)->setMarginGroup(QCP::msAll, group);
	topLayout->element(1, 0)->setMarginGroup(QCP::msAll, group);
}
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;
	}


}
void MainWindow::setupLayoutTest(QCustomPlot *customPlot)
{

	QCPLayoutGrid *mainLayout = customPlot->plotLayout();
	mainLayout->removeAt(0);
	// create 3x3 grid:
	mainLayout->addElement(0, 0, new QCPAxisRect(customPlot));
	mainLayout->addElement(0, 1, new QCPAxisRect(customPlot));
	mainLayout->addElement(0, 2, new QCPAxisRect(customPlot));
	mainLayout->addElement(1, 0, new QCPAxisRect(customPlot));
	mainLayout->addElement(1, 1, new QCPAxisRect(customPlot));
	mainLayout->addElement(1, 2, new QCPAxisRect(customPlot));
	mainLayout->addElement(2, 0, new QCPAxisRect(customPlot));
	mainLayout->addElement(2, 1, new QCPAxisRect(customPlot));
	mainLayout->addElement(2, 2, new QCPAxisRect(customPlot));
	QList<QCPAxisRect*> rlist;
	for (int i=0; i<mainLayout->elementCount(); ++i)
	{
		rlist << qobject_cast<QCPAxisRect*>(mainLayout->elementAt(i));
		rlist.last()->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom);
	}

	mainLayout->setColumnStretchFactors(QList<double>() << 1 << 2 << 1);
	mainLayout->setRowStretchFactors(QList<double>() << 1 << 2 << 3);

	mainLayout->element(0, 0)->setMinimumSize(200, 100);
	mainLayout->element(0, 1)->setMaximumSize(150, 100);
	mainLayout->element(2, 2)->setMinimumSize(100, 100);


	/*
	customPlot->setFont(QFont(customPlot->font().family(), 7));
	customPlot->axisRect(0)->axis(QCPAxis::atRight)->setTickLabels(true);
	customPlot->axisRect(0)->axis(QCPAxis::atTop)->setTickLabels(true);
	customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setTickLabelFont(customPlot->font());
	customPlot->axisRect(0)->axis(QCPAxis::atRight)->setTickLabelFont(customPlot->font());
	customPlot->axisRect(0)->axis(QCPAxis::atTop)->setTickLabelFont(customPlot->font());
	customPlot->axisRect(0)->axis(QCPAxis::atBottom)->setTickLabelFont(customPlot->font());

	QCPLayoutGrid *layout = customPlot->plotLayout();
	layout->setRowSpacing(8);
	layout->setColumnSpacing(8);
	layout->addElement(0, 1, new QCPAxisRect(customPlot));
	layout->addElement(1, 0, new QCPAxisRect(customPlot));

	QCPLayoutGrid *subLayout = new QCPLayoutGrid;
	subLayout->addElement(0, 0, new QCPAxisRect(customPlot));
	subLayout->addElement(0, 1, new QCPAxisRect(customPlot));
	subLayout->setColumnStretchFactor(0, 0.7);
	layout->addElement(1, 1, subLayout);

	QList<QCPAxisRect*> rects = customPlot->axisRects();
	for (int i=0; i<rects.size(); ++i)
	{
	rects.at(i)->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom);
	rects.at(i)->axis(QCPAxis::atLeft)->grid()->setVisible(true);
	rects.at(i)->axis(QCPAxis::atBottom)->grid()->setVisible(true);
	}

	QCPCurve *c = new QCPCurve(customPlot->xAxis, customPlot->yAxis);
	customPlot->addPlottable(c);

	QCPCurveDataMap *d1 = new QCPCurveDataMap;
	d1->insert(0, QCPCurveData(0, 2, 1));
	d1->insert(1, QCPCurveData(1, 3, 2));
	d1->insert(2, QCPCurveData(2, 6, 4));

	c->clearData();
	c->setData(d1, false);

	QCPCurveDataMap *d2 = new QCPCurveDataMap;
	d2->insert(0, QCPCurveData(0, 26, 14));
	d2->insert(2, QCPCurveData(2, 31, 22));
	d2->insert(4, QCPCurveData(4, 61, 42));

	c->clearData();
	c->setData(d2, false);

	customPlot->replot();
	*/

	/*
	QCPLayoutGrid *topLayout = customPlot->plotLayout();
	QList<QCPAxisRect*> rects;
	for (int i=0; i<5; ++i)
	rects << new QCPAxisRect(customPlot);

	for (int i=0; i<rects.size(); ++i)
	{
	topLayout->addElement(0, i+1, rects.at(i));
	rects.at(i)->addAxis(QCPAxis::atLeft);
	rects.at(i)->addAxis(QCPAxis::atRight);
	rects.at(i)->addAxis(QCPAxis::atBottom);
	rects.at(i)->addAxis(QCPAxis::atTop);
	for (int k=0; k<rects.at(i)->axes().size(); ++k)
	{
	QCPAxis *ax = rects.at(i)->axes().at(k);
	ax->setTicks(false);
	ax->setTickLabels(false);
	ax->grid()->setVisible(false);
	}
	rects.at(i)->setAutoMargins(QCP::msNone);
	rects.at(i)->setMargins(QMargins(1, 1, 1, 1));
	}

	topLayout->setColumnStretchFactors(QList<double>() << 1 << 1e9 << 1e7 << 1e9 << 1e3 << 1e1);
	rects.at(0)->setMaximumSize(300, QWIDGETSIZE_MAX);
	rects.at(1)->setMaximumSize(250, QWIDGETSIZE_MAX);
	rects.at(2)->setMinimumSize(200, 0);
	rects.at(3)->setMaximumSize(150, QWIDGETSIZE_MAX);
	rects.at(4)->setMaximumSize(100, QWIDGETSIZE_MAX);

	QCPLayoutGrid *subLayout = new QCPLayoutGrid;
	topLayout->addElement(1, 3, subLayout);
	QCPAxisRect *r0 = new QCPAxisRect(customPlot);
	subLayout->addElement(0, 0, r0);
	r0->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom);
	QCPAxisRect *r1 = new QCPAxisRect(customPlot);
	subLayout->addElement(0, 1, r1);
	r1->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom);
	r1->setMaximumSize(200, QWIDGETSIZE_MAX);*/
}
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


}