From fe73fcb2ffefde661dc1f499a6a6357b090c064d Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 27 Jul 2015 13:08:17 +0100 Subject: [PATCH] Fixup Chart Preset Workflow and SEGV/Bug .. remove all the editing/import/export functions from the chart settings now they have their own sidebar. .. this also removes some of the problems with conflicts and bugs in the code e.g. setting the first chart name to "" by accident in the editingFinished() method (since that is no longer supported !) --- src/HomeWindow.cpp | 1 - src/LTMSidebar.cpp | 1 - src/LTMTool.cpp | 200 ++------------------------------------------- src/LTMTool.h | 10 --- 4 files changed, 7 insertions(+), 205 deletions(-) diff --git a/src/HomeWindow.cpp b/src/HomeWindow.cpp index a573f2acb..ca1c05ec0 100644 --- a/src/HomeWindow.cpp +++ b/src/HomeWindow.cpp @@ -1093,7 +1093,6 @@ void GcWindowDialog::okClicked() // note that in reject they are not and will // get deleted (this has been verified with // some debug statements in ~GcWindow). - // set its title property and geometry factors win->setProperty("title", title->text()); win->setProperty("widthFactor", 2.00); diff --git a/src/LTMSidebar.cpp b/src/LTMSidebar.cpp index 9f14d2e64..d89193c7c 100644 --- a/src/LTMSidebar.cpp +++ b/src/LTMSidebar.cpp @@ -1381,7 +1381,6 @@ LTMSidebar::addPreset() // returns null if cancelled or closed if (newone) { - // append to the chart list ... LTMSettings set = static_cast(newone)->getSettings(); set.name = set.title = newone->property("title").toString(); diff --git a/src/LTMTool.cpp b/src/LTMTool.cpp index 34f4f70a2..c692dc1d2 100644 --- a/src/LTMTool.cpp +++ b/src/LTMTool.cpp @@ -43,7 +43,7 @@ // PDModel estimate support #include "PDModel.h" -LTMTool::LTMTool(Context *context, LTMSettings *settings) : QWidget(context->mainWindow), settings(settings), context(context), active(false), _amFiltered(false), editing(false) +LTMTool::LTMTool(Context *context, LTMSettings *settings) : QWidget(context->mainWindow), settings(settings), context(context), active(false), _amFiltered(false) { setStyleSheet("QFrame { FrameStyle = QFrame::NoFrame };" "QWidget { background = Qt::white; border:0 px; margin: 2px; };"); @@ -132,26 +132,6 @@ LTMTool::LTMTool(Context *context, LTMSettings *settings) : QWidget(context->mai QGridLayout *presetLayout = new QGridLayout; basicLayout->addLayout(presetLayout); - importButton = new QPushButton(tr("Import...")); - exportButton = new QPushButton(tr("Export...")); - upButton = new QPushButton(tr("Move up")); - downButton = new QPushButton(tr("Move down")); - renameButton = new QPushButton(tr("Rename")); - deleteButton = new QPushButton(tr("Delete")); - newButton = new QPushButton(tr("Add Current")); // connected in LTMWindow.cpp - connect(newButton, SIGNAL(clicked()), this, SLOT(addCurrent())); - - QVBoxLayout *actionButtons = new QVBoxLayout; - actionButtons->addWidget(renameButton); - actionButtons->addWidget(deleteButton); - actionButtons->addWidget(upButton); - actionButtons->addWidget(downButton); - actionButtons->addStretch(); - actionButtons->addWidget(importButton); - actionButtons->addWidget(exportButton); - actionButtons->addStretch(); - actionButtons->addWidget(newButton); - charts = new QTreeWidget; #ifdef Q_OS_MAC charts->setAttribute(Qt::WA_MacShowFocusRect, 0); @@ -163,25 +143,19 @@ LTMTool::LTMTool(Context *context, LTMSettings *settings) : QWidget(context->mai charts->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); charts->setIndentation(0); - applyButton = new QPushButton(tr("Apply")); // connected in LTMWindow.cpp + applyButton = new QPushButton(tr("Apply")); // connected in LTMWindow.cpp (weird!?) + newButton = new QPushButton(tr("Add Current")); // connected in LTMWindow.cpp + connect(newButton, SIGNAL(clicked()), this, SLOT(addCurrent())); + QHBoxLayout *buttons = new QHBoxLayout; buttons->addWidget(applyButton); buttons->addStretch(); + buttons->addWidget(newButton); basicLayout->addLayout(buttons); presetLayout->addWidget(charts, 0,0); - presetLayout->addLayout(actionButtons, 0,1,1,2); // connect up slots - connect(upButton, SIGNAL(clicked()), this, SLOT(upClicked())); - connect(downButton, SIGNAL(clicked()), this, SLOT(downClicked())); - connect(renameButton, SIGNAL(clicked()), this, SLOT(renameClicked())); - connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); - connect(importButton, SIGNAL(clicked()), this, SLOT(importClicked())); - connect(exportButton, SIGNAL(clicked()), this, SLOT(exportClicked())); - connect(charts, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(editingFinished())); - connect(charts, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(editingStarted())); - tabs = new QTabWidget(this); mainLayout->addWidget(tabs); @@ -277,7 +251,6 @@ LTMTool::LTMTool(Context *context, LTMSettings *settings) : QWidget(context->mai customLayout->addWidget(customTable); connect(customTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(doubleClicked(int, int))); - // custom buttons editCustomButton = new QPushButton(tr("Edit")); connect(editCustomButton, SIGNAL(clicked()), this, SLOT(editMetric())); @@ -1211,7 +1184,7 @@ LTMTool::presetsChanged() foreach(LTMSettings chart, context->athlete->presets) { QTreeWidgetItem *add; add = new QTreeWidgetItem(charts->invisibleRootItem()); - add->setFlags(add->flags() | Qt::ItemIsEditable); + add->setFlags(add->flags() & ~Qt::ItemIsEditable); add->setText(0, chart.name); } @@ -1426,7 +1399,6 @@ LTMTool::addCurrent() context->athlete->presets.append(*settings); // tree will now be refreshed - editing = false; context->notifyPresetsChanged(); } @@ -2225,161 +2197,3 @@ LTMTool::setFilter(QStringList files) emit filterChanged(); } - -void -LTMTool::editingStarted() -{ - editing = true; // also set from renameClicked -} - -void -LTMTool::editingFinished() -{ - if (!editing) return; - - // take the edited versions of the name first - for(int i=0; iinvisibleRootItem()->childCount(); i++) - (context->athlete->presets)[i].name = charts->invisibleRootItem()->child(i)->text(0); - - // let everyone know once we're done - editing = false; - context->notifyPresetsChanged(); -} - -void -LTMTool::importClicked() -{ - QFileDialog existing(this); - existing.setFileMode(QFileDialog::ExistingFile); - existing.setNameFilter(tr("Chart File (*.xml)")); - if (existing.exec()){ - // we will only get one (ExistingFile not ExistingFiles) - QStringList filenames = existing.selectedFiles(); - - if (QFileInfo(filenames[0]).exists()) { - - QList imported; - QFile chartsFile(filenames[0]); - - // setup XML processor - QXmlInputSource source( &chartsFile ); - QXmlSimpleReader xmlReader; - LTMChartParser handler; - xmlReader.setContentHandler(&handler); - xmlReader.setErrorHandler(&handler); - - // parse and get return values - xmlReader.parse(source); - imported = handler.getSettings(); - - // now append to the QList and QTreeWidget - context->athlete->presets += imported; - - // notify we changed and tree updates - editing = false; - context->notifyPresetsChanged(); - - } else { - // oops non existent - does this ever happen? - QMessageBox::warning( 0, tr("Entry Error"), QString(tr("Selected file (%1) does not exist")).arg(filenames[0])); - } - } -} - -void -LTMTool::exportClicked() -{ - QFileDialog newone(this); - newone.setFileMode(QFileDialog::AnyFile); - newone.setNameFilter(tr("Chart File (*.xml)")); - if (newone.exec()){ - // we will only get one (ExistingFile not ExistingFiles) - QStringList filenames = newone.selectedFiles(); - - // if exists confirm overwrite - if (QFileInfo(filenames[0]).exists()) { - QMessageBox msgBox; - msgBox.setText(QString(tr("The selected file (%1) exists.")).arg(filenames[0])); - msgBox.setInformativeText(tr("Do you want to overwrite it?")); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - msgBox.setIcon(QMessageBox::Warning); - if (msgBox.exec() != QMessageBox::Ok) - return; - } - LTMChartParser::serialize(filenames[0], context->athlete->presets); - } -} - -void -LTMTool::upClicked() -{ - if (charts->currentItem()) { - int index = charts->invisibleRootItem()->indexOfChild(charts->currentItem()); - if (index == 0) return; // its at the top already - - // movin on up! - LTMSettings save = (context->athlete->presets)[index]; - context->athlete->presets.removeAt(index); - context->athlete->presets.insert(index-1, save); - - // notify we changed - editing = false; - context->notifyPresetsChanged(); - - // reselect - charts->setCurrentItem(charts->invisibleRootItem()->child(index-1)); - } -} - -void -LTMTool::downClicked() -{ - if (charts->currentItem()) { - int index = charts->invisibleRootItem()->indexOfChild(charts->currentItem()); - if (index == (charts->invisibleRootItem()->childCount()-1)) return; // its at the bottom already - - // movin on up! - LTMSettings save = (context->athlete->presets)[index]; - context->athlete->presets.removeAt(index); - context->athlete->presets.insert(index+1, save); - - // notify we changed - editing = false; - context->notifyPresetsChanged(); - - // reselect - charts->setCurrentItem(charts->invisibleRootItem()->child(index+1)); - } -} - -void -LTMTool::renameClicked() -{ - // which one is selected? - if (charts->currentItem()) { - editing = true; - charts->editItem(charts->currentItem(), 0); - } -} - -void -LTMTool::deleteClicked() -{ - // must have at least 1 child - if (charts->invisibleRootItem()->childCount() == 1) { - QMessageBox::warning(0, tr("Error"), tr("You must have at least one chart")); - return; - - } else if (charts->currentItem()) { - - int index = charts->invisibleRootItem()->indexOfChild(charts->currentItem()); - - // zap! - context->athlete->presets.removeAt(index); - - // notify we changed - editing = false; - context->notifyPresetsChanged(); - } -} diff --git a/src/LTMTool.h b/src/LTMTool.h index 9a0986efb..f895476c8 100644 --- a/src/LTMTool.h +++ b/src/LTMTool.h @@ -114,14 +114,6 @@ class LTMTool : public QWidget void presetsChanged(); // presets changed in the athlete class void usePresetChanged(); // we changed the checkbox - void exportClicked(); - void importClicked(); - void editingStarted(); - void editingFinished(); - void upClicked(); - void downClicked(); - void renameClicked(); - void deleteClicked(); void addCurrent(); private: @@ -142,8 +134,6 @@ class LTMTool : public QWidget // preset tab: QWidget *presetWidget; QLineEdit *chartName; - QPushButton *importButton, *exportButton; - QPushButton *upButton, *downButton, *renameButton, *deleteButton; // custom tab: QTableWidget *customTable;