Q3TextString Class Reference

#include <q3richtext_p.h>

Collaboration diagram for Q3TextString:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 154 of file q3richtext_p.h.

Public Member Functions

 Q3TextString ()
 Q3TextString (const Q3TextString &s)
virtual ~Q3TextString ()
QString toString () const
Q3TextStringCharat (int i) const
int length () const
int width (int idx) const
void insert (int index, const QString &s, Q3TextFormat *f)
void insert (int index, const QChar *unicode, int len, Q3TextFormat *f)
void insert (int index, Q3TextStringChar *c, bool doAddRefFormat=false)
void truncate (int index)
void remove (int index, int len)
void clear ()
void setFormat (int index, Q3TextFormat *f, bool useCollection)
void setBidi (bool b)
bool isBidi () const
bool isRightToLeft () const
QChar::Direction direction () const
void setDirection (QChar::Direction dr)
QVector< Q3TextStringCharrawData () const
void operator= (const QString &s)
void operator+= (const QString &s)
void prepend (const QString &s)
int appendParagraphs (Q3TextParagraph *start, Q3TextParagraph *end)
bool validCursorPosition (int idx)
int nextCursorPosition (int idx)
int previousCursorPosition (int idx)

Static Public Member Functions

static QString toString (const QVector< Q3TextStringChar > &data)

Private Member Functions

void checkBidi () const

Private Attributes

QVector< Q3TextStringChardata
QString stringCache
uint bidiDirty: 1
uint bidi: 1
uint rightToLeft: 1


Constructor & Destructor Documentation

Q3TextString::Q3TextString (  ) 

Definition at line 3676 of file q3richtext.cpp.

References bidi, bidiDirty, and rightToLeft.

03677 {
03678     bidiDirty = true;
03679     bidi = false;
03680     rightToLeft = false;
03681 }

Q3TextString::Q3TextString ( const Q3TextString s  ) 

Definition at line 3683 of file q3richtext.cpp.

References bidi, bidiDirty, data, QVector< T >::detach(), i, int, rightToLeft, s, and QVector< T >::size().

03684 {
03685     bidiDirty = true;
03686     bidi = s.bidi;
03687     rightToLeft = s.rightToLeft;
03688     data = s.data;
03689     data.detach();
03690     for (int i = 0; i < (int)data.size(); ++i) {
03691         Q3TextFormat *f = data[i].format();
03692         if (f)
03693             f->addRef();
03694     }
03695 }

Here is the call graph for this function:

Q3TextString::~Q3TextString (  )  [virtual]

Definition at line 3724 of file q3richtext.cpp.

References clear().

03725 {
03726     clear();
03727 }

Here is the call graph for this function:


Member Function Documentation

QString Q3TextString::toString ( const QVector< Q3TextStringChar > &  data  )  [static]

Definition at line 412 of file q3richtext_p.cpp.

References c, data, QVector< T >::data(), l, s, and QVector< T >::size().

Referenced by Q3TextDocument::find(), Q3TextEdit::optimDrawContents(), Q3TextParagraph::paint(), Q3TextDocument::plainText(), Q3TextCursor::splitAndInsertEmptyParagraph(), and Q3MultiLineEdit::textLine().

00413 {
00414     QString s;
00415     int l = data.size();
00416     s.setUnicode(0, l);
00417     const Q3TextStringChar *c = data.data();
00418     QChar *uc = (QChar *)s.unicode();
00419     while (l--)
00420         *(uc++) = (c++)->c;
00421 
00422     return s;
00423 }

Here is the call graph for this function:

QString Q3TextString::toString (  )  const [inline]

Definition at line 223 of file q3richtext_p.h.

References bidiDirty, checkBidi(), and stringCache.

Referenced by checkBidi(), Q3TextDeleteCommand::unexecute(), and width().

00224 {
00225     if (bidiDirty)
00226         checkBidi();
00227     return stringCache;
00228 }

Here is the call graph for this function:

Q3TextStringChar& Q3TextString::at ( int  i  )  const [inline]

Definition at line 165 of file q3richtext_p.h.

References data.

