Skip to content

Commit

Permalink
Import .gchart workflow improvements
Browse files Browse the repository at this point in the history
.. allow user to select target view for trends/diary charts
   since they can be used on either

.. don't just add when only 1 chart imported, always let the
   user confirm and adjust

.. use translated names for the views so they are more meaningful
   to the end user
  • Loading branch information
liversedge committed May 24, 2016
1 parent 659d25a commit 06197cf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 50 deletions.
71 changes: 58 additions & 13 deletions src/Charts/HomeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ ImportChartDialog::ImportChartDialog(Context *context, QList<QMap<QString,QStrin
#ifdef Q_OS_MAC
table->setAttribute(Qt::WA_MacShowFocusRect, 0);
#endif
table->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
table->setRowCount(list.count());
table->setColumnCount(3);
QStringList headings;
Expand All @@ -1620,16 +1621,47 @@ ImportChartDialog::ImportChartDialog(Context *context, QList<QMap<QString,QStrin
table->setCellWidget(i, 0, c);

QString view = list[i].value("VIEW");
#ifdef GC_HAVE_ICAL

// convert to user name for view from here, since
// they won't recognise the names used internally
// as they need to be translated too
if (view == "diary") view = tr("Diary");
if (view == "home") view = tr("Trends");
if (view == "analysis") view = tr("Activities");
if (view == "train") view = tr("Train");

QTableWidgetItem *t;
#ifndef GC_HAVE_ICAL
// diary not available!
if (view == "diary") view = "home";
#endif
if (view == tr("Diary")) view = tr("Trends");
// View
QTableWidgetItem *t = new QTableWidgetItem;
t = new QTableWidgetItem;
t->setText(view);
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
table->setItem(i, 1, t);

#else
// we should be able to select trend/diary
if (view == tr("Diary") || view == tr("Trends")) {

QComboBox *com = new QComboBox(this);
com->addItem(tr("Diary"));
com->addItem(tr("Trends"));
table->setCellWidget(i,1,com);
if (view == tr("Diary")) com->setCurrentIndex(0);
else com->setCurrentIndex(1);

} else {

// View
t = new QTableWidgetItem;
t->setText(view);
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
table->setItem(i, 1, t);

}
#endif

// title
t = new QTableWidgetItem;
t->setText(list[i].value("title"));
Expand All @@ -1639,7 +1671,6 @@ ImportChartDialog::ImportChartDialog(Context *context, QList<QMap<QString,QStrin
}

layout->addWidget(table);
layout->addStretch();

QHBoxLayout *buttons = new QHBoxLayout;
buttons->addStretch();
Expand All @@ -1660,17 +1691,31 @@ ImportChartDialog::importClicked()
// is it checked?
if (static_cast<QCheckBox*>(table->cellWidget(i,0))->isChecked()) {

// import this one !
QString view = table->item(i,1)->text();
// where we putting it?
QString view;

// is there a combo box?
QComboBox *com = static_cast<QComboBox*>(table->cellWidget(i,1));
if (com) {
switch(com->currentIndex()) {

case 0 : view = tr("Diary"); break;

default:
case 1 : view = tr("Trends"); break;
}
} else {
view = table->item(i,1)->text();
}

int x=0;
if (view == "home") { x=0; context->mainWindow->selectHome(); }
if (view == "analysis") { x=1; context->mainWindow->selectAnalysis(); }
if (view == "diary") { x=2; context->mainWindow->selectDiary(); }
if (view == "train") { x=3; context->mainWindow->selectTrain(); }
if (view == tr("Trends")) { x=0; context->mainWindow->selectHome(); }
if (view == tr("Activities")) { x=1; context->mainWindow->selectAnalysis(); }
if (view == tr("Diary")) { x=2; context->mainWindow->selectDiary(); }
if (view == tr("Train")) { x=3; context->mainWindow->selectTrain(); }

// add to the currently selected tab and select=false
context->mainWindow->athleteTab()->view(x)->importChart(list[i], false);
// add to the currently selected tab and select if only adding one chart
context->mainWindow->athleteTab()->view(x)->importChart(list[i], (list.count()==1));
}
}
accept();
Expand Down
3 changes: 3 additions & 0 deletions src/Charts/RCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ RCanvas::RCanvas(Context *context, QWidget *parent) : QGraphicsView(parent), con
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
#endif

// allow to click and drag
setDragMode(QGraphicsView::ScrollHandDrag);

// add a scene
scene = new QGraphicsScene(this);
this->setScene(scene);
Expand Down
40 changes: 3 additions & 37 deletions src/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,43 +1356,9 @@ MainWindow::importCharts(QStringList list)
charts << GcChartWindow::chartProperties(filename);
}

if (list.count() == 1) {

// just add it and be done
QString view = charts[0].value("VIEW", "");
if (view == "") {

// parse error
QMessageBox oops(QMessageBox::Critical, tr("Chart Parse Failed"),
tr("Failed to parse chart."));
oops.exec();
return;

}

#ifdef GC_HAVE_ICAL
// diary not available!
if (view == "diary") {
charts[0].insert("VIEW", "home");
view = "home";
}
#endif

int x=0;
if (view == "home") { x=0; selectHome(); }
if (view == "analysis") { x=1; selectAnalysis(); }
if (view == "diary") { x=2; selectDiary(); }
if (view == "train") { x=3; selectTrain(); }

// add to the currently selected tab and select=true
currentTab->view(x)->importChart(charts[0], true);

} else {

// run an import dialog
ImportChartDialog importer(currentTab->context, charts, this);
importer.exec();
}
// And import them with a dialog to select location
ImportChartDialog importer(currentTab->context, charts, this);
importer.exec();
}


Expand Down

0 comments on commit 06197cf

Please sign in to comment.