File indexing completed on 2024-05-12 04:43:21
0001 /* 0002 * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk) 0003 * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #include "KReportDesignerItemMaps.h" 0020 #include "KReportDesignerItemBase.h" 0021 #include "KReportDesigner.h" 0022 0023 #include <KProperty> 0024 #include <KPropertySet> 0025 0026 #include <QGraphicsScene> 0027 #include <QGraphicsSceneMouseEvent> 0028 #include <QDomDocument> 0029 #include <QPainter> 0030 #include "kreportplugin_debug.h" 0031 0032 void KReportDesignerItemMaps::init(QGraphicsScene *scene) 0033 { 0034 if (scene) 0035 scene->addItem(this); 0036 0037 connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), 0038 this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); 0039 0040 dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames()); 0041 setZValue(z()); 0042 } 0043 0044 KReportDesignerItemMaps::KReportDesignerItemMaps(KReportDesigner *rw, QGraphicsScene *scene, const QPointF &pos) 0045 : KReportDesignerItemRectBase(rw, this) 0046 { 0047 Q_UNUSED(pos); 0048 init(scene); 0049 setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH)); 0050 nameProperty()->setValue(designer()->suggestEntityName(typeName())); 0051 } 0052 0053 KReportDesignerItemMaps::KReportDesignerItemMaps(const QDomNode &element, KReportDesigner *rw, QGraphicsScene* scene) 0054 : KReportItemMaps(element), KReportDesignerItemRectBase(rw, this) 0055 { 0056 init(scene); 0057 setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); 0058 } 0059 0060 KReportDesignerItemMaps* KReportDesignerItemMaps::clone() 0061 { 0062 QDomDocument d; 0063 QDomElement e = d.createElement(QLatin1String("clone")); 0064 QDomNode n; 0065 buildXML(&d, &e); 0066 n = e.firstChild(); 0067 return new KReportDesignerItemMaps(n, designer(), nullptr); 0068 } 0069 0070 KReportDesignerItemMaps::~KReportDesignerItemMaps() 0071 { 0072 // do we need to clean anything up? 0073 } 0074 0075 void KReportDesignerItemMaps::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) 0076 { 0077 Q_UNUSED(option); 0078 Q_UNUSED(widget); 0079 // store any values we plan on changing so we can restore them 0080 QPen p = painter->pen(); 0081 painter->fillRect(rect(), QColor(0xc2, 0xfc, 0xc7));//C2FCC7 0082 0083 //Draw a border so user knows the object edge 0084 painter->setPen(QPen(QColor(224, 224, 224))); 0085 painter->drawRect(rect()); 0086 painter->setPen(Qt::black); 0087 painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("map"))); 0088 0089 drawHandles(painter); 0090 0091 // restore an values before we started just in case 0092 painter->setPen(p); 0093 } 0094 0095 void KReportDesignerItemMaps::buildXML(QDomDocument *doc, QDomElement *parent) 0096 { 0097 QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); 0098 0099 // properties 0100 addPropertyAsAttribute(&entity, nameProperty()); 0101 addPropertyAsAttribute(&entity, dataSourceProperty()); 0102 addPropertyAsAttribute(&entity, m_latitudeProperty); 0103 addPropertyAsAttribute(&entity, m_longitudeProperty); 0104 addPropertyAsAttribute(&entity, m_zoomProperty); 0105 addPropertyAsAttribute(&entity, m_themeProperty); 0106 //addPropertyAsAttribute(&entity, m_resizeMode); 0107 entity.setAttribute(QLatin1String("report:z-index"), z()); 0108 buildXMLRect(doc, &entity, this); 0109 0110 parent->appendChild(entity); 0111 } 0112 0113 void KReportDesignerItemMaps::slotPropertyChanged(KPropertySet &s, KProperty &p) 0114 { 0115 //kreportpluginDebug() << p.name() << ":" << p.value(); 0116 if (p.name().toLower() == "name") { 0117 //For some reason p.oldValue returns an empty string 0118 if (!designer()->isEntityNameUnique(p.value().toString(), this)) { 0119 p.setValue(oldName()); 0120 } else { 0121 setOldName(p.value().toString()); 0122 } 0123 } 0124 0125 KReportDesignerItemRectBase::propertyChanged(s, p); 0126 if (designer()) designer()->setModified(true); 0127 }