File indexing completed on 2024-04-21 04:32:15
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 * @file 0013 * Header file for the SymbolLibrary class. 0014 */ 0015 0016 #ifndef SymbolLibrary_H 0017 #define SymbolLibrary_H 0018 0019 #include <QMap> 0020 #include <QPainterPath> 0021 #include <QUndoStack> 0022 #include <QUrl> 0023 0024 #include "Symbol.h" 0025 0026 class QDataStream; 0027 class QListWidgetItem; 0028 0029 class SymbolListWidget; 0030 0031 /** 0032 * @brief Manages the library of symbols. 0033 * 0034 * The symbol library holds all the symbols that have been added to it or loaded from a file. 0035 * The symbols are indexed and the index is incremented for each symbol added starting from 1. 0036 * When a SymbolListWidget is assigned to the SymbolLibrary each of the symbols is added to 0037 * the SymbolListWidget which will create a QListWidgetItem which is assigned the QIcon that 0038 * is generated from the QPainterPath associated with the index. 0039 */ 0040 class SymbolLibrary 0041 { 0042 public: 0043 explicit SymbolLibrary(SymbolListWidget *listWidget = nullptr); 0044 ~SymbolLibrary(); 0045 0046 void clear(); 0047 0048 Symbol symbol(qint16 index) const; 0049 Symbol takeSymbol(qint16 index); 0050 qint16 setSymbol(qint16 index, const Symbol &symbol); 0051 0052 QUrl url() const; 0053 void setUrl(const QUrl &url); 0054 0055 QString name() const; 0056 void setName(const QString &name); 0057 0058 QList<qint16> indexes() const; 0059 0060 QUndoStack *undoStack(); 0061 0062 friend QDataStream &operator<<(QDataStream &stream, const SymbolLibrary &library); 0063 friend QDataStream &operator>>(QDataStream &stream, SymbolLibrary &library); 0064 0065 private: 0066 void generateItems(); 0067 0068 static const qint32 version = 101; /**< stream version of this file */ 0069 0070 QUndoStack m_undoStack; /**< holds the commands that have made changes to this library */ 0071 0072 QUrl m_url; /**< url of the file loaded, this may be Untitled */ 0073 0074 QString m_name; /**< name of the symbol library */ 0075 0076 SymbolListWidget *m_listWidget; /**< pointer to a QListWidget containing the QListWidgetItems for the QIcons, this may be null for an imported file */ 0077 0078 qint16 m_nextIndex; /**< index for the next symbol added */ 0079 QMap<qint16, Symbol> m_symbols; /**< map of the Symbol to indexes */ 0080 }; 0081 0082 QDataStream &operator<<(QDataStream &stream, const SymbolLibrary &library); 0083 QDataStream &operator>>(QDataStream &stream, SymbolLibrary &library); 0084 0085 #endif