RealtimeChart::RealtimeChart(const char* ytitle, const char* mainTitle, const char* labela, const char* labelb, QWidget *parent) : QWidget(parent), m_yTitle(ytitle), m_mainTitle(mainTitle), m_labelA(labela), m_labelB(labelb) { // Chart Viewer m_ChartViewer = new QChartViewer(this); m_ChartViewer->setGeometry(0, 0, 645, 270); m_ChartViewer->setFrameShape(QFrame::NoFrame); connect(m_ChartViewer, SIGNAL(viewPortChanged()), SLOT(drawChart())); // Clear data arrays to Chart::NoValue for (int i = 0; i < sampleSize; ++i) m_timeStamps[i] = m_dataSeriesA[i] = m_dataSeriesB[i] = m_dataSeriesC[i] = Chart::NoValue; // Set m_nextDataTime to the current time. It is used by the real time random number // generator so it knows what timestamp should be used for the next data point. m_nextDataTime = QDateTime::currentDateTime(); // Set up the data acquisition mechanism. In this demo, we just use a timer to get a // sample every 250ms. QTimer *dataRateTimer = new QTimer(this); dataRateTimer->start(DataInterval); connect(dataRateTimer, SIGNAL(timeout()), SLOT(getData())); // Set up the chart update timer m_ChartUpdateTimer = new QTimer(this); connect(m_ChartUpdateTimer, SIGNAL(timeout()), SLOT(updateChart())); m_ChartUpdateTimer->start(1000); }
void PieChart3D::paintEvent(QPaintEvent *event) { Q_UNUSED(event) QPainter painter( viewport() ); painter.save(); painter.setRenderHint( QPainter::Antialiasing ); updateChart(); if ( myRender != Plain ) { paintExternal( painter, true ); paintSides( painter ); paintExternal( painter, false ); } else { paintExternal( painter, false ); } for ( int i = 0; i < myAngles.count() - 2; i+=2 ) { QModelIndex index = this->model()->index( i/2, 0 ); QColor color( this->model()->data( index, Qt::DecorationRole ).toString() ); if ( !color.isValid() ) { color = Marb::predefinedColor( i/2 ); } bool isSelected = this->selectionModel()->selectedIndexes().contains( index ) || this->currentIndex() == index; if ( mySplitted == false ) { paintPart( painter, myAngles[i], myAngles[i + 1], color, isSelected ); } else { paintPartSplitted( painter, myAngles[i], myAngles[i + 1], color, isSelected ); } } painter.restore(); }
void CChartTable::slotVesselPointDestroyed( QObject* _pqObject ) { if( !_pqObject || (QObject*)poVesselPointSynchronize != _pqObject ) return; resetVesselPointSynchronize(); QVCTRuntime::usePointerOverlay()->forceRedraw(); updateChart(); }
void CChartTable::slotPointerTarget( bool _bEnable ) { if( bIgnoreUpdate ) return; enablePointerTarget( _bEnable ); QVCTRuntime::usePointerOverlay()->forceRedraw(); updateChart(); }
void HistogramWindow::setFilter(QStringList list) { isfiltered = true; files = list; stale = true; updateChart(); repaint(); }
void HistogramWindow::clearFilter() { isfiltered = false; files.clear(); stale = true; updateChart(); repaint(); }
void CChartTable::slotPointerPathSingle( bool _bEnable ) { if( bIgnoreUpdate ) return; QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange(); __pqMutexDataChange->lock(); enablePointerPathSingle( _bEnable ); __pqMutexDataChange->unlock(); QVCTRuntime::usePointerOverlay()->forceRedraw(); updateChart(); }
bool CChartTable::handlerWheelEvent( QWheelEvent* _pqWheelEvent ) { if( QTabWidget::currentIndex() < 0 ) return false; int __iMouseDelta = _pqWheelEvent->delta() / 120; if( !__iMouseDelta ) return true; bool __bIncrease = true; if( __iMouseDelta < 0 ) { __bIncrease = false; __iMouseDelta = -__iMouseDelta; } for( int __i=0; __i<__iMouseDelta; __i++ ) stepScale( __bIncrease, true ); updateChart(); return true; }
void CChartTable::setOverlayObjectSelected( COverlayObject* _poOverlayObject ) { bool __bRedraw = poOverlayObjectSelected != _poOverlayObject; poOverlayObjectSelected = _poOverlayObject; if( __bRedraw ) { QVCTRuntime::useLandmarkOverlay()->forceRedraw(); QVCTRuntime::useRouteOverlay()->forceRedraw(); QVCTRuntime::useVesselOverlay()->forceRedraw(); QVCTRuntime::useTrackOverlay()->forceRedraw(); updateChart(); } }
void HistogramWindow::dateRangeChanged(DateRange dateRange) { // if we're using a custom one lets keep it if (rangemode && (useCustom || useToToday)) dateRange = custom; // has it changed? if (dateRange.from != cfrom || dateRange.to != cto) stale = true; if (!amVisible() || !stale) return; updateChart(); }
void CChartTable::slotLoad() { if( bProjectModified && !QVCTRuntime::useMainWindow()->deleteConfirm( tr("Unsaved project data") ) ) return; QString __qsFilename = QVCTRuntime::useMainWindow()->fileDialog( QVCT::OPEN, tr("Load Project"), tr("QVCT Files")+" (*.qvct)" ); if( __qsFilename.isEmpty() ) return; if( !QVCTRuntime::useMainWindow()->fileCheck( QVCT::OPEN, __qsFilename ) ) return; QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange(); __pqMutexDataChange->lock(); clear(); __pqMutexDataChange->unlock(); load( __qsFilename ); updateChart(); bProjectModified = false; }
// // User selected a new interval // void HistogramWindow::intervalSelected() { if (!amVisible()) return; RideItem *ride = myRideItem; // null? or not plotting current ride, ignore signal if (!ride || rangemode) return; // update interval = true; updateChart(); }
// // Set Bin Width property by setting the slider // void HistogramWindow::setBin(double x) { if (bactive) return; bactive = true; binWidthSlider->setValue(x/getDelta()); rBinSlider->setValue(x/getDelta()); binWidthLineEdit->setText(QString("%1").arg(x, 0, 'f', getDigits())); rBinEdit->setText(QString("%1").arg(x, 0, 'f', getDigits())); powerHist->setBinWidth(x); bactive = false; // redraw stale = true; updateChart(); }
// // A new ride was selected // void HistogramWindow::rideSelected() { if (!amVisible()) return; RideItem *ride = myRideItem; if (!ride || (rangemode && !stale)) return; if (rangemode) { // get range that applies to this ride powerRange = context->athlete->zones()->whichRange(ride->dateTime.date()); hrRange = context->athlete->hrZones()->whichRange(ride->dateTime.date()); } // update updateChart(); }
// // When user selects a different data series // void HistogramWindow::seriesChanged() { // series changed so tell power hist powerHist->setSeries(static_cast<RideFile::SeriesType>(seriesCombo->itemData(seriesCombo->currentIndex()).toInt())); powerHist->setDelta(getDelta()); powerHist->setDigits(getDigits()); // now update the slider stepper and linedit setBinEditors(); // set an initial bin width value setBin(getDelta()); // replot stale = true; updateChart(); }
void HistogramWindow::treeSelectionTimeout() { // new metric chosen, so set up all the bin width, line edit // delta, precision etc powerHist->setSeries(RideFile::none); powerHist->setDelta(getDelta()); powerHist->setDigits(getDigits()); // now update the slider stepper and linedit setBinEditors(); // initial value -- but only if need to double minbinw = getDelta(); double maxbinw = getDelta() * 100; double current = binWidthLineEdit->text().toDouble(); if (current < minbinw || current > maxbinw) setBin(getDelta()); // replot updateChart(); }
bool CChartTable::handlerGestureEvent( QGestureEvent* _pqGestureEvent ) { if( QTabWidget::currentIndex() < 0 ) return false; bool __bReturn = false; QGesture* __pqGesture = _pqGestureEvent->gesture( Qt::PinchGesture ); if( __pqGesture ) { // NOTE: To provide a good "user experience", we must use the underlying // chart's linear zoom factor rather than the UI's logarithmic scale // factor. QPinchGesture* __pqPinchGesture = static_cast<QPinchGesture *>(__pqGesture); switch( __pqPinchGesture->state() ) { case Qt::GestureStarted: __pqPinchGesture->setGestureCancelPolicy( QGesture::CancelAllInContext ); _pqGestureEvent->accept( __pqPinchGesture ); fdGestureZoomReference = ((CChart*)QTabWidget::currentWidget())->getZoom(); break; case Qt::GestureUpdated: case Qt::GestureFinished: if( __pqPinchGesture->changeFlags() & QPinchGesture::ScaleFactorChanged ) { setZoom( fdGestureZoomReference * __pqPinchGesture->totalScaleFactor() ); updateChart(); } break; default:; } __bReturn = true; } return __bReturn; }
void Chart::processGrid(Grid *grid) { if (active) { /*MyVector3D *vorticities = 0; double *streams = 0;*/ if (grid == 0) { grid = lastGrid; /*if (grid != 0) { vorticities = grid->computeVorticity(); streams = grid->computeStream(Singleton::instance()->getPainterConfig()->getStreamIntegrationX(), Singleton::instance()->getPainterConfig()->getStreamIntegrationY()); }*/ } else { lastGrid = grid; /*vorticities = grid->computeVorticity(); streams = grid->computeStream(Singleton::instance()->getPainterConfig()->getStreamIntegrationX(), Singleton::instance()->getPainterConfig()->getStreamIntegrationY());*/ if (ui->chartType->currentText() == "-log(DeltaP)") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), -log10(grid->getSimulation()->getDeltaP()))); } if (ui->chartType->currentText() == "Drag") { grid->computeDrag(); if (grid->getDrags() > 0) { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), grid->getDrag(0).norm())); } } if (ui->chartType->currentText() != "" && ui->time->isChecked()) { int x = ui->xValue->text().toInt() - 1, y = ui->yValue->text().toInt() - 1, z = ui->zValue->text().toInt() - 1; BaseCell *cell = grid->getGrid(y, x, z); if (cell != 0 && cell->isFluid()) { if (ui->chartType->currentText() == "Pressure") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), cell->getP(ui->other->text().toInt()))); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), cell->getU(ui->other->text().toInt()).norm())); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "x") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), cell->getU(ui->other->text().toInt()).getX())); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "y") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), cell->getU(ui->other->text().toInt()).getY())); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "z") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), cell->getU(ui->other->text().toInt()).getZ())); /*} else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), vorticities[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()].norm())); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "x") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), vorticities[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()].getX())); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "y") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), vorticities[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()].getY())); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "z") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), vorticities[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()].getZ())); } else if (ui->chartType->currentText() == "Stream") { temp.push_back(XYPoint(grid->getSimulation()->getIterations(), streams[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()]));*/ } } } } std::list<XYPoint> points; if (grid != 0) { for (int var = 0; var < (ui->x->isChecked() ? grid->getConfig()->getWidth() : (ui->y->isChecked() ? grid->getConfig()->getHeight() : ui->z->isChecked() ? grid->getConfig()->getLength() : 0)); var++) { int y = (ui->y->isChecked() ? var : ui->yValue->text().toInt() - 1); int x = (ui->x->isChecked() ? var : ui->xValue->text().toInt() - 1); int z = (ui->z->isChecked() ? var : ui->zValue->text().toInt() - 1); BaseCell *lattice = (grid->getGrid(y, x, z)); if (lattice != 0 && lattice->isFluid()) { /*MyVector3D vorticity = vorticities[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()]; double stream = streams[x + y * grid->getConfig()->getWidth() + z * grid->getConfig()->getWidth() * grid->getConfig()->getHeight()];*/ double value = 0; if (ui->chartType->currentText() == "Pressure") { value = lattice->getP(ui->other->text().toInt()); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "") { value = lattice->getU(ui->other->text().toInt()).norm(); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "x") { value = lattice->getU(ui->other->text().toInt()).getX(); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "y") { value = lattice->getU(ui->other->text().toInt()).getY(); } else if (ui->chartType->currentText() == "Velocity" && ui->axis->currentText() == "z") { value = lattice->getU(ui->other->text().toInt()).getZ(); /*} else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "") { value = vorticity.norm(); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "x") { value = vorticity.getX(); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "y") { value = vorticity.getY(); } else if (ui->chartType->currentText() == "Vorticity" && ui->axis->currentText() == "z") { value = vorticity.getZ(); } else if (ui->chartType->currentText() == "Stream") { value = stream;*/ } points.push_back(XYPoint(var, value)); } } if (ui->chartType->currentText() == "-log(DeltaP)" || ui->chartType->currentText() == "Drag" || ui->time->isChecked()) { points = temp; } updateChart(points, curve); ui->chart->replot(); } //delete[] vorticities; } }
void HistogramWindow::forceReplot() { stale = true; if (amVisible()) updateChart(); }
void CChartTable::slotScaleFit() { if( bIgnoreUpdate ) return; setScaleFit(); updateChart(); }
bool CChartTable::handlerMouseEvent( QMouseEvent* _pqMouseEvent ) { if( QTabWidget::currentIndex() < 0 ) return false; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QPointF __qPointFMouse = _pqMouseEvent->localPos(); #else QPointF __qPointFMouse = _pqMouseEvent->posF(); #endif int __iMouseButton = _pqMouseEvent->button(); switch( _pqMouseEvent->type() ) { case QEvent::MouseButtonDblClick: switch( __iMouseButton ) { case Qt::LeftButton: { CChart* __poChart = (CChart*)QTabWidget::currentWidget(); CVesselPoint* __poVesselPoint = (CVesselPoint*)QVCTRuntime::useVesselOverlay()->matchScrPosition( __poChart, __qPointFMouse ); if( __poVesselPoint ) { __poVesselPoint->toggleMultiSelected(); break; } CTrackPoint* __poTrackPoint = (CTrackPoint*)QVCTRuntime::useTrackOverlay()->matchScrPosition( __poChart, __qPointFMouse ); if( __poTrackPoint ) { __poTrackPoint->toggleMultiSelected(); break; } CRoutePoint* __poRoutePoint = (CRoutePoint*)QVCTRuntime::useRouteOverlay()->matchScrPosition( __poChart, __qPointFMouse ); if( __poRoutePoint ) { __poRoutePoint->toggleMultiSelected(); break; } CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)QVCTRuntime::useLandmarkOverlay()->matchScrPosition( __poChart, __qPointFMouse ); if( __poLandmarkPoint ) { __poLandmarkPoint->toggleMultiSelected(); break; } } setScaleActual(); updateChart(); break; case Qt::RightButton: setScaleActual(); updateChart(); break; default:; // we don't care about other buttons } break; case QEvent::MouseButtonPress: switch( __iMouseButton ) { case Qt::LeftButton: bMousePressed = true; qPointFMouse = __qPointFMouse; break; case Qt::RightButton: { CChart* __poChart = (CChart*)QTabWidget::currentWidget(); setGeoPosition( __poChart->toGeoPosition( __qPointFMouse ) ); updateChart(); } break; default:; // we don't care about other buttons } break; case QEvent::MouseButtonRelease: if( __iMouseButton == Qt::LeftButton ) { bMousePressed = false; if( bMouseDrag ) { bMouseDrag = false; dragScrPosition( __qPointFMouse - qPointFMouse ); updateChart(); } else { CChart* __poChart = (CChart*)QTabWidget::currentWidget(); // Match mouse position with overlays' item CPointerOverlay* __poPointerOverlay = QVCTRuntime::usePointerOverlay(); CPointerPoint* __poPointerPoint = __poPointerOverlay->usePointerPoint(); bool __bPointerTargetPending = bPointerTarget ? __poPointerOverlay->usePointerTarget()->CDataPosition::operator==( CDataPosition::UNDEFINED ) : false; CDataPosition __oGeoPosition; do { __poPointerPoint->resetPosition(); __poPointerOverlay->forceRedraw(); if( !poOverlayPointMove ) { // ... vessel CVesselOverlay* __poVesselOverlay = QVCTRuntime::useVesselOverlay(); CVesselPoint* __poVesselPoint = (CVesselPoint*)__poVesselOverlay->matchScrPosition( __poChart, __qPointFMouse ); if( __poVesselPoint ) { __oGeoPosition = *__poVesselPoint; if( __bPointerTargetPending || bPointerPath || bPointerPathSingle ) break; __poVesselOverlay->setCurrentItem( __poVesselPoint ); __poVesselPoint->showDetail(); break; } // ... track CTrackOverlay* __poTrackOverlay = QVCTRuntime::useTrackOverlay(); CTrackPoint* __poTrackPoint = (CTrackPoint*)__poTrackOverlay->matchScrPosition( __poChart, __qPointFMouse ); if( __poTrackPoint ) { __oGeoPosition = *__poTrackPoint; if( __bPointerTargetPending || bPointerPath || bPointerPathSingle ) break; __poTrackOverlay->setCurrentItem( __poTrackPoint ); __poTrackPoint->showDetail(); break; } // ... route CRouteOverlay* __poRouteOverlay = QVCTRuntime::useRouteOverlay(); CRoutePoint* __poRoutePoint = (CRoutePoint*)__poRouteOverlay->matchScrPosition( __poChart, __qPointFMouse ); if( __poRoutePoint ) { __oGeoPosition = *__poRoutePoint; if( __bPointerTargetPending || bPointerPath || bPointerPathSingle ) break; __poRouteOverlay->setCurrentItem( __poRoutePoint ); __poRoutePoint->showDetail(); break; } // ... landmark CLandmarkOverlay* __poLandmarkOverlay = QVCTRuntime::useLandmarkOverlay(); CLandmarkPoint* __poLandmarkPoint = (CLandmarkPoint*)__poLandmarkOverlay->matchScrPosition( __poChart, __qPointFMouse ); if( __poLandmarkPoint ) { __oGeoPosition = *__poLandmarkPoint; if( __bPointerTargetPending || bPointerPath || bPointerPathSingle ) break; __poLandmarkOverlay->setCurrentItem( __poLandmarkPoint ); __poLandmarkPoint->showDetail(); break; } } // ... pointer __oGeoPosition = __poChart->toGeoPosition( __qPointFMouse ); if( poOverlayPointMove || __bPointerTargetPending ) break; __poPointerPoint->setPosition( __oGeoPosition ); __poPointerOverlay->showDetail( __poPointerOverlay->usePointerPoint() ); __poPointerOverlay->forceRedraw(); __poChart->update(); } while( false ); // Overlay point move if( poOverlayPointMove ) { poOverlayPointMove->setPosition( CDataPosition( __oGeoPosition.getLongitude(), __oGeoPosition.getLatitude(), poOverlayPointMove->getElevation() ) ); poOverlayPointMove->showDetail(); poOverlayPointMove->useOverlay()->forceRedraw(); __poChart->update(); break; } // Set pointer target if( setPointerTarget( __oGeoPosition ) ) break; // Extend pointer path if( extendPointerPath( __oGeoPosition ) ) break; } } break; case QEvent::MouseMove: if( bMouseDrag ) { dragScrPosition( qPointFMouse - __qPointFMouse ); updateChart(); qPointFMouse = __qPointFMouse; } else if( bMousePressed ) { QPointF __qPointFDelta = __qPointFMouse - qPointFMouse; if( __qPointFDelta.x()*__qPointFDelta.x() + __qPointFDelta.y()*__qPointFDelta.y() > 100 ) bMouseDrag = true; } break; default: return false; // Other events don't get here but better safe than sorry } return true; }
void HistogramWindow::switchMode() { if (!rangemode) return; // ! only valid in rangemode if (data->isChecked()) { // hide all the metric controls blankLabel1->hide(); blankLabel2->hide(); distMetricTree->hide(); totalMetricTree->hide(); metricLabel1->hide(); metricLabel2->hide(); colorLabel->hide(); colorButton->hide(); // show all the data series controls comboLabel->show(); seriesCombo->show(); blankLabel3->show(); blankLabel4->show(); blankLabel5->show(); blankLabel6->show(); showSumY->show(); showLabel->show(); showLnY->show(); showZeroes->show(); shadeZones->show(); showInZones->show(); // select the series.. seriesChanged(); } else { // hide all the data series controls comboLabel->hide(); seriesCombo->hide(); blankLabel3->hide(); blankLabel4->hide(); blankLabel5->hide(); blankLabel6->hide(); showSumY->hide(); showLabel->hide(); showLnY->hide(); showZeroes->hide(); shadeZones->hide(); showInZones->hide(); // show all the metric controls blankLabel1->show(); blankLabel2->show(); metricLabel1->show(); metricLabel2->show(); distMetricTree->show(); totalMetricTree->show(); colorLabel->show(); colorButton->show(); // select the series.. (but without the half second delay) treeSelectionTimeout(); } stale = true; updateChart(); // to whatever is currently selected. }
//---------------------------------------------------------------------------- // Set Transaction Filter //---------------------------------------------------------------------------- void ReportPieChart::setTransactionFilter( const Transaction::FilterType& aFilter ) { hideDisplayLabel(); mFilter = aFilter; mDataList.clear(); switch( mChartType ) { case ASSET_BY_ACCOUNT: case DEBT_BY_ACCOUNT: { Month* month = Month::getMonth( aFilter.mEndDate ); if( month ) { for( int i = 0; i < aFilter.mAccountList.size() && i < Account::sAccountList.size(); i++ ) { if( aFilter.mAccountList[i] ) { Account* account = Account::sAccountList[i]; bool accountExist = false; float netWorth = month->getNetWorth( account, &accountExist ); if( accountExist ) { bool allow = false; if( netWorth >= 0 ) { allow = (mChartType == ASSET_BY_ACCOUNT); } else { allow = (mChartType == DEBT_BY_ACCOUNT); netWorth = -netWorth; } if( allow ) { PieDataType data; data.mName = account->getName(); data.mValue = netWorth; mDataList.append( data ); } } } } } } break; case INCOME_BY_CATEGORY: case EXPENSE_BY_CATEGORY: { QList<Transaction*> transactionList = Transaction::filterTransactions( TransactionManager::sTransactionList, aFilter ); int categoryCnt = ( mGroupCategories ) ? (int)Category::PARENT_CATEGORY_TYPE_CNT : (int)Category::getCategoryCount(); QVector<float> categoryList( categoryCnt, 0 ); for( int i = 0; i < transactionList.size(); i++ ) { Transaction* transaction = transactionList[i]; Category::TransactionType transType = transaction->getTransactionType(); int categoryIdx = ( mGroupCategories ) ? transaction->getParentCategory() : transaction->getCategory(); if( ( mChartType == INCOME_BY_CATEGORY && transType == Category::TRANSACTION_TYPE_INCOME ) || ( mChartType == EXPENSE_BY_CATEGORY && transType == Category::TRANSACTION_TYPE_EXPENSE ) || ( mShowTransfers && transType == Category::TRANSACTION_TYPE_TRANSFER ) ) { categoryList[categoryIdx] += transaction->getAmount(); } } for( int i = 0; i < categoryList.size(); i++ ) { bool addItem = ( (mChartType == INCOME_BY_CATEGORY && categoryList[i] > 0) || (mChartType == EXPENSE_BY_CATEGORY && categoryList[i] < 0) ); if( addItem ) { PieDataType data; data.mName = ( mGroupCategories ) ? Category::getParentCategoryText( (Category::ParentCategoryType)i ) : Category::getCategoryText( (Category::CategoryIdxType)i, true ); data.mValue = categoryList[i]; mDataList.append( data ); } } } break; default: break; } updateChart(); } // ReportPieChart::setTransactionFilter
void CChartTable::showElevation( bool _bShow ) { if( QTabWidget::currentIndex() < 0 ) return; ((CChart*)QTabWidget::currentWidget())->showElevation( _bShow ); updateChart(); }
// // Constructor // HistogramWindow::HistogramWindow(Context *context, bool rangemode) : GcChartWindow(context), context(context), stale(true), source(NULL), active(false), bactive(false), rangemode(rangemode), useCustom(false), useToToday(false), precision(99) { QWidget *c = new QWidget; c->setContentsMargins(0,0,0,0); QFormLayout *cl = new QFormLayout(c); cl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); cl->setSpacing(5); setControls(c); // // reveal controls widget // // reveal controls rWidth = new QLabel(tr("Bin Width")); rBinEdit = new QLineEdit(); rBinEdit->setFixedWidth(40); rBinSlider = new QSlider(Qt::Horizontal); rBinSlider->setTickPosition(QSlider::TicksBelow); rBinSlider->setTickInterval(10); rBinSlider->setMinimum(1); rBinSlider->setMaximum(100); rShade = new QCheckBox(tr("Shade zones")); rZones = new QCheckBox(tr("Show in zones")); // layout reveal controls QHBoxLayout *r = new QHBoxLayout; r->setContentsMargins(0,0,0,0); r->addStretch(); r->addWidget(rWidth); r->addWidget(rBinEdit); r->addWidget(rBinSlider); QVBoxLayout *v = new QVBoxLayout; v->addWidget(rShade); v->addWidget(rZones); r->addSpacing(20); r->addLayout(v); r->addStretch(); setRevealLayout(r); // plot QVBoxLayout *vlayout = new QVBoxLayout; vlayout->setSpacing(10); powerHist = new PowerHist(context); vlayout->addWidget(powerHist); setChartLayout(vlayout); #ifdef GC_HAVE_LUCENE // search filter box isfiltered = false; searchBox = new SearchFilterBox(this, context); connect(searchBox, SIGNAL(searchClear()), this, SLOT(clearFilter())); connect(searchBox, SIGNAL(searchResults(QStringList)), this, SLOT(setFilter(QStringList))); if (!rangemode) searchBox->hide(); else { cl->addRow(new QLabel(tr("Filter")), searchBox); cl->addWidget(new QLabel("")); } #endif // date selection dateSetting = new DateSettingsEdit(this); if (rangemode) { cl->addRow(new QLabel(tr("Date Range")), dateSetting); cl->addWidget(new QLabel("")); // spacing // default to data series! data = new QRadioButton(tr("Ride Data Samples")); metric = new QRadioButton(tr("Ride Metrics")); data->setChecked(true); metric->setChecked(false); QHBoxLayout *radios = new QHBoxLayout; radios->addWidget(data); radios->addWidget(metric); cl->addRow(new QLabel(tr("Plot")), radios); connect(data, SIGNAL(toggled(bool)), this, SLOT(dataToggled(bool))); connect(metric, SIGNAL(toggled(bool)), this, SLOT(metricToggled(bool))); } // data series seriesCombo = new QComboBox(); addSeries(); if (rangemode) comboLabel = new QLabel(""); else comboLabel = new QLabel(tr("Data Series")); cl->addRow(comboLabel, seriesCombo); if (rangemode) { // TOTAL METRIC totalMetricTree = new QTreeWidget; #ifdef Q_OS_MAC totalMetricTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif totalMetricTree->setColumnCount(2); totalMetricTree->setColumnHidden(1, true); totalMetricTree->setSelectionMode(QAbstractItemView::SingleSelection); totalMetricTree->header()->hide(); //totalMetricTree->setFrameStyle(QFrame::NoFrame); //totalMetricTree->setAlternatingRowColors (true); totalMetricTree->setIndentation(5); totalMetricTree->setContextMenuPolicy(Qt::CustomContextMenu); // ALL METRIC distMetricTree = new QTreeWidget; #ifdef Q_OS_MAC distMetricTree->setAttribute(Qt::WA_MacShowFocusRect, 0); #endif distMetricTree->setColumnCount(2); distMetricTree->setColumnHidden(1, true); distMetricTree->setSelectionMode(QAbstractItemView::SingleSelection); distMetricTree->header()->hide(); //distMetricTree->setFrameStyle(QFrame::NoFrame); distMetricTree->setIndentation(5); distMetricTree->setContextMenuPolicy(Qt::CustomContextMenu); // add them all const RideMetricFactory &factory = RideMetricFactory::instance(); for (int i = 0; i < factory.metricCount(); ++i) { const RideMetric *m = factory.rideMetric(factory.metricName(i)); QTextEdit processHTML(m->name()); // process html encoding of(TM) QString processed = processHTML.toPlainText(); QTreeWidgetItem *add; add = new QTreeWidgetItem(distMetricTree->invisibleRootItem()); add->setText(0, processed); add->setText(1, m->symbol()); // we only want totalising metrics if (m->type() != RideMetric::Total) continue; add = new QTreeWidgetItem(totalMetricTree->invisibleRootItem()); add->setText(0, processed); add->setText(1, m->symbol()); } QHBoxLayout *labels = new QHBoxLayout; metricLabel1 = new QLabel(tr("Total (x-axis)")); labels->addWidget(metricLabel1); metricLabel1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); metricLabel2 = new QLabel(tr("Distribution (y-axis)")); metricLabel2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); labels->addWidget(metricLabel2); cl->addRow((blankLabel1=new QLabel("")), labels); QHBoxLayout *trees = new QHBoxLayout; trees->addWidget(totalMetricTree); trees->addWidget(distMetricTree); cl->addRow((blankLabel2 = new QLabel("")), trees); colorButton = new ColorButton(this, "Color", QColor(Qt::blue)); colorLabel = new QLabel(tr("Color")); connect(colorButton, SIGNAL(colorChosen(QColor)), this, SLOT(updateChart())); cl->addRow(colorLabel, colorButton); // by default select number of rides by duration // which are the metrics workout_time and ride_count selectTotal("ride_count"); selectMetric("workout_time"); } showSumY = new QComboBox(); showSumY->addItem(tr("Absolute Time")); showSumY->addItem(tr("Percentage Time")); showLabel = new QLabel(tr("Show")); cl->addRow(showLabel, showSumY); showLnY = new QCheckBox; showLnY->setText(tr("Log Y")); cl->addRow(blankLabel3 = new QLabel(""), showLnY); showZeroes = new QCheckBox; showZeroes->setText(tr("With zeros")); cl->addRow(blankLabel4 = new QLabel(""), showZeroes); shadeZones = new QCheckBox; shadeZones->setText(tr("Shade zones")); cl->addRow(blankLabel5 = new QLabel(""), shadeZones); showInZones = new QCheckBox; showInZones->setText(tr("Show in zones")); cl->addRow(blankLabel6 = new QLabel(""), showInZones); // bin width QHBoxLayout *binWidthLayout = new QHBoxLayout; QLabel *binWidthLabel = new QLabel(tr("Bin width"), this); binWidthLineEdit = new QLineEdit(this); binWidthLineEdit->setFixedWidth(40); binWidthLayout->addWidget(binWidthLineEdit); binWidthSlider = new QSlider(Qt::Horizontal); binWidthSlider->setTickPosition(QSlider::TicksBelow); binWidthSlider->setTickInterval(1); binWidthSlider->setMinimum(1); binWidthSlider->setMaximum(100); binWidthLayout->addWidget(binWidthSlider); cl->addRow(binWidthLabel, binWidthLayout); // sort out default values setBinEditors(); showLnY->setChecked(powerHist->islnY()); showZeroes->setChecked(powerHist->withZeros()); shadeZones->setChecked(powerHist->shade); binWidthSlider->setValue(powerHist->binWidth()); rBinSlider->setValue(powerHist->binWidth()); rShade->setChecked(powerHist->shade); // fixup series selected by default seriesChanged(); // hide/show according to default mode switchMode(); // does nothing if not in rangemode // set the defaults etc updateChart(); // the bin slider/input update each other // only the input box triggers an update to the chart connect(binWidthSlider, SIGNAL(valueChanged(int)), this, SLOT(setBinWidthFromSlider())); connect(binWidthLineEdit, SIGNAL(editingFinished()), this, SLOT(setBinWidthFromLineEdit())); connect(rBinSlider, SIGNAL(valueChanged(int)), this, SLOT(setrBinWidthFromSlider())); connect(rBinEdit, SIGNAL(editingFinished()), this, SLOT(setrBinWidthFromLineEdit())); connect(rZones, SIGNAL(stateChanged(int)), this, SLOT(setZoned(int))); connect(rShade, SIGNAL(stateChanged(int)), this, SLOT(setShade(int))); // when season changes we need to retrieve data from the cache then update the chart if (rangemode) { connect(this, SIGNAL(dateRangeChanged(DateRange)), this, SLOT(dateRangeChanged(DateRange))); connect(dateSetting, SIGNAL(useCustomRange(DateRange)), this, SLOT(useCustomRange(DateRange))); connect(dateSetting, SIGNAL(useThruToday()), this, SLOT(useThruToday())); connect(dateSetting, SIGNAL(useStandardRange()), this, SLOT(useStandardRange())); connect(distMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged())); connect(totalMetricTree, SIGNAL(itemSelectionChanged()), this, SLOT(treeSelectionChanged())); lagger = new QTimer; lagger->setSingleShot(true); connect(lagger, SIGNAL(timeout()), this, SLOT(treeSelectionTimeout())); } else { dateSetting->hide(); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(context, SIGNAL(intervalSelected()), this, SLOT(intervalSelected())); } // if any of the controls change we pass the chart everything connect(showLnY, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(showZeroes, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(seriesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(seriesChanged())); connect(showInZones, SIGNAL(stateChanged(int)), this, SLOT(setZoned(int))); connect(showInZones, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(shadeZones, SIGNAL(stateChanged(int)), this, SLOT(setShade(int))); connect(shadeZones, SIGNAL(stateChanged(int)), this, SLOT(updateChart())); connect(showSumY, SIGNAL(currentIndexChanged(int)), this, SLOT(updateChart())); connect(context->athlete, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); connect(context, SIGNAL(configChanged()), powerHist, SLOT(configChanged())); connect(context, SIGNAL(rideAdded(RideItem*)), this, SLOT(rideAddorRemove(RideItem*))); connect(context, SIGNAL(rideDeleted(RideItem*)), this, SLOT(rideAddorRemove(RideItem*))); connect(context, SIGNAL(filterChanged()), this, SLOT(forceReplot())); connect(context, SIGNAL(homeFilterChanged()), this, SLOT(forceReplot())); }
//---------------------------------------------------------------------------- // Sort Chart //---------------------------------------------------------------------------- void ReportPieChart::sortChart( SortType aSortType ) { mSortType = aSortType; updateChart(); } // ReportPieChart::sortChart