mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
RideCacheModel Part 2 of 3
.. add/remove ride now works .. fixed metric value in data() .. need to test (especially with the diary window and new athlete with zero rides and then import, add, delete, change, sort merge, split etc and push update to fix such bugs in Part 3
This commit is contained in:
@@ -32,6 +32,8 @@ RideCacheModel::RideCacheModel(Context *context, RideCache *cache) : QAbstractTa
|
||||
connect(context, SIGNAL(refreshStart()), this, SLOT(refreshStart()));
|
||||
connect(context, SIGNAL(refreshEnd()), this, SLOT(refreshEnd()));
|
||||
connect(context, SIGNAL(refreshUpdate(QDate)), this, SLOT(refreshUpdate(QDate)));
|
||||
connect(context, SIGNAL(rideAdded(RideItem*)), this, SLOT(itemAddedOrRemoved()));
|
||||
connect(context, SIGNAL(rideDeleted(RideItem*)), this, SLOT(itemAddedOrRemoved()));
|
||||
connect(rideCache, SIGNAL(itemChanged(RideItem*)), this, SLOT(itemChanged(RideItem*)));
|
||||
}
|
||||
|
||||
@@ -80,7 +82,12 @@ RideCacheModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
// is a metric
|
||||
int i=index.column()-5;
|
||||
return 0;
|
||||
|
||||
// unpack metric value into ridemetric and use it to get a stringified
|
||||
// version using the right metric/imperial conversion
|
||||
RideMetric *m = const_cast<RideMetric*>(factory->rideMetric(factory->metricName(i)));
|
||||
m->setValue(rideCache->rides().at(index.row())->metrics_[m->index()]);
|
||||
return m->toString(context->athlete->useMetricUnits);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -95,7 +102,6 @@ RideCacheModel::data(const QModelIndex &index, int role) const
|
||||
void
|
||||
RideCacheModel::itemChanged(RideItem *item)
|
||||
{
|
||||
qDebug()<<"ooh"<<item->fileName<<"changed";
|
||||
// ok so lets signal that
|
||||
int row = rideCache->rides().indexOf(item);
|
||||
if (row >= 0 && row <= rideCache->count()) {
|
||||
@@ -103,6 +109,14 @@ qDebug()<<"ooh"<<item->fileName<<"changed";
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RideCacheModel::itemAddedOrRemoved()
|
||||
{
|
||||
// reset the model
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
bool
|
||||
RideCacheModel::setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
@@ -129,6 +143,9 @@ RideCacheModel::headerData(int section, Qt::Orientation orientation, int role) c
|
||||
void
|
||||
RideCacheModel::configChanged()
|
||||
{
|
||||
// we are resetting
|
||||
beginResetModel();
|
||||
|
||||
// get field config
|
||||
metadata = context->athlete->rideMetadata()->getFields();
|
||||
|
||||
@@ -172,6 +189,10 @@ RideCacheModel::configChanged()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// all good
|
||||
endResetModel();
|
||||
|
||||
headerDataChanged (Qt::Horizontal, 0, columns_-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class RideCacheModel : public QAbstractTableModel
|
||||
|
||||
// and updates to ride items
|
||||
void itemChanged(RideItem *item);
|
||||
void itemAddedOrRemoved();
|
||||
|
||||
private:
|
||||
Context *context;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
class RideFile;
|
||||
class RideFileCache;
|
||||
class RideCache;
|
||||
class RideCacheModel;
|
||||
class Context;
|
||||
|
||||
Q_DECLARE_METATYPE(RideItem*)
|
||||
@@ -44,6 +45,7 @@ class RideItem : public QObject
|
||||
protected:
|
||||
|
||||
friend class ::RideCache;
|
||||
friend class ::RideCacheModel;
|
||||
|
||||
// ridefile
|
||||
RideFile *ride_;
|
||||
|
||||
@@ -584,6 +584,8 @@ FormField::FormField(FieldDefinition field, RideMetadata *meta) : definition(fie
|
||||
|
||||
// if save is being called flush all the values out ready to save as they are
|
||||
connect(meta->context, SIGNAL(metadataFlush()), this, SLOT(editFinished()));
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
FormField::~FormField()
|
||||
@@ -663,6 +665,7 @@ FormField::editFinished()
|
||||
case FIELD_TIME : text = ((QTimeEdit*)widget)->time().toString("hh:mm:ss.zzz"); break;
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
||||
// Update special field
|
||||
if (definition.name == "Device") {
|
||||
@@ -732,6 +735,7 @@ FormField::editFinished()
|
||||
ourRideItem->notifyRideMetadataChanged();
|
||||
}
|
||||
}
|
||||
active = false;
|
||||
|
||||
// default values
|
||||
setLinkedDefault(text);
|
||||
@@ -820,6 +824,8 @@ FormField::stateChanged(int state)
|
||||
void
|
||||
FormField::metadataChanged()
|
||||
{
|
||||
if (active == true) return;
|
||||
|
||||
active = true;
|
||||
edited = false;
|
||||
QString value;
|
||||
|
||||
Reference in New Issue
Block a user