Referenced by Q3TextParagraph::at(), Q3TextFormatter::bidiReorderLine(), Q3TextCursor::fixCursorPosition(), Q3TextFormatterBreakInWords::format(), Q3TextFormatterBreakWords::format(), Q3TextFormatter::formatLine(), Q3TextFormatter::formatVertically(), isBreakable(), Q3TextParagraph::join(), Q3TextParagraph::leftGap(), Q3TextParagraph::lineStartOfChar(), Q3TextParagraph::lineStartOfLine(), Q3TextParagraph::paint(), Q3TextParagraph::richText(), Q3TextParagraph::setFormat(), Q3TextDocument::setRichTextInternal(), validCursorPosition(), and width().

00165                                              {
00166         return const_cast<Q3TextString *>(this)->data[i];
00167     }

int Q3TextString::length (  )  const [inline]

Definition at line 168 of file q3richtext_p.h.

References data.

Referenced by Q3TextParagraph::append(), checkBidi(), Q3TextEdit::doKeyboardAction(), Q3TextParagraph::format(), Q3TextParagraph::fullSelected(), Q3TextEdit::insert(), Q3TextParagraph::join(), Q3TextParagraph::leftGap(), Q3TextParagraph::length(), nextCursorPosition(), Q3TextEdit::pasteSubType(), Q3TextParagraph::remove(), and Q3TextParagraph::setFormat().

00168 { return data.size(); }

int Q3TextString::width ( int  idx  )  const

Definition at line 4026 of file q3richtext.cpp.

References at(), c, Q3TextCustomItem::PlaceInline, toString(), and w.

Referenced by Q3TextFormatter::bidiReorderLine(), Q3TextCursor::fixCursorPosition(), Q3TextFormatterBreakInWords::format(), Q3TextFormatterBreakWords::format(), Q3TextFormatter::formatLine(), Q3TextParagraph::paint(), and Q3TextCursor::x().

04027 {
04028      int w = 0;
04029      Q3TextStringChar *c = &at(idx);
04030      if (!c->charStop || c->c.unicode() == 0xad || c->c.unicode() == 0x2028)
04031          return 0;
04032 #ifndef QT_NO_TEXTCUSTOMITEM
04033      if(c->isCustom()) {
04034          if(c->customItem()->placement() == Q3TextCustomItem::PlaceInline)
04035              w = c->customItem()->width;
04036      } else
04037 #endif
04038      {
04039          int r = c->c.row();
04040          if(r < 0x06
04041 #ifndef Q_WS_WIN
04042              // Uniscribe's handling of Asian makes the condition below fail.
04043              || (r > 0x1f && !(r > 0xd7 && r < 0xe0))
04044 #endif
04045              ) {
04046              w = c->format()->width(c->c);
04047          } else {
04048              // complex text. We need some hacks to get the right metric here
04049              w = c->format()->width(toString(), idx);
04050          }
04051      }
04052      return w;
04053 }

Here is the call graph for this function:

void Q3TextString::insert ( int  index,
const QString s,
Q3TextFormat f 
)

Definition at line 3697 of file q3richtext.cpp.

References s.

Referenced by Q3TextEdit::doKeyboardAction(), Q3TextParagraph::insert(), and Q3TextParagraph::Q3TextParagraph().

03698 {
03699     insert(index, s.unicode(), s.length(), f);
03700 }

void Q3TextString::insert ( int  index,
const QChar unicode,
int  len,
Q3TextFormat f 
)

Definition at line 3702 of file q3richtext.cpp.

References bidiDirty, data, QVector< T >::data(), i, Q3TextStringChar::Regular, QVector< T >::resize(), QVector< T >::size(), and Q3TextStringChar::x.

03703 {
03704     int os = data.size();
03705     data.resize(data.size() + len);
03706     if (index < os) {
03707         memmove(data.data() + index + len, data.data() + index,
03708                  sizeof(Q3TextStringChar) * (os - index));
03709     }
03710     Q3TextStringChar *ch = data.data() + index;
03711     for (int i = 0; i < len; ++i) {
03712         ch->x = 0;
03713         ch->lineStart = 0;
03714         ch->nobreak = false;
03715         ch->type = Q3TextStringChar::Regular;
03716         ch->p.format = f;
03717         ch->rightToLeft = 0;
03718         ch->c = unicode[i];
03719         ++ch;
03720     }
03721     bidiDirty = true;
03722 }

