Remove References in Dialog

.. you can now choose to remove reference lines in the
   allplot when you double click on the axis.

.. we might want to put the table and buttons for deleting
   references into the chart settings too (?)
This commit is contained in:
Mark Liversedge
2013-11-12 13:16:44 +00:00
parent 613ddb916b
commit 24e12eb024
6 changed files with 130 additions and 27 deletions

View File

@@ -25,12 +25,15 @@ ReferenceLineDialog::ReferenceLineDialog(AllPlot *parent, Context *context, bool
parent(parent), context(context), allowDelete(allowDelete), axis(-1)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(tr("Add Reference"));
setWindowFlags(windowFlags() | Qt::Tool);
setWindowTitle(tr("References"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QHBoxLayout *referenceValueLayout = new QHBoxLayout;
referenceValueLayout->setSpacing(0);
referenceValueLayout->setContentsMargins(0,0,0,0);
QLabel *refLabel = new QLabel();
refLabel->setText(tr("Add a reference at :"));
refLabel->setText(tr("Reference:"));
refValue = new QLineEdit();
refUnit = new QLabel();
refUnit->setText(tr("Watts"));
@@ -38,20 +41,79 @@ ReferenceLineDialog::ReferenceLineDialog(AllPlot *parent, Context *context, bool
referenceValueLayout->addWidget(refLabel);
referenceValueLayout->addWidget(refValue);
referenceValueLayout->addWidget(refUnit);
addButton = new QPushButton(tr(" + "));
#ifndef Q_OS_MAC
addButton->setFixedSize(20,20);
#endif
referenceValueLayout->addStretch();
referenceValueLayout->addWidget(addButton);
mainLayout->addLayout(referenceValueLayout);
QHBoxLayout *buttonLayout = new QHBoxLayout;
addButton = new QPushButton(tr("&Add"));
buttonLayout->addWidget(addButton);
cancelButton = new QPushButton(tr("&Cancel"));
buttonLayout->addWidget(cancelButton);
mainLayout->addLayout(buttonLayout);
// below that line we will show the existing references
// so they can be deleted
connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
// custom table
refsTable = new QTableWidget(this);
#ifdef Q_OS_MAX
refsTable->setAttribute(Qt::WA_MacShowFocusRect, 0);
#endif
refsTable->setColumnCount(2);
refsTable->horizontalHeader()->setStretchLastSection(true);
refsTable->setSortingEnabled(false);
refsTable->verticalHeader()->hide();
refsTable->setShowGrid(false);
refsTable->setSelectionMode(QAbstractItemView::SingleSelection);
refsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
mainLayout->addWidget(refsTable);
deleteRefButton = new QPushButton(" - ");
#ifndef Q_OS_MAC
deleteRefButton->setFixedSize(20,20);
#endif
connect(deleteRefButton, SIGNAL(clicked()), this, SLOT(deleteRef()));
QHBoxLayout *refButtons = new QHBoxLayout;
refButtons->setSpacing(2);
refButtons->addStretch();
refButtons->addWidget(deleteRefButton);
mainLayout->addLayout(refButtons);
// hide all the delete widgets if there's nothing to delete!
if (!allowDelete || context->rideItem()->ride()->referencePoints().count() == 0) {
refsTable->hide();
deleteRefButton->hide();
} else {
refreshTable();
}
// zapped
connect(this, SIGNAL(rejected()), this, SLOT(closed()));
}
void
ReferenceLineDialog::deleteRef()
{
// delete the ref that is highlighted
QList<QTableWidgetItem*> selections = refsTable->selectedItems();
if (selections.count()) {
QTableWidgetItem *which = refsTable->selectedItems().first();
int index = refsTable->row(which);
// wipe
context->rideItem()->ride()->removeReference(index);
context->rideItem()->setDirty(true);
refreshTable();
// plot needs to refresh markers
parent->refreshReferenceLinesForAllPlots();
parent->plotTmpReference(axis, 0, 0); //unplot
}
}
void
@@ -62,13 +124,6 @@ ReferenceLineDialog::setValueForAxis(double value, int axis)
}
void
ReferenceLineDialog::cancelClicked()
{
parent->plotTmpReference(axis, 0, 0); //unplot
done(0);
}
void
ReferenceLineDialog::addClicked()
{
@@ -81,3 +136,39 @@ ReferenceLineDialog::addClicked()
parent->plotTmpReference(axis, 0, 0); //unplot
done(1);
}
void
ReferenceLineDialog::closed()
{
parent->plotTmpReference(axis, 0, 0); //unplot
}
void
ReferenceLineDialog::refreshTable()
{
int i=0;
// reset the table
refsTable->clear();
QStringList header;
header << tr("Series") << tr("Value");
refsTable->setHorizontalHeaderLabels(header);
refsTable->setRowCount(context->rideItem()->ride()->referencePoints().count());
foreach(RideFilePoint *rp, context->rideItem()->ride()->referencePoints()) {
// watts only at this point
QTableWidgetItem *t = new QTableWidgetItem();
t->setText(tr("Power"));
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
refsTable->setItem(i,0,t);
t = new QTableWidgetItem();
t->setText(QString("%1").arg(rp->watts));
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
refsTable->setItem(i,1,t);
i++;
}
}