Changeset - c8ad43700b6a
[Not reviewed]
snapshots
0 3 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-09-30 03:25:59
hy@ozderya.net
refactored mainwindow to use plot menu items from Plot.menuActions
3 files changed with 10 insertions and 71 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -57,54 +57,42 @@ MainWindow::MainWindow(QWidget *parent) 
 
    snapshotMan(this, &channelBuffers)
 
{
 
    ui->setupUi(this);
 
    ui->tabWidget->insertTab(0, &portControl, "Port");
 
    ui->tabWidget->setCurrentIndex(0);
 
    addToolBar(portControl.toolBar());
 

	
 
    ui->mainToolBar->addAction(snapshotMan.takeSnapshotAction());
 
    ui->menuBar->insertMenu(ui->menuHelp->menuAction(), snapshotMan.menu());
 

	
 
    setupAboutDialog();
 

	
 
    // init view menu
 
    for (auto a : ui->plot->menuActions())
 
    {
 
        ui->menuView->addAction(a);
 
    }
 

	
 
    // init UI signals
 

	
 
    // menu signals
 
    QObject::connect(ui->actionHelpAbout, &QAction::triggered,
 
              &aboutDialog, &QWidget::show);
 

	
 
    QObject::connect(ui->actionExportCsv, &QAction::triggered,
 
                     this, &MainWindow::onExportCsv);
 

	
 
    QObject::connect(ui->actionQuit, &QAction::triggered,
 
                     this, &MainWindow::close);
 

	
 
    QObject::connect(ui->actionGrid, &QAction::toggled, [this](bool show)
 
                     {
 
                         ui->plot->showGrid(show);
 
                         ui->actionMinorGrid->setEnabled(show);
 
                     });
 

	
 
    ui->actionMinorGrid->setEnabled(ui->actionGrid->isChecked());
 
    QObject::connect(ui->actionMinorGrid, &QAction::toggled,
 
                     ui->plot, &Plot::showMinorGrid);
 

	
 
    QObject::connect(ui->actionUnzoom, &QAction::triggered,
 
                     ui->plot, &Plot::unzoom);
 

	
 
    QObject::connect(ui->actionDarkBackground, &QAction::toggled,
 
                     ui->plot, &Plot::darkBackground);
 

	
 
    ui->plot->darkBackground(ui->actionDarkBackground->isChecked());
 

	
 
    // port control signals
 
    QObject::connect(&portControl, &PortControl::portToggled,
 
                     this, &MainWindow::onPortToggled);
 

	
 
    QObject::connect(&portControl, &PortControl::skipByteRequested,
 
                     this, &MainWindow::skipByte);
 

	
 
    QObject::connect(ui->spNumOfSamples, SELECT<int>::OVERLOAD_OF(&QSpinBox::valueChanged),
 
                     this, &MainWindow::onNumOfSamplesChanged);
 

	
 
    QObject::connect(ui->cbAutoScale, &QCheckBox::toggled,
 
                     this, &MainWindow::onAutoScaleChecked);
 
@@ -160,28 +148,24 @@ MainWindow::MainWindow(QWidget *parent) 
 
    {
 
        channelBuffers.append(new FrameBuffer(numOfSamples));
 
        curves.append(new QwtPlotCurve());
 
        curves[i]->setSamples(channelBuffers[i]);
 
        curves[i]->setPen(Plot::makeColor(i));
 
        curves[i]->attach(ui->plot);
 
    }
 

	
 
    // init auto scale
 
    ui->plot->setAxis(ui->cbAutoScale->isChecked(),
 
                      ui->spYmin->value(), ui->spYmax->value());
 

	
 
    // init grid
 
    ui->plot->showGrid(ui->actionGrid->isChecked());
 
    ui->plot->showMinorGrid(ui->actionMinorGrid->isChecked());
 

	
 
    // init scale range preset list
 
    for (int nbits = 8; nbits <= 24; nbits++) // signed binary formats
 
    {
 
        int rmax = pow(2, nbits-1)-1;
 
        int rmin = -rmax-1;
 
        Range r = {double(rmin),  double(rmax)};
 
        ui->cbRangePresets->addItem(
 
            QString().sprintf("Signed %d bits %d to +%d", nbits, rmin, rmax),
 
            QVariant::fromValue(r));
 
    }
 
    for (int nbits = 8; nbits <= 24; nbits++) // unsigned binary formats
 
    {
mainwindow.ui
Show inline comments
 
@@ -474,28 +474,24 @@
 
   <widget class="QMenu" name="menuFile">
 
    <property name="title">
 
     <string>File</string>
 
    </property>
 
    <addaction name="actionExportCsv"/>
 
    <addaction name="separator"/>
 
    <addaction name="actionQuit"/>
 
   </widget>
 
   <widget class="QMenu" name="menuView">
 
    <property name="title">
 
     <string>View</string>
 
    </property>
 
    <addaction name="actionGrid"/>
 
    <addaction name="actionMinorGrid"/>
 
    <addaction name="actionUnzoom"/>
 
    <addaction name="actionDarkBackground"/>
 
   </widget>
 
   <addaction name="menuFile"/>
 
   <addaction name="menuView"/>
 
   <addaction name="menuHelp"/>
 
  </widget>
 
  <widget class="QToolBar" name="mainToolBar">
 
   <attribute name="toolBarArea">
 
    <enum>TopToolBarArea</enum>
 
   </attribute>
 
   <attribute name="toolBarBreak">
 
    <bool>false</bool>
 
   </attribute>
 
@@ -551,68 +547,24 @@
 
   <property name="toolTip">
 
    <string>Export plot data to CSV</string>
 
   </property>
 
  </action>
 
  <action name="actionQuit">
 
   <property name="text">
 
    <string>Quit</string>
 
   </property>
 
   <property name="shortcut">
 
    <string>Ctrl+Q</string>
 
   </property>
 
  </action>
 
  <action name="actionGrid">
 
   <property name="checkable">
 
    <bool>true</bool>
 
   </property>
 
   <property name="text">
 
    <string>Grid</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Show/hide grid</string>
 
   </property>
 
   <property name="shortcut">
 
    <string>G</string>
 
   </property>
 
  </action>
 
  <action name="actionUnzoom">
 
   <property name="text">
 
    <string>UnZoom</string>
 
   </property>
 
  </action>
 
  <action name="actionMinorGrid">
 
   <property name="checkable">
 
    <bool>true</bool>
 
   </property>
 
   <property name="text">
 
    <string>Minor Grid</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Show/hide minor grid</string>
 
   </property>
 
   <property name="shortcut">
 
    <string>M</string>
 
   </property>
 
  </action>
 
  <action name="actionDarkBackground">
 
   <property name="checkable">
 
    <bool>true</bool>
 
   </property>
 
   <property name="text">
 
    <string>Dark Background</string>
 
   </property>
 
   <property name="toolTip">
 
    <string>Toggle Dark Background</string>
 
   </property>
 
  </action>
 
 </widget>
 
 <layoutdefault spacing="6" margin="11"/>
 
 <customwidgets>
 
  <customwidget>
 
   <class>Plot</class>
 
   <extends>QWidget</extends>
 
   <header>plot.h</header>
 
   <container>1</container>
 
  </customwidget>
 
  <customwidget>
 
   <class>HidableTabWidget</class>
 
   <extends>QTabWidget</extends>
plot.cpp
Show inline comments
 
@@ -33,42 +33,45 @@ Plot::Plot(QWidget* parent) :
 
    _darkBackgroundAction("Dark Background", this)
 
{
 
    isAutoScaled = true;
 

	
 
    QObject::connect(&zoomer, &Zoomer::unzoomed, this, &Plot::unzoomed);
 

	
 
    zoomer.setZoomBase();
 
    grid.attach(this);
 

	
 
    rectItem.setRect(QRectF(0,0,100,1));
 
    // rectItem.attach(this);
 

	
 
    showGrid(false);
 
    darkBackground(false);
 

	
 
    _showGridAction.setToolTip("Show Grid");
 
    _showMinorGridAction.setToolTip("Show Minor Grid");
 
    _unzoomAction.setToolTip("Unzoom the Plot");
 
    _darkBackgroundAction.setToolTip("Enable Dark Plot Background");
 

	
 
    _showGridAction.setShortcut(QKeySequence("G"));
 
    _showMinorGridAction.setShortcut(QKeySequence("M"));
 

	
 
    _showGridAction.setCheckable(true);
 
    _showMinorGridAction.setCheckable(true);
 
    _darkBackgroundAction.setCheckable(true);
 

	
 
    _showGridAction.setChecked(true);
 
    _showGridAction.setChecked(false);
 
    _showMinorGridAction.setChecked(false);
 
    _darkBackgroundAction.setChecked(false);
 

	
 
    _showMinorGridAction.setEnabled(false);
 

	
 
    connect(&_showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::showGrid);
 
    connect(&_showGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            &_showMinorGridAction, &QAction::setEnabled);
 
    connect(&_showMinorGridAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::showMinorGrid);
 
    connect(&_unzoomAction, &QAction::triggered, this, &Plot::unzoom);
 
    connect(&_darkBackgroundAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &Plot::darkBackground);
 
}
 

	
 
void Plot::setAxis(bool autoScaled, double yAxisMin, double yAxisMax)
0 comments (0 inline, 0 general)