[6dd4ed]: src / interfaces / component / icomponentitem.cpp  Maximize  Restore  History

Download this file

114 lines (94 with data), 3.0 kB

  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
/*
Copyright (C) 2009-2010 Julian B채ume <julian@svg4all.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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.
*/
#include "icomponentitem.h"
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <KDebug>
#include <idocumentmodel.h>
#include "node.h"
using namespace KTechLab;
IComponentItem::IComponentItem(QGraphicsItem* parentItem)
: QGraphicsSvgItem(parentItem),
m_document(0)
{
setAcceptHoverEvents(true);
setFlags(
ItemIsFocusable | ItemIsSelectable |
ItemIsMovable
);
}
IComponentItem::~IComponentItem()
{
}
QString IComponentItem::id() const
{
if (!m_id.isEmpty())
return m_id;
if (data(0).toMap().contains("id")) {
return data(0).toMap().value("id").toString();
}
kWarning() << "no id for IComponentItem:" << this;
return QString();
}
bool IComponentItem::hasNode(const Node* node) const
{
if (!node->isValid() || id() != node->parentId())
return false;
return this->node(node->id()) != 0;
}
const Node* IComponentItem::node(const QString& id) const
{
foreach (const QGraphicsItem* item, childItems()){
//TODO: make this a qgraphicsitem_cast
const Node* n = dynamic_cast<const Node*>(item);
if (n && n->id() == id){
return n;
}
}
return 0;
}
QList<const Node*> IComponentItem::nodes() const
{
QList<const Node*> list;
foreach (const QGraphicsItem* item, childItems()){
//TODO: make this a qgraphicsitem_cast
const Node* n = dynamic_cast<const Node*>(item);
if (n) list.append(n);
}
return list;
}
void IComponentItem::setDocumentModel(IDocumentModel* model)
{
m_document = model;
}
IDocumentModel* IComponentItem::documentModel() const
{
return m_document;
}
QVariant KTechLab::IComponentItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value)
{
if (change == QGraphicsItem::ItemScenePositionHasChanged && m_document){
QPointF p = value.toPointF();
QVariantMap newData = data(0).toMap();
newData.insert("x", p.x());
newData.insert("y", p.y());
setData(0, newData);
m_document->updateData( "position", newData);
}
return QGraphicsItem::itemChange(change, value);
}
void IComponentItem::updateData(const QString& name, const QVariantMap& data)
{
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks