Editor for sensor channel calibrations. More...
#include <projecteditor.h>
Public Member Functions | |
SensorChannelCalibrationEditor (int sens_id, int sens_chan_nr, int positionOnId=-1, QWidget *parent=0) | |
Protected Member Functions | |
virtual void | onNewButtonPress () |
Editor for sensor channel calibrations.
SensorChannelCalibrationEditor::SensorChannelCalibrationEditor | ( | int | sens_id, | |
int | sens_chan_nr, | |||
int | positionOnId = -1 , |
|||
QWidget * | parent = 0 | |||
) | [inline] |
: MappedBaseEditor(parent), m_sens_id(sens_id), m_sens_chan_nr(sens_chan_nr) { setObjectName("SensorChannelCalibrationEditor"); // set units QSqlRecord result = Database::execStaticR(QString("SELECT su.unit_symbol AS unit_from, scu.unit_symbol AS unit_to, s.unit_id, sc.sens_chan_cali_unit_id " "FROM tbl_sensors s " "INNER JOIN tbl_sensor_channels sc USING (sens_id) " "INNER JOIN tbl_units su ON (s.unit_id = su.unit_id) " "INNER JOIN tbl_units scu ON (sc.sens_chan_cali_unit_id = scu.unit_id) " "WHERE sens_id = %1 AND sens_chan_nr = %2") .arg(QString::number(m_sens_id), QString::number(m_sens_chan_nr))); bool ok; m_sens_unit_id = result.value("unit_id").toInt(&ok); Q_ASSERT(ok); m_sens_chan_cali_unit_id = result.value("sens_chan_cali_unit_id").toInt(&ok); Q_ASSERT(ok); // sanity check Q_ASSERT(sens_id > 0); Q_ASSERT(sens_chan_nr > 0); // convert constraint numbers to strings const QString sens_id_str = QString::number(sens_id); const QString sens_chan_nr_str = QString::number(sens_chan_nr); // make title static const QString baseQuery("SELECT sens_type || ' [SN: ' || sens_serialnr || '] Channel #' || sens_chan_nr " "FROM tbl_sensors s INNER JOIN tbl_sensor_channels sc USING (sens_id) " "WHERE sens_id = %1 AND sens_chan_nr = %2"); const QString query(baseQuery.arg(sens_id_str, sens_chan_nr_str)); const QString title = Database::execStaticR(query).value(0).toString(); // set window title setWindowTitle(QString("Calibration editor for ").append(title)); // set source setTable("tbl_sensor_channel_calibrations", "sens_chan_cali_timestamp", Qt::DescendingOrder, "sens_id = " + sens_id_str + " AND sens_chan_nr = " + sens_chan_nr_str); // widget setup QLabel *timestamp = new QLabel("&Timestamp*:", this); QLabel *formula = new QLabel(QString("&Formula* [%1]->[%2]:").arg(result.value("unit_from").toString(), result.value("unit_to").toString()), this); QLabel *desc = new QLabel("&Description:", this); QDateTimeEdit *timestampEdit = new QDateTimeEdit(this); QLineEdit *formulaEdit = new QLineEdit(this); QTextEdit *descEdit = new QTextEdit(this); timestamp->setBuddy(timestampEdit); formula->setBuddy(timestampEdit); desc->setBuddy(descEdit); // adjust imput widgets timestampEdit->setCalendarPopup(true); // add widgets addWidget(timestamp, 0, 0, 1, 1); addWidget(timestampEdit, 0, 1, 1, 1, "sens_chan_cali_timestamp"); addWidget(formula, 1, 0, 1, 1); addWidget(formulaEdit, 1, 1, 1, 1, "sens_chan_cali_formula"); addWidget(desc, 2, 0, 1, 1); addWidget(descEdit, 3, 0, 1, 2, "sens_chan_cali_desc", "plainText"); // setup connections connect(timestampEdit, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateButtons())); connect(formulaEdit, SIGNAL(textChanged(QString)), this, SLOT(updateButtons())); connect(descEdit, SIGNAL(textChanged()), this, SLOT(updateButtons())); // setup formula note QLabel *formulaNote = new QLabel(GlobalConst::CALI_FORMULA_HELP, this); formulaNote->setTextInteractionFlags(Qt::LinksAccessibleByMouse); formulaNote->setOpenExternalLinks(true); formulaNote->setWordWrap(true); bottomLayout()->addWidget(bottomLayout()->itemAtPosition(0, 0)->widget(), 1, 0); bottomLayout()->addWidget(formulaNote, 0, 0); // update changes select(); // update mapper to current record if (positionOnId > 0) setCurrent("sens_chan_cali_id", QVariant::fromValue<int>(positionOnId)); }
virtual void SensorChannelCalibrationEditor::onNewButtonPress | ( | ) | [inline, protected, virtual] |
Reimplemented from MappedBaseEditor.
{ MappedBaseEditor::onNewButtonPress(); model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_id")), QVariant::fromValue(m_sens_id)); model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_chan_nr")), QVariant::fromValue(m_sens_chan_nr)); model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_chan_cali_unit_from_id")), QVariant::fromValue(m_sens_unit_id)); model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_chan_cali_unit_to_id")), QVariant::fromValue(m_sens_chan_cali_unit_id)); }