23 QGridLayout* gridLayout,
int row) :
24 BaseWidget(parent,
"SpaceEditWidget",
"SpaceEditWidget")
26 this->setToolTip(
"Edit a space (coordinate system)");
27 CX_ASSERT(dataInterface->getAllowOnlyValuesInRange()==
true);
29 this->setEnabled(dataInterface->getEnabled());
31 mData = dataInterface;
32 connect(mData.get(), SIGNAL(changed()),
this, SLOT(
setModified()));
34 mLabel =
new QLabel(
this);
35 mLabel->setText(mData->getDisplayName());
37 mIdCombo =
new QComboBox(
this);
38 connect(mIdCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
40 mRefCombo =
new QComboBox(
this);
41 connect(mRefCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
46 gridLayout->addWidget(mIdCombo, row, 1);
47 gridLayout->addWidget(mRefCombo, row, 2);
63 void SpaceEditWidget::attemptSetValue(COORDINATE_SYSTEM
id, QString ref)
67 QStringList refs = this->getAvailableSpaceRefs(space.
mId);
74 std::vector<Space> range = mData->getValueRange();
75 if (!count(range.begin(), range.end(), space))
81 mData->setValue(space);
84 void SpaceEditWidget::comboIndexChanged()
86 this->attemptSetValue(COORDINATE_SYSTEM(mIdCombo->currentData().toInt()), mRefCombo->currentData().toString());
91 mLabel->setVisible(on);
95 void SpaceEditWidget::rebuildIdCombobox()
99 Space currentValue = mData->getValue();
100 std::vector<COORDINATE_SYSTEM> ids = this->getAvailableSpaceIds();
102 int currentIndex = -1;
103 for (
int i = 0; i < ids.size(); ++i)
105 COORDINATE_SYSTEM
id = ids[i];
106 QString name = enum2string<COORDINATE_SYSTEM>(id);
108 mIdCombo->addItem(name);
109 mIdCombo->setItemData(i, QVariant::fromValue<int>(
id));
110 if (
id == currentValue.
mId)
113 mIdCombo->setCurrentIndex(currentIndex);
116 std::vector<COORDINATE_SYSTEM> SpaceEditWidget::getAvailableSpaceIds()
118 std::vector<COORDINATE_SYSTEM> retval;
119 std::vector<Space> range = mData->getValueRange();
121 for (
unsigned i=0; i<range.size(); ++i)
123 if (!count(retval.begin(), retval.end(), range[i].mId))
124 retval.push_back(range[i].mId);
130 void SpaceEditWidget::rebuildRefCombobox()
134 Space currentValue = mData->getValue();
135 QStringList refs = this->getAvailableSpaceRefs(currentValue.
mId);
137 int currentIndex = -1;
138 for (
int i = 0; i < refs.size(); ++i)
140 QString ref = refs[i];
141 QString name = mData->convertRefObjectInternal2Display(ref);
142 mRefCombo->addItem(name);
143 mRefCombo->setItemData(i, ref);
147 mRefCombo->setCurrentIndex(currentIndex);
151 this->setRefComboVisibilityQueued();
154 void SpaceEditWidget::setRefComboVisibilityQueued()
156 bool show = mRefCombo->count();
158 if (mRefCombo->isVisible()==show)
162 QMetaObject::invokeMethod(mRefCombo,
"show", Qt::QueuedConnection);
164 QMetaObject::invokeMethod(mRefCombo,
"hide", Qt::QueuedConnection);
167 QStringList SpaceEditWidget::getAvailableSpaceRefs(COORDINATE_SYSTEM
id)
170 std::vector<Space> range = mData->getValueRange();
172 for (
unsigned i=0; i<range.size(); ++i)
174 if (range[i].mId ==
id)
175 retval.push_back(range[i].mRefObject);
177 retval.removeDuplicates();
178 retval.removeAll(
"");
183 void SpaceEditWidget::prePaintEvent()
185 mRefCombo->blockSignals(
true);
186 mIdCombo->blockSignals(
true);
190 this->setEnabled(mData->getEnabled());
191 mLabel->setEnabled(mData->getEnabled());
192 mIdCombo->setEnabled(mData->getEnabled());
193 mRefCombo->setEnabled(mData->getEnabled());
195 this->rebuildIdCombobox();
196 this->rebuildRefCombobox();
198 mIdCombo->setToolTip(QString(
"%1\nSet space type").arg(mData->getHelp()));
199 mRefCombo->setToolTip(QString(
"%1\nSet space identifier").arg(mData->getHelp()));
200 mLabel->setToolTip(mData->getHelp());
202 mRefCombo->blockSignals(
false);
203 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.