Here is the call graph for this function:

void Q3TextString::insert ( int  index,
Q3TextStringChar c,
bool  doAddRefFormat = false 
)

Definition at line 3729 of file q3richtext.cpp.

References bidiDirty, c, data, QVector< T >::data(), int, Q3TextStringChar::Regular, QVector< T >::resize(), and QVector< T >::size().

03730 {
03731     int os = data.size();
03732     data.resize(data.size() + 1);
03733     if (index < os) {
03734         memmove(data.data() + index + 1, data.data() + index,
03735                  sizeof(Q3TextStringChar) * (os - index));
03736     }
03737     Q3TextStringChar &ch = data[(int)index];
03738     ch.c = c->c;
03739     ch.x = 0;
03740     ch.lineStart = 0;
03741     ch.rightToLeft = 0;
03742     ch.p.format = 0;
03743     ch.type = Q3TextStringChar::Regular;
03744     ch.nobreak = false;
03745     if (doAddRefFormat && c->format())
03746         c->format()->addRef();
03747     ch.setFormat(c->format());
03748     bidiDirty = true;
03749 }

Here is the call graph for this function:

void Q3TextString::truncate ( int  index  ) 

Definition at line 3792 of file q3richtext.cpp.

References bidiDirty, data, i, int, QVector< T >::p, qMax(), qMin(), Q3TextStringChar::Regular, QVector< T >::resize(), and QVector< T >::size().

Referenced by Q3TextParagraph::truncate().

03793 {
03794     index = qMax(index, 0);
03795     index = qMin(index, (int)data.size() - 1);
03796     if (index < (int)data.size()) {
03797         for (int i = index + 1; i < (int)data.size(); ++i) {
03798             Q3TextStringChar &ch = data[i];
03799 #ifndef QT_NO_TEXTCUSTOMITEM
03800             if (!(ch.type == Q3TextStringChar::Regular)) {
03801                 delete ch.customItem();
03802                 if (ch.p.custom->format)
03803                     ch.p.custom->format->removeRef();
03804                 delete ch.p.custom;
03805                 ch.p.custom = 0;
03806             } else
03807 #endif
03808                 if (ch.format()) {
03809                     ch.format()->removeRef();
03810                 }
03811         }
03812     }
03813     data.resize(index);
03814     bidiDirty = true;
03815 }

Here is the call graph for this function:

void Q3TextString::remove ( int  index,
int  len 
)

Definition at line 3817 of file q3richtext.cpp.

References bidiDirty, data, QVector< T >::data(), i, int, QVector< T >::p, Q3TextStringChar::Regular, QVector< T >::resize(), and QVector< T >::size().

Referenced by Q3TextParagraph::remove().

03818 {
03819     for (int i = index; i < (int)data.size() && i - index < len; ++i) {
03820         Q3TextStringChar &ch = data[i];
03821 #ifndef QT_NO_TEXTCUSTOMITEM
03822         if (!(ch.type == Q3TextStringChar::Regular)) {
03823             delete ch.customItem();
03824             if (ch.p.custom->format)
03825                 ch.p.custom->format->removeRef();
03826             delete ch.p.custom;
03827             ch.p.custom = 0;
03828         } else
03829 #endif
03830             if (ch.format()) {
03831                 ch.format()->removeRef();
03832             }
03833     }
03834     memmove(data.data() + index, data.data() + index + len,
03835              sizeof(Q3TextStringChar) * (data.size() - index - len));
03836     data.resize(data.size() - len);
03837     bidiDirty = true;
03838 }

Here is the call graph for this function:

void Q3TextString::clear (  ) 

Definition at line 3840 of file q3richtext.cpp.

References bidiDirty, QVector< T >::count(), data, i, int, QVector< T >::p, Q3TextCustomItem::PlaceInline, Q3TextStringChar::Regular, and QVector< T >::resize().

