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)
88 QStringList refs = this->getAvailableSpaceRefs(space.mId);
90 space.mRefObject =
"";
91 else if (!refs.contains(space.mRefObject))
92 space.mRefObject = refs[0];
95 std::vector<Space> range = mData->getValueRange();
96 if (!count(range.begin(), range.end(), space))
102 mData->setValue(space);
105 void SpaceEditWidget::comboIndexChanged()
107 this->attemptSetValue(COORDINATE_SYSTEM(mIdCombo->currentData().toInt()), mRefCombo->currentData().toString());
112 mLabel->setVisible(on);
116 void SpaceEditWidget::rebuildIdCombobox()
120 Space currentValue = mData->getValue();
121 std::vector<COORDINATE_SYSTEM> ids = this->getAvailableSpaceIds();
123 int currentIndex = -1;
124 for (
int i = 0; i < ids.size(); ++i)
126 COORDINATE_SYSTEM
id = ids[i];
127 QString name = enum2string<COORDINATE_SYSTEM>(id);
129 mIdCombo->addItem(name);
130 mIdCombo->setItemData(i, QVariant::fromValue<int>(
id));
131 if (
id == currentValue.
mId)
134 mIdCombo->setCurrentIndex(currentIndex);
137 std::vector<COORDINATE_SYSTEM> SpaceEditWidget::getAvailableSpaceIds()
139 std::vector<COORDINATE_SYSTEM> retval;
140 std::vector<Space> range = mData->getValueRange();
142 for (
unsigned i=0; i<range.size(); ++i)
144 if (!count(retval.begin(), retval.end(), range[i].mId))
145 retval.push_back(range[i].mId);
151 void SpaceEditWidget::rebuildRefCombobox()
155 Space currentValue = mData->getValue();
156 QStringList refs = this->getAvailableSpaceRefs(currentValue.mId);
158 int currentIndex = -1;
159 for (
int i = 0; i < refs.size(); ++i)
161 QString ref = refs[i];
162 QString name = mData->convertRefObjectInternal2Display(ref);
163 mRefCombo->addItem(name);
164 mRefCombo->setItemData(i, ref);
165 if (ref == currentValue.mRefObject)
168 mRefCombo->setCurrentIndex(currentIndex);
172 this->setRefComboVisibilityQueued();
175 void SpaceEditWidget::setRefComboVisibilityQueued()
177 bool show = mRefCombo->count();
179 if (mRefCombo->isVisible()==show)
183 QMetaObject::invokeMethod(mRefCombo,
"show", Qt::QueuedConnection);
185 QMetaObject::invokeMethod(mRefCombo,
"hide", Qt::QueuedConnection);
188 QStringList SpaceEditWidget::getAvailableSpaceRefs(COORDINATE_SYSTEM
id)
191 std::vector<Space> range = mData->getValueRange();
193 for (
unsigned i=0; i<range.size(); ++i)
195 if (range[i].mId ==
id)
196 retval.push_back(range[i].mRefObject);
198 retval.removeDuplicates();
199 retval.removeAll(
"");
204 void SpaceEditWidget::prePaintEvent()
206 mRefCombo->blockSignals(
true);
207 mIdCombo->blockSignals(
true);
211 this->setEnabled(mData->getEnabled());
212 mLabel->setEnabled(mData->getEnabled());
213 mIdCombo->setEnabled(mData->getEnabled());
214 mRefCombo->setEnabled(mData->getEnabled());
216 this->rebuildIdCombobox();
217 this->rebuildRefCombobox();
219 mIdCombo->setToolTip(QString(
"%1\nSet space type").arg(mData->getHelp()));
220 mRefCombo->setToolTip(QString(
"%1\nSet space identifier").arg(mData->getHelp()));
221 mLabel->setToolTip(mData->getHelp());
223 mRefCombo->blockSignals(
false);
224 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.