mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Honor type of Perspective when import/exporting
.. the perspective type is added to the xml when exporting and also when saving state. .. on import the perspective type is checked to make sure we don't import trends views into activities and vice versa.
This commit is contained in:
@@ -997,12 +997,15 @@ MainWindow::importPerspective()
|
||||
|
||||
// import and select it
|
||||
pactive = true;
|
||||
current->importPerspective(fileName);
|
||||
current->setPerspectives(perspectiveSelector);
|
||||
if (current->importPerspective(fileName)) {
|
||||
|
||||
// and select remember pactive is true, so we do the heavy lifting here
|
||||
perspectiveSelector->setCurrentIndex(current->perspectives_.count()-1);
|
||||
current->perspectiveSelected(perspectiveSelector->currentIndex());
|
||||
// on success we select the new one
|
||||
current->setPerspectives(perspectiveSelector);
|
||||
|
||||
// and select remember pactive is true, so we do the heavy lifting here
|
||||
perspectiveSelector->setCurrentIndex(current->perspectives_.count()-1);
|
||||
current->perspectiveSelected(perspectiveSelector->currentIndex());
|
||||
}
|
||||
pactive = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1443,11 +1443,15 @@ Perspective *Perspective::fromFile(Context *context, QString filename, int type)
|
||||
// none loaded ?
|
||||
if (handler.perspectives.count() == 0) return returning;
|
||||
|
||||
// return the first one (if there are multiple)
|
||||
returning = handler.perspectives[0];
|
||||
// return the first one with the right type (if there are multiple)
|
||||
for(int i=0; i<handler.perspectives.count(); i++)
|
||||
if (returning == NULL && handler.perspectives[i]->type == type)
|
||||
returning = handler.perspectives[i];
|
||||
|
||||
// delete any further perspectives
|
||||
for(int i=1; i<handler.perspectives.count(); i++) delete (handler.perspectives[i]);
|
||||
for(int i=0; i<handler.perspectives.count(); i++)
|
||||
if (handler.perspectives[i] != returning)
|
||||
delete (handler.perspectives[i]);
|
||||
|
||||
// return it, but bear in mind it hasn't been initialised (current ride, date range etc)
|
||||
return returning;
|
||||
@@ -1476,7 +1480,7 @@ Perspective::toFile(QString filename)
|
||||
void
|
||||
Perspective::toXml(QTextStream &out)
|
||||
{
|
||||
out<<"<layout name=\""<< title_ <<"\" style=\"" << currentStyle <<"\">\n";
|
||||
out<<"<layout name=\""<< title_ <<"\" style=\"" << currentStyle <<"\" type=\"" << type<<"\">\n";
|
||||
|
||||
// iterate over charts
|
||||
foreach (GcChartWindow *chart, charts) {
|
||||
|
||||
@@ -268,13 +268,14 @@ PerspectiveDialog::importPerspectiveClicked()
|
||||
} else {
|
||||
|
||||
// import and select it
|
||||
tabView->importPerspective(fileName);
|
||||
if (tabView->importPerspective(fileName)) {
|
||||
|
||||
// update the table
|
||||
setTables();
|
||||
// update the table
|
||||
setTables();
|
||||
|
||||
// new one added
|
||||
emit perspectivesChanged();
|
||||
// new one added
|
||||
emit perspectivesChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -441,11 +441,18 @@ TabView::appendPerspective(Perspective *page)
|
||||
page->configChanged(0); // set colors correctly- will have missed from startup
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
TabView::importPerspective(QString filename)
|
||||
{
|
||||
Perspective *newone = Perspective::fromFile(context, filename, type);
|
||||
if (newone) appendPerspective(newone);
|
||||
if (newone) {
|
||||
appendPerspective(newone);
|
||||
return true;
|
||||
} else {
|
||||
// no valid perspective found for this view... (maybe its for another type of view)
|
||||
QMessageBox::information(this, tr("Perspective Import"), tr("No perspectives found that are appropriate for the current view."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -907,6 +914,7 @@ bool ViewParser::startElement( const QString&, const QString&, const QString &na
|
||||
if (name == "layout") {
|
||||
|
||||
QString name="General";
|
||||
int typetouse=type;
|
||||
for(int i=0; i<attrs.count(); i++) {
|
||||
if (attrs.qName(i) == "style") {
|
||||
style = Utils::unprotect(attrs.value(i)).toInt();
|
||||
@@ -914,10 +922,13 @@ bool ViewParser::startElement( const QString&, const QString&, const QString &na
|
||||
if (attrs.qName(i) == "name") {
|
||||
name = Utils::unprotect(attrs.value(i));
|
||||
}
|
||||
if (attrs.qName(i) == "type") {
|
||||
typetouse = Utils::unprotect(attrs.value(i)).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
// we need a new perspective for this view type
|
||||
page = new Perspective(context, name, type);
|
||||
page = new Perspective(context, name, typetouse);
|
||||
perspectives.append(page);
|
||||
}
|
||||
else if (name == "chart") {
|
||||
|
||||
@@ -105,7 +105,7 @@ class TabView : public QWidget
|
||||
|
||||
void importChart(QMap<QString,QString>properties, bool select) { perspective_->importChart(properties, select); }
|
||||
|
||||
void importPerspective(QString filename);
|
||||
bool importPerspective(QString filename);
|
||||
void exportPerspective(Perspective *, QString filename);
|
||||
|
||||
signals:
|
||||
|
||||
Reference in New Issue
Block a user