File indexing completed on 2024-04-28 04:31:55
0001 /* 0002 * Copyright (C) 2010-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 /** @file 0012 * This file defines a collection of background images to be used as overlays on 0013 * a canvas for the purpose of tracing. 0014 */ 0015 0016 #ifndef BackgroundImages_H 0017 #define BackgroundImages_H 0018 0019 // Qt includes 0020 #include <QList> 0021 #include <QRect> 0022 #include <QSharedPointer> 0023 0024 // Forward declaration of Qt classes 0025 class QDataStream; 0026 0027 // Forward declaration of application classes 0028 class BackgroundImage; 0029 0030 /** 0031 * This class defines a collection of background images allowing the addition 0032 * and removal of background images, setting the area occupied by an image and 0033 * changing the visibility status. 0034 * 0035 * The collection is stored in a QList of QSharedPointer objects. Generally the 0036 * BackgroundImage pointers would be owned by the collection and deleted in the 0037 * destructor. However if a background image is created and added to the list and 0038 * then undo is used it will be removed from the list but still referenced by the 0039 * AddBackgroundImageCommand which then becomes the owner. Using a QSharedPointer 0040 * to the BackgroundImage will ensure the BackgroundImage will be deleted 0041 * regardless of which object owns it or how many references there are to it. 0042 */ 0043 class BackgroundImages 0044 { 0045 public: 0046 /** 0047 * Constructor to create an empty list of background images. Use the default 0048 * implementation for this. 0049 */ 0050 BackgroundImages() = default; 0051 0052 /** 0053 * Clear the contents of the collection. 0054 */ 0055 void clear(); 0056 0057 /** 0058 * Get an iterator for the list of QSharedPointer to the background images. 0059 * 0060 * @return a QListIterator for BackgroundImage 0061 */ 0062 QListIterator<QSharedPointer<BackgroundImage>> backgroundImages(); 0063 0064 /** 0065 * Add a background image to the list. 0066 * 0067 * @param backgroundImage is a QSharedPointer to the BackgroundImage to add 0068 */ 0069 void addBackgroundImage(QSharedPointer<BackgroundImage> backgroundImage); 0070 0071 /** 0072 * Remove a background image from the list. 0073 * 0074 * @param backgroundImage is a QSharedPointer to the BackgroundImage to remove 0075 * 0076 * @return @c true if the pointer was in the list, @c false otherwise 0077 */ 0078 bool removeBackgroundImage(QSharedPointer<BackgroundImage> backgroundImage); 0079 0080 /** 0081 * Fit a background image to a new location. 0082 * 0083 * @param backgroundImage is a QSharedPointer to the BackgroundImage to change 0084 * @param location is a const reference to a QRect defining the new location 0085 * 0086 * @return a QRect representing the previous location 0087 */ 0088 QRect fitBackgroundImage(QSharedPointer<BackgroundImage> backgroundImage, const QRect &location); 0089 0090 /** 0091 * Show or hide a background image. 0092 * 0093 * @param backgroundImage is a QSharedPointer to the BackgroundImage to change 0094 * @param show is @c true if the image is to be shown, @c false to hide 0095 * 0096 * @return the previous visibility state, @c true if shown, @c false if hidden 0097 */ 0098 bool showBackgroundImage(QSharedPointer<BackgroundImage> backgroundImage, bool show); 0099 0100 /** 0101 * Operator to stream out the class instance to a QDataStream. This will 0102 * stream the instance of the BackgroundImage contained in the list. 0103 * 0104 * @param stream a reference to the QDataStream to write to 0105 * @param backgroundImages a const reference to the class instance to write 0106 * 0107 * @return a reference to the QDataStream allowing chaining 0108 */ 0109 friend QDataStream &operator<<(QDataStream &stream, const BackgroundImages &backgroundImages); 0110 0111 /** 0112 * Operator to stream in the class instance from a QDataStream. The class 0113 * instance will have been created previously as an empty instance. This will 0114 * create instances of BackgroundImage and read those from the stream adding 0115 * them to the list. 0116 * 0117 * @param stream a reference to the QDataStream to read from 0118 * @param backgroundImages a reference to the class instance to read into 0119 * 0120 * @return a reference to the QDataStream allowing chaining 0121 */ 0122 friend QDataStream &operator>>(QDataStream &stream, BackgroundImages &backgroundImages); 0123 0124 private: 0125 static const int version = 100; /**< The version of the streamed object */ 0126 0127 QList<QSharedPointer<BackgroundImage>> m_backgroundImages; /**< A list of BackgroundImage shared pointers */ 0128 }; 0129 0130 QDataStream &operator<<(QDataStream &, const BackgroundImages &); 0131 QDataStream &operator>>(QDataStream &, BackgroundImages &); 0132 0133 #endif // BackgroundImages_H