Source Code (Use browser search to find items of interest.)

Class Index

qt'QTextFormatCollection (./qt-2.1.0/src/kernel/qrichtext_p.h:113)

class QTextFormatCollection
{
    friend class QTextCharFormat;

public:
    QTextFormatCollection();

    QTextCharFormat*  registerFormat( const QTextCharFormat &format );
    void unregisterFormat( const QTextCharFormat &format  );

protected:
    QDict<QTextCharFormat > cKey;
    QTextCharFormat* lastRegisterFormat;
};



qt'QTextFormatCollection::QTextFormatCollection() (./qt-2.1.0/src/kernel/qrichtext.cpp:2829)

QTextFormatCollection::QTextFormatCollection()
    : cKey(199),lastRegisterFormat( 0 )
{
}


qt'QTextFormatCollection::registerFormat() (./qt-2.1.0/src/kernel/qrichtext.cpp:2834)

QTextCharFormat* QTextFormatCollection::registerFormat( const QTextCharFormat &format )
{
    if ( format.parent == this ) {
	QTextCharFormat* f = ( QTextCharFormat*) &format;
	f->ref();
	lastRegisterFormat = f;
	return f;
    }

    if ( lastRegisterFormat ) {
        if ( format.key == lastRegisterFormat->key ) {
	    lastRegisterFormat->ref();
	    return lastRegisterFormat;
        }
    }

    if ( format.isAnchor() ) {
	// fancy speed optimization: do _not_ share any anchors to keep the map smaller
	// see unregisterFormat()
	lastRegisterFormat =  new QTextCharFormat( format );
	return lastRegisterFormat;
    }

    QTextCharFormat *fc = cKey[ format.key ];
    if ( fc ) {
	fc->ref();
	lastRegisterFormat = fc;
	return fc;
    } else {
	QTextCharFormat *f = new QTextCharFormat( format );
	f->parent = this;
	cKey.insert( f->key, f );
	lastRegisterFormat = f;
	return f;
    }
}


qt'QTextFormatCollection::unregisterFormat() (./qt-2.1.0/src/kernel/qrichtext.cpp:2871)

void QTextFormatCollection::unregisterFormat( const QTextCharFormat &format )
{
    QTextCharFormat* f;

    if ( format.isAnchor() ) {
	// fancy speed optimization: do _not_ share any anchors to keep the map smaller
	// see registerFormat()
	f = (QTextCharFormat*)&format;
	if ( f->deref() ) {
	    if ( f == lastRegisterFormat )
		lastRegisterFormat = 0;
	    delete f;
	}
	return;
    }

    if ( format.parent == this )
	f = ( QTextCharFormat*)&format;
    else
	f = cKey[ format.key ];

    if ( f ) {
	if ( f->deref() ) {
	    if ( f == lastRegisterFormat )
		lastRegisterFormat = 0;
	    cKey.remove( format.key );
	    delete f;
	}
    }
}