# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2017-01-02 09:42:15 # Node ID 601fe4ade58bcc03975134f7459347290028c94a # Parent ff0a686c939f8bb7822149b4ce6a3233f956550d added button to reset channel info diff --git a/src/channelinfomodel.cpp b/src/channelinfomodel.cpp --- a/src/channelinfomodel.cpp +++ b/src/channelinfomodel.cpp @@ -212,6 +212,46 @@ void ChannelInfoModel::setNumOfChannels( } } +void ChannelInfoModel::resetInfos() +{ + beginResetModel(); + for (unsigned ci = 0; (int) ci < infos.length(); ci++) + { + infos[ci] = {QString("Channel %1").arg(ci+1), true, colors[ci % 8]}; + } + endResetModel(); +} + +void ChannelInfoModel::resetNames() +{ + beginResetModel(); + for (unsigned ci = 0; (int) ci < infos.length(); ci++) + { + infos[ci].name = QString("Channel %1").arg(ci+1); + } + endResetModel(); +} + +void ChannelInfoModel::resetColors() +{ + beginResetModel(); + for (unsigned ci = 0; (int) ci < infos.length(); ci++) + { + infos[ci].color = colors[ci % 8]; + } + endResetModel(); +} + +void ChannelInfoModel::resetVisibility() +{ + beginResetModel(); + for (unsigned ci = 0; (int) ci < infos.length(); ci++) + { + infos[ci].visibility = true; + } + endResetModel(); +} + void ChannelInfoModel::saveSettings(QSettings* settings) { settings->beginGroup(SettingGroup_Channels); diff --git a/src/channelinfomodel.h b/src/channelinfomodel.h --- a/src/channelinfomodel.h +++ b/src/channelinfomodel.h @@ -52,6 +52,16 @@ public: /// Loads all channel info from a `QSettings`. void loadSettings(QSettings* settings); +public slots: + /// reset all channel info (names, color etc.) + void resetInfos(); + /// reset all channel names + void resetNames(); + /// reset all channel colors + void resetColors(); + /// reset visibility + void resetVisibility(); + private: struct ChannelInfo { diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp --- a/src/plotcontrolpanel.cpp +++ b/src/plotcontrolpanel.cpp @@ -42,7 +42,12 @@ Q_DECLARE_METATYPE(Range); PlotControlPanel::PlotControlPanel(QWidget *parent) : QWidget(parent), - ui(new Ui::PlotControlPanel) + ui(new Ui::PlotControlPanel), + resetAct(tr("Reset"), this), + resetNamesAct(tr("Reset Names"), this), + resetColorsAct(tr("Reset Colors"), this), + showAllAct(tr("Show All"), this), + resetMenu(tr("Reset Menu"), this) { ui->setupUi(this); @@ -98,6 +103,13 @@ PlotControlPanel::PlotControlPanel(QWidg ui->colorSelector->setColor(QColor(0,0,0,0)); ui->colorSelector->setDisplayMode(color_widgets::ColorPreview::AllAlpha); ui->colorSelector->setDisabled(true); + + // reset button + resetMenu.addAction(&resetNamesAct); + resetMenu.addAction(&resetColorsAct); + resetMenu.addAction(&showAllAct); + resetAct.setMenu(&resetMenu); + ui->tbReset->setDefaultAction(&resetAct); } PlotControlPanel::~PlotControlPanel() @@ -275,6 +287,12 @@ void PlotControlPanel::setChannelInfoMod ui->colorSelector->setColor(color); ui->colorSelector->blockSignals(wasBlocked); }); + + // reset actions + connect(&resetAct, &QAction::triggered, model, &ChannelInfoModel::resetInfos); + connect(&resetNamesAct, &QAction::triggered, model, &ChannelInfoModel::resetNames); + connect(&resetColorsAct, &QAction::triggered, model, &ChannelInfoModel::resetColors); + connect(&showAllAct, &QAction::triggered, model, &ChannelInfoModel::resetVisibility); } void PlotControlPanel::saveSettings(QSettings* settings) diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h --- a/src/plotcontrolpanel.h +++ b/src/plotcontrolpanel.h @@ -22,6 +22,8 @@ #include #include +#include +#include #include "channelinfomodel.h" @@ -61,6 +63,9 @@ private: /// User can disable this setting in the checkbox bool warnNumOfSamples; + QAction resetAct, resetNamesAct, resetColorsAct, showAllAct; + QMenu resetMenu; + /// Show a confirmation dialog before setting #samples to a big value bool askNSConfirmation(int value); diff --git a/src/plotcontrolpanel.ui b/src/plotcontrolpanel.ui --- a/src/plotcontrolpanel.ui +++ b/src/plotcontrolpanel.ui @@ -42,26 +42,56 @@ - - - - 0 - 0 - - - - - 20 - 20 - - - - - 20 - 20 - - - + + + + + + 0 + 0 + + + + + 20 + 20 + + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + + 1 + 20 + + + + + + + + Reset + + + QToolButton::MenuButtonPopup + + + Qt::NoArrow + + + +