File: prefsDialog.cpp

package info (click to toggle)
linssid 3.6-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,424 kB
  • sloc: cpp: 1,667; xml: 51; sh: 17; makefile: 6
file content (100 lines) | stat: -rw-r--r-- 3,750 bytes parent folder | download | duplicates (4)
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
/*
 * File:   PrefsDialog.cpp
 * Author: warren
 *
 * Created on January 2, 2013, 2:40 PM
 */

#include <string>
#include <iostream>
#include "prefsDialog.h"
#include "MainForm.h"

struct sEntryValue {
    QString tblFntSize;
    int plotMin;
    int plotMax;
    bool showGrid;
    bool logDataState;
} prefsDialog::entryValue;

prefsDialog::prefsDialog(QString tblFntSize, int plotMin, int plotMax, bool showGrid, int logDataState, QObject* mommy) {
    widget.setupUi(this);
    prefsDialog::entryValue.tblFntSize = tblFntSize;
    prefsDialog::entryValue.plotMin = plotMin;
    prefsDialog::entryValue.plotMax = plotMax;
    prefsDialog::entryValue.showGrid = showGrid;
    prefsDialog::entryValue.logDataState = logDataState;
    // now set initial values of widgets in the prefs dialog
    for (int item = 0; item < MainForm::numFntSizes; item++) {
        widget.tblFntSizeSb->addItem(MainForm::fntSizes[item]);
        if (MainForm::fntSizes[item] == tblFntSize) {
            widget.tblFntSizeSb->setCurrentIndex(item);
        }
    }
    // widget.tblFntSizeSb->setCurrentIndex(widget.tblFntSizeSb->findData(tblFntSize));
    widget.dbMinsb->setValue(plotMin);
    widget.dbMaxsb->setValue(plotMax);
    widget.plotGridcbx->setChecked(showGrid);
    widget.logDatacbx->setCheckState((Qt::CheckState) logDataState);
    widget.dbMinsb->setMinimum(-100);
    widget.dbMaxsb->setMaximum(0);
    widget.dbMinsb->setMaximum(widget.dbMaxsb->value() - 10);
    widget.dbMaxsb->setMinimum(widget.dbMinsb->value() + 10);
    // disable user text editing the spin boxes. Yeah, this is the only way.
    widget.dbMinsb->findChild<QLineEdit*>()->setReadOnly(true);
    widget.dbMaxsb->findChild<QLineEdit*>()->setReadOnly(true);
    connect(prefsDialog::widget.tblFntSizeSb, SIGNAL(currentTextChanged(QString)), this, SLOT(tblFntSizeSbChanged(QString)));
    connect(prefsDialog::widget.dbMinsb, SIGNAL(valueChanged(int)), this, SLOT(minSbChanged(int)));
    connect(prefsDialog::widget.dbMaxsb, SIGNAL(valueChanged(int)), this, SLOT(maxSbChanged(int)));
    connect(prefsDialog::widget.plotGridcbx, SIGNAL(stateChanged(int)), this, SLOT(gridChanged(int)));
    connect(prefsDialog::widget.logDatacbx, SIGNAL(stateChanged(int)), mommy, SLOT(logPrefChanged(int)));
    connect(this, SIGNAL(plotPrefsChanged(QString, int, int, bool)),
            mommy, SLOT(updatePlotPrefs(QString, int, int, bool)));
    connect(this, SIGNAL(finished(int)), this, SLOT(bailOut(int)));
}

prefsDialog::~prefsDialog() {
}

// the emit values in this order:
// QString fontsize, int minplot, int maxplot, bool plotgrid

void prefsDialog::tblFntSizeSbChanged(QString newValue) {
    emit plotPrefsChanged(newValue,
        // plotPrefsChanged(widget.tblFntSizeSb->currentText(),
        widget.dbMinsb->value(),
        widget.dbMaxsb->value(),
        widget.plotGridcbx->isChecked());
}

void prefsDialog::minSbChanged(int newValue) {

    emit plotPrefsChanged(widget.tblFntSizeSb->currentText(),
        newValue,
        widget.dbMaxsb->value(),
        widget.plotGridcbx->isChecked());
    widget.dbMaxsb->setMinimum(newValue + 10);
}

void prefsDialog::maxSbChanged(int newValue) {

    emit plotPrefsChanged(widget.tblFntSizeSb->currentText(),
        widget.dbMinsb->value(),
        newValue,
        widget.plotGridcbx->isChecked());
    widget.dbMinsb->setMaximum(newValue - 10);
}

void prefsDialog::gridChanged(int newValue) {

    emit plotPrefsChanged(widget.tblFntSizeSb->currentText(),
        widget.dbMinsb->value(),
        widget.dbMaxsb->value(),
        newValue);
}

void prefsDialog::bailOut(int result) {
    if (result == 0)
        emit plotPrefsChanged(entryValue.tblFntSize, entryValue.plotMin, entryValue.plotMax, entryValue.showGrid);
}