Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
graphicsviewadapter.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //============================================================================
21 // Adapter for viewing graphical elements
22 //============================================================================
23 
24 #include "graphicsviewadapter.h"
25 #include "../system/eptexception.h"
26 
27 //-----------------------------------------------------------------------------
28 // Clear graphics panel
29 //-----------------------------------------------------------------------------
30 
36 
38 {
39  // Delete all elements in the list of GraphicsItems
40  // Note that the destructor of the graphics item calls this function
41  while (mGraphicItems.size() > 0) delete mGraphicItems.front();
42 }
43 
44 
45 //-----------------------------------------------------------------------------
46 // Get the list of the graphic items.
47 //-----------------------------------------------------------------------------
48 
55 
57 { return mGraphicItems; }
58 
59 
60 //-----------------------------------------------------------------------------
61 // Get a constant list of the graphic items.
62 //-----------------------------------------------------------------------------
63 
70 
72 { return mGraphicItems; }
73 
74 
75 //-----------------------------------------------------------------------------
76 // Get a pointer to a single graphics element
77 //-----------------------------------------------------------------------------
78 
91 
93 {
94  GraphicItemsList list(getGraphicItems (keyIndex, role));
95  EptAssert(list.size() <= 1, "Either the item is unique or does not exist at all");
96  if (list.size() > 0) return list.front();
97  else return nullptr;
98 }
99 
100 
101 //-----------------------------------------------------------------------------
102 // Get the first of all graphics elements with a given role
103 //-----------------------------------------------------------------------------
104 
114 
116 {
118  EptAssert(list.size() <= 1, "Either the item is unique or does not exist at all");
119  if (list.size() > 0) return list.front();
120  else return nullptr;
121 }
122 
123 
124 //-----------------------------------------------------------------------------
125 // Get a list of graphic items that match with the keyIndex.
126 //-----------------------------------------------------------------------------
127 
133 
135 {
136  GraphicItemsList list;
137  for (GraphicsItem *item : mGraphicItems)
138  if (item->getKeyIndex() == keyIndex) list.push_back(item);
139  return list;
140 }
141 
142 
143 //-----------------------------------------------------------------------------
144 // Get the list of all graphics elements that match with a given role.
145 //-----------------------------------------------------------------------------
146 
152 
154 {
155  GraphicItemsList list;
156  for (GraphicsItem *item : mGraphicItems)
157  if ((role & item->getItemRole()) == role) list.push_back(item);
158  return list;
159 }
160 
161 
162 //-----------------------------------------------------------------------------
163 // Get the list of all graphics elements of a given key index
164 //-----------------------------------------------------------------------------
165 
172 
174 {
175  GraphicItemsList list;
176  for (GraphicsItem *item : mGraphicItems)
177  if (item->getKeyIndex() == keyIndex and (role & item->getItemRole()) == role)
178  list.push_back(item);
179  return list;
180 }
GraphicsItem * getGraphicItem(int keyIndex, RoleType role)
Get a single graphics element specified by its index and its role.
std::list< GraphicsItem * > GraphicItemsList
A list of GraphicItem (global)
Definition: graphicsitem.h:148
GraphicItemsList mGraphicItems
List of all graphic items in the view.
GraphicItemsList getGraphicItemsByRole(RoleType role)
Get a list of graphic items that match with the given role.
GraphicItemsList & getGraphicItems()
Get the list of the graphic items.
#define EptAssert(a, b)
Definition: eptexception.h:47
Class for a single item in a graphics view.
Definition: graphicsitem.h:55
GraphicsItem * getGraphicItemByRole(RoleType role)
Get the first of all graphics elements with a given role.
GraphicsItem::RoleType RoleType
virtual void clear()
Clear the graphics panel.