17 #include <YPropertyEditor.h> 20 #include <YWidgetFactory.h> 22 #include <YLayoutBox.h> 23 #include <YAlignment.h> 24 #include <YButtonBox.h> 25 #include <YPushButton.h> 27 #include <YPopupInternal.h> 28 #include <YComboBox.h> 29 #include <YInputField.h> 30 #include <YIntField.h> 34 #define YUILogComponent "ui-property-editor" 42 popup(
nullptr), combo(
nullptr), intfield(
nullptr),
43 input(
nullptr), okButton(
nullptr), cancelButton(
nullptr)
46 bool edit(
const std::string &property);
54 void show(
const std::string &property);
61 bool run(
const std::string &property);
80 bool isReadOnly(
const std::string &property);
101 bool editable(
const std::string &property);
108 void YPropertyEditorPriv::refreshDialog()
114 bool YPropertyEditorPriv::edit(
const std::string &property)
116 if (!_widget || !editable(property))
return false;
118 yuiMilestone() <<
"editing property \"" <<
property <<
"\" (type: " <<
122 bool changed = run(property);
128 bool YPropertyEditorPriv::isReadOnly(
const std::string &property)
138 if (prop.
name() == property)
145 YUI_THROW(
YUIException(
"Unknown property: " + property) );
151 void YPropertyEditorPriv::show(
const std::string &property)
154 YPropertyType type = prop_value.
type();
158 popup = f->createPopupDialog();
159 auto vbox = f->createVBox(popup);
161 if (type == YBoolProperty)
163 combo = f->createComboBox(vbox, property);
167 items.push_back(
new YItem(
"true"));
168 items.push_back(
new YItem(
"false"));
170 combo->
setValue(prop_value.boolVal() ?
"true" :
"false");
172 else if (type == YIntegerProperty)
174 intfield = f->createIntField(vbox, property,
177 std::numeric_limits<int>::min(), std::numeric_limits<int>::max(),
178 prop_value.integerVal());
181 else if (type == YStringProperty)
183 input = f->createInputField(vbox, property);
188 auto bbox = f->createButtonBox(vbox);
189 okButton = f->createPushButton(bbox,
"OK");
192 cancelButton = f->createPushButton(bbox,
"Cancel");
193 cancelButton->
setRole(YCancelButton);
196 void YPropertyEditorPriv::close()
209 bool YPropertyEditorPriv::run(
const std::string &property)
220 if (event->widget() == cancelButton ||
event->eventType() == YEvent::CancelEvent)
232 else if (event->widget() == okButton)
236 else if (event->widget() == combo)
238 std::string value = combo->
value();
239 yuiMilestone() <<
"Value changed to " << value;
243 else if (event->widget() == input)
245 std::string value = input->
value();
246 yuiMilestone() <<
"Value changed to " << value;
251 else if (event->widget() == intfield)
253 int value = intfield->
value();
254 yuiMilestone() <<
"Value changed to " << value;
263 bool YPropertyEditorPriv::editable(
const std::string &property)
268 if (isReadOnly(property))
274 YPropertyType type = prop_value.
type();
276 if (type != YBoolProperty && type != YStringProperty && type != YIntegerProperty)
286 return priv->edit(property);
294 YPropertyEditor::~YPropertyEditor()
static YWidgetFactory * widgetFactory()
Return the widget factory that provides all the createXY() methods for standard (mandatory, i.e.
Transport class for the value of simple properties.
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
const_iterator propertiesEnd() const
Returns an iterator that points after the last property in this set.
A set of properties to check names and types against.
void setValue(const std::string &newText)
Set the value of this ComboBox by string: Try to find a list item with that label and select it...
Abstract base class for events to be returned upon UI::UserInput() and related functions.
std::string name() const
Returns the name of this property.
bool edit(const std::string &property)
Display a popup for editing a widget property.
ComboBox (or "drop down box", "drop down selection"); may be editable.
const_iterator propertiesBegin() const
Returns an iterator that points to the first property in this set.
std::string stringVal() const
Methods to get the value of this property.
Class for widget properties.
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
bool isReadOnly() const
Returns 'true' if this property cannot be changed, only retrieved.
std::string typeAsStr() const
Returns the type of this property value as string.
virtual int value()=0
Get the current value (the number entered by the user or set from the outside) of this IntField...
IntField: Input field for integer values.
void recalcLayout()
Recalculate the layout of the dialog and of all its children after children have been added or remove...
A window in the desktop environment.
std::string value()
Return the value of this ComboBox:
YPropertyEditor(YWidget *widget)
Constructor.
Base class for UI Exceptions.
YPropertyType type() const
Returns the type of this property value.
bool destroy(bool doThrow=true)
Close and delete this dialog (and all its children) if it is the topmost dialog.
YEvent * waitForEvent(int timeout_millisec=0)
Wait for a user event.