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
graphicsitemforqt.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 // Graphics Item implementation for Qt
22 //============================================================================
23 
24 #include "graphicsitemforqt.h"
25 
26 #include "../core/system/eptexception.h"
28 
29 
30 //-----------------------------------------------------------------------------
31 // Constructor
32 //-----------------------------------------------------------------------------
33 
38  QGraphicsItem *item) :
39  GraphicsItem(graphicsView),
40  mItem(item)
41 {
42  EptAssert(item, "The item must exist");
43 }
44 
45 
46 //-----------------------------------------------------------------------------
47 // Destructor
48 //-----------------------------------------------------------------------------
49 
53 
55 {
56  if (mItem)
57  {
58  delete mItem;
59  mItem = nullptr;
60  }
61 }
62 
63 
64 //-----------------------------------------------------------------------------
65 // Set the associated QGraphicsItem pointer
66 //-----------------------------------------------------------------------------
67 
72 
73 void GraphicsItemForQt::setItem (QGraphicsItem *item)
74 {
75  mItem = item;
76 }
77 
78 
79 //-----------------------------------------------------------------------------
80 // Set or change the position of the graphical item
81 //-----------------------------------------------------------------------------
82 
88 
89 void GraphicsItemForQt::setPosition (double x, double y)
90 {
91  QPointF pos(static_cast<GraphicsViewAdapterForQt*>(mGraphicsView)->
92  convertRelToAbs(QPointF(x, y)));
93  mItem->setPos(pos);
94 }
95 
96 
97 //-----------------------------------------------------------------------------
98 // Set or change the z-order of the graphical item
99 //-----------------------------------------------------------------------------
100 
105 
107 {
108  mItem->setZValue(z);
109 }
GraphicsItemForQt(GraphicsViewAdapter *graphicsView, QGraphicsItem *item)
Constructor, initializing the pointer mItem.
QGraphicsItem * mItem
Pointer pointing to the QGraphicsItem.
void setItem(QGraphicsItem *item)
Set the associated QGraphicsItem pointer.
virtual void setZOrder(double z) overridefinal
Set or change the z-order of the graphical item.
~GraphicsItemForQt()
Destructor, deletes the item and sets mItem to nullptr.
virtual void setPosition(double x, double y) overridefinal
Set or change the position of the graphical item.
GraphicsViewAdapter * mGraphicsView
Pointer to the parent GraphicsViewAdapter.
Definition: graphicsitem.h:142
Abstract base class for implementations rendering graphics.
#define EptAssert(a, b)
Definition: eptexception.h:47
Class for a single item in a graphics view.
Definition: graphicsitem.h:55