Referenced by Q3TextEdit::UndoRedoInfo::clear(), Q3TextEdit::doKeyboardAction(), Q3TextEdit::insert(), Q3TextEdit::pasteSubType(), Q3TextEdit::removeSelectedText(), Q3TextEdit::UndoRedoInfo::UndoRedoInfo(), and ~Q3TextString().

03841 {
03842     for (int i = 0; i < (int)data.count(); ++i) {
03843         Q3TextStringChar &ch = data[i];
03844 #ifndef QT_NO_TEXTCUSTOMITEM
03845         if (!(ch.type == Q3TextStringChar::Regular)) {
03846             if (ch.customItem() && ch.customItem()->placement() == Q3TextCustomItem::PlaceInline)
03847                 delete ch.customItem();
03848             if (ch.p.custom->format)
03849                 ch.p.custom->format->removeRef();
03850             delete ch.p.custom;
03851             ch.p.custom = 0;
03852         } else
03853 #endif
03854             if (ch.format()) {
03855                 ch.format()->removeRef();
03856             }
03857     }
03858     data.resize(0);
03859     bidiDirty = true;
03860 }

Here is the call graph for this function:

void Q3TextString::setFormat ( int  index,
Q3TextFormat f,
bool  useCollection 
)

Definition at line 3862 of file q3richtext.cpp.

References data, Q3TextStringChar::format, Q3TextFormat::removeRef(), and Q3TextStringChar::setFormat().

Referenced by Q3TextCursor::insert(), Q3TextParagraph::join(), and Q3TextParagraph::setFormat().

03863 {
03864     Q3TextStringChar &ch = data[index];
03865     if (useCollection && ch.format())
03866         ch.format()->removeRef();
03867     ch.setFormat(f);
03868 }

Here is the call graph for this function:

void Q3TextString::setBidi ( bool  b  )  [inline]

Definition at line 181 of file q3richtext_p.h.

00181 { bidi = b; }

bool Q3TextString::isBidi (  )  const [inline]

Definition at line 209 of file q3richtext_p.h.

References bidi, bidiDirty, and checkBidi().

Referenced by Q3TextFormatterBreakInWords::format(), Q3TextFormatterBreakWords::format(), Q3TextFormatter::formatLine(), Q3TextParagraph::leftGap(), and Q3TextParagraph::paint().

00210 {
00211     if (bidiDirty)
00212         checkBidi();
00213     return bidi;
00214 }

Here is the call graph for this function:

bool Q3TextString::isRightToLeft (  )  const [inline]

Definition at line 216 of file q3richtext_p.h.

References bidiDirty, checkBidi(), and rightToLeft.

Referenced by Q3TextFormatter::bidiReorderLine(), Q3TextParagraph::drawLabel(), Q3TextCursor::gotoLeft(), Q3TextCursor::gotoRight(), Q3TextCursor::gotoWordLeft(), Q3TextCursor::gotoWordRight(), and Q3TextParagraph::paint().

00217 {
00218     if (bidiDirty)
00219         checkBidi();
00220     return rightToLeft;
00221 }

Here is the call graph for this function:

QChar::Direction Q3TextString::direction (  )  const [inline]

Definition at line 230 of file q3richtext_p.h.

References QChar::DirL, QChar::DirR, and rightToLeft.

Referenced by Q3TextParagraph::copyParagData(), Q3TextParagraph::direction(), Q3TextParagraph::setDirection(), and Q3TextParagraph::writeStyleInformation().

00231 {
00232     return rightToLeft ? QChar::DirR : QChar::DirL;
00233 }

void Q3TextString::setDirection ( QChar::Direction  dr  )  [inline]

Definition at line 185 of file q3richtext_p.h.

References QChar::DirR.

Referenced by Q3TextParagraph::copyParagData(), Q3TextParagraph::readStyleInformation(), and Q3TextParagraph::setDirection().

00185 { rightToLeft = (dr == QChar::DirR); bidiDirty = true; }

QVector<Q3TextStringChar> Q3TextString::rawData (  )  const [inline]

