void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e ) { QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas ); if ( vlayer == NULL ) { return; } QgsRubberBand rubberBand( mCanvas, true ); QRect selectRect( 0, 0, 0, 0 ); QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() ); QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, &rubberBand ); QgsGeometry* selectGeom = rubberBand.asGeometry(); bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false; QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, doDifference, true ); delete selectGeom; rubberBand.reset( true ); }
/*! \brief Translate a position into a position string In case of HLineRubberBand the label is the value of the y position, in case of VLineRubberBand the value of the x position. Otherwise the label contains x and y position separated by a ',' . The format for the double to string conversion is "%.4f". \param pos Position \return Position string */ QwtText QwtPlotPicker::trackerTextF( const QPointF &pos ) const { QString text; switch ( rubberBand() ) { case HLineRubberBand: text.sprintf( "%.4f", pos.y() ); break; case VLineRubberBand: text.sprintf( "%.4f", pos.x() ); break; default: text.sprintf( "%.4f, %.4f", pos.x(), pos.y() ); } return QwtText( text ); }
QwtText QwtPicker::trackerText(const QPoint &pos) const { QString label; switch(rubberBand()) { case HLineRubberBand: label.sprintf("%d", pos.y()); break; case VLineRubberBand: label.sprintf("%d", pos.x()); break; default: label.sprintf("%d, %d", pos.x(), pos.y()); } return label; }
void OptMapToolDeleteLink::canvasReleaseEvent( QMouseEvent * e ) { QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas ); OptLineLayer* lineLayer = qobject_cast<OptLineLayer*>(vlayer); if ( NULL == lineLayer ) { QMessageBox::information(NULL, "", "only link layer can be edited"); return; } QgsRubberBand rubberBand( mCanvas, true ); QRect selectRect( 0, 0, 0, 0 ); QgsMapToolSelectUtils::expandSelectRectangle( selectRect, vlayer, e->pos() ); QgsMapToolSelectUtils::setRubberBand( mCanvas, selectRect, &rubberBand ); QgsGeometry* selectGeom = rubberBand.asGeometry(); bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false; QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, doDifference, true ); delete selectGeom; rubberBand.reset( true ); deleteSelected( vlayer ); }
void AdvPlotZoomer::drawRubberBand( QPainter *painter ) const { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( stateMachine() ) selectionType = stateMachine()->selectionType(); if ( d_zoomConstrain == NoConstrain || rubberBand() != RectRubberBand ) { QwtPlotZoomer::drawRubberBand(painter); return; } const QRect &pRect = pickArea().boundingRect().toRect(); const QPolygon &pa = pickedPoints(); const int npa = pa.count(); switch ( d_zoomConstrain ) { case HZoomOnly: if ( npa >= 1 ) QwtPainter::drawLine(painter, pa[0].x(), pRect.top(), pa[0].x(), pRect.bottom()); if ( npa >= 2 ) QwtPainter::drawLine(painter, pa[1].x(), pRect.top(), pa[1].x(), pRect.bottom()); break; case VZoomOnly: if ( npa >= 1 ) QwtPainter::drawLine(painter, pRect.left(), pa[0].y(), pRect.right(), pa[0].y()); if ( npa >= 2 ) QwtPainter::drawLine(painter, pRect.left(), pa[1].y(), pRect.right(), pa[1].y()); break; default: // Nothing to be done here break; } }
void QwtCustomPlotZoomer::drawRubberBand(QPainter* painter) const { if ( rubberBand() < UserRubberBand ) QwtPlotPicker::drawRubberBand( painter ); else { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QPolygon p = selection(); if ( p.count() < 2 ) return; const QPoint& pt1 = p[0]; const QPoint& pt2 = p[1]; const int end = canvas()->size().height(); painter->drawLine(pt1.x(), 0, pt1.x(), end); painter->drawLine(pt2.x(), 0, pt2.x(), end); painter->fillRect(QRect(pt1.x(), 0, pt2.x() - pt1.x(), end), QBrush(QColor("black"), Qt::Dense7Pattern)); } }
void QwtPicker::drawRubberBand(QPainter *painter) const { if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return; } const QRect &pRect = pickRect(); const SelectedPoints &pa = d_data->selection; if ( selectionFlags() & PointSelection ) { if ( pa.count() < 1 ) return; const QPoint pos = pa[0]; switch(rubberBand()) { case VLineRubberBand: QwtPainter::drawLine(painter, pos.x(), pRect.top(), pos.x(), pRect.bottom()); break; case HLineRubberBand: QwtPainter::drawLine(painter, pRect.left(), pos.y(), pRect.right(), pos.y()); break; case CrossRubberBand: QwtPainter::drawLine(painter, pos.x(), pRect.top(), pos.x(), pRect.bottom()); QwtPainter::drawLine(painter, pRect.left(), pos.y(), pRect.right(), pos.y()); break; default: break; } } else if ( selectionFlags() & RectSelection ) { if ( pa.count() < 2 ) return; QPoint p1 = pa[0]; QPoint p2 = pa[int(pa.count() - 1)]; if ( selectionFlags() & CenterToCorner ) { p1.setX(p1.x() - (p2.x() - p1.x())); p1.setY(p1.y() - (p2.y() - p1.y())); } else if ( selectionFlags() & CenterToRadius ) { const int radius = qwtMax(qwtAbs(p2.x() - p1.x()), qwtAbs(p2.y() - p1.y())); p2.setX(p1.x() + radius); p2.setY(p1.y() + radius); p1.setX(p1.x() - radius); p1.setY(p1.y() - radius); } #if QT_VERSION < 0x040000 const QRect rect = QRect(p1, p2).normalize(); #else const QRect rect = QRect(p1, p2).normalized(); #endif switch(rubberBand()) { case EllipseRubberBand: QwtPainter::drawEllipse(painter, rect); break; case RectRubberBand: QwtPainter::drawRect(painter, rect); break; default: break; } } else if ( selectionFlags() & PolygonSelection ) { if ( rubberBand() == PolygonRubberBand ) painter->drawPolyline(pa); } }
LogPlotZoomer::LogPlotZoomer(QWidget *canvas) : QwtPlotZoomer(canvas) #else LogPlotZoomer::LogPlotZoomer(QwtPlotCanvas *canvas): QwtPlotZoomer(canvas) #endif {} #if QWT_VERSION > 0x060000 QwtText LogPlotZoomer::trackerTextF(const QwtDoublePoint &pos) const #else QwtText LogPlotZoomer::trackerText(const QwtDoublePoint &pos) const #endif { switch (rubberBand()) { case HLineRubberBand: return QString().sprintf("%.4g", pos.y()); case VLineRubberBand: return QString().sprintf("%.4g", pos.x()); default: return QString().sprintf("%.4g, %.4g", pos.x(), pos.y()); } return QwtText(); // make some dumb compilers happy } /*void QwtPlotZoomer::move(double x, double y) { x = qwtMax(x, zoomBase().left()); x = qwtMin(x, zoomBase().right() - zoomRect().width()); y = qwtMax(y, zoomBase().top()); y = qwtMin(y, zoomBase().bottom() - zoomRect().height()); if (x != zoomRect().left() || y != zoomRect().top()) { d_data->zoomStack[d_data->zoomRectIndex].moveTo(x, y); rescale(); } }*/ #if QWT_VERSION > 0x060000 void LogPlotZoomer::moveTo(const QPointF & pos) { double x = pos.x(); double y = pos.y(); #else void LogPlotZoomer::move(double x, double y) { #endif //QwtPlotZoomer::move(x,y); x = qwtMax(x, (double)zoomBase().left()); x = qwtMin(x, (double)(zoomBase().right() - zoomRect().width())); y = qwtMax(y, (double)zoomBase().top()); y = qwtMin(y, (double)(zoomBase().bottom() - zoomRect().height())); if (x != zoomRect().left() || y != zoomRect().top()) { //zoomStack()[zoomRectIndex()].moveTo(x, y); QwtDoubleRect & rect = const_cast<QwtDoubleRect &>(zoomStack()[zoomRectIndex()]); //handle x axis const int xAxis = QwtPlotZoomer::xAxis(); const QwtScaleEngine *sex = plot()->axisScaleEngine(xAxis); #if QWT_VERSION > 0x060000 if (dynamic_cast<const QwtLogScaleEngine*>(sex)) #else if (dynamic_cast<const QwtLog10ScaleEngine*>(sex)) #endif { //logarithmic double factor = rect.right() / rect.left(); rect.setRight(x * factor); rect.setLeft(x); } else { rect.moveLeft(x); } const int yAxis = QwtPlotZoomer::yAxis(); const QwtScaleEngine *sey = plot()->axisScaleEngine(yAxis); #if QWT_VERSION > 0x060000 if (dynamic_cast<const QwtLogScaleEngine*>(sey)) #else if (dynamic_cast<const QwtLog10ScaleEngine*>(sey)) #endif { //logarithmic double factor = rect.bottom() / rect.top(); rect.setBottom(y * factor); rect.setTop(y); } else { rect.moveTop(y); } //zoomStack()[zoomRectIndex()].moveTo(x, y); rescale(); } }
//! Update the state of rubberband and tracker label void QwtPicker::updateDisplay() { QWidget *w = parentWidget(); bool showRubberband = false; bool showTracker = false; if ( w && w->isVisible() && d_data->enabled ) { if ( rubberBand() != NoRubberBand && isActive() && rubberBandPen().style() != Qt::NoPen ) { showRubberband = true; } if ( trackerMode() == AlwaysOn || (trackerMode() == ActiveOnly && isActive() ) ) { if ( trackerPen() != Qt::NoPen ) showTracker = true; } } #if QT_VERSION < 0x040000 QGuardedPtr<PickerWidget> &rw = d_data->rubberBandWidget; #else QPointer<PickerWidget> &rw = d_data->rubberBandWidget; #endif if ( showRubberband ) { if ( rw.isNull() ) { rw = new PickerWidget( this, w, PickerWidget::RubberBand); rw->hide(); rw->resize(w->size()); } rw->updateMask(); rw->update(); // Needed, when the mask doesn't change } else delete rw; #if QT_VERSION < 0x040000 QGuardedPtr<PickerWidget> &tw = d_data->trackerWidget; #else QPointer<PickerWidget> &tw = d_data->trackerWidget; #endif if ( showTracker ) { if ( tw.isNull() ) { tw = new PickerWidget( this, w, PickerWidget::Text); tw->hide(); tw->resize(w->size()); } tw->setFont(d_data->trackerFont); tw->updateMask(); tw->update(); // Needed, when the mask doesn't change } else delete tw; }
/*! Calculate the bounding rectangle for the tracker text from the current position of the tracker \param font Font of the tracker text \return Bounding rectangle of the tracker text \sa trackerPosition() */ QRect QwtPicker::trackerRect( const QFont &font ) const { if ( trackerMode() == AlwaysOff || ( trackerMode() == ActiveOnly && !isActive() ) ) { return QRect(); } if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 ) return QRect(); QwtText text = trackerText( d_data->trackerPosition ); if ( text.isEmpty() ) return QRect(); const QSizeF textSize = text.textSize( font ); QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) ); const QPoint &pos = d_data->trackerPosition; int alignment = 0; if ( isActive() && d_data->pickedPoints.count() > 1 && rubberBand() != NoRubberBand ) { const QPoint last = d_data->pickedPoints[int( d_data->pickedPoints.count() ) - 2]; alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft; alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop; } else alignment = Qt::AlignTop | Qt::AlignRight; const int margin = 5; int x = pos.x(); if ( alignment & Qt::AlignLeft ) x -= textRect.width() + margin; else if ( alignment & Qt::AlignRight ) x += margin; int y = pos.y(); if ( alignment & Qt::AlignBottom ) y += margin; else if ( alignment & Qt::AlignTop ) y -= textRect.height() + margin; textRect.moveTopLeft( QPoint( x, y ) ); const QRect pickRect = pickArea().boundingRect().toRect(); int right = qMin( textRect.right(), pickRect.right() - margin ); int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin ); textRect.moveBottomRight( QPoint( right, bottom ) ); int left = qMax( textRect.left(), pickRect.left() + margin ); int top = qMax( textRect.top(), pickRect.top() + margin ); textRect.moveTopLeft( QPoint( left, top ) ); return textRect; }
void QwtPicker::drawRubberBand( QPainter *painter ) const { if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return; } const QPolygon pa = adjustedPoints( d_data->pickedPoints ); QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( d_data->stateMachine ) selectionType = d_data->stateMachine->selectionType(); switch ( selectionType ) { case QwtPickerMachine::NoSelection: case QwtPickerMachine::PointSelection: { if ( pa.count() < 1 ) return; const QPoint pos = pa[0]; const QRect pRect = pickArea().boundingRect().toRect(); switch ( rubberBand() ) { case VLineRubberBand: { QwtPainter::drawLine( painter, pos.x(), pRect.top(), pos.x(), pRect.bottom() ); break; } case HLineRubberBand: { QwtPainter::drawLine( painter, pRect.left(), pos.y(), pRect.right(), pos.y() ); break; } case CrossRubberBand: { QwtPainter::drawLine( painter, pos.x(), pRect.top(), pos.x(), pRect.bottom() ); QwtPainter::drawLine( painter, pRect.left(), pos.y(), pRect.right(), pos.y() ); break; } default: break; } break; } case QwtPickerMachine::RectSelection: { if ( pa.count() < 2 ) return; const QRect rect = QRect( pa.first(), pa.last() ).normalized(); switch ( rubberBand() ) { case EllipseRubberBand: { QwtPainter::drawEllipse( painter, rect ); break; } case RectRubberBand: { QwtPainter::drawRect( painter, rect ); break; } default: break; } break; } case QwtPickerMachine::PolygonSelection: { if ( rubberBand() == PolygonRubberBand ) painter->drawPolyline( pa ); break; } default: break; } }
/*! Calculate the mask for the rubber band overlay \return Region for the mask \sa QWidget::setMask() */ QRegion QwtPicker::rubberBandMask() const { QRegion mask; if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return mask; } const QPolygon pa = adjustedPoints( d_data->pickedPoints ); QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( d_data->stateMachine ) selectionType = d_data->stateMachine->selectionType(); switch ( selectionType ) { case QwtPickerMachine::NoSelection: case QwtPickerMachine::PointSelection: { if ( pa.count() < 1 ) return mask; const QPoint pos = pa[0]; const int pw = rubberBandPen().width(); const QRect pRect = pickArea().boundingRect().toRect(); switch ( rubberBand() ) { case VLineRubberBand: { mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), pos.x(), pRect.bottom() ), pw ); break; } case HLineRubberBand: { mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), pRect.right(), pos.y() ), pw ); break; } case CrossRubberBand: { mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), pos.x(), pRect.bottom() ), pw ); mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), pRect.right(), pos.y() ), pw ); break; } default: break; } break; } case QwtPickerMachine::RectSelection: { if ( pa.count() < 2 ) return mask; const int pw = rubberBandPen().width(); switch ( rubberBand() ) { case RectRubberBand: { const QRect r = QRect( pa.first(), pa.last() ); mask = qwtMaskRegion( r.normalized(), pw ); break; } case EllipseRubberBand: { const QRect r = QRect( pa.first(), pa.last() ); mask += r.adjusted( -pw, -pw, pw, pw ); break; } default: break; } break; } case QwtPickerMachine::PolygonSelection: { const int pw = rubberBandPen().width(); if ( pw <= 1 ) { // because of the join style we better // return a mask for a pen width <= 1 only const int off = 2 * pw; const QRect r = pa.boundingRect(); mask += r.adjusted( -off, -off, off, off ); } break; } default: break; } return mask; }
//! Update the state of rubber band and tracker label void QwtPicker::updateDisplay() { QWidget *w = parentWidget(); bool showRubberband = false; bool showTracker = false; if ( w && w->isVisible() && d_data->enabled ) { if ( rubberBand() != NoRubberBand && isActive() && rubberBandPen().style() != Qt::NoPen ) { showRubberband = true; } if ( trackerMode() == AlwaysOn || ( trackerMode() == ActiveOnly && isActive() ) ) { if ( trackerPen() != Qt::NoPen && !trackerRect( QFont() ).isEmpty() ) { showTracker = true; } } } QPointer< QwtPickerRubberband > &rw = d_data->rubberBandOverlay; if ( showRubberband ) { if ( rw.isNull() ) { rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter rw->setObjectName( "PickerRubberBand" ); rw->setParent( w ); rw->resize( w->size() ); } if ( d_data->rubberBand <= RectRubberBand ) rw->setMaskMode( QwtWidgetOverlay::MaskHint ); else rw->setMaskMode( QwtWidgetOverlay::AlphaMask ); rw->updateOverlay(); } else { if ( d_data->openGL ) { // Qt 4.8 crashes for a delete if ( !rw.isNull() ) { rw->hide(); rw->deleteLater(); rw = NULL; } } else { delete rw; } } QPointer< QwtPickerTracker > &tw = d_data->trackerOverlay; if ( showTracker ) { if ( tw.isNull() ) { tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter tw->setObjectName( "PickerTracker" ); tw->setParent( w ); tw->resize( w->size() ); } tw->setFont( d_data->trackerFont ); tw->updateOverlay(); } else { if ( d_data->openGL ) { // Qt 4.8 crashes for a delete if ( !tw.isNull() ) { tw->hide(); tw->deleteLater(); tw = NULL; } } else { delete tw; } } }
void QwtCustomPlotPicker::drawRubberBand(QPainter* painter) const { if ( rubberBand() < UserRubberBand ) QwtPlotPicker::drawRubberBand( painter ); else { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QPolygon p = selection(); if ( p.count() != 1 ) return; const QPoint& pt1 = p[0]; const double x_val = plot()->invTransform(QwtPlot::xBottom,pt1.x()); // determine x value (time or dist) // Draw vertical line where curser is const int bot = 400; const int top = 0; painter->drawLine(pt1.x(), bot, pt1.x(), top); // Set pen and fond for all coming text painter->setPen(QColor(Qt::black)); painter->setFont(QFont("Helvetica", 8, QFont::Bold)); // Compute the index based on the x value int idx; if (_x_axis_units == TimeAxis) { painter->drawText(QPoint(pt1.x()-65, 10), "time: " + DataProcessing::minsFromSecs(x_val)); idx = _data_log->indexFromTime(x_val); } else if (_x_axis_units == DistAxis) { painter->drawText(QPoint(pt1.x()-60, 10), "dist: " + DataProcessing::kmFromMeters(x_val,2)); idx = _data_log->indexFromDist(x_val); } // Using the index, determine the curve values const double hr = (int)_data_log->heartRateFltd(idx); const QPoint pt1_hr(pt1.x(),plot()->transform(QwtPlot::yLeft,hr)); const double speed = _data_log->speedFltd(idx); const QPoint pt1_speed(pt1.x(),plot()->transform(QwtPlot::yLeft,speed)); const double alt = (int)_data_log->altFltd(idx); const QPoint pt1_alt(pt1.x(),plot()->transform(QwtPlot::yRight,alt)); const double cadence = (int)_data_log->cadenceFltd(idx); const QPoint pt1_cadence(pt1.x(),plot()->transform(QwtPlot::yLeft,cadence)); const double power = _data_log->powerFltd(idx); const QPoint pt1_power(pt1.x(),plot()->transform(QwtPlot::yLeft,power)); const double temp = _data_log->temp(idx); const QPoint pt1_temp(pt1.x(),plot()->transform(QwtPlot::yLeft,temp)); // Draw highlights on all curves const QPoint offset(8,-5); const QwtPlotItemList item_list = plot()->itemList(QwtPlotCurve::Rtti_PlotCurve); for (int i = 0; i < item_list.size(); ++i) { if (item_list.at(i)->title().text() == "Heart Rate" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_hr.x(), pt1_hr.y(), pt1_hr.x()+6, pt1_hr.y()); painter->drawText(pt1_hr + offset, QString::number(hr,'g',3)); } if (item_list.at(i)->title().text() == "Speed" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_speed.x(), pt1_speed.y(), pt1_speed.x()+6, pt1_speed.y()); painter->drawText(pt1_speed + offset, QString::number(speed,'g',3)); } if (item_list.at(i)->title().text() == "Elevation" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_alt.x(), pt1_alt.y(), pt1_alt.x()+6, pt1_alt.y()); painter->drawText(pt1_alt + offset, QString::number(alt,'g',4)); } if (item_list.at(i)->title().text() == "Cadence" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_cadence.x(), pt1_cadence.y(), pt1_cadence.x()+6, pt1_cadence.y()); painter->drawText(pt1_cadence + offset, QString::number(cadence,'g',3)); } if (item_list.at(i)->title().text() == "Power" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_power.x(), pt1_power.y(), pt1_power.x()+6, pt1_power.y()); painter->drawText(pt1_power + offset, QString::number(power,'g',3)); } if (item_list.at(i)->title().text() == "Temp" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_temp.x(), pt1_temp.y(), pt1_temp.x()+6, pt1_temp.y()); painter->drawText(pt1_temp + offset, QString::number(temp,'g',3)); } // Draw current values on graph labels if (_hr_cb->isChecked()) _hr_cb->setText("Heart Rate " + QString::number(hr,'g',3).leftJustified(3,' ') + " bpm"); else _hr_cb->setText("Heart Rate"); if (_speed_cb->isChecked()) _speed_cb->setText("Speed " + QString::number(speed,'g',3) + " km/h"); else _speed_cb->setText("Speed"); if (_alt_cb->isChecked()) _alt_cb->setText("Elevation " + QString::number(alt,'g',4).leftJustified(4,' ') + " m"); else _alt_cb->setText("Elevation"); if (_cadence_cb->isChecked()) _cadence_cb->setText("Cadence " + QString::number(cadence,'g',3) + " rpm"); else _cadence_cb->setText("Cadence"); if (_power_cb->isChecked()) _power_cb->setText("Power " + QString::number(power,'g',3) + " W"); else _power_cb->setText("Power"); if (_temp_cb->isChecked()) _temp_cb->setText("Temp " + QString::number(temp,'g',3) + " C"); else _temp_cb->setText("Temp"); } } }
QwtText CViewingPlotPicker::trackerTextF(const QPointF& pos) const { const QDateTime DT2006(QDate(2006, 1, 1), QTime(0, 0, 0, 0)); QString text; switch (rubberBand()) { case HLineRubberBand: { if (!m_timeModeY) { text.sprintf("%.4f", pos.y()); } else { double v = pos.y(); qint64 seconds = qint64(v); v -= seconds; int days = seconds/86400; QDateTime dt = DT2006.addDays(days); seconds %= 86400; dt = dt.addSecs(seconds); int milliseconds = int(ceil(v * 10000.0) / 10.0); dt = dt.addMSecs(milliseconds); text = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); } break; } case VLineRubberBand: { if (!m_timeModeX) { text.sprintf("%.4f", pos.x()); } else { double v = pos.x(); qint64 seconds = qint64(v); v -= seconds; int days = seconds/86400; QDateTime dt = DT2006.addDays(days); seconds %= 86400; dt = dt.addSecs(seconds); int milliseconds = int(ceil(v * 10000)/10); dt = dt.addMSecs(milliseconds); text = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); } break; } default: { if ((!m_timeModeX) && (!m_timeModeY)) { text.sprintf("%.4f, %.4f", pos.x(), pos.y()); } else { if (!m_timeModeX) { text.sprintf("%.4f", pos.x()); } else { double v = pos.x(); qint64 seconds = qint64(v); v -= seconds; int days = seconds/86400; QDateTime dt = DT2006.addDays(days); seconds %= 86400; dt = dt.addSecs(seconds); int milliseconds = int(ceil(v * 10000)/10); dt = dt.addMSecs(milliseconds); text = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); } text += QObject::tr(", "); if (!m_timeModeY) { text += QString::number(pos.y(), 'f', 4); } else { double v = pos.y(); qint64 seconds = qint64(v); v -= seconds; int days = seconds/86400; QDateTime dt = DT2006.addDays(days); seconds %= 86400; dt = dt.addSecs(seconds); int milliseconds = int(ceil(v * 10000)/10); dt = dt.addMSecs(milliseconds); text += dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); } } } } return QwtText(text); }