A QComboBox that displays units. More...
#include <unitcombobox.h>


Public Member Functions | |
| UnitComboBox (ConvertableUnitModel *model, QWidget *parent=0) | |
| void | setTreeIdConstraint (const int &tree_id, const bool &constrainUnitTo=true, const bool &showUnitFrom=true, const bool &calibrationUnit=false) |
| void | setCurrentUnitFromId (int unit_from_id) |
| int | currentUnitFromId () const |
| int | currentUnitToId () const |
| void | reset () |
| void | setModel (ConvertableUnitModel *model) |
| ConvertableUnitModel * | model () |
A QComboBox that displays units.
This class displays the UnitFromSymbols which are convertable and possibly constrained with a UnitToSymbol.
| UnitComboBox::UnitComboBox | ( | ConvertableUnitModel * | model, | |
| QWidget * | parent = 0 | |||
| ) |
| int UnitComboBox::currentUnitFromId | ( | ) | const |
Referenced by DataHeaderSection::getSqlForColumn(), and setTreeIdConstraint().
{
if (currentIndex() == -1) return 0;
return itemData(currentIndex(), ConvertableUnitModel::UnitFromId).toInt();
}
| int UnitComboBox::currentUnitToId | ( | ) | const |
Referenced by DataHeaderSection::getSqlForColumn().
{
if (currentIndex() == -1) return 0;
return itemData(currentIndex(), ConvertableUnitModel::UnitToId).toInt();
}
| ConvertableUnitModel * UnitComboBox::model | ( | ) |
Reimplemented from QComboBox.
Referenced by ImportFileHeaderSection::adjustContent(), DataHeaderSection::getSqlForColumn(), reset(), and setTreeIdConstraint().
{
ConvertableUnitModel *model = dynamic_cast<ConvertableUnitModel*>(QComboBox::model());
Q_ASSERT(model);
return model;
}
| void UnitComboBox::reset | ( | ) |
Referenced by ImportFileHeaderSection::adjustContent().
{
model()->unconstrain();
}
| void UnitComboBox::setCurrentUnitFromId | ( | int | unit_from_id | ) |
Referenced by ImportFileHeaderSection::adjustContent(), and setTreeIdConstraint().
{
int index = findData(QVariant::fromValue(unit_from_id), ConvertableUnitModel::UnitFromId);
//qDebug() << "In ImportFileHeaderSection " << logicalIndex << " searching in unitComboBox unit_id: " << data.toInt() << "and finding index: " << index << " of " << unitComboBox->count() << " possible values from query: " << dynamic_cast<ConvertableUnitModel*>(unitComboBox->model())->query().lastQuery();
setCurrentIndex(index);
}
| void UnitComboBox::setModel | ( | ConvertableUnitModel * | model | ) |
Referenced by UnitComboBox().
{
QComboBox::setModel(model);
}
| void UnitComboBox::setTreeIdConstraint | ( | const int & | tree_id, | |
| const bool & | constrainUnitTo = true, |
|||
| const bool & | showUnitFrom = true, |
|||
| const bool & | calibrationUnit = false | |||
| ) |
It checks whether the last index was -1 (i.e. invalid unit), If so, then it searches the default unit of the tree_id and sets it. Else it tries to retain the index (i.e. it tries to retain the unit which was selected prior to tree_id change. If it secceeds, then this unit is set. If the unit doesn't exist under this new tree_id, then the default unit is set.
Referenced by ImportFileHeaderSection::adjustContent(), DataHeaderSection::DataHeaderSection(), and DataHeaderSection::onCalibrationSelectionChange().
{
int index = currentIndex();
int unit_from_id = currentUnitFromId();
model()->setConstraint(tree_id, ConvertableUnitModel::ConstraintKindTreeId, constrainUnitTo, showUnitFrom, calibrationUnit);
if (index == -1) {
setCurrentConstrainedIndex(); // Index is set to -1 if not found.
} else {
setCurrentUnitFromId(unit_from_id); // Index is set to -1 if not found.
if (currentIndex() == -1) setCurrentConstrainedIndex();
}
}
1.7.1