44 QGridLayout* gridLayout,
int row) :
45 BaseWidget(parent,
"SpaceEditWidget",
"SpaceEditWidget")
47 CX_ASSERT(dataInterface->getAllowOnlyValuesInRange()==
true);
49 this->setEnabled(dataInterface->getEnabled());
51 mData = dataInterface;
52 connect(mData.get(), SIGNAL(changed()),
this, SLOT(
setModified()));
54 mLabel =
new QLabel(
this);
55 mLabel->setText(mData->getDisplayName());
57 mIdCombo =
new QComboBox(
this);
58 connect(mIdCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
60 mRefCombo =
new QComboBox(
this);
61 connect(mRefCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(comboIndexChanged()));
66 gridLayout->addWidget(mIdCombo, row, 1);
67 gridLayout->addWidget(mRefCombo, row, 2);
85 return "<html></html>";
88 void SpaceEditWidget::attemptSetValue(COORDINATE_SYSTEM
id, QString ref)
93 QStringList refs = this->getAvailableSpaceRefs(space.mId);
95 space.mRefObject =
"";
96 else if (!refs.contains(space.mRefObject))
97 space.mRefObject = refs[0];
100 std::vector<Space> range = mData->getValueRange();
101 if (!count(range.begin(), range.end(), space))
108 mData->setValue(space);
111 void SpaceEditWidget::comboIndexChanged()
113 this->attemptSetValue(COORDINATE_SYSTEM(mIdCombo->currentData().toInt()), mRefCombo->currentData().toString());
118 mLabel->setVisible(on);
122 void SpaceEditWidget::rebuildIdCombobox()
124 mIdCombo->blockSignals(
true);
127 Space currentValue = mData->getValue();
128 std::vector<COORDINATE_SYSTEM> ids = this->getAvailableSpaceIds();
130 int currentIndex = -1;
131 for (
int i = 0; i < ids.size(); ++i)
133 COORDINATE_SYSTEM
id = ids[i];
134 QString name = enum2string<COORDINATE_SYSTEM>(id);
136 mIdCombo->addItem(name);
137 mIdCombo->setItemData(i, QVariant::fromValue<int>(
id));
138 if (
id == currentValue.
mId)
141 mIdCombo->setCurrentIndex(currentIndex);
144 std::vector<COORDINATE_SYSTEM> SpaceEditWidget::getAvailableSpaceIds()
146 std::vector<COORDINATE_SYSTEM> retval;
147 std::vector<Space> range = mData->getValueRange();
149 for (
unsigned i=0; i<range.size(); ++i)
151 if (!count(retval.begin(), retval.end(), range[i].mId))
152 retval.push_back(range[i].mId);
158 void SpaceEditWidget::rebuildRefCombobox()
160 mRefCombo->blockSignals(
true);
163 Space currentValue = mData->getValue();
164 QStringList refs = this->getAvailableSpaceRefs(currentValue.mId);
166 int currentIndex = -1;
167 for (
int i = 0; i < refs.size(); ++i)
169 QString ref = refs[i];
170 QString name = mData->convertRefObjectInternal2Display(ref);
171 mRefCombo->addItem(name);
172 mRefCombo->setItemData(i, ref);
173 if (ref == currentValue.mRefObject)
176 mRefCombo->setCurrentIndex(currentIndex);
177 mRefCombo->setVisible(!refs.empty());
180 QStringList SpaceEditWidget::getAvailableSpaceRefs(COORDINATE_SYSTEM
id)
183 std::vector<Space> range = mData->getValueRange();
185 for (
unsigned i=0; i<range.size(); ++i)
187 if (range[i].mId ==
id)
188 retval.push_back(range[i].mRefObject);
190 retval.removeDuplicates();
191 retval.removeAll(
"");
196 void SpaceEditWidget::prePaintEvent()
198 mRefCombo->blockSignals(
true);
199 mIdCombo->blockSignals(
true);
203 this->setEnabled(mData->getEnabled());
204 mLabel->setEnabled(mData->getEnabled());
205 mIdCombo->setEnabled(mData->getEnabled());
206 mRefCombo->setEnabled(mData->getEnabled());
208 this->rebuildIdCombobox();
209 this->rebuildRefCombobox();
211 mIdCombo->setToolTip(QString(
"%1\nSet space type").arg(mData->getHelp()));
212 mRefCombo->setToolTip(QString(
"%1\nSet space identifier").arg(mData->getHelp()));
213 mLabel->setToolTip(mData->getHelp());
215 mRefCombo->blockSignals(
false);
216 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.