9#include <QtQml/qqmlcontext.h>
10#include <QtQml/qqmlfile.h>
11#include <QtQml/qqmlinfo.h>
12#include <QtQuick/private/qquickpixmap_p.h>
14#include <QtCore/qfile.h>
15#include <QtCore/qpointer.h>
21using namespace
Qt::StringLiterals;
66 d->editor = qobject_cast<QQuickTextEdit *>(parent);
69 this, &QQuickTextDocument::modifiedChanged);
172 return d->errorString;
182 emit q->statusChanged();
187 emit q->errorStringChanged();
242 qmlWarning(
this) <<
"Existing document modified: you should save(),"
243 "or call TextEdit.clear() before setting a different source";
248 emit sourceChanged();
287 return doc && doc->isModified();
298 auto *doc =
editor->document();
301 QQuickTextDocument::tr(
"Null document object: cannot load"));
309#if QT_CONFIG(mimetype)
311 const bool isHtml =
mimeType.inherits(
"text/html"_L1);
312 const bool isMarkdown =
mimeType.inherits(
"text/markdown"_L1);
329#if QT_CONFIG(textmarkdownreader) || QT_CONFIG(texthtmlparser)
332#if QT_CONFIG(textmarkdownreader)
337#if QT_CONFIG(texthtmlparser)
344 doc->setHtml(decoder(
data));
357#if QT_CONFIG(mimetype)
361 doc->setModified(
false);
368 QQuickTextDocument::tr(
"%1 does not exist").
arg(filePath));
374 auto *doc =
editor->document();
379 const bool sameUrl = fileUrl ==
url;
381#if QT_CONFIG(mimetype)
383 if (
type.inherits(
"text/html"_L1))
385 else if (
type.inherits(
"text/markdown"_L1))
411#if QT_CONFIG(textmarkdownwriter)
413 raw = doc->toMarkdown().toUtf8();
416#if QT_CONFIG(texthtmlparser)
420 raw = enc.encode(doc->toHtml());
423 raw = doc->toHtml().toUtf8();
428 raw = doc->toPlainText().toUtf8();
435 doc->setModified(
false);
440 return editor->document();
454 q, &QQuickTextDocument::modifiedChanged);
457 emit q->textDocumentChanged();
466 return d->document();
477 d_func()->setDocument(document);
532void QQuickTextDocument::save()
565void QQuickTextDocument::saveAs(
const QUrl &
url)
570 QQuickTextDocument::tr(
"Can only save to local files"));
579 emit sourceChanged();
590 if (
format.isImageFormat()) {
597 if (!hasWidth || !hasHeight) {
600 if (
image.isNull()) {
630#include "moc_qquicktextdocument.cpp"
631#include "moc_qquicktextdocument_p.cpp"
void close() override
Calls QFileDevice::flush() and closes the file.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
QMimeType mimeTypeForUrl(const QUrl &url) const
Returns a MIME type for url.
QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode=MatchDefault) const
Returns a MIME type for the file named fileName using mode.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QQmlContext class defines a context within a QML engine.
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to \l{QFile}.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Qt::TextFormat detectedFormat
QQuickTextDocument::Status status
QTextDocument * document() const
std::optional< QStringConverter::Encoding > encoding
void setStatus(QQuickTextDocument::Status s, const QString &err)
void setDocument(QTextDocument *doc)
void writeTo(const QUrl &fileUrl)
\qmltype TextDocument \instantiates QQuickTextDocument \inqmlmodule QtQuick
Status status
the status of document loading or saving
bool isModified() const
\qmlproperty bool QtQuick::TextDocument::modified
QUrl source
the URL from which to load document contents
void setSource(const QUrl &url)
void setModified(bool modified)
void setTextDocument(QTextDocument *document)
Sets the given document.
bool modified
whether the document has been modified by the user
QTextDocument * textDocument() const
Returns a pointer to the QTextDocument object.
QString errorString
a human-readable string describing the error that occurred during loading or saving,...
QQuickTextImageHandler(QObject *parent=nullptr)
QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override
The intrinsicSize() function returns the size of the text object represented by format in the given d...
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
static Q_CORE_EXPORT std::optional< Encoding > encodingForHtml(QByteArrayView data)
Tries to determine the encoding of the HTML in data by looking at leading byte order marks or a chars...
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
\reentrant \inmodule QtGui
void modificationChanged(bool m)
This signal is emitted whenever the content of the document changes in a way that affects the modific...
QVariant resource(int type, const QUrl &name) const
Returns data of the specified type from the resource with the given name.
QTextImageFormat toImageFormat() const
Returns this format as an image format.
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false.
qreal width() const
Returns the width of the rectangle occupied by the image.
qreal height() const
Returns the height of the rectangle occupied by the image.
QString name() const
Returns the name of the image.
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Combined button and popup list for selecting options.
int qRound(qfloat16 d) noexcept
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLdouble GLdouble GLdouble GLdouble q
QQmlContext * qmlContext(const QObject *obj)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static QUrl resolvedUrl(const QUrl &url, const QQmlRefPointer< QQmlContextData > &context)
QUrl url("example.com")
[constructor-url-reference]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
const QByteArray plainText