Qt 4.8
Public Functions | Protected Functions | Private Slots | Properties | Static Private Attributes | List of all members
QTextDocumentWithImageResources Class Reference
Inheritance diagram for QTextDocumentWithImageResources:
QTextDocument QObject

Public Functions

 QTextDocumentWithImageResources (QDeclarativeText *parent)
 
int resourcesLoading () const
 
void setText (const QString &)
 
virtual ~QTextDocumentWithImageResources ()
 
- Public Functions inherited from QTextDocument
void addResource (int type, const QUrl &name, const QVariant &resource)
 Adds the resource resource to the resource cache, using type and name as identifiers. More...
 
void adjustSize ()
 Adjusts the document to a reasonable size. More...
 
QVector< QTextFormatallFormats () const
 Returns a vector of text formats for all the formats used in the document. More...
 
int availableRedoSteps () const
 Returns the number of available redo steps. More...
 
int availableUndoSteps () const
 Returns the number of available undo steps. More...
 
QTextBlock begin () const
 Returns the document's first text block. More...
 
int blockCount () const
 
QChar characterAt (int pos) const
 Returns the character at position pos, or a null character if the position is out of range. More...
 
int characterCount () const
 Returns the number of characters of this document. More...
 
virtual void clear ()
 Clears the document. More...
 
void clearUndoRedoStacks (Stacks historyToClear=UndoAndRedoStacks)
 Clears the stacks specified by stacksToClear. More...
 
QTextDocumentclone (QObject *parent=0) const
 Creates a new QTextDocument that is a copy of this text document. More...
 
Qt::CursorMoveStyle defaultCursorMoveStyle () const
 The default cursor movement style is used by all QTextCursor objects created from the document. More...
 
QFont defaultFont () const
 
QString defaultStyleSheet () const
 
QTextOption defaultTextOption () const
 the default text option will be set on all QTextLayout in the document. More...
 
QTextDocumentPrivatedocHandle () const
 So that not all classes have to be friends of each other. More...
 
QAbstractTextDocumentLayoutdocumentLayout () const
 Returns the document layout for this document. More...
 
qreal documentMargin () const
 
void drawContents (QPainter *painter, const QRectF &rect=QRectF())
 Draws the content of the document with painter p, clipped to rect. More...
 
QTextBlock end () const
 This function returns a block to test for the end of the document while iterating over it. More...
 
QTextCursor find (const QString &subString, int from=0, FindFlags options=0) const
 Finds the next occurrence of the string, subString, in the document. More...
 
QTextCursor find (const QString &subString, const QTextCursor &from, FindFlags options=0) const
 Finds the next occurrence of the string, subString, in the document. More...
 
QTextCursor find (const QRegExp &expr, int from=0, FindFlags options=0) const
 Finds the next occurrence, matching the regular expression, expr, in the document. More...
 
QTextCursor find (const QRegExp &expr, const QTextCursor &from, FindFlags options=0) const
 Finds the next occurrence, matching the regular expression, expr, in the document. More...
 
QTextBlock findBlock (int pos) const
 Returns the text block that contains the {pos}-th character. More...
 
QTextBlock findBlockByLineNumber (int blockNumber) const
 Returns the text block that contains the specified lineNumber. More...
 
QTextBlock findBlockByNumber (int blockNumber) const
 Returns the text block with the specified blockNumber. More...
 
QTextBlock firstBlock () const
 Returns the document's first text block. More...
 
QTextFrameframeAt (int pos) const
 Returns the frame that contains the text cursor position pos. More...
 
qreal idealWidth () const
 Returns the ideal width of the text document. More...
 
qreal indentWidth () const
 
bool isEmpty () const
 Returns true if the document is empty; otherwise returns false. More...
 
bool isModified () const
 
bool isRedoAvailable () const
 Returns true if redo is available; otherwise returns false. More...
 
bool isUndoAvailable () const
 Returns true if undo is available; otherwise returns false. More...
 
bool isUndoRedoEnabled () const
 
QTextBlock lastBlock () const
 Returns the document's last (valid) text block. More...
 
int lineCount () const
 Returns the number of lines of this document (if the layout supports this). More...
 
void markContentsDirty (int from, int length)
 Marks the contents specified by the given position and length as "dirty", informing the document that it needs to be laid out again. More...
 
int maximumBlockCount () const
 
QString metaInformation (MetaInformation info) const
 Returns meta information about the document of the type specified by info. More...
 
QTextObjectobject (int objectIndex) const
 Returns the text object associated with the given objectIndex. More...
 
QTextObjectobjectForFormat (const QTextFormat &) const
 Returns the text object associated with the format f. More...
 
int pageCount () const
 returns the number of pages in this document. More...
 
QSizeF pageSize () const
 
void print (QPrinter *printer) const
 Prints the document to the given printer. More...
 
 QTextDocument (QObject *parent=0)
 Constructs an empty QTextDocument with the given parent. More...
 
 QTextDocument (const QString &text, QObject *parent=0)
 Constructs a QTextDocument containing the plain (unformatted) text specified, and with the given parent. More...
 
