36 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
38 v = mTextEdit->toHtml();
42 v = mTextEdit->toPlainText();
48 v = mPlainTextEdit->toPlainText();
53 v = mLineEdit->text();
66 if (
field().convertCompatible( res ) )
70 else if (
field().type() == QVariant::String &&
field().length() > 0 )
74 return QVariant( v.left(
field().length() ) );
78 return QVariant(
field().type() );
84 if (
config( QStringLiteral(
"IsMultiline" ) ).toBool() )
86 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
88 return new QTextBrowser( parent );
92 return new QPlainTextEdit( parent );
103 mTextBrowser = qobject_cast<QTextBrowser *>( editor );
104 mTextEdit = qobject_cast<QTextEdit *>( editor );
105 mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
106 mLineEdit = qobject_cast<QLineEdit *>( editor );
111 if ( mPlainTextEdit )
119 if ( defVal.isNull() )
127 mPlaceholderText = defVal.toString();
128 mLineEdit->setPlaceholderText( mPlaceholderText );
135 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString &
value ) { emit
valueChanged( value ); } );
136 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsTextEditWrapper::textChanged );
138 mWritablePalette = mLineEdit->palette();
139 mReadOnlyPalette = mLineEdit->palette();
145 return mLineEdit || mTextEdit || mPlainTextEdit;
152 mTextEdit->blockSignals(
true );
153 if ( mPlainTextEdit )
154 mPlainTextEdit->blockSignals(
true );
157 mLineEdit->blockSignals(
true );
160 mLineEdit->setPlaceholderText( QString() );
163 setWidgetValue( QString() );
166 mTextEdit->blockSignals(
false );
167 if ( mPlainTextEdit )
168 mPlainTextEdit->blockSignals(
false );
170 mLineEdit->blockSignals(
false );
178 mLineEdit->setPlaceholderText( mPlaceholderText );
180 setWidgetValue( val );
186 mTextEdit->setReadOnly( !enabled );
188 if ( mPlainTextEdit )
189 mPlainTextEdit->setReadOnly( !enabled );
193 mLineEdit->setReadOnly( !enabled );
195 mLineEdit->setPalette( mWritablePalette );
198 mLineEdit->setPalette( mReadOnlyPalette );
201 mLineEdit->setStyleSheet( QStringLiteral(
"background-color: rgba(255, 255, 255, 75%);" ) );
203 mLineEdit->setFrame( enabled );
207 void QgsTextEditWrapper::textChanged(
const QString & )
212 mLineEdit->setPlaceholderText( mPlaceholderText );
216 void QgsTextEditWrapper::setWidgetValue(
const QVariant &val )
221 if ( !(
field().type() == QVariant::Int ||
field().type() == QVariant::Double ||
field().type() == QVariant::LongLong ||
field().type() == QVariant::Date ) )
236 bool canConvertToDouble;
237 QLocale().toDouble( v, &canConvertToDouble );
238 if ( canConvertToDouble &&
layer() &&
layer()->isEditable() && ! QLocale().groupSeparator().isNull() &&
field().isNumeric() )
240 v = v.remove( QLocale().groupSeparator() );
245 if ( val !=
value() )
247 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
249 mTextEdit->setHtml( v );
252 mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
253 mTextBrowser->setOpenExternalLinks(
true );
257 mTextEdit->setPlainText( v );
261 if ( mPlainTextEdit )
263 if ( val !=
value() )
264 mPlainTextEdit->setPlainText( v );
268 mLineEdit->setText( v );
273 if ( hintText.isNull() )
274 mPlaceholderText = mPlaceholderTextBackup;
277 mPlaceholderTextBackup = mPlaceholderText;
278 mPlaceholderText = hintText;
281 mLineEdit->setPlaceholderText( mPlaceholderText );
void setEnabled(bool enabled) override
QString displayString(const QVariant &v) const
Formats string for display.
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
QVariant value() const override
Will be used to access the widget's value.
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QgsTextEditWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
bool valid() const override
Returns true if the widget has been properly initialized.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
void setValue(const QVariant &value) override
void setNullValue(const QString &nullValue)
Sets the string representation for null values in the widget.
Represents a vector layer which manages a vector based data sets.
void setHint(const QString &hintText) override
Add a hint text on the widget.