Public Member Functions | Protected Slots

ProjectCalibrationEditor Class Reference
[Editors]

Table based project-specific calibrations editor. More...

#include <calibrationeditor.h>

Inheritance diagram for ProjectCalibrationEditor:
Inheritance graph
[legend]
Collaboration diagram for ProjectCalibrationEditor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ProjectCalibrationEditor (QWidget *parent=0)

Protected Slots

void onSensorChannelSelection (const QItemSelection &newSelection, const QItemSelection &)
virtual void updateButtons ()
virtual void onNewButtonPress ()
bool isChannelSelected ()

Detailed Description

Table based project-specific calibrations editor.


Constructor & Destructor Documentation

ProjectCalibrationEditor::ProjectCalibrationEditor ( QWidget parent = 0  )  [inline]

                                                  : CalibrationEditor(parent) {
        setObjectName("ProjectCalibrationEditorEditor");
        setWindowTitle("Calibrations editor, project based");
        treeView = new QTreeView(this);
        treeView->setModel(new AdjustedTreeModel(treeView));

        QSplitter *splitter = new QSplitter(this);
        splitter->addWidget(treeView);
        splitter->addWidget(table());
        splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

        QLabel *note = new QLabel(this);
        note->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
        note->setOpenExternalLinks(true);
        note->setTextFormat(Qt::RichText);
        note->setWordWrap(true);
        note->setText(GlobalConst::CALI_FORMULA_HELP);

        QGridLayout *widgetLayout = new QGridLayout();
        widgetLayout->addWidget(splitter, 0, 0, 1, 1);
        widgetLayout->addWidget(note, 1, 0, 1, 1);

        // main layout setup
        mainLayout()->addLayout(widgetLayout, 0, 0, 1, 1);

        // setup connections
        connect(treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
                this, SLOT(onSensorChannelSelection(QItemSelection,QItemSelection)));

        // initialize
        onSensorChannelSelection(QItemSelection(), QItemSelection());

        // setup connections
        connect(table()->itemDelegate(), SIGNAL(closeEditor(QWidget*)), this, SLOT(updateButtons()));
    }


Member Function Documentation

bool ProjectCalibrationEditor::isChannelSelected (  )  [inline, protected, slot]

Referenced by onNewButtonPress(), and onSensorChannelSelection().

                            {
        Q_ASSERT(treeView->selectionModel()->selection().indexes().count() <= 1);
        return !treeView->selectionModel()->selection().indexes().isEmpty();
    }

virtual void ProjectCalibrationEditor::onNewButtonPress (  )  [inline, protected, virtual, slot]

Reimplemented from TableBaseEditor.

                                    {
        CalibrationEditor::onNewButtonPress();
        Q_ASSERT(isChannelSelected());
        Q_ASSERT(table()->isEnabled());

        // fill in foreign key of the currently selected tree_id
        bool ok;
        int tree_id = treeView->selectionModel()->selection().indexes().first().data(ProjectTreeModel::TreeId).toInt(&ok);
        Q_ASSERT(ok);
        QSqlRecord key = Database::execStaticR(QString::number(tree_id).prepend("SELECT DISTINCT sens_id, sens_chan_nr FROM tbl_trees WHERE tree_id = "));
        int sens_id = key.value("sens_id").toInt(&ok);
        Q_ASSERT(ok);
        int sens_chan_nr = key.value("sens_chan_nr").toInt(&ok);
        Q_ASSERT(ok);
        model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_id")), sens_id);
        model()->setData(model()->index(model()->rowCount() - 1, model()->record().indexOf("sens_chan_nr")), sens_chan_nr);
    }

void ProjectCalibrationEditor::onSensorChannelSelection ( const QItemSelection newSelection,
const QItemSelection  
) [inline, protected, slot]

Referenced by ProjectCalibrationEditor().

                                                                                            {
        int tree_id = 0;
        QString filter("(sens_id, sens_chan_nr) IN (SELECT DISTINCT sens_id, sens_chan_nr FROM tbl_trees INNER JOIN tbl_sensor_channel_calibrations USING (sens_id, sens_chan_nr) WHERE tree_id = %1)");
        bool channelIsSelected = isChannelSelected();

        table()->setEnabled(channelIsSelected);
        if (!channelIsSelected) {
            // if there is no selection
            tree_id = 0;
        } else {
            // if there is a selection
            tree_id = newSelection.indexes().first().data(ProjectTreeModel::TreeId).toInt();

            // sanity check
            Q_ASSERT(newSelection.indexes().count() == 1);
            Q_ASSERT(tree_id != 0);
            Q_ASSERT(tree_id != -1);
        }

        // There is a minor problem here: once a non-empty model was selected(),
        // and an other empty is selected afterwards, then the header
        // will display questionmarks.
        model()->setTable(channelIsSelected ? "tbl_sensor_channel_calibrations" : QString());
        model()->setFilter(filter.arg(QString::number(tree_id)));
        model()->setSort(model()->record().indexOf("sens_chan_cali_timestamp"), Qt::AscendingOrder);
        model()->select();

        // hide pk column
        QSqlIndex pk = model()->primaryKey();
        for(int i = 0; i < pk.count() ; i++){
            table()->setColumnHidden(model()->record().indexOf(pk.fieldName(i)), true);
        }

        // hide sens_id & sens_chan_nr columns
        table()->setColumnHidden(model()->record().indexOf("sens_id"), true);
        table()->setColumnHidden(model()->record().indexOf("sens_chan_nr"), true);
    }

virtual void ProjectCalibrationEditor::updateButtons (  )  [inline, protected, virtual, slot]

Reimplemented from TableBaseEditor.

Referenced by ProjectCalibrationEditor().

                                 {
        CalibrationEditor::updateButtons();
        treeView->setEnabled(!isDirty());
    }


The documentation for this class was generated from the following file: