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();
140 mReadOnlyPalette.setColor( QPalette::Text, mWritablePalette.color( QPalette::Disabled, QPalette::Text ) );
146 return mLineEdit || mTextEdit || mPlainTextEdit;
153 mTextEdit->blockSignals(
true );
154 if ( mPlainTextEdit )
155 mPlainTextEdit->blockSignals(
true );
158 mLineEdit->blockSignals(
true );
161 mLineEdit->setPlaceholderText( QString() );
164 setWidgetValue( QLatin1String(
"" ) );
167 mTextEdit->blockSignals(
false );
168 if ( mPlainTextEdit )
169 mPlainTextEdit->blockSignals(
false );
171 mLineEdit->blockSignals(
false );
179 mLineEdit->setPlaceholderText( mPlaceholderText );
181 setWidgetValue( val );
187 mTextEdit->setReadOnly( !enabled );
189 if ( mPlainTextEdit )
190 mPlainTextEdit->setReadOnly( !enabled );
194 mLineEdit->setReadOnly( !enabled );
196 mLineEdit->setPalette( mWritablePalette );
198 mLineEdit->setPalette( mReadOnlyPalette );
202 void QgsTextEditWrapper::textChanged(
const QString & )
207 mLineEdit->setPlaceholderText( mPlaceholderText );
211 void QgsTextEditWrapper::setWidgetValue(
const QVariant &val )
216 if ( !(
field().type() == QVariant::Int ||
field().type() == QVariant::Double ||
field().type() == QVariant::LongLong ||
field().type() == QVariant::Date ) )
226 if ( val !=
value() )
228 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
230 mTextEdit->setHtml( v );
233 mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
234 mTextBrowser->setOpenExternalLinks(
true );
238 mTextEdit->setPlainText( v );
242 if ( mPlainTextEdit )
244 if ( val !=
value() )
245 mPlainTextEdit->setPlainText( v );
249 mLineEdit->setText( v );
254 if ( hintText.isNull() )
255 mPlaceholderText = mPlaceholderTextBackup;
258 mPlaceholderTextBackup = mPlaceholderText;
259 mPlaceholderText = hintText;
262 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.
QString displayString(const QVariant &v) const
Formats string for display.
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.