mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Fix SEGV when adding/deleting metadata fields
.. model header data updates need to trigger a reset of the views and internal state e.g. index of the calendar text and the headings_ string list.
This commit is contained in:
@@ -174,6 +174,7 @@ RideCacheModel::configChanged(qint32)
|
||||
// 5 bool isRun;
|
||||
|
||||
columns_ = 5 + factory->metricCount() + metadata.count();
|
||||
headings_.clear();
|
||||
|
||||
for (int section=0; section<columns_; section++) {
|
||||
|
||||
@@ -206,10 +207,10 @@ RideCacheModel::configChanged(qint32)
|
||||
}
|
||||
}
|
||||
|
||||
headerDataChanged (Qt::Horizontal, 0, columns_-1);
|
||||
|
||||
// all good
|
||||
endResetModel();
|
||||
|
||||
headerDataChanged (Qt::Horizontal, 0, columns_-1);
|
||||
}
|
||||
|
||||
// catch ridecache refreshes
|
||||
|
||||
@@ -156,7 +156,7 @@ RideNavigator::RideNavigator(Context *context, bool mainwindow) : context(contex
|
||||
setAcceptDrops(true);
|
||||
|
||||
// lets go
|
||||
configChanged(CONFIG_APPEARANCE | CONFIG_NOTECOLOR);
|
||||
configChanged(CONFIG_APPEARANCE | CONFIG_NOTECOLOR | CONFIG_FIELDS);
|
||||
}
|
||||
|
||||
RideNavigator::~RideNavigator()
|
||||
@@ -166,7 +166,7 @@ RideNavigator::~RideNavigator()
|
||||
}
|
||||
|
||||
void
|
||||
RideNavigator::configChanged(qint32)
|
||||
RideNavigator::configChanged(qint32 state)
|
||||
{
|
||||
ColorEngine ce(context);
|
||||
fontHeight = QFontMetrics(QFont()).height();
|
||||
@@ -195,6 +195,9 @@ RideNavigator::configChanged(qint32)
|
||||
|
||||
#endif
|
||||
|
||||
// if the fields changed we need to reset indexes etc
|
||||
if (state & CONFIG_FIELDS) resetView();
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -348,6 +351,9 @@ RideNavigator::resetView()
|
||||
// Select the current ride
|
||||
cursorRide();
|
||||
|
||||
// get height
|
||||
tableView->doItemsLayout();
|
||||
|
||||
columnsChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
};
|
||||
|
||||
RideNavigator *rideNavigator;
|
||||
QAbstractItemModel *model;
|
||||
int groupBy;
|
||||
int calendarText;
|
||||
int colorColumn;
|
||||
@@ -103,9 +104,7 @@ public:
|
||||
}
|
||||
~GroupByModel() {}
|
||||
|
||||
void setSourceModel(QAbstractItemModel *model) {
|
||||
QAbstractProxyModel::setSourceModel(model);
|
||||
setGroupBy(groupBy);
|
||||
void setIndexes() {
|
||||
|
||||
// find the Calendar TextColumn
|
||||
calendarText = -1;
|
||||
@@ -134,6 +133,14 @@ public:
|
||||
}
|
||||
starttimeHeader = "ride_time"; //initialisation with techname
|
||||
}
|
||||
}
|
||||
|
||||
void setSourceModel(QAbstractItemModel *model) {
|
||||
|
||||
this->model=model;
|
||||
QAbstractProxyModel::setSourceModel(model);
|
||||
setGroupBy(groupBy);
|
||||
setIndexes();
|
||||
|
||||
connect(model, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
|
||||
connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(sourceModelChanged()));
|
||||
@@ -279,7 +286,6 @@ public:
|
||||
int groupNo = ((QModelIndex*)proxyIndex.internalPointer())->row();
|
||||
if (groupNo < 0 || groupNo >= groups.count() || proxyIndex.column() == 0) returning="";
|
||||
else string = sourceModel()->data(sourceModel()->index(groupToSourceRow.value(groups[groupNo])->at(proxyIndex.row()), calendarText)).toString();
|
||||
|
||||
// get rid of cr, lf and tab chars
|
||||
string.replace("\n", " ");
|
||||
string.replace("\t", " ");
|
||||
@@ -578,12 +584,17 @@ public slots:
|
||||
|
||||
clearGroups();
|
||||
setGroupBy(groupBy+2); // accommodate virtual columns
|
||||
setIndexes();
|
||||
|
||||
endResetModel();// we're clean
|
||||
|
||||
// lets expand column 0 for the groupBy heading
|
||||
for (int i=0; i < groupCount(); i++)
|
||||
rideNavigator->tableView->setFirstColumnSpanned(i, QModelIndex(), true);
|
||||
|
||||
// reset the view
|
||||
rideNavigator->resetView();
|
||||
|
||||
// now show em
|
||||
rideNavigator->tableView->expandAll();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user