37 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
39 v = mTextEdit->toHtml();
43 v = mTextEdit->toPlainText();
49 v = mPlainTextEdit->toPlainText();
54 v = mLineEdit->text();
67 if (
field().convertCompatible( res ) )
71 else if (
field().type() == QVariant::String &&
field().length() > 0 )
75 return QVariant( v.left(
field().length() ) );
79 return QVariant(
field().type() );
85 if (
config( QStringLiteral(
"IsMultiline" ) ).toBool() )
87 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
89 return new QTextBrowser( parent );
93 return new QPlainTextEdit( parent );
104 mTextBrowser = qobject_cast<QTextBrowser *>( editor );
105 mTextEdit = qobject_cast<QTextEdit *>( editor );
106 mPlainTextEdit = qobject_cast<QPlainTextEdit *>( editor );
107 mLineEdit = qobject_cast<QLineEdit *>( editor );
112 if ( mPlainTextEdit )
120 if ( defVal.isNull() )
128 mPlaceholderText = defVal.toString();
129 mLineEdit->setPlaceholderText( mPlaceholderText );
136 connect( mLineEdit, &QLineEdit::textChanged,
this, [ = ](
const QString &
value ) { emit
valueChanged( value ); } );
137 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsTextEditWrapper::textChanged );
139 mWritablePalette = mLineEdit->palette();
140 mReadOnlyPalette = mLineEdit->palette();
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( QString() );
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 );
199 mLineEdit->setPalette( mReadOnlyPalette );
202 mLineEdit->setStyleSheet( QStringLiteral(
"background-color: rgba(255, 255, 255, 75%);" ) );
204 mLineEdit->setFrame( enabled );
208 void QgsTextEditWrapper::textChanged(
const QString & )
213 mLineEdit->setPlaceholderText( mPlaceholderText );
217 void QgsTextEditWrapper::setWidgetValue(
const QVariant &val )
222 if ( !(
field().type() == QVariant::Int ||
field().type() == QVariant::Double ||
field().type() == QVariant::LongLong ||
field().type() == QVariant::Date ) )
237 bool canConvertToDouble;
238 QLocale().toDouble( v, &canConvertToDouble );
239 if ( canConvertToDouble &&
layer() &&
layer()->isEditable() && ! QLocale().groupSeparator().isNull() &&
field().isNumeric() )
241 v = v.remove( QLocale().groupSeparator() );
246 if ( val !=
value() )
248 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
250 mTextEdit->setHtml( v );
253 mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
254 mTextBrowser->setOpenExternalLinks(
true );
258 mTextEdit->setPlainText( v );
262 if ( mPlainTextEdit )
264 if ( val !=
value() )
265 mPlainTextEdit->setPlainText( v );
269 mLineEdit->setText( v );
274 if ( hintText.isNull() )
275 mPlaceholderText = mPlaceholderTextBackup;
278 mPlaceholderTextBackup = mPlaceholderText;
279 mPlaceholderText = hintText;
282 mLineEdit->setPlaceholderText( mPlaceholderText );
void setEnabled(bool enabled) override
QgsTextEditWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsTextEditWrapper.
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.
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.