44 QGridLayout* gridLayout,
int row) :
45 BaseWidget(parent,
"SpaceEditWidget",
"SpaceEditWidget")
47 this->setToolTip(
"Edit a space (coordinate system)");
48 CX_ASSERT(dataInterface->getAllowOnlyValuesInRange()==
true);
50 this->setEnabled(dataInterface->getEnabled());
52 mData = dataInterface;
53 connect(mData.get(), SIGNAL(changed()),
this, SLOT(
setModified()));
55 mLabel =
new QLabel(
this);
56 mLabel->setText(mData->getDisplayName());
58 mIdCombo =
new QComboBox(
this);
59 connect(mIdCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
61 mRefCombo =
new QComboBox(
this);
62 connect(mRefCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
67 gridLayout->addWidget(mIdCombo, row, 1);
68 gridLayout->addWidget(mRefCombo, row, 2);
84 void SpaceEditWidget::attemptSetValue(COORDINATE_SYSTEM
id, QString ref)
89 QStringList refs = this->getAvailableSpaceRefs(space.mId);
91 space.mRefObject =
"";
92 else if (!refs.contains(space.mRefObject))
93 space.mRefObject = refs[0];
96 std::vector<Space> range = mData->getValueRange();
97 if (!count(range.begin(), range.end(), space))
104 mData->setValue(space);
107 void SpaceEditWidget::comboIndexChanged()
109 this->attemptSetValue(COORDINATE_SYSTEM(mIdCombo->currentData().toInt()), mRefCombo->currentData().toString());
114 mLabel->setVisible(on);
118 void SpaceEditWidget::rebuildIdCombobox()
120 mIdCombo->blockSignals(
true);
123 Space currentValue = mData->getValue();
124 std::vector<COORDINATE_SYSTEM> ids = this->getAvailableSpaceIds();
126 int currentIndex = -1;
127 for (
int i = 0; i < ids.size(); ++i)
129 COORDINATE_SYSTEM
id = ids[i];
130 QString name = enum2string<COORDINATE_SYSTEM>(id);
132 mIdCombo->addItem(name);
133 mIdCombo->setItemData(i, QVariant::fromValue<int>(
id));
134 if (
id == currentValue.
mId)
137 mIdCombo->setCurrentIndex(currentIndex);
140 std::vector<COORDINATE_SYSTEM> SpaceEditWidget::getAvailableSpaceIds()
142 std::vector<COORDINATE_SYSTEM> retval;
143 std::vector<Space> range = mData->getValueRange();
145 for (
unsigned i=0; i<range.size(); ++i)
147 if (!count(retval.begin(), retval.end(), range[i].mId))
148 retval.push_back(range[i].mId);
154 void SpaceEditWidget::rebuildRefCombobox()
156 mRefCombo->blockSignals(
true);
159 Space currentValue = mData->getValue();
160 QStringList refs = this->getAvailableSpaceRefs(currentValue.mId);
162 int currentIndex = -1;
163 for (
int i = 0; i < refs.size(); ++i)
165 QString ref = refs[i];
166 QString name = mData->convertRefObjectInternal2Display(ref);
167 mRefCombo->addItem(name);
168 mRefCombo->setItemData(i, ref);
169 if (ref == currentValue.mRefObject)
172 mRefCombo->setCurrentIndex(currentIndex);
173 mRefCombo->setVisible(!refs.empty());
176 QStringList SpaceEditWidget::getAvailableSpaceRefs(COORDINATE_SYSTEM
id)
179 std::vector<Space> range = mData->getValueRange();
181 for (
unsigned i=0; i<range.size(); ++i)
183 if (range[i].mId ==
id)
184 retval.push_back(range[i].mRefObject);
186 retval.removeDuplicates();
187 retval.removeAll(
"");
192 void SpaceEditWidget::prePaintEvent()
194 mRefCombo->blockSignals(
true);
195 mIdCombo->blockSignals(
true);
199 this->setEnabled(mData->getEnabled());
200 mLabel->setEnabled(mData->getEnabled());
201 mIdCombo->setEnabled(mData->getEnabled());
202 mRefCombo->setEnabled(mData->getEnabled());
204 this->rebuildIdCombobox();
205 this->rebuildRefCombobox();
207 mIdCombo->setToolTip(QString(
"%1\nSet space type").arg(mData->getHelp()));
208 mRefCombo->setToolTip(QString(
"%1\nSet space identifier").arg(mData->getHelp()));
209 mLabel->setToolTip(mData->getHelp());
211 mRefCombo->blockSignals(
false);
212 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.