File size: 3,485 Bytes
a5ffdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software 
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
**
** This copyright notice MUST APPEAR in all copies of the script!  
**
**********************************************************************/


#ifndef RS_BLOCKLIST_H
#define RS_BLOCKLIST_H

#include <QList>

class QString;
class RS_Block;
class RS_BlockListListener;

/**
 * List of blocks.
 *
 * @see RS_Block
 *
 * @author Andrew Mustun
 */
class RS_BlockList {
public:
    RS_BlockList(bool owner=false);
	virtual ~RS_BlockList() = default;

    void clear();
    /**
     * @return Number of blocks available.
     */
	int count() const;

    /**
     * @return Block at given position or NULL if i is out of range.
     */
	RS_Block* at(int i);
	RS_Block* at(int i) const;
	//! \{ \brief range based loop
	QList<RS_Block*>::iterator begin();
	QList<RS_Block*>::iterator end();
	QList<RS_Block*>::const_iterator begin()const;
	QList<RS_Block*>::const_iterator end()const;
	//! \}

    void activate(const QString& name);
    void activate(RS_Block* block);
    //! @return The active block of NULL if no block is activated.
    RS_Block* getActive() const;

    bool add(RS_Block* block, bool notify=true);
    void addNotification();
    void remove(RS_Block* block);
    bool rename(RS_Block* block, const QString& name);
    //virtual void editBlock(RS_Block* block, const RS_Block& source);
    RS_Block* find(const QString& name);
    RS_Block* findCaseInsensitive(const QString& name) const;
    QString newName(const QString& suggestion = "");
    void toggle(const QString& name);
    void toggle(RS_Block* block);
    void freezeAll(bool freeze);

    void addListener(RS_BlockListListener* listener);
    void removeListener(RS_BlockListListener* listener);

    bool isOwner() const {return m_owner;}
    void setOwner(bool ow) {m_owner = ow;}

    /**
     * Sets the block list modified status to 'm'.
     */
	void setModified(bool m);

    /**
     * @retval true The block list has been modified.
     * @retval false The block list has not been modified.
     */
	bool isModified() const;

    friend std::ostream& operator << (std::ostream& os, RS_BlockList& b);

private:
    //! Is the list owning the blocks?
    bool m_owner = false;
    //! Blocks in the graphic
    QList<RS_Block*> m_blocks;
    //! List of registered BlockListListeners
    QList<RS_BlockListListener*> m_blockListListeners;
    //! Currently active block
    RS_Block* m_activeBlock = nullptr;
    /** Flag set if the block list was modified and not yet saved. */
    bool m_modified = false;
};

#endif