Definition at line 187 of file q3richtext_p.h.

References data.

Referenced by Q3TextEdit::UndoRedoInfo::clear().

00187 { return data; }

void Q3TextString::operator= ( const QString s  )  [inline]

Definition at line 189 of file q3richtext_p.h.

References clear(), and s.

00189 { clear(); insert(0, s, 0); }

Here is the call graph for this function:

void Q3TextString::operator+= ( const QString s  )  [inline]

Definition at line 190 of file q3richtext_p.h.

References length, and s.

00190 { insert(length(), s, 0); }

void Q3TextString::prepend ( const QString s  )  [inline]

Definition at line 191 of file q3richtext_p.h.

References s.

00191 { insert(0, s, 0); }

int Q3TextString::appendParagraphs ( Q3TextParagraph start,
Q3TextParagraph end 
)

Definition at line 3751 of file q3richtext.cpp.

References bidiDirty, c, d, data, i, p, Q3TextStringChar::Regular, QVector< T >::resize(), QVector< T >::size(), and start.

03752 {
03753     int paragCount = 0;
03754     int newLength = data.size();
03755     for (Q3TextParagraph *p = start; p != end; p = p->next()) {
03756         newLength += p->length();
03757         ++paragCount;
03758     }
03759 
03760     const int oldLength = data.size();
03761     data.resize(newLength);
03762 
03763     Q3TextStringChar *d = &data[oldLength];
03764     for (Q3TextParagraph *p = start; p != end; p = p->next()) {
03765         const Q3TextStringChar * const src = p->at(0);
03766         int i = 0;
03767         for (; i < p->length() - 1; ++i) {
03768             d[i].c = src[i].c;
03769             d[i].x = 0;
03770             d[i].lineStart = 0;
03771             d[i].rightToLeft = 0;
03772             d[i].type = Q3TextStringChar::Regular;
03773             d[i].nobreak = false;
03774             d[i].p.format = src[i].format();
03775             if (d[i].p.format)
03776                 d[i].p.format->addRef();
03777         }
03778         d[i].x = 0;
03779         d[i].lineStart = 0;
03780         d[i].nobreak = false;
03781         d[i].type = Q3TextStringChar::Regular;
03782         d[i].p.format = 0;
03783         d[i].rightToLeft = 0;
03784         d[i].c = '\n';
03785         d += p->length();
03786     }
03787 
03788     bidiDirty = true;
03789     return paragCount;
03790 }

Here is the call graph for this function:

bool Q3TextString::validCursorPosition ( int  idx  )  [inline]

Definition at line 266 of file q3richtext_p.h.

References at(), bidiDirty, and checkBidi().

Referenced by Q3TextCursor::fixCursorPosition(), and Q3TextCursor::place().

00267 {
00268     if (bidiDirty)
00269         checkBidi();
00270 
00271     return (at(idx).charStop);
00272 }

Here is the call graph for this function:

int Q3TextString::nextCursorPosition ( int  idx  )  [inline]

Definition at line 235 of file q3richtext_p.h.

References bidiDirty, c, checkBidi(), data, QVector< T >::data(), len, and length().

Referenced by Q3TextCursor::gotoNextLetter(), and Q3TextCursor::remove().

00236 {
00237     if (bidiDirty)
00238         checkBidi();
00239 
00240     const Q3TextStringChar *c = data.data();
00241     int len = length();
00242 
00243     if (next < len - 1) {
00244         next++;
00245         while (next < len - 1 && !c[next].charStop)
00246             next++;
00247     }
00248     return next;
00249 }

Here is the call graph for this function:

int Q3TextString::previousCursorPosition ( int  idx  )  [inline]

Definition at line 251 of file q3richtext_p.h.

References bidiDirty, c, checkBidi(), data, and QVector< T >::data().

Referenced by Q3TextCursor::gotoPreviousLetter().

00252 {
00253     if (bidiDirty)
00254         checkBidi();
00255 
00256     const Q3TextStringChar *c = data.data();
00257 
00258     if (prev) {
00259         prev--;
00260         while (prev && !c[prev].charStop)
00261             prev--;
00262     }
00263     return prev;
00264 }

