本文整理汇总了C++中QCPGraph::valueAxis方法的典型用法代码示例。如果您正苦于以下问题:C++ QCPGraph::valueAxis方法的具体用法?C++ QCPGraph::valueAxis怎么用?C++ QCPGraph::valueAxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCPGraph
的用法示例。
在下文中一共展示了QCPGraph::valueAxis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mousePress
void smart_plot::mousePress(QMouseEvent *event)
{
static double prevKey, prevValue;
if(event->button() == Qt::MiddleButton)
{
QCPAbstractPlottable *plottable = activePlot()->plottableAt(event->localPos());
if(plottable)
{
QCPGraph *graph = qobject_cast<QCPGraph*>(plottable);
plot_analytics analytics;
plotStats stats;
if(graph)
{
//Do diff by % range vs
double mouseKey = graph->keyAxis()->pixelToCoord(event->localPos().x());
double mouseValue = graph->valueAxis()->pixelToCoord(event->localPos().y());
double keyRange = graph->keyAxis()->range().size();
double keyDistance_no_abs = 0;
double value = 0;
double key = 0;
bool ok = false;
double m = std::numeric_limits<double>::max();
//QCPGraphDataContainer
analytics.plotAnalyze( graph, &stats, graph->keyAxis()->range());
//Iterate through on screen data and see which point is closest
QCPGraphDataContainer::const_iterator QCPGraphDataBegin = graph->data().data()->findBegin(graph->keyAxis()->range().lower,true);
QCPGraphDataContainer::const_iterator QCPGraphDataEnd = graph->data().data()->findEnd(graph->keyAxis()->range().upper,true);
for (QCPGraphDataContainer::const_iterator QCPGraphDataIt=QCPGraphDataBegin; QCPGraphDataIt!=QCPGraphDataEnd; ++QCPGraphDataIt)
{
double valueRange = graph->valueAxis()->range().size();
double keyDistance = qAbs(mouseKey - QCPGraphDataIt->key)/keyRange;
double valueDistance = qAbs(mouseValue - QCPGraphDataIt->value)/valueRange;
if( (valueDistance + keyDistance) < m )
{
value = QCPGraphDataIt->value;
key = QCPGraphDataIt->key;
keyDistance_no_abs = mouseKey - QCPGraphDataIt->key;
ok = true;
m = (valueDistance + keyDistance);
}
}
// qDebug () << QDateTime::fromTime_t((int)mouseKey) << value;
if(ok)
{
QToolTip::hideText();
if(!qSharedPointerDynamicCast<QCPAxisTickerDateTime>(graph->keyAxis()->ticker()).isNull())
{
if(QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
{
quint32 timeDelta = qAbs(mouseKey-prevKey);
// add the bracket at the top:
QCPItemBracket *bracket = new QCPItemBracket(activePlot());
bracket->left->setAxes(graph->keyAxis(), graph->valueAxis());
bracket->left->setCoords(prevKey, value);
bracket->right->setAxes(graph->keyAxis(), graph->valueAxis());
bracket->right->setCoords(mouseKey, value);
// add the text label at the top:
QCPItemText *wavePacketText = new QCPItemText(activePlot());
wavePacketText->position->setParentAnchor(bracket->center);
wavePacketText->position->setCoords(0, -10); // move 10 pixels to the top from bracket center anchor
wavePacketText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
wavePacketText->setText(
QString("%L1: ΔX->%L2 ΔY->%L3").
arg(graph->name().isEmpty() ? "..." : graph->name()).
arg(seconds_to_DHMS(timeDelta)).
arg(value-prevValue));
wavePacketText->setFont(QFont(font().family(), 12));
activePlot()->replot();
}
else if(QApplication::keyboardModifiers().testFlag(Qt::AltModifier))
{
if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
graph->addData(graph->keyAxis()->pixelToCoord(event->localPos().x()),
graph->valueAxis()->pixelToCoord(event->localPos().y()));
else if(keyDistance_no_abs < 0)
graph->addData(key - 1, std::numeric_limits<double>::quiet_NaN());
else
graph->addData(key + 1, std::numeric_limits<double>::quiet_NaN());
activePlot()->replot();
}
else if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
{
//Delete point
graph->data().data()->remove(key);
activePlot()->replot();
}
//Hold Alt to insert NAN(Break link?)
else
{
//.........这里部分代码省略.........