void redo (QTextCursor *cursor)
 Redoes the last editing operation on the document if redo is available. More...
 
QVariant resource (int type, const QUrl &name) const
 Returns data of the specified type from the resource with the given name. More...
 
int revision () const
 Returns the document's revision (if undo is enabled). More...
 
QTextFramerootFrame () const
 Returns the document's root frame. More...
 
void setDefaultCursorMoveStyle (Qt::CursorMoveStyle style)
 Sets the default cursor movement style to the given style. More...
 
void setDefaultFont (const QFont &font)
 Sets the default font to use in the document layout. More...
 
void setDefaultStyleSheet (const QString &sheet)
 
void setDefaultTextOption (const QTextOption &option)
 Sets the default text option. More...
 
void setDocumentLayout (QAbstractTextDocumentLayout *layout)
 Sets the document to use the given layout. More...
 
void setDocumentMargin (qreal margin)
 
void setHtml (const QString &html)
 Replaces the entire contents of the document with the given HTML-formatted text in the html string. More...
 
void setIndentWidth (qreal width)
 Sets the width used for text list and text block indenting. More...
 
void setMaximumBlockCount (int maximum)
 
void setMetaInformation (MetaInformation info, const QString &)
 Sets the document's meta information of the type specified by info to the given string. More...
 
void setPageSize (const QSizeF &size)
 
void setPlainText (const QString &text)
 Replaces the entire contents of the document with the given plain text. More...
 
void setTextWidth (qreal width)
 
void setUndoRedoEnabled (bool enable)
 
void setUseDesignMetrics (bool b)
 
QSizeF size () const
 
qreal textWidth () const
 
QString toHtml (const QByteArray &encoding=QByteArray()) const
 Returns a string containing an HTML representation of the document. More...
 
QString toPlainText () const
 Returns the plain text contained in the document. More...
 
void undo (QTextCursor *cursor)
 Undoes the last editing operation on the document if undo is available. More...
 
bool useDesignMetrics () const
 
 ~QTextDocument ()
 Destroys the document. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

QVariant loadResource (int type, const QUrl &name)
 Loads data of the specified type from the resource with the given name. More...
 
- Protected Functions inherited from QTextDocument
virtual QTextObjectcreateObject (const QTextFormat &f)
 Creates and returns a new document object (a QTextObject), based on the given format. More...
 
 QTextDocument (QTextDocumentPrivate &dd, QObject *parent)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void requestFinished ()
 

Properties

QHash< QUrl, QDeclarativePixmap * > m_resources
 
int outstanding
 

Static Private Attributes

static QSet< QUrlerrors
 

Additional Inherited Members

- Public Types inherited from QTextDocument
enum  FindFlag { FindBackward = 0x00001, FindCaseSensitively = 0x00002, FindWholeWords = 0x00004 }
 This enum describes the options available to QTextDocument's find function. More...
 
enum  MetaInformation { DocumentTitle, DocumentUrl }
 This enum describes the different types of meta information that can be added to a document. More...
 
enum  ResourceType { HtmlResource = 1, ImageResource = 2, StyleSheetResource = 3, UserResource = 100 }
 This enum describes the types of resources that can be loaded by QTextDocument's loadResource() function. More...
 
enum  Stacks { UndoStack = 0x01, RedoStack = 0x02, UndoAndRedoStacks = UndoStack | RedoStack }
 
- Public Slots inherited from QTextDocument
void appendUndoItem (QAbstractUndoItem *)
 Appends a custom undo item to the undo stack. More...
 
void redo ()
 Redoes the last editing operation on the document if redo is available. More...
 
void setModified (bool m=true)
 
void undo ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QTextDocument
void blockCountChanged (int newBlockCount)
 This signal is emitted when the total number of text blocks in the document changes. More...
 
void contentsChange (int from, int charsRemoves, int charsAdded)
 This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. More...
 
void contentsChanged ()
 This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied. More...
 
void cursorPositionChanged (const QTextCursor &cursor)
 This signal is emitted whenever the position of a cursor changed due to an editing operation. More...
 
void documentLayoutChanged ()
 This signal is emitted when a new document layout is set. More...
 
void modificationChanged (bool m)
 This signal is emitted whenever the content of the document changes in a way that affects the modification state. More...
 
void redoAvailable (bool)
 This signal is emitted whenever redo operations become available (available is true) or unavailable (available is false). More...
 
void undoAvailable (bool)
 This signal is emitted whenever undo operations become available (available is true) or unavailable (available is false). More...
 
void undoCommandAdded ()
 This signal is emitted every time a new level of undo is added to the QTextDocument. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 62 of file qdeclarativetext.cpp.

Constructors and Destructors

◆ QTextDocumentWithImageResources()

QTextDocumentWithImageResources::QTextDocumentWithImageResources ( QDeclarativeText parent)

Definition at line 103 of file qdeclarativetext.cpp.

Referenced by QDeclarativeTextPrivate::ensureDoc().

