mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Using MultiMetricSelector in FavouriteMetricsPage (#4728)
As the same type of metrics selector was needed for the settings of the PlanningCalendarView, a reusable widget MultiMetricSelector was created in #4679, duplicating code from FavouriteMetricsPage. This change elminates the duplication and uses the MultiMetricSelector also in the global settings. A user visible change for FavouriteMetricsPage is the new filter field for available metrics.
This commit is contained in:
committed by
GitHub
parent
cae6038cc2
commit
81a4a2da24
@@ -1591,62 +1591,11 @@ ColorsPage::saveClicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
FavouriteMetricsPage::FavouriteMetricsPage(QWidget *parent) :
|
FavouriteMetricsPage::FavouriteMetricsPage(QWidget *parent) :
|
||||||
QWidget(parent), changed(false)
|
QWidget(parent)
|
||||||
{
|
{
|
||||||
HelpWhatsThis *help = new HelpWhatsThis(this);
|
HelpWhatsThis *help = new HelpWhatsThis(this);
|
||||||
this->setWhatsThis(help->getWhatsThisText(HelpWhatsThis::Preferences_Metrics_Favourites));
|
this->setWhatsThis(help->getWhatsThisText(HelpWhatsThis::Preferences_Metrics_Favourites));
|
||||||
|
|
||||||
availList = new QListWidget;
|
|
||||||
availList->setSortingEnabled(true);
|
|
||||||
availList->setAlternatingRowColors(true);
|
|
||||||
availList->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
|
|
||||||
QVBoxLayout *availLayout = new QVBoxLayout;
|
|
||||||
availLayout->addWidget(new QLabel(HLO + tr("Available Metrics") + HLC));
|
|
||||||
availLayout->addWidget(availList);
|
|
||||||
|
|
||||||
selectedList = new QListWidget;
|
|
||||||
selectedList->setAlternatingRowColors(true);
|
|
||||||
selectedList->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
|
|
||||||
ActionButtonBox *actionButtons = new ActionButtonBox(ActionButtonBox::UpDownGroup);
|
|
||||||
actionButtons->defaultConnect(ActionButtonBox::UpDownGroup, selectedList);
|
|
||||||
|
|
||||||
QVBoxLayout *selectedLayout = new QVBoxLayout;
|
|
||||||
selectedLayout->addWidget(new QLabel(HLO + tr("Favourites") + HLC));
|
|
||||||
selectedLayout->addWidget(selectedList);
|
|
||||||
selectedLayout->addWidget(actionButtons);
|
|
||||||
|
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
leftButton = new QToolButton(this);
|
|
||||||
leftButton->setArrowType(Qt::LeftArrow);
|
|
||||||
leftButton->setFixedSize(20*dpiXFactor,20*dpiYFactor);
|
|
||||||
rightButton = new QToolButton(this);
|
|
||||||
rightButton->setArrowType(Qt::RightArrow);
|
|
||||||
rightButton->setFixedSize(20*dpiXFactor,20*dpiYFactor);
|
|
||||||
#else
|
|
||||||
leftButton = new QPushButton("<");
|
|
||||||
rightButton = new QPushButton(">");
|
|
||||||
#endif
|
|
||||||
leftButton->setEnabled(false);
|
|
||||||
rightButton->setEnabled(false);
|
|
||||||
|
|
||||||
QHBoxLayout *inexcLayout = new QHBoxLayout;
|
|
||||||
inexcLayout->addStretch();
|
|
||||||
inexcLayout->addWidget(leftButton);
|
|
||||||
inexcLayout->addWidget(rightButton);
|
|
||||||
inexcLayout->addStretch();
|
|
||||||
|
|
||||||
QVBoxLayout *buttonGrid = new QVBoxLayout;
|
|
||||||
buttonGrid->addStretch();
|
|
||||||
buttonGrid->addLayout(inexcLayout);
|
|
||||||
buttonGrid->addStretch();
|
|
||||||
|
|
||||||
QHBoxLayout *hlayout = new QHBoxLayout(this);;
|
|
||||||
hlayout->addLayout(availLayout, 2);
|
|
||||||
hlayout->addLayout(buttonGrid, 1);
|
|
||||||
hlayout->addLayout(selectedLayout, 2);
|
|
||||||
|
|
||||||
QString s;
|
QString s;
|
||||||
if (appsettings->contains(GC_SETTINGS_FAVOURITE_METRICS))
|
if (appsettings->contains(GC_SETTINGS_FAVOURITE_METRICS))
|
||||||
s = appsettings->value(this, GC_SETTINGS_FAVOURITE_METRICS).toString();
|
s = appsettings->value(this, GC_SETTINGS_FAVOURITE_METRICS).toString();
|
||||||
@@ -1654,96 +1603,12 @@ FavouriteMetricsPage::FavouriteMetricsPage(QWidget *parent) :
|
|||||||
s = GC_SETTINGS_FAVOURITE_METRICS_DEFAULT;
|
s = GC_SETTINGS_FAVOURITE_METRICS_DEFAULT;
|
||||||
QStringList selectedMetrics = s.split(",");
|
QStringList selectedMetrics = s.split(",");
|
||||||
|
|
||||||
const RideMetricFactory &factory = RideMetricFactory::instance();
|
multiMetricSelector = new MultiMetricSelector(HLO + tr("Available Metrics") + HLC, HLO + tr("Favourites") + HLC, selectedMetrics);
|
||||||
for (int i = 0; i < factory.metricCount(); ++i) {
|
|
||||||
QString symbol = factory.metricName(i);
|
|
||||||
if (selectedMetrics.contains(symbol) || symbol.startsWith("compatibility_"))
|
|
||||||
continue;
|
|
||||||
QSharedPointer<RideMetric> m(factory.newMetric(symbol));
|
|
||||||
QListWidgetItem *item = new QListWidgetItem(Utils::unprotect(m->name()));
|
|
||||||
item->setData(Qt::UserRole, symbol);
|
|
||||||
item->setToolTip(m->description());
|
|
||||||
availList->addItem(item);
|
|
||||||
}
|
|
||||||
foreach (QString symbol, selectedMetrics) {
|
|
||||||
if (!factory.haveMetric(symbol))
|
|
||||||
continue;
|
|
||||||
QSharedPointer<RideMetric> m(factory.newMetric(symbol));
|
|
||||||
QListWidgetItem *item = new QListWidgetItem(Utils::unprotect(m->name()));
|
|
||||||
item->setData(Qt::UserRole, symbol);
|
|
||||||
item->setToolTip(m->description());
|
|
||||||
selectedList->addItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(actionButtons, &ActionButtonBox::upRequested, this, &FavouriteMetricsPage::upClicked);
|
QHBoxLayout *hlayout = new QHBoxLayout(this);
|
||||||
connect(actionButtons, &ActionButtonBox::downRequested, this, &FavouriteMetricsPage::downClicked);
|
hlayout->addWidget(multiMetricSelector);
|
||||||
connect(leftButton, SIGNAL(clicked()), this, SLOT(leftClicked()));
|
|
||||||
connect(rightButton, SIGNAL(clicked()), this, SLOT(rightClicked()));
|
|
||||||
connect(availList, SIGNAL(itemSelectionChanged()), this, SLOT(availChanged()));
|
|
||||||
connect(selectedList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedChanged()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
connect(multiMetricSelector, &MultiMetricSelector::selectedChanged, [=]() { changed = true; });
|
||||||
FavouriteMetricsPage::upClicked()
|
|
||||||
{
|
|
||||||
assert(!selectedList->selectedItems().isEmpty());
|
|
||||||
QListWidgetItem *item = selectedList->selectedItems().first();
|
|
||||||
int row = selectedList->row(item);
|
|
||||||
assert(row > 0);
|
|
||||||
selectedList->takeItem(row);
|
|
||||||
selectedList->insertItem(row - 1, item);
|
|
||||||
selectedList->setCurrentItem(item);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FavouriteMetricsPage::downClicked()
|
|
||||||
{
|
|
||||||
assert(!selectedList->selectedItems().isEmpty());
|
|
||||||
QListWidgetItem *item = selectedList->selectedItems().first();
|
|
||||||
int row = selectedList->row(item);
|
|
||||||
assert(row < selectedList->count() - 1);
|
|
||||||
selectedList->takeItem(row);
|
|
||||||
selectedList->insertItem(row + 1, item);
|
|
||||||
selectedList->setCurrentItem(item);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FavouriteMetricsPage::leftClicked()
|
|
||||||
{
|
|
||||||
assert(!selectedList->selectedItems().isEmpty());
|
|
||||||
QListWidgetItem *item = selectedList->selectedItems().first();
|
|
||||||
selectedList->takeItem(selectedList->row(item));
|
|
||||||
availList->addItem(item);
|
|
||||||
changed = true;
|
|
||||||
selectedChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FavouriteMetricsPage::rightClicked()
|
|
||||||
{
|
|
||||||
assert(!availList->selectedItems().isEmpty());
|
|
||||||
QListWidgetItem *item = availList->selectedItems().first();
|
|
||||||
availList->takeItem(availList->row(item));
|
|
||||||
selectedList->addItem(item);
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FavouriteMetricsPage::availChanged()
|
|
||||||
{
|
|
||||||
rightButton->setEnabled(!availList->selectedItems().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
FavouriteMetricsPage::selectedChanged()
|
|
||||||
{
|
|
||||||
if (selectedList->selectedItems().isEmpty()) {
|
|
||||||
leftButton->setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
leftButton->setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32
|
qint32
|
||||||
@@ -1751,10 +1616,7 @@ FavouriteMetricsPage::saveClicked()
|
|||||||
{
|
{
|
||||||
if (!changed) return 0;
|
if (!changed) return 0;
|
||||||
|
|
||||||
QStringList metrics;
|
appsettings->setValue(GC_SETTINGS_FAVOURITE_METRICS, multiMetricSelector->getSymbols().join(","));
|
||||||
for (int i = 0; i < selectedList->count(); ++i)
|
|
||||||
metrics << selectedList->item(i)->data(Qt::UserRole).toString();
|
|
||||||
appsettings->setValue(GC_SETTINGS_FAVOURITE_METRICS, metrics.join(","));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
#include "RideAutoImportConfig.h"
|
#include "RideAutoImportConfig.h"
|
||||||
#include "RemoteControl.h"
|
#include "RemoteControl.h"
|
||||||
#include "Measures.h"
|
#include "Measures.h"
|
||||||
|
#include "MetricSelect.h"
|
||||||
#include "TagStore.h"
|
#include "TagStore.h"
|
||||||
#include "ActionButtonBox.h"
|
#include "ActionButtonBox.h"
|
||||||
#include "StyledItemDelegates.h"
|
#include "StyledItemDelegates.h"
|
||||||
@@ -374,25 +375,11 @@ class FavouriteMetricsPage : public QWidget
|
|||||||
FavouriteMetricsPage(QWidget *parent = NULL);
|
FavouriteMetricsPage(QWidget *parent = NULL);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void upClicked();
|
|
||||||
void downClicked();
|
|
||||||
void leftClicked();
|
|
||||||
void rightClicked();
|
|
||||||
void availChanged();
|
|
||||||
void selectedChanged();
|
|
||||||
qint32 saveClicked();
|
qint32 saveClicked();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool changed;
|
bool changed = false;
|
||||||
QListWidget *availList;
|
MultiMetricSelector *multiMetricSelector;
|
||||||
QListWidget *selectedList;
|
|
||||||
#ifndef Q_OS_MAC
|
|
||||||
QToolButton *leftButton;
|
|
||||||
QToolButton *rightButton;
|
|
||||||
#else
|
|
||||||
QPushButton *leftButton;
|
|
||||||
QPushButton *rightButton;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class KeywordsPage : public QWidget
|
class KeywordsPage : public QWidget
|
||||||
|
|||||||
Reference in New Issue
Block a user