Here is the call graph for this function:

void Q3TextString::checkBidi (  )  const [private]

Definition at line 3870 of file q3richtext.cpp.

References QScriptItem::analysis, QTextEngine::attributes(), bidi, bidiDirty, Q3TextStringChar::bidiLevel, QCharAttributes::charStop, Q3TextStringChar::charStop, data, QVector< T >::data(), QTextEngine::itemize(), QTextEngine::layoutData, Qt::LeftToRight, length(), QTextEngine::option, QScriptItem::position, Qt::RightToLeft, Q3TextStringChar::rightToLeft, rightToLeft, QTextOption::setTextDirection(), QVector< T >::size(), QCharAttributes::softBreak, Q3TextStringChar::softBreak, start, QTextEngine::text, toString(), QCharAttributes::whiteSpace, and Q3TextStringChar::whiteSpace.

Referenced by isBidi(), isRightToLeft(), nextCursorPosition(), previousCursorPosition(), toString(), and validCursorPosition().

03871 {
03872     // ############ fix BIDI handling
03873     Q3TextString *that = (Q3TextString *)this;
03874     that->bidiDirty = false;
03875     int length = data.size();
03876     if (!length) {
03877         that->bidi = rightToLeft;
03878         return;
03879     }
03880     const Q3TextStringChar *start = data.data();
03881     const Q3TextStringChar *end = start + length;
03882 
03883     ((Q3TextString *)this)->stringCache = toString(data);
03884 
03885     // determines the properties we need for layouting
03886     QTextEngine textEngine;
03887     textEngine.text = toString();
03888     textEngine.option.setTextDirection(rightToLeft ? Qt::RightToLeft : Qt::LeftToRight);
03889     textEngine.itemize();
03890     const QCharAttributes *ca = textEngine.attributes() + length-1;
03891     Q3TextStringChar *ch = (Q3TextStringChar *)end - 1;
03892     QScriptItem *item = &textEngine.layoutData->items[textEngine.layoutData->items.size()-1];
03893     unsigned char bidiLevel = item->analysis.bidiLevel;
03894     that->bidi = (bidiLevel || rightToLeft);
03895     int pos = length-1;
03896     while (ch >= start) {
03897         if (item->position > pos) {
03898             --item;
03899             Q_ASSERT(item >= &textEngine.layoutData->items[0]);
03900             bidiLevel = item->analysis.bidiLevel;
03901             if (bidiLevel)
03902                 that->bidi = true;
03903         }
03904         ch->softBreak = ca->softBreak;
03905         ch->whiteSpace = ca->whiteSpace;
03906         ch->charStop = ca->charStop;
03907         ch->bidiLevel = bidiLevel;
03908         ch->rightToLeft = (bidiLevel%2);
03909         --ch;
03910         --ca;
03911         --pos;
03912     }
03913 }

Here is the call graph for this function:


Member Data Documentation

QVector<Q3TextStringChar> Q3TextString::data [private]

Definition at line 202 of file q3richtext_p.h.

Referenced by appendParagraphs(), checkBidi(), clear(), insert(), nextCursorPosition(), previousCursorPosition(), Q3TextString(), remove(), setFormat(), toString(), and truncate().

QString Q3TextString::stringCache [private]

Definition at line 203 of file q3richtext_p.h.

Referenced by toString().

uint Q3TextString::bidiDirty [private]

Definition at line 204 of file q3richtext_p.h.

Referenced by appendParagraphs(), checkBidi(), clear(), insert(), isBidi(), isRightToLeft(), nextCursorPosition(), previousCursorPosition(), Q3TextString(), remove(), toString(), truncate(), and validCursorPosition().

uint Q3TextString::bidi [private]

Definition at line 205 of file q3richtext_p.h.

Referenced by checkBidi(), isBidi(), and Q3TextString().

uint Q3TextString::rightToLeft [private]

Definition at line 206 of file q3richtext_p.h.

Referenced by checkBidi(), direction(), isRightToLeft(), and Q3TextString().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:33:38 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1