104 : QTextDocument(parent), outstanding(0)
105 {
106 }
QTextDocument(QObject *parent=0)
Constructs an empty QTextDocument with the given parent.

◆ ~QTextDocumentWithImageResources()

QTextDocumentWithImageResources::~QTextDocumentWithImageResources ( )
virtual

Definition at line 108 of file qdeclarativetext.cpp.

109 {
110  if (!m_resources.isEmpty())
112 }
QHash< QUrl, QDeclarativePixmap * > m_resources
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ loadResource()

QVariant QTextDocumentWithImageResources::loadResource ( int  type,
const QUrl name 
)
protectedvirtual

Loads data of the specified type from the resource with the given name.

This function is called by the rich text engine to request data that isn't directly stored by QTextDocument, but still associated with it. For example, images are referenced indirectly by the name attribute of a QTextImageFormat object.

When called by Qt, type is one of the values of QTextDocument::ResourceType.

If the QTextDocument is a child object of a QTextEdit, QTextBrowser, or a QTextDocument itself then the default implementation tries to retrieve the data from the parent.

Reimplemented from QTextDocument.

Definition at line 114 of file qdeclarativetext.cpp.

Referenced by resourcesLoading().

115 {
116  QDeclarativeContext *context = qmlContext(parent());
117  QUrl url = context->resolvedUrl(name);
118 
121 
122  if (iter == m_resources.end()) {
123  QDeclarativePixmap *p = new QDeclarativePixmap(context->engine(), url);
124  iter = m_resources.insert(name, p);
125 
126  if (p->isLoading()) {
127  p->connectFinished(this, SLOT(requestFinished()));
128  outstanding++;
129  }
130  }
131 
132  QDeclarativePixmap *p = *iter;
133  if (p->isReady()) {
134  return p->pixmap();
135  } else if (p->isError()) {
136  if (!errors.contains(url)) {
137  errors.insert(url);
138  qmlInfo(parent()) << p->error();
139  }
140  }
141  }
142 
143  return QTextDocument::loadResource(type,url); // The *resolved* URL
144 }
int type
Definition: qmetatype.cpp:239
QHash< QUrl, QDeclarativePixmap * > m_resources
#define SLOT(a)
Definition: qobjectdefs.h:226
QUrl resolvedUrl(const QUrl &)
Resolves the URL src relative to the URL of the containing component.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const QPixmap & pixmap() const
bool contains(const T &value) const
Definition: qset.h:91
virtual QVariant loadResource(int type, const QUrl &name)
Loads data of the specified type from the resource with the given name.
const_iterator insert(const T &value)
Definition: qset.h:179
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
bool connectFinished(QObject *, const char *)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
The QDeclarativeContext class defines a context within a QML engine.
QDeclarativeEngine * engine() const
Return the context&#39;s QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the QDeclar...
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
QDeclarativeInfo qmlInfo(const QObject *me)

◆ requestFinished

void QTextDocumentWithImageResources::requestFinished ( )
privateslot

Definition at line 146 of file qdeclarativetext.cpp.

Referenced by loadResource(), and resourcesLoading().

147 {
148  outstanding--;
149  if (outstanding == 0) {
150  QDeclarativeText *textItem = static_cast<QDeclarativeText*>(parent());
151  QString text = textItem->text();
152 #ifndef QT_NO_TEXTHTMLPARSER
153  setHtml(text);
154 #else
155  setPlainText(text);
156 #endif
158  d->updateLayout();
159  }
160 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static QDeclarativeTextPrivate * get(QDeclarativeText *t)
#define text
Definition: qobjectdefs.h:80

◆ resourcesLoading()

int QTextDocumentWithImageResources::resourcesLoading ( ) const
inline

Definition at line 70 of file qdeclarativetext.cpp.

◆ setText()

void QTextDocumentWithImageResources::setText ( const QString text)

Definition at line 162 of file qdeclarativetext.cpp.

163 {
164  if (!m_resources.isEmpty()) {
166  m_resources.clear();
167  outstanding = 0;
168  }
169 
170 #ifndef QT_NO_TEXTHTMLPARSER
171  setHtml(text);
172 #else
173  setPlainText(text);
174 #endif
175 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QHash< QUrl, QDeclarativePixmap * > m_resources
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Properties

◆ errors

QSet< QUrl > QTextDocumentWithImageResources::errors
staticprivate

Definition at line 82 of file qdeclarativetext.cpp.

Referenced by loadResource(), and setText().

◆ m_resources

QHash<QUrl, QDeclarativePixmap *> QTextDocumentWithImageResources::m_resources
private

Definition at line 79 of file qdeclarativetext.cpp.

Referenced by loadResource(), setText(), and ~QTextDocumentWithImageResources().

◆ outstanding

int QTextDocumentWithImageResources::outstanding
private

Definition at line 81 of file qdeclarativetext.cpp.

Referenced by loadResource(), requestFinished(), resourcesLoading(), and setText().


The documentation for this class was generated from the following file: