SymbolEditor  1.3.0
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
SymbolLibrary Class Reference

Manages the library of symbols. More...

#include <SymbolLibrary.h>

Collaboration diagram for SymbolLibrary:

Public Member Functions

 SymbolLibrary (SymbolListWidget *listWidget=0)
 
 ~SymbolLibrary ()
 
void clear ()
 
Symbol symbol (qint16 index)
 
Symbol takeSymbol (qint16 index)
 
qint16 setSymbol (qint16 index, const Symbol &symbol)
 
QString name () const
 
void setName (const QString &name)
 
QList< qint16 > indexes () const
 
QUndoStack * undoStack ()
 

Private Member Functions

void generateItems ()
 

Private Attributes

QUndoStack m_undoStack
 
QString m_name
 
SymbolListWidgetm_listWidget
 
qint16 m_nextIndex
 
QMap< qint16, Symbolm_symbols
 

Static Private Attributes

static const qint32 version = 101
 

Friends

QDataStream & operator<< (QDataStream &stream, const SymbolLibrary &library)
 
QDataStream & operator>> (QDataStream &stream, SymbolLibrary &library)
 

Detailed Description

Manages the library of symbols.

The symbol library holds all the symbols that have been added to it or loaded from a file. The symbols are indexed and the index is incremented for each symbol added starting from 1. When a SymbolListWidget is assigned to the SymbolLibrary each of the symbols is added to the SymbolListWidget which will create a QListWidgetItem which is assigned the QIcon that is generated from the QPainterPath associated with the index.

Definition at line 46 of file SymbolLibrary.h.

Constructor & Destructor Documentation

SymbolLibrary::SymbolLibrary ( SymbolListWidget listWidget = 0)
explicit

Construct a SymbolLibrary. Set the index to 1. The index will be set when a file is loaded and will be incremented when new symbols have been added. It will be saved with the file for the next time it is loaded.

Definition at line 70 of file SymbolLibrary.cpp.

Here is the call graph for this function:

SymbolLibrary::~SymbolLibrary ( )

Destructor

Definition at line 80 of file SymbolLibrary.cpp.

Here is the call graph for this function:

Member Function Documentation

void SymbolLibrary::clear ( )

Clear the file of symbols. Clears the undo stack, deletes all the QListWidgetItems and clears the symbol map. The index is reset to 1.

Definition at line 91 of file SymbolLibrary.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void SymbolLibrary::generateItems ( )
private

Generate all the items in the library. This will be called when a library file is loaded to generate all the new QListWidgetItems for the symbols in the library and generate an icon for it. A list of sorted QMap keys is retrieved to allow adding items in the correct order.

Definition at line 225 of file SymbolLibrary.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

QList< qint16 > SymbolLibrary::indexes ( ) const

Get a sorted list of symbol indexes

Returns
a QList<qint16> of sorted indexes

Definition at line 199 of file SymbolLibrary.cpp.

Here is the caller graph for this function:

QString SymbolLibrary::name ( ) const

Get the name of the symbol library.

Definition at line 177 of file SymbolLibrary.cpp.

Here is the caller graph for this function:

void SymbolLibrary::setName ( const QString &  name)

Set the name of the symbol library.

Parameters
namethe name to be set

Definition at line 188 of file SymbolLibrary.cpp.

Here is the call graph for this function:

qint16 SymbolLibrary::setSymbol ( qint16  index,
const Symbol symbol 
)

Update the Symbol for an index in the library. If the index supplied is 0, a new index will be taken from the m_nextIndex value which is then incremented. This value will be returned. When a LibraryListWidget has been linked to the SymbolLibrary the symbol is added to the LibraryListWidget.

Parameters
indexa qint16 representing the index
symbola const reference to a Symbol
Returns
a qint16 representing the index, this is useful when the original index was 0

Definition at line 158 of file SymbolLibrary.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Symbol SymbolLibrary::symbol ( qint16  index)

Get the path associated with an index. If the index is not in the library it returns a default constructed Symbol.

Parameters
indexa qint16 representing the index to find
Returns
a Symbol

Definition at line 114 of file SymbolLibrary.cpp.

Here is the caller graph for this function:

Symbol SymbolLibrary::takeSymbol ( qint16  index)

Take a symbol from the library. Remove a symbol identified by it's index and return it. The QListWidgetItem associated with the symbol is also removed and deleted. If the index is not in the library it returns a default constructed symbol.

Parameters
indexthe index of the Symbol to be removed
Returns
a Symbol

Definition at line 130 of file SymbolLibrary.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

QUndoStack * SymbolLibrary::undoStack ( )

Get a pointer to the symbol library undo stack.

Returns
a pointer to a QUndoStack

Definition at line 212 of file SymbolLibrary.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

QDataStream& operator<< ( QDataStream &  stream,
const SymbolLibrary library 
)
friend

Stream out the file. Symbol files are indicated with a magic string of KXStitchSymbols. The stream version is set to maintain consistency with the streamed objects. Write the version, current index and the map of symbols.

Parameters
streama reference to a QDataStream
librarya const reference to a SymbolLibrary
Returns
a reference to a QDataStream

Definition at line 246 of file SymbolLibrary.cpp.

QDataStream& operator>> ( QDataStream &  stream,
SymbolLibrary library 
)
friend

Stream in the file. Initially clear the current contents. Symbol files are indicated with a magic string of KXStitchSymbols. The stream version is set to maintain consistency with the streamed objects. Read and check the magic string. If this is not a symbol file throw an exception. Read in the version. Read the data for the specified version. The stream is checked for errors and an exception is thrown if there was an error.

Parameters
streama reference to a QDataStream
librarya reference to a SymbolLibrary
Returns
a reference to a QDataStream

Definition at line 287 of file SymbolLibrary.cpp.

Member Data Documentation

SymbolListWidget* SymbolLibrary::m_listWidget
private

pointer to a QListWidget containing the QListWidgetItems for the QIcons, this may be null for an imported file

Definition at line 77 of file SymbolLibrary.h.

QString SymbolLibrary::m_name
private

name of the symbol library

Definition at line 75 of file SymbolLibrary.h.

qint16 SymbolLibrary::m_nextIndex
private

index for the next symbol added

Definition at line 79 of file SymbolLibrary.h.

QMap<qint16, Symbol> SymbolLibrary::m_symbols
private

map of the Symbol to indexes

Definition at line 80 of file SymbolLibrary.h.

QUndoStack SymbolLibrary::m_undoStack
private

holds the commands that have made changes to this library

Definition at line 73 of file SymbolLibrary.h.

const qint32 SymbolLibrary::version = 101
staticprivate

stream version of this file

Definition at line 71 of file SymbolLibrary.h.


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