fix 3d plot performance issues

Scrolling up and down the ride files is painfully slow when
3d is compiled in. This patch uses a setActive mechanism in
the same fashion as the pfpv and performance manager tabs.

Additionally, a recent patch to support user preferences for
units added a settings lookup that was called for every point.
This is also fixed.

fixes #16
This commit is contained in:
Mark Liversedge
2010-01-13 18:58:21 +00:00
committed by Sean Rhea
parent 195937f186
commit 4d1783276c
4 changed files with 29 additions and 19 deletions

View File

@@ -1185,6 +1185,9 @@ MainWindow::tabChanged(int index)
{
criticalPowerWindow->setActive(index == 2);
performanceManagerWindow->setActive(tabWidget->widget(index) == performanceManagerWindow);
#ifdef GC_HAVE_QWTPLOT3D
modelWindow->setActive(tabWidget->widget(index) == modelWindow);
#endif
}
void

View File

@@ -196,14 +196,12 @@ class ModelDataProvider : public Function
QString describeType(int, bool);
double maxz, minz;
double cranklength; // used for CPV/AEPF calculation
bool useMetricUnits;
};
double
ModelDataProvider::pointType(const RideFilePoint *point, int type)
{
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
bool metric = settings->value(GC_UNIT).toString() == "Metric";
// return the point value for the given type
switch(type) {
@@ -211,13 +209,13 @@ ModelDataProvider::pointType(const RideFilePoint *point, int type)
case MODEL_CADENCE : return point->cad;
case MODEL_HEARTRATE : return point->hr;
case MODEL_SPEED :
if (metric == true){
if (useMetricUnits == true){
return point->kph;
}else {
return point->kph * MILES_PER_KM;
}
case MODEL_ALT :
if (metric == true){
if (useMetricUnits == true){
return point->alt;
}else {
return point->alt * FEET_PER_METER;
@@ -225,7 +223,7 @@ ModelDataProvider::pointType(const RideFilePoint *point, int type)
case MODEL_TORQUE : return point->nm;
case MODEL_TIME : return point->secs;
case MODEL_DISTANCE :
if (metric == true){
if (useMetricUnits == true){
return point->km;
}else {
return point->km * MILES_PER_KM;
@@ -249,9 +247,6 @@ ModelDataProvider::pointType(const RideFilePoint *point, int type)
QString
ModelDataProvider::describeType(int type, bool longer)
{
boost::shared_ptr<QSettings> settings = GetApplicationSettings();
bool metric = settings->value(GC_UNIT).toString() == "Metric";
// return the point value for the given type
if (longer == true) {
switch(type) {
@@ -260,13 +255,13 @@ ModelDataProvider::describeType(int type, bool longer)
case MODEL_CADENCE : return ("Cadence (rpm)");
case MODEL_HEARTRATE : return ("Heartrate (bpm)");
case MODEL_SPEED :
if (metric == true){
if (useMetricUnits == true){
return ("Speed (kph)");
}else {
return ("Speed (mph)");
}
case MODEL_ALT :
if (metric == true){
if (useMetricUnits == true){
return ("Altitude (meters)");
}else {
return ("Altitude (feet)");
@@ -274,7 +269,7 @@ ModelDataProvider::describeType(int type, bool longer)
case MODEL_TORQUE : return ("Torque (N)");
case MODEL_TIME : return ("Elapsed Time (secs)");
case MODEL_DISTANCE :
if (metric == true){
if (useMetricUnits == true){
return ("Elapsed Distance (km)");
}else {
return ("Elapsed Distance (mi)");
@@ -324,6 +319,15 @@ ModelDataProvider::describeType(int type, bool longer)
*----------------------------------------------------------------------*/
ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *settings) : Function(plot)
{
// get application settings
cranklength = 0.0;
useMetricUnits = false; // the default for Non-Europeans ;-)
boost::shared_ptr<QSettings> appsettings = GetApplicationSettings();
if (appsettings) {
cranklength = appsettings->value(GC_CRANKLENGTH).toDouble() / 1000.0;
useMetricUnits = appsettings->value(GC_UNIT).toString() == "Metric";
}
// if there are no settings or incomplete settings
// create a null data plot
if (settings == NULL || settings->ride == NULL || settings->ride->ride() == NULL ||
@@ -336,11 +340,6 @@ ModelDataProvider::ModelDataProvider (BasicModelPlot &plot, ModelSettings *setti
return;
}
cranklength = 0.0;
boost::shared_ptr<QSettings> appsettings = GetApplicationSettings();
if (appsettings) {
cranklength = appsettings->value(GC_CRANKLENGTH).toDouble() / 1000.0;
}
// if its not setup or no settings exist default to 175mm cranks
if (cranklength == 0.0) cranklength = 0.175;

View File

@@ -46,7 +46,7 @@ ModelWindow::addStandardChannels(QComboBox *box)
//box->addItem(tr("Longitude"), MODEL_LONG); //XXX weird values make the plot ugly
}
ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) : QWidget(parent), home(home), main(parent)
ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) : QWidget(parent), home(home), main(parent), active(false)
{
// Layouts
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -182,11 +182,17 @@ ModelWindow::ModelWindow(MainWindow *parent, const QDir &home) : QWidget(parent)
connect(zpane, SIGNAL(valueChanged(int)), this, SLOT(setZPane(int)));
}
void
ModelWindow::setActive(bool active)
{
this->active = active;
if (active) setData(true);
}
void
ModelWindow::rideSelected()
{
ride = main->rideItem();
setData(true);
if (active) setData(true);
}
void

View File

@@ -52,6 +52,7 @@ class ModelWindow : public QWidget
public:
ModelWindow(MainWindow *, const QDir &);
void setActive(bool);
public slots:
void rideSelected();
@@ -75,6 +76,7 @@ class ModelWindow : public QWidget
QDir home;
MainWindow *main;
bool useMetricUnits;
bool active;
bool dirty; // settings changed but not reploted
ModelSettings settings; // last used settings