22 QGridLayout* gridLayout,
int row) :
23 BaseWidget(parent,
"SpaceEditWidget",
"SpaceEditWidget")
25 this->setToolTip(
"Edit a space (coordinate system)");
26 CX_ASSERT(dataInterface->getAllowOnlyValuesInRange()==
true);
28 this->setEnabled(dataInterface->getEnabled());
30 mData = dataInterface;
31 connect(mData.get(), SIGNAL(changed()),
this, SLOT(
setModified()));
33 mLabel =
new QLabel(
this);
34 mLabel->setText(mData->getDisplayName());
36 mIdCombo =
new QComboBox(
this);
37 connect(mIdCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
39 mRefCombo =
new QComboBox(
this);
40 connect(mRefCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
45 gridLayout->addWidget(mIdCombo, row, 1);
46 gridLayout->addWidget(mRefCombo, row, 2);
62 void SpaceEditWidget::attemptSetValue(COORDINATE_SYSTEM
id, QString ref)
66 QStringList refs = this->getAvailableSpaceRefs(space.
mId);
73 std::vector<Space> range = mData->getValueRange();
74 if (!count(range.begin(), range.end(), space))
80 mData->setValue(space);
83 void SpaceEditWidget::comboIndexChanged()
85 this->attemptSetValue(COORDINATE_SYSTEM(mIdCombo->currentData().toInt()), mRefCombo->currentData().toString());
90 mLabel->setVisible(on);
94 void SpaceEditWidget::rebuildIdCombobox()
98 Space currentValue = mData->getValue();
99 std::vector<COORDINATE_SYSTEM> ids = this->getAvailableSpaceIds();
101 int currentIndex = -1;
102 for (
int i = 0; i < ids.size(); ++i)
104 COORDINATE_SYSTEM
id = ids[i];
105 QString name = enum2string<COORDINATE_SYSTEM>(id);
107 mIdCombo->addItem(name);
108 mIdCombo->setItemData(i, QVariant::fromValue<int>(
id));
109 if (
id == currentValue.
mId)
112 mIdCombo->setCurrentIndex(currentIndex);
115 std::vector<COORDINATE_SYSTEM> SpaceEditWidget::getAvailableSpaceIds()
117 std::vector<COORDINATE_SYSTEM> retval;
118 std::vector<Space> range = mData->getValueRange();
120 for (
unsigned i=0; i<range.size(); ++i)
122 if (!count(retval.begin(), retval.end(), range[i].mId))
123 retval.push_back(range[i].mId);
129 void SpaceEditWidget::rebuildRefCombobox()
133 Space currentValue = mData->getValue();
134 QStringList refs = this->getAvailableSpaceRefs(currentValue.
mId);
136 int currentIndex = -1;
137 for (
int i = 0; i < refs.size(); ++i)
139 QString ref = refs[i];
140 QString name = mData->convertRefObjectInternal2Display(ref);
141 mRefCombo->addItem(name);
142 mRefCombo->setItemData(i, ref);
146 mRefCombo->setCurrentIndex(currentIndex);
150 this->setRefComboVisibilityQueued();
153 void SpaceEditWidget::setRefComboVisibilityQueued()
155 bool show = mRefCombo->count();
157 if (mRefCombo->isVisible()==show)
161 QMetaObject::invokeMethod(mRefCombo,
"show", Qt::QueuedConnection);
163 QMetaObject::invokeMethod(mRefCombo,
"hide", Qt::QueuedConnection);
166 QStringList SpaceEditWidget::getAvailableSpaceRefs(COORDINATE_SYSTEM
id)
169 std::vector<Space> range = mData->getValueRange();
171 for (
unsigned i=0; i<range.size(); ++i)
173 if (range[i].mId ==
id)
174 retval.push_back(range[i].mRefObject);
176 retval.removeDuplicates();
177 retval.removeAll(
"");
182 void SpaceEditWidget::prePaintEvent()
184 mRefCombo->blockSignals(
true);
185 mIdCombo->blockSignals(
true);
189 this->setEnabled(mData->getEnabled());
190 mLabel->setEnabled(mData->getEnabled());
191 mIdCombo->setEnabled(mData->getEnabled());
192 mRefCombo->setEnabled(mData->getEnabled());
194 this->rebuildIdCombobox();
195 this->rebuildRefCombobox();
197 mIdCombo->setToolTip(QString(
"%1\nSet space type").arg(mData->getHelp()));
198 mRefCombo->setToolTip(QString(
"%1\nSet space identifier").arg(mData->getHelp()));
199 mLabel->setToolTip(mData->getHelp());
201 mRefCombo->blockSignals(
false);
202 mIdCombo->blockSignals(
false);
#define CX_ASSERT(statement)
boost::shared_ptr< SpacePropertyBase > SpacePropertyBasePtr
COORDINATE_SYSTEM mId
the type of coordinate system
Identification of a Coordinate system.
QString mRefObject
for tool, sensor and data we need a object uid to define the coordinate system
Namespace for all CustusX production code.