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 )
143 connect( mLineEdit, &QLineEdit::textChanged,
this, &QgsTextEditWrapper::textChanged );
145 mWritablePalette = mLineEdit->palette();
146 mReadOnlyPalette = mLineEdit->palette();
152 return mLineEdit || mTextEdit || mPlainTextEdit;
159 mTextEdit->blockSignals(
true );
160 if ( mPlainTextEdit )
161 mPlainTextEdit->blockSignals(
true );
164 mLineEdit->blockSignals(
true );
167 mLineEdit->setPlaceholderText( QString() );
170 setWidgetValue( QString() );
173 mTextEdit->blockSignals(
false );
174 if ( mPlainTextEdit )
175 mPlainTextEdit->blockSignals(
false );
177 mLineEdit->blockSignals(
false );
180 void QgsTextEditWrapper::updateValues(
const QVariant &val,
const QVariantList & )
185 mLineEdit->setPlaceholderText( mPlaceholderText );
187 setWidgetValue( val );
193 mTextEdit->setReadOnly( !enabled );
195 if ( mPlainTextEdit )
196 mPlainTextEdit->setReadOnly( !enabled );
200 mLineEdit->setReadOnly( !enabled );
202 mLineEdit->setPalette( mWritablePalette );
205 mLineEdit->setPalette( mReadOnlyPalette );
208 mLineEdit->setStyleSheet( QStringLiteral(
"background-color: rgba(255, 255, 255, 75%);" ) );
210 mLineEdit->setFrame( enabled );
214 void QgsTextEditWrapper::textChanged(
const QString & )
219 mLineEdit->setPlaceholderText( mPlaceholderText );
223 void QgsTextEditWrapper::setWidgetValue(
const QVariant &val )
228 if ( !(
field().type() == QVariant::Int ||
field().type() == QVariant::Double ||
field().type() == QVariant::LongLong ||
field().type() == QVariant::Date ) )
243 bool canConvertToDouble;
244 QLocale().toDouble( v, &canConvertToDouble );
245 if ( canConvertToDouble &&
layer() &&
layer()->isEditable() && ! QLocale().groupSeparator().isNull() &&
field().isNumeric() )
247 v = v.remove( QLocale().groupSeparator() );
252 if ( val !=
value() )
254 if (
config( QStringLiteral(
"UseHtml" ) ).toBool() )
256 mTextEdit->setHtml( v );
259 mTextBrowser->setTextInteractionFlags( Qt::LinksAccessibleByMouse );
260 mTextBrowser->setOpenExternalLinks(
true );
264 mTextEdit->setPlainText( v );
268 if ( mPlainTextEdit )
270 if ( val !=
value() )
271 mPlainTextEdit->setPlainText( v );
275 mLineEdit->setText( v );
280 if ( hintText.isNull() )
281 mPlaceholderText = mPlaceholderTextBackup;
284 mPlaceholderTextBackup = mPlaceholderText;
285 mPlaceholderText = hintText;
288 mLineEdit->setPlaceholderText( mPlaceholderText );
void setEnabled(bool enabled) override
#define Q_NOWARN_DEPRECATED_PUSH
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.
#define Q_NOWARN_DEPRECATED_POP
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.