File indexing completed on 2025-03-16 13:13:04
0001 /******************************************************************************** 0002 * Copyright (C) 2011-2015 by Stephen Allewell * 0003 * steve.allewell@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ********************************************************************************/ 0010 0011 0012 /** 0013 * @file 0014 * Header file for the SymbolLibrary class. 0015 */ 0016 0017 0018 #ifndef SymbolLibrary_H 0019 #define SymbolLibrary_H 0020 0021 0022 #include <QMap> 0023 #include <QPainterPath> 0024 #include <QUndoStack> 0025 0026 #include "Symbol.h" 0027 0028 0029 class QDataStream; 0030 class QListWidgetItem; 0031 0032 class SymbolListWidget; 0033 0034 0035 /** 0036 * @brief Manages the library of symbols. 0037 * 0038 * The symbol library holds all the symbols that have been added to it or loaded from a file. 0039 * The symbols are indexed and the index is incremented for each symbol added starting from 1. 0040 * When a SymbolListWidget is assigned to the SymbolLibrary each of the symbols is added to 0041 * the SymbolListWidget which will create a QListWidgetItem which is assigned the QIcon that 0042 * is generated from the QPainterPath associated with the index. 0043 */ 0044 class SymbolLibrary 0045 { 0046 public: 0047 explicit SymbolLibrary(SymbolListWidget *listWidget = 0); 0048 ~SymbolLibrary(); 0049 0050 void clear(); 0051 0052 Symbol symbol(qint16 index); 0053 Symbol takeSymbol(qint16 index); 0054 qint16 setSymbol(qint16 index, const Symbol &symbol); 0055 0056 QString name() const; 0057 void setName(const QString &name); 0058 0059 QList<qint16> indexes() const; 0060 0061 QUndoStack *undoStack(); 0062 0063 friend QDataStream &operator<<(QDataStream &stream, const SymbolLibrary &library); 0064 friend QDataStream &operator>>(QDataStream &stream, SymbolLibrary &library); 0065 0066 private: 0067 void generateItems(); 0068 0069 static const qint32 version = 101; /**< stream version of this file */ 0070 0071 QUndoStack m_undoStack; /**< holds the commands that have made changes to this library */ 0072 0073 QString m_name; /**< name of the symbol library */ 0074 0075 SymbolListWidget *m_listWidget; /**< pointer to a QListWidget containing the QListWidgetItems for the QIcons, this may be null for an imported file */ 0076 0077 qint16 m_nextIndex; /**< index for the next symbol added */ 0078 QMap<qint16, Symbol> m_symbols; /**< map of the Symbol to indexes */ 0079 }; 0080 0081 0082 QDataStream &operator<<(QDataStream &stream, const SymbolLibrary &library); 0083 QDataStream &operator>>(QDataStream &stream, SymbolLibrary &library); 0084 0085 0086 #endif 0087