Files
@ a30d48dab8b8
Branch filter:
Location: tempo-plotter/src/plotmenu.cpp
a30d48dab8b8
7.4 KiB
text/x-c++hdr
Merge with default
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /*
Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#include "plotmenu.h"
#include "setting_defines.h"
#include "utils.h"
PlotMenu::PlotMenu(QWidget* parent) :
QMenu(tr("&View"), parent),
showGridAction("&Grid", this),
showMinorGridAction("&Minor Grid", this),
unzoomAction("&Unzoom", this),
darkBackgroundAction("&Dark Background", this),
showLegendAction("&Legend", this),
showMultiAction("Multi &Plot", this),
setSymbolsAction("&Symbols", this),
setSymbolsAutoAct("Show When &Zoomed", this),
setSymbolsShowAct("Always &Show", this),
setSymbolsHideAct("Always &Hide", this)
{
showGridAction.setToolTip("Show Grid");
showMinorGridAction.setToolTip("Show Minor Grid");
unzoomAction.setToolTip("Unzoom the Plot");
darkBackgroundAction.setToolTip("Enable Dark Plot Background");
showLegendAction.setToolTip("Display the Legend on Plot");
showMultiAction.setToolTip("Display All Channels Separately");
setSymbolsAction.setToolTip("Show/Hide symbols");
showGridAction.setShortcut(QKeySequence("G"));
showMinorGridAction.setShortcut(QKeySequence("M"));
showGridAction.setCheckable(true);
showMinorGridAction.setCheckable(true);
darkBackgroundAction.setCheckable(true);
showLegendAction.setCheckable(true);
showMultiAction.setCheckable(true);
showGridAction.setChecked(false);
showMinorGridAction.setChecked(false);
darkBackgroundAction.setChecked(false);
showLegendAction.setChecked(true);
showMultiAction.setChecked(false);
// minor grid is only enabled when _major_ grid is enabled
showMinorGridAction.setEnabled(false);
connect(&showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
&showMinorGridAction, &QAction::setEnabled);
// setup set symbols menu
setSymbolsMenu.addAction(&setSymbolsAutoAct);
setSymbolsAutoAct.setCheckable(true);
setSymbolsAutoAct.setChecked(true);
connect(&setSymbolsAutoAct, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
[this](bool checked)
{
if (checked) emit symbolShowChanged(Plot::ShowSymbolsAuto);
});
setSymbolsMenu.addAction(&setSymbolsShowAct);
setSymbolsShowAct.setCheckable(true);
connect(&setSymbolsShowAct, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
[this](bool checked)
{
if (checked) symbolShowChanged(Plot::ShowSymbolsShow);
});
setSymbolsMenu.addAction(&setSymbolsHideAct);
setSymbolsHideAct.setCheckable(true);
connect(&setSymbolsHideAct, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
[this](bool checked)
{
if (checked) symbolShowChanged(Plot::ShowSymbolsHide);
});
// add symbol actions to same group so that they appear as radio buttons
auto group = new QActionGroup(this);
group->addAction(&setSymbolsAutoAct);
group->addAction(&setSymbolsShowAct);
group->addAction(&setSymbolsHideAct);
setSymbolsAction.setMenu(&setSymbolsMenu);
// add all actions to create this menu
addAction(&showGridAction);
addAction(&showMinorGridAction);
addAction(&unzoomAction);
addAction(&darkBackgroundAction);
addAction(&showLegendAction);
addAction(&showMultiAction);
addAction(&setSymbolsAction);
}
PlotMenu::PlotMenu(PlotViewSettings s, QWidget* parent) :
PlotMenu(parent)
{
showGridAction.setChecked(s.showGrid);
showMinorGridAction.setChecked(s.showMinorGrid);
darkBackgroundAction.setChecked(s.darkBackground);
showLegendAction.setChecked(s.showLegend);
showMultiAction.setChecked(s.showMulti);
switch (s.showSymbols)
{
case Plot::ShowSymbolsAuto:
setSymbolsAutoAct.setChecked(true);
break;
case Plot::ShowSymbolsShow:
setSymbolsShowAct.setChecked(true);
break;
case Plot::ShowSymbolsHide:
setSymbolsHideAct.setChecked(true);
break;
}
}
PlotViewSettings PlotMenu::viewSettings() const
{
return PlotViewSettings(
{
showGridAction.isChecked(),
showMinorGridAction.isChecked(),
darkBackgroundAction.isChecked(),
showLegendAction.isChecked(),
showMultiAction.isChecked(),
showSymbols()
});
}
Plot::ShowSymbols PlotMenu::showSymbols() const
{
if (setSymbolsAutoAct.isChecked())
{
return Plot::ShowSymbolsAuto;
}
else if (setSymbolsShowAct.isChecked())
{
return Plot::ShowSymbolsShow;
}
else // setSymbolsHideAct.isChecked()
{
return Plot::ShowSymbolsHide;
}
}
void PlotMenu::saveSettings(QSettings* settings)
{
settings->beginGroup(SettingGroup_Plot);
settings->setValue(SG_Plot_DarkBackground, darkBackgroundAction.isChecked());
settings->setValue(SG_Plot_Grid, showGridAction.isChecked());
settings->setValue(SG_Plot_MinorGrid, showMinorGridAction.isChecked());
settings->setValue(SG_Plot_Legend, showLegendAction.isChecked());
settings->setValue(SG_Plot_MultiPlot, showMultiAction.isChecked());
QString showSymbolsStr;
if (showSymbols() == Plot::ShowSymbolsAuto)
{
showSymbolsStr = "auto";
}
else if (showSymbols() == Plot::ShowSymbolsShow)
{
showSymbolsStr = "show";
}
else
{
showSymbolsStr = "hide";
}
settings->setValue(SG_Plot_Symbols, showSymbolsStr);
settings->endGroup();
}
void PlotMenu::loadSettings(QSettings* settings)
{
settings->beginGroup(SettingGroup_Plot);
darkBackgroundAction.setChecked(
settings->value(SG_Plot_DarkBackground, darkBackgroundAction.isChecked()).toBool());
showGridAction.setChecked(
settings->value(SG_Plot_Grid, showGridAction.isChecked()).toBool());
showMinorGridAction.setChecked(
settings->value(SG_Plot_MinorGrid, showMinorGridAction.isChecked()).toBool());
showMinorGridAction.setEnabled(showGridAction.isChecked());
showLegendAction.setChecked(
settings->value(SG_Plot_Legend, showLegendAction.isChecked()).toBool());
showMultiAction.setChecked(
settings->value(SG_Plot_MultiPlot, showMultiAction.isChecked()).toBool());
QString showSymbolsStr = settings->value(SG_Plot_Symbols, QString()).toString();
if (showSymbolsStr == "auto")
{
// setSymbols(Plot::ShowSymbolsAuto);
setSymbolsAutoAct.setChecked(true);
}
else if (showSymbolsStr == "show")
{
// setSymbols(Plot::ShowSymbolsShow);
setSymbolsShowAct.setChecked(true);
}
else if (showSymbolsStr == "hide")
{
// setSymbols(Plot::ShowSymbolsHide);
setSymbolsHideAct.setChecked(true);
}
else
{
qCritical() << "Invalid symbol setting:" << showSymbolsStr;
}
settings->endGroup();
}
|