~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/koreport/wrtembed/reportentities.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * OpenRPT report writer and rendering engine
 
3
 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
 
4
 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "reportentities.h"
 
21
 
 
22
// qt
 
23
#include <qpainter.h>
 
24
#include <qstring.h>
 
25
#include <qlabel.h>
 
26
#include <qlineedit.h>
 
27
#include <qdom.h>
 
28
#include <qinputdialog.h>
 
29
#include <qslider.h>
 
30
#include <qdatastream.h>
 
31
#include <qcheckbox.h>
 
32
#include <qradiobutton.h>
 
33
#include <qsettings.h>
 
34
#include <kdebug.h>
 
35
 
 
36
#include <koproperty/Property.h>
 
37
#include <koproperty/Set.h>
 
38
#include <koproperty/EditorView.h>
 
39
#include <KoGlobal.h>
 
40
#include <krobjectdata.h>
 
41
#include <krutils.h>
 
42
 
 
43
#include "reportentitylabel.h"
 
44
#include "reportentityfield.h"
 
45
#include "reportentitytext.h"
 
46
#include "reportentityline.h"
 
47
#include "reportentitybarcode.h"
 
48
#include "reportentityimage.h"
 
49
#include "reportentitychart.h"
 
50
 
 
51
//
 
52
// ReportEntity
 
53
//
 
54
ReportEntity::ReportEntity(KoReportDesigner* r)
 
55
{
 
56
    m_reportDesigner = r;
 
57
}
 
58
 
 
59
void ReportEntity::buildXML(QGraphicsItem * item, QDomDocument & doc, QDomElement & parent)
 
60
{
 
61
    ReportEntity *re = 0;
 
62
    re = dynamic_cast<ReportEntity*>(item);
 
63
 
 
64
    if (re) {
 
65
        re->buildXML(doc, parent);
 
66
    }
 
67
 
 
68
}
 
69
 
 
70
void ReportEntity::buildXMLRect(QDomDocument & doc, QDomElement & entity, KRPos *pos, KRSize *siz)
 
71
{
 
72
    Q_UNUSED(doc);
 
73
    KoUnit unit = pos->unit();
 
74
 
 
75
    entity.setAttribute("svg:x", QString::number(pos->toUnit().x()) + KoUnit::unitName(unit));
 
76
    entity.setAttribute("svg:y", QString::number(pos->toUnit().y()) + KoUnit::unitName(unit));
 
77
    entity.setAttribute("svg:width", QString::number(siz->toUnit().width()) + KoUnit::unitName(unit));
 
78
    entity.setAttribute("svg:height", QString::number(siz->toUnit().height()) + KoUnit::unitName(unit));
 
79
}
 
80
 
 
81
void ReportEntity::buildXMLTextStyle(QDomDocument & doc, QDomElement & entity, KRTextStyleData ts)
 
82
{
 
83
    QDomElement element = doc.createElement("report:text-style");
 
84
 
 
85
    element.setAttribute("fo:background-color", ts.backgroundColor.name());
 
86
    element.setAttribute("fo:foreground-color", ts.foregroundColor.name());
 
87
    element.setAttribute("fo:background-opacity", QString::number(ts.backgroundOpacity) + '%');
 
88
    KRUtils::writeFontAttributes(element, ts.font);
 
89
 
 
90
    entity.appendChild(element);
 
91
}
 
92
 
 
93
void ReportEntity::buildXMLLineStyle(QDomDocument & doc, QDomElement & entity, KRLineStyleData ls)
 
94
{
 
95
    QDomElement element = doc.createElement("report:line-style");
 
96
 
 
97
    element.setAttribute("report:line-color", ls.lineColor.name());
 
98
    element.setAttribute("report:line-weight", QString::number(ls.weight));
 
99
 
 
100
    QString l;
 
101
    switch (ls.style) {
 
102
    case Qt::NoPen:
 
103
        l = "nopen";
 
104
        break;
 
105
    case Qt::SolidLine:
 
106
        l = "solid";
 
107
        break;
 
108
    case Qt::DashLine:
 
109
        l = "dash";
 
110
        break;
 
111
    case Qt::DotLine:
 
112
        l = "dot";
 
113
        break;
 
114
    case Qt::DashDotLine:
 
115
        l = "dashdot";
 
116
        break;
 
117
    case Qt::DashDotDotLine:
 
118
        l = "dashdotdot";
 
119
        break;
 
120
    default:
 
121
        l = "solid";
 
122
 
 
123
    }
 
124
    element.setAttribute("report:line-style", l);
 
125
 
 
126
    entity.appendChild(element);
 
127
}
 
128
 
 
129
QString ReportEntity::dataSourceAndObjectTypeName(const QString& dataSource, const QString& objectTypeName)
 
130
{
 
131
    return i18nc("<data-source>: <object>", "%1: %2", dataSource, objectTypeName);
 
132
}
 
133
 
 
134
// static
 
135
void ReportEntity::addPropertyAsAttribute(QDomElement* e, KoProperty::Property* p)
 
136
{
 
137
    switch (p->value().type()) {
 
138
    case QVariant::Int :
 
139
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toInt());
 
140
        break;
 
141
    case QVariant::Double:
 
142
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toDouble());
 
143
        break;
 
144
    case QVariant::Bool:
 
145
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toInt());
 
146
        break;
 
147
    default:
 
148
        e->setAttribute(QLatin1String("report:") + p->name().toLower(), p->value().toString());
 
149
        break;
 
150
    }
 
151
}