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 QTextEdit( parent );
92 return new QPlainTextEdit( parent );
103 mTextEdit = qobject_cast<QTextEdit *>( editor );
104 mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
105 mLineEdit = qobject_cast<QLineEdit *>( editor );
110 if ( mPlainTextEdit )
118 if ( defVal.isNull() )
126 mPlaceholderText = defVal.toString();
127 mLineEdit->setPlaceholderText( mPlaceholderText );
134 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString &
value ) { emit
valueChanged( value ); } );
135 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsTextEditWrapper::textChanged );
137 mWritablePalette = mLineEdit->palette();
138 mReadOnlyPalette = mLineEdit->palette();
139 mReadOnlyPalette.setColor( QPalette::Text, mWritablePalette.color( QPalette::Disabled, QPalette::Text ) );
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( QLatin1String(
"" ) );
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 );
197 mLineEdit->setPalette( mReadOnlyPalette );
201 void QgsTextEditWrapper::textChanged(
const QString & )
206 mLineEdit->setPlaceholderText( mPlaceholderText );
210 void QgsTextEditWrapper::setWidgetValue(
const QVariant &val )
215 if ( !(
field().type() == QVariant::Int ||
field().type() == QVariant::Double ||
field().type() == QVariant::LongLong ||
field().type() == QVariant::Date ) )
223 if ( val !=
value() )
225 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
226 mTextEdit->setHtml( v );
228 mTextEdit->setPlainText( v );
232 if ( mPlainTextEdit )
234 if ( val !=
value() )
235 mPlainTextEdit->setPlainText( v );
239 mLineEdit->setText( v );
244 if ( hintText.isNull() )
245 mPlaceholderText = mPlaceholderTextBackup;
248 mPlaceholderTextBackup = mPlaceholderText;
249 mPlaceholderText = hintText;
252 mLineEdit->setPlaceholderText( mPlaceholderText );
void setEnabled(bool enabled) override
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
Return 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.