23#include "KPropertyEditorView.h"
24#include "KPropertyListData.h"
25#include "KPropertyUtils.h"
26#include "KPropertyUtils_p.h"
27#include "KPropertyWidgetsFactory.h"
28#include "kproperty_debug.h"
31#include <QGuiApplication>
33KPropertyComboBoxEditorOptions::KPropertyComboBoxEditorOptions()
34 : extraValueAllowed(false)
38KPropertyComboBoxEditorOptions::KPropertyComboBoxEditorOptions(
39 const KPropertyComboBoxEditorOptions &other)
44KPropertyComboBoxEditorOptions::~KPropertyComboBoxEditorOptions()
49KPropertyComboBoxEditorOptions& KPropertyComboBoxEditorOptions::operator=(
const KPropertyComboBoxEditorOptions &other)
52 if (other.iconProvider) {
53 iconProvider = other.iconProvider->clone();
56 iconProvider =
nullptr;
58 extraValueAllowed = other.extraValueAllowed;
64class Q_DECL_HIDDEN KPropertyComboBoxEditor::Private
74 KPropertyListData listData;
75 bool setValueEnabled =
true;
76 KPropertyComboBoxEditorOptions options;
77 QCompleter *completer =
nullptr;
80KPropertyComboBoxEditor::KPropertyComboBoxEditor(
const KPropertyListData &listData,
81 const KPropertyComboBoxEditorOptions &options,
86 setEditable(d->options.extraValueAllowed);
88 setAutoCompletion(
true);
90 setListData(listData);
91 connect(
this, SIGNAL(activated(
int)),
this, SLOT(slotValueChanged(
int)));
96 if (!KPropertyUtilsPrivate::gridLineColor(
this).
isValid()) {
107 padding-top: %2px; padding-left: %3px; }").
arg(borderSheet(
this)).
arg(paddingTop).
arg(paddingLeft);
108 setStyleSheet(styleSheet);
111KPropertyComboBoxEditor::~KPropertyComboBoxEditor()
117QString KPropertyComboBoxEditor::borderSheet(
const QWidget *widget)
121 if (
style == QLatin1String(
"windowsvista")
122 ||
style == QLatin1String(
"fusion"))
126 return QLatin1String(
"border: 0px; ");
129bool KPropertyComboBoxEditor::listDataKeysAvailable()
const
131 return !d->listData.keys().isEmpty();
134QVariant KPropertyComboBoxEditor::value()
const
136 if (!listDataKeysAvailable())
140 if (idx < 0 || idx >= d->listData.keys().count()
141 || d->listData.names()[idx].toString() !=
currentText().trimmed())
143 if (!d->options.extraValueAllowed ||
currentText().isEmpty())
147 return d->listData.keys()[idx];
150void KPropertyComboBoxEditor::setValue(
const QVariant &value)
152 if (!d->setValueEnabled)
154 const int idx = d->listData.keys().isEmpty() ? -1 : d->listData.keys().indexOf(value);
156 if (idx >= 0 && idx <
count()) {
161 if (d->options.extraValueAllowed) {
165 kprWarning() <<
"NO SUCH KEY:" << value.toString()
169 for (
int i = 0; i <
count(); i++)
171 kprWarning() <<
"NO SUCH INDEX WITHIN COMBOBOX:" << idx
172 <<
"count=" <<
count() <<
"value=" << value.toString()
173 <<
"property=" <<
objectName() <<
"\nActual combobox contents"
180void KPropertyComboBoxEditor::fillValues()
184 if (!listDataKeysAvailable())
188 for (
const QString &itemName : d->listData.namesAsStringList()) {
190 if (d->options.iconProvider) {
191 QIcon icon = d->options.iconProvider->icon(index);
197 d->completer =
new QCompleter(d->listData.namesAsStringList());
198 d->completer->setWidget(
this);
204 d->listData = listData;
208void KPropertyComboBoxEditor::slotValueChanged(
int)
210 emit commitData(
this );
213void KPropertyComboBoxEditor::paintEvent(
QPaintEvent * event )
216 KPropertyWidgetsFactory::paintTopGridLine(
this);
221KPropertyComboBoxDelegate::KPropertyComboBoxDelegate()
223 options()->setBordersVisible(
true);
226QString KPropertyComboBoxDelegate::propertyValueToString(
const KProperty* property,
const QLocale &locale)
const
229 KPropertyListData *listData =
property->listData();
231 return property->value().toString();
235 const int idx = listData->
keys().indexOf(property->
value());
241 return property->value().toString();
243 return property->listData()->names()[idx].toString();
252QWidget* KPropertyComboBoxDelegate::createEditor(
int type,
QWidget *parent,
258 KProperty *
property = KPropertyUtils::propertyForIndex(index);
262 KPropertyComboBoxEditorOptions
options;
263 options.extraValueAllowed =
property->option(
"extraValueAllowed",
false).toBool();
264 KPropertyComboBoxEditor *cb =
new KPropertyComboBoxEditor(*property->
listData(),
options, parent);
const KPropertyEditorCreatorOptions * options() const
Options for editor creating.
A data container for properties of list type.
QVariantList keys() const
A list containing all possible keys for a property.
The base class representing a single property.
QVariant option(const char *name, const QVariant &defaultValue=QVariant()) const
Returns value of given option Option is set if returned value is not null. If there is no option for ...
KPropertyListData * listData() const
bool isValid(QStringView ifopt)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
bool isEditable() const const
QString itemText(int index) const const
virtual void paintEvent(QPaintEvent *e) override
void setEditText(const QString &text)
void setItemIcon(int index, const QIcon &icon)
void setItemText(int index, const QString &text)
virtual bool event(QEvent *e)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isNull() const const
bool toBool() const const
QString toString() const const