Header section for data used in BuilderView. More...
#include <builderview.h>
Public Slots | |
void | slot_updateTitle () |
void | slot_caliChkBoxCheckEnable () |
void | onCalibrationSelectionChange () |
Signals | |
void | signal_removalRequested () |
void | signal_curve_setEnabled (bool) |
Public Member Functions | |
DataHeaderSection (TreeItem *treeItem, QWidget *parent=0) | |
~DataHeaderSection () | |
CalibrationsCheckBox * | calibrationsCheckBox () |
QString | getName () |
virtual QVariant | data (int role) const |
QString | getSqlForColumn () |
int | getTreeId () |
QString | getTitle () |
DataHeaderViewPort * | parentHeader () |
int | logicalIndex () |
Protected Member Functions | |
bool | eventFilter (QObject *object, QEvent *event) |
Header section for data used in BuilderView.
The calibration window shows up when you hover over the "Calibrations?" checkbox. It consists of two columns: the timestamp and the calibration formula. "RAW" references the raw data.
Calibration formulas are classified in tree types, based on the selected time range.
The selected calibration closest to the data timestamp is used for computation. If there is data before any calibration, the closest (i.e. oldest selected) calibration is used in computation.
: HeaderSection(parent) { qRegisterMetaType<Qt::CheckState>("Qt::CheckState"); //to use it with queued (!) signals & slots setObjectName("DataHeaderSection"); m_treeItem = treeItem; sectionName = new QLabel(this); int tree_id = treeItem->data(TreeItem::TreeItemId).toInt(); Q_ASSERT(tree_id != -1); Q_ASSERT(tree_id != 0); this->installEventFilter(this); cView = new CalibrationsView(tree_id, this); cView->setWindowFlags(Qt::ToolTip); cView->setFrameStyle(QFrame::Box | QFrame::Panel); cView->installEventFilter(this); caliChkBox = new CalibrationsCheckBox("Calibrations?", this); slot_caliChkBoxCheckEnable(); caliChkBox->installEventFilter(this); unitCB = new UnitComboBox(new ConvertableUnitModel(this), this); unitCB->setTreeIdConstraint(tree_id, false, false); connect(caliChkBox, SIGNAL(stateChanged(int)), cView->model(), SLOT(slot_allCalibrations_toggle(int))); connect(cView->model(), SIGNAL(signal_calibrationSelections_changed(Qt::CheckState)), caliChkBox, SLOT(slot_setCheckState(Qt::CheckState))); connect(cView->model(), SIGNAL(signal_calibrationSelections_changed(Qt::CheckState)), this, SLOT(onCalibrationSelectionChange())); connect(cView->model(), SIGNAL(signal_calibrationSelections_changed(Qt::CheckState)), this, SIGNAL(signal_userSetting_changed()), Qt::QueuedConnection); connect(cView->model(), SIGNAL(modelReset()), this, SLOT(slot_caliChkBoxCheckEnable())); connect(unitCB, SIGNAL(currentIndexChanged(int)), this, SIGNAL(signal_userSetting_changed()), Qt::QueuedConnection); deleteAction = new QAction("Delete", this); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteLater())); graphAction = new QAction("Graph", this); graphAction->setCheckable(true); connect(graphAction, SIGNAL(triggered(bool)), this, SIGNAL(signal_curve_setEnabled(bool))); QToolBar *toolBar = new QToolBar("Actions", this); toolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); toolBar->addAction(graphAction); toolBar->addAction(deleteAction); //Always put as last: it shows as last. QHBoxLayout *middleLayout = new QHBoxLayout; middleLayout->addWidget(sectionName, 1); middleLayout->addWidget(unitCB); vLayout = new QVBoxLayout(this); vLayout->addWidget(toolBar, 0, Qt::AlignRight); vLayout->addLayout(middleLayout); vLayout->addWidget(caliChkBox); setLayout(vLayout); setToolTip(m_treeItem->data(TreeItem::TreeItemFullName).toString()); // Title update must be called after the construction finishes, // and the item is DataHeaderSection is added to the headder. // If we call it during construction, the DataHeader cannot form the name. QTimer::singleShot(0, this, SLOT(slot_updateTitle())); }
DataHeaderSection::~DataHeaderSection | ( | ) |
{ emit signal_curve_setEnabled(false); //make sure no corresponding curve stays over. }
CalibrationsCheckBox * DataHeaderSection::calibrationsCheckBox | ( | ) |
{
return caliChkBox;
}
QVariant DataHeaderSection::data | ( | int | role | ) | const [virtual] |
Reimplemented from HeaderSection.
Referenced by DataHeader::data().
{ if (role == GlobalEnum::BuilderHeaderDataUnitSymbolRole) return unitCB->currentText(); else return QVariant(); }
{ if (object == caliChkBox && event->type() == QEvent::Enter){ // Getting builderView: goes beyond the modular nature of objects. It's probably better to // implement something similar with signals/slots? BuilderView *builderView = dynamic_cast<BuilderView*>(parent()->parent()->parent()->parent()->parent()); Q_ASSERT(builderView); // Calculate cordinates of the calibrationsView QPoint topLeft = builderView->dataView()->mapToGlobal(QPoint(0,0)); QPoint top = this->mapToGlobal(QPoint(0, this->height()-1)); //-1, otherwise one pixel remains in between! QSize size = builderView->dataView()->size(); size.setHeight(size.height() + (topLeft.y() - top.y()) - 1); //-1, only one pixel remains of the bottom of the view QRect r(QPoint(topLeft.x(), top.y()), size); // Show calibrationsView cView->setGeometry(r); cView->show(); } if ((object == this || object == cView) && event->type() == QEvent::Leave){ QRect thisGeo = this->geometry(); QPoint globalPoint = this->parentWidget()->mapToGlobal(thisGeo.topLeft()); thisGeo.moveTopLeft(globalPoint); if (thisGeo.contains(QCursor::pos(), false) || cView->geometry().contains(QCursor::pos(), false)) return HeaderSection::eventFilter(object, event); cView->hide(); } return HeaderSection::eventFilter(object, event); }
QString DataHeaderSection::getName | ( | ) |
Referenced by DataHeaderViewPort::getHeaderNames(), and DataHeaderViewPort::getSql().
{
return sectionName->text();
}
QString DataHeaderSection::getSqlForColumn | ( | ) |
Referenced by DataHeaderViewPort::getSql().
{ // Initialize int tree_id = m_treeItem->data(TreeItem::TreeItemId).toInt(); QString sql = TREE_ID_COLUMN.arg(QString::number(tree_id)); QString selectedCalibrationIds = cView->model()->getSelectedCalibrationIds().join(","); // Calibrate if necessary if (selectedCalibrationIds != QString()) sql = CALIBRATION_FUNCTION.arg(sql, selectedCalibrationIds, QString::number(tree_id)); // Convert unit if necessary Q_ASSERT(unitCB->model()->isUnitFromConstrained()); Q_ASSERT(unitCB->model()->currentConstraintUnitId().toInt() == unitCB->currentUnitFromId()); if (unitCB->currentUnitToId() != unitCB->model()->currentConstraintUnitId()) sql = UNITCONVERT_FUNCTION.arg(sql, QString::number(unitCB->currentUnitFromId()), QString::number(unitCB->currentUnitToId())); return sql; }
QString DataHeaderSection::getTitle | ( | ) |
Referenced by slot_updateTitle().
{ QVector<DataHeaderSection*> sections = parentHeader()->sections(getTreeId()); QString name = m_treeItem->data(TreeItem::TreeItemName).toString(); Q_ASSERT(sections.count() != 0); if (sections.count() == 1) return name; else return name.append("_(%1)").arg(QString::number(sections.indexOf(this))); }
int DataHeaderSection::getTreeId | ( | ) |
Referenced by DataHeaderViewPort::getSql(), getTitle(), and DataHeaderViewPort::sections().
{ return m_treeItem->data(TreeItem::TreeItemId).toInt(); }
int DataHeaderSection::logicalIndex | ( | ) |
{ return parentHeader()->logicalIndex(this); }
void DataHeaderSection::onCalibrationSelectionChange | ( | ) | [slot] |
Referenced by DataHeaderSection().
{ Q_ASSERT(m_treeItem); unitCB->setTreeIdConstraint(m_treeItem->data(TreeItem::TreeItemId).toInt(), false, false, cView->model()->isAnyItemChecked()); }
DataHeaderViewPort * DataHeaderSection::parentHeader | ( | ) |
Referenced by getTitle(), and logicalIndex().
{ Q_ASSERT(dynamic_cast<DataHeaderViewPort*>(parent())); return dynamic_cast<DataHeaderViewPort*>(parent()); }
void DataHeaderSection::signal_curve_setEnabled | ( | bool | ) | [signal] |
Referenced by DataHeaderSection(), and ~DataHeaderSection().
void DataHeaderSection::signal_removalRequested | ( | ) | [signal] |
void DataHeaderSection::slot_caliChkBoxCheckEnable | ( | ) | [slot] |
Referenced by DataHeaderSection().
void DataHeaderSection::slot_updateTitle | ( | ) | [slot] |
Referenced by DataHeaderSection().
{ sectionName->setText(getTitle()); }