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

« back to all changes in this revision

Viewing changes to filters/kspread/gnumeric/gnumericexport.cc

  • 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:
55
55
using namespace KSpread;
56
56
 
57
57
typedef KGenericFactory<GNUMERICExport> GNUMERICExportFactory;
58
 
K_EXPORT_COMPONENT_FACTORY( libgnumericexport, GNUMERICExportFactory( "kofficefilters" ) )
 
58
K_EXPORT_COMPONENT_FACTORY(libgnumericexport, GNUMERICExportFactory("kofficefilters"))
59
59
 
60
60
GNUMERICExport::GNUMERICExport(QObject* parent, const QStringList&)
61
 
    : KoFilter(parent)
 
61
        : KoFilter(parent)
62
62
{
63
63
    isLink = false;
64
64
    isLinkBold = false;
68
68
/**
69
69
 * This function will check if a cell has any type of border.
70
70
 */
71
 
bool GNUMERICExport::hasBorder( const Cell& cell, int currentcolumn, int currentrow)
 
71
bool GNUMERICExport::hasBorder(const Cell& cell, int currentcolumn, int currentrow)
72
72
{
 
73
    Q_UNUSED(currentcolumn);
 
74
    Q_UNUSED(currentrow);
73
75
    const Style style = cell.style();
74
 
    if ( ( (style.leftBorderPen().width() != 0) &&
75
 
           (style.leftBorderPen().style() != Qt::NoPen ) ) ||
76
 
         ( (style.rightBorderPen().width() != 0) &&
77
 
           (style.rightBorderPen().style() != Qt::NoPen ) ) ||
78
 
         ( (style.topBorderPen().width() != 0) &&
79
 
           (style.topBorderPen().style() != Qt::NoPen ) ) ||
80
 
         ( (style.bottomBorderPen().width() != 0) &&
81
 
           (style.bottomBorderPen().style() != Qt::NoPen ) ) ||
82
 
         ( (style.fallDiagonalPen().width() != 0) &&
83
 
           (style.fallDiagonalPen().style() != Qt::NoPen ) ) ||
84
 
         ( (style.goUpDiagonalPen().width() != 0) &&
85
 
           (style.goUpDiagonalPen().style() != Qt::NoPen ) ) )
 
76
    if (((style.leftBorderPen().width() != 0) &&
 
77
            (style.leftBorderPen().style() != Qt::NoPen)) ||
 
78
            ((style.rightBorderPen().width() != 0) &&
 
79
             (style.rightBorderPen().style() != Qt::NoPen)) ||
 
80
            ((style.topBorderPen().width() != 0) &&
 
81
             (style.topBorderPen().style() != Qt::NoPen)) ||
 
82
            ((style.bottomBorderPen().width() != 0) &&
 
83
             (style.bottomBorderPen().style() != Qt::NoPen)) ||
 
84
            ((style.fallDiagonalPen().width() != 0) &&
 
85
             (style.fallDiagonalPen().style() != Qt::NoPen)) ||
 
86
            ((style.goUpDiagonalPen().width() != 0) &&
 
87
             (style.goUpDiagonalPen().style() != Qt::NoPen)))
86
88
        return true;
87
89
    else
88
90
        return false;
90
92
 
91
93
const QString GNUMERICExport::ColorToString(int red, int green, int blue)
92
94
{
93
 
    return QString::number(red,16)+':'+QString::number(green,16)+':'+QString::number(blue,16);
 
95
    return QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16);
94
96
}
95
97
 
96
 
QDomElement GNUMERICExport::GetBorderStyle(QDomDocument gnumeric_doc,const Cell& cell, int currentcolumn, int currentrow)
 
98
QDomElement GNUMERICExport::GetBorderStyle(QDomDocument gnumeric_doc, const Cell& cell, int currentcolumn, int currentrow)
97
99
{
 
100
    Q_UNUSED(currentcolumn);
 
101
    Q_UNUSED(currentrow);
 
102
 
98
103
    QDomElement border_style;
99
104
    QDomElement border;
100
105
 
104
109
    border_style = gnumeric_doc.createElement("gmr:StyleBorder");
105
110
    const Style style = cell.style();
106
111
 
107
 
    if ( (style.leftBorderPen().width() != 0) &&
108
 
         (style.leftBorderPen().style() != Qt::NoPen ) )
109
 
    {
 
112
    if ((style.leftBorderPen().width() != 0) &&
 
113
            (style.leftBorderPen().style() != Qt::NoPen)) {
110
114
        border = gnumeric_doc.createElement("gmr:Left");
111
 
        border.setAttribute("Style","1");
 
115
        border.setAttribute("Style", "1");
112
116
 
113
117
        color =  style.leftBorderPen().color();
114
 
        red = color.red()<<8;
115
 
        green = color.green()<<8;
116
 
        blue = color.blue()<<8;
 
118
        red = color.red() << 8;
 
119
        green = color.green() << 8;
 
120
        blue = color.blue() << 8;
117
121
 
118
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
119
 
    }
120
 
    else
121
 
    {
 
122
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
123
    } else {
122
124
        border = gnumeric_doc.createElement("gmr:Left");
123
 
        border.setAttribute("Style","0");
 
125
        border.setAttribute("Style", "0");
124
126
    }
125
127
 
126
128
    border_style.appendChild(border);
127
129
 
128
 
    if ( (style.rightBorderPen().width() != 0) &&
129
 
         (style.rightBorderPen().style() != Qt::NoPen ) )
130
 
    {
 
130
    if ((style.rightBorderPen().width() != 0) &&
 
131
            (style.rightBorderPen().style() != Qt::NoPen)) {
131
132
        border = gnumeric_doc.createElement("gmr:Right");
132
 
        border.setAttribute("Style","1");
 
133
        border.setAttribute("Style", "1");
133
134
 
134
135
        color =  style.rightBorderPen().color();
135
 
        red = color.red()<<8;
136
 
        green = color.green()<<8;
137
 
        blue = color.blue()<<8;
 
136
        red = color.red() << 8;
 
137
        green = color.green() << 8;
 
138
        blue = color.blue() << 8;
138
139
 
139
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
140
 
    }
141
 
    else
142
 
    {
 
140
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
141
    } else {
143
142
        border = gnumeric_doc.createElement("gmr:Right");
144
 
        border.setAttribute("Style","0");
 
143
        border.setAttribute("Style", "0");
145
144
    }
146
145
 
147
146
    border_style.appendChild(border);
148
147
 
149
 
    if ( (style.topBorderPen().width() != 0) &&
150
 
         (style.topBorderPen().style() != Qt::NoPen ) )
151
 
    {
 
148
    if ((style.topBorderPen().width() != 0) &&
 
149
            (style.topBorderPen().style() != Qt::NoPen)) {
152
150
        border = gnumeric_doc.createElement("gmr:Top");
153
 
        border.setAttribute("Style","1");
 
151
        border.setAttribute("Style", "1");
154
152
 
155
153
        color =  style.topBorderPen().color();
156
 
        red = color.red()<<8;
157
 
        green = color.green()<<8;
158
 
        blue = color.blue()<<8;
 
154
        red = color.red() << 8;
 
155
        green = color.green() << 8;
 
156
        blue = color.blue() << 8;
159
157
 
160
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
161
 
    }
162
 
    else
163
 
    {
 
158
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
159
    } else {
164
160
        border = gnumeric_doc.createElement("gmr:Top");
165
 
        border.setAttribute("Style","0");
 
161
        border.setAttribute("Style", "0");
166
162
    }
167
163
 
168
164
    border_style.appendChild(border);
169
165
 
170
 
    if ( (style.bottomBorderPen().width() != 0) &&
171
 
         (style.bottomBorderPen().style() != Qt::NoPen ) )
172
 
    {
 
166
    if ((style.bottomBorderPen().width() != 0) &&
 
167
            (style.bottomBorderPen().style() != Qt::NoPen)) {
173
168
        border = gnumeric_doc.createElement("gmr:Bottom");
174
 
        border.setAttribute("Style","1");
 
169
        border.setAttribute("Style", "1");
175
170
 
176
171
        color =  style.bottomBorderPen().color();
177
 
        red = color.red()<<8;
178
 
        green = color.green()<<8;
179
 
        blue = color.blue()<<8;
 
172
        red = color.red() << 8;
 
173
        green = color.green() << 8;
 
174
        blue = color.blue() << 8;
180
175
 
181
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
182
 
    }
183
 
    else
184
 
    {
 
176
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
177
    } else {
185
178
        border = gnumeric_doc.createElement("gmr:Bottom");
186
 
        border.setAttribute("Style","0");
 
179
        border.setAttribute("Style", "0");
187
180
    }
188
181
 
189
182
    border_style.appendChild(border);
190
183
 
191
 
    if ( (style.fallDiagonalPen().width() != 0) &&
192
 
         (style.fallDiagonalPen().style() != Qt::NoPen ) )
193
 
    {
 
184
    if ((style.fallDiagonalPen().width() != 0) &&
 
185
            (style.fallDiagonalPen().style() != Qt::NoPen)) {
194
186
        border = gnumeric_doc.createElement("gmr:Diagonal");
195
 
        border.setAttribute("Style","1");
 
187
        border.setAttribute("Style", "1");
196
188
 
197
189
        color =  style.fallDiagonalPen().color();
198
 
        red = color.red()<<8;
199
 
        green = color.green()<<8;
200
 
        blue = color.blue()<<8;
 
190
        red = color.red() << 8;
 
191
        green = color.green() << 8;
 
192
        blue = color.blue() << 8;
201
193
 
202
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
203
 
    }
204
 
    else
205
 
    {
 
194
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
195
    } else {
206
196
        border = gnumeric_doc.createElement("gmr:Diagonal");
207
 
        border.setAttribute("Style","0");
 
197
        border.setAttribute("Style", "0");
208
198
    }
209
199
 
210
200
    border_style.appendChild(border);
211
201
 
212
 
    if ( (style.goUpDiagonalPen().width() != 0) &&
213
 
         (style.goUpDiagonalPen().style() != Qt::NoPen ) )
214
 
    {
 
202
    if ((style.goUpDiagonalPen().width() != 0) &&
 
203
            (style.goUpDiagonalPen().style() != Qt::NoPen)) {
215
204
        border = gnumeric_doc.createElement("gmr:Rev-Diagonal");
216
 
        border.setAttribute("Style","1");
 
205
        border.setAttribute("Style", "1");
217
206
 
218
207
        color =  style.goUpDiagonalPen().color();
219
 
        red = color.red()<<8;
220
 
        green = color.green()<<8;
221
 
        blue = color.blue()<<8;
 
208
        red = color.red() << 8;
 
209
        green = color.green() << 8;
 
210
        blue = color.blue() << 8;
222
211
 
223
 
        border.setAttribute("Color", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
224
 
    }
225
 
    else
226
 
    {
 
212
        border.setAttribute("Color", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
213
    } else {
227
214
        border = gnumeric_doc.createElement("gmr:Rev-Diagonal");
228
 
        border.setAttribute("Style","0");
 
215
        border.setAttribute("Style", "0");
229
216
    }
230
217
 
231
218
    border_style.appendChild(border);
233
220
    return border_style;
234
221
}
235
222
 
236
 
QDomElement GNUMERICExport::GetValidity( QDomDocument gnumeric_doc, const Cell& cell )
 
223
QDomElement GNUMERICExport::GetValidity(QDomDocument gnumeric_doc, const Cell& cell)
237
224
{
238
225
    //<gmr:Validation Style="1" Type="1" Operator="7" AllowBlank="true" UseDropdown="false" Title="ghhg" Message="ghghhhjfhfghjfghj&#10;fg&#10;hjgf&#10;hj">
239
226
    //        <gmr:Expression0>45</gmr:Expression0>
240
227
    //      </gmr:Validation>
241
228
    Validity kspread_validity = cell.validity();
242
 
    QDomElement val = gnumeric_doc.createElement( "gmr:Validation" );
243
 
    val.setAttribute( "Title", kspread_validity.title() );
244
 
    val.setAttribute( "Message", kspread_validity.message() );
245
 
    val.setAttribute( "AllowBlank", kspread_validity.allowEmptyCell() ? "true":"false" );
246
 
    if ( !kspread_validity.displayMessage() )
247
 
    {
248
 
        val.setAttribute("Style", "0" );
249
 
    }
250
 
    else
251
 
    {
252
 
        switch( kspread_validity.action() )
253
 
        {
254
 
          case Validity::Stop:
255
 
            val.setAttribute("Style", "1" );
256
 
            break;
257
 
          case Validity::Warning:
258
 
            val.setAttribute("Style", "2" );
259
 
            break;
260
 
          case Validity::Information:
261
 
            val.setAttribute("Style", "3" );
 
229
    QDomElement val = gnumeric_doc.createElement("gmr:Validation");
 
230
    val.setAttribute("Title", kspread_validity.title());
 
231
    val.setAttribute("Message", kspread_validity.message());
 
232
    val.setAttribute("AllowBlank", kspread_validity.allowEmptyCell() ? "true" : "false");
 
233
    if (!kspread_validity.displayMessage()) {
 
234
        val.setAttribute("Style", "0");
 
235
    } else {
 
236
        switch (kspread_validity.action()) {
 
237
        case Validity::Stop:
 
238
            val.setAttribute("Style", "1");
 
239
            break;
 
240
        case Validity::Warning:
 
241
            val.setAttribute("Style", "2");
 
242
            break;
 
243
        case Validity::Information:
 
244
            val.setAttribute("Style", "3");
262
245
            break;
263
246
        }
264
247
    }
265
248
 
266
 
    switch( kspread_validity.condition() )
267
 
    {
268
 
      case Conditional::None:
 
249
    switch (kspread_validity.condition()) {
 
250
    case Conditional::None:
269
251
        //Nothing
270
252
        break;
271
 
      case Conditional::Equal:
272
 
        val.setAttribute("Operator", "2" );
273
 
        break;
274
 
      case Conditional::Superior:
275
 
        val.setAttribute("Operator", "4" );
276
 
        break;
277
 
      case Conditional::Inferior:
278
 
        val.setAttribute("Operator", "5" );
279
 
        break;
280
 
      case Conditional::SuperiorEqual:
281
 
        val.setAttribute("Operator", "6" );
282
 
        break;
283
 
      case Conditional::InferiorEqual:
284
 
        val.setAttribute("Operator", "7" );
285
 
        break;
286
 
      case Conditional::Between:
287
 
        val.setAttribute("Operator", "0" );
288
 
        break;
289
 
      case Conditional::Different:
290
 
        val.setAttribute("Operator", "3" );
291
 
        break;
292
 
      case Conditional::DifferentTo:
293
 
        val.setAttribute("Operator", "1" );
 
253
    case Conditional::Equal:
 
254
        val.setAttribute("Operator", "2");
 
255
        break;
 
256
    case Conditional::Superior:
 
257
        val.setAttribute("Operator", "4");
 
258
        break;
 
259
    case Conditional::Inferior:
 
260
        val.setAttribute("Operator", "5");
 
261
        break;
 
262
    case Conditional::SuperiorEqual:
 
263
        val.setAttribute("Operator", "6");
 
264
        break;
 
265
    case Conditional::InferiorEqual:
 
266
        val.setAttribute("Operator", "7");
 
267
        break;
 
268
    case Conditional::Between:
 
269
        val.setAttribute("Operator", "0");
 
270
        break;
 
271
    case Conditional::Different:
 
272
        val.setAttribute("Operator", "3");
 
273
        break;
 
274
    case Conditional::DifferentTo:
 
275
        val.setAttribute("Operator", "1");
294
276
        break;
295
277
    }
296
 
    switch( kspread_validity.restriction() )
297
 
    {
 
278
    switch (kspread_validity.restriction()) {
298
279
    case Validity::None:
299
 
        val.setAttribute("Type", "0" );
 
280
        val.setAttribute("Type", "0");
300
281
        break;
301
 
    case Validity::Number:
302
 
    {
303
 
        val.setAttribute("Type", "2" );
304
 
        switch( kspread_validity.condition() )
305
 
        {
306
 
          case Conditional::None:
 
282
    case Validity::Number: {
 
283
        val.setAttribute("Type", "2");
 
284
        switch (kspread_validity.condition()) {
 
285
        case Conditional::None:
307
286
            //Nothing
308
287
            break;
309
 
          case Conditional::Equal:
310
 
          case Conditional::Superior:
311
 
          case Conditional::Inferior:
312
 
          case Conditional::SuperiorEqual:
313
 
          case Conditional::InferiorEqual:
314
 
          case Conditional::Different:
315
 
        {
316
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
317
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number( kspread_validity.minimumValue() ) ) );
318
 
            val.appendChild( tmp );
 
288
        case Conditional::Equal:
 
289
        case Conditional::Superior:
 
290
        case Conditional::Inferior:
 
291
        case Conditional::SuperiorEqual:
 
292
        case Conditional::InferiorEqual:
 
293
        case Conditional::Different: {
 
294
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
295
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
296
            val.appendChild(tmp);
319
297
        }
320
298
        break;
321
 
          case Conditional::Between:
322
 
          case Conditional::DifferentTo:
323
 
        {
324
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
325
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.minimumValue() ) ) );
326
 
            val.appendChild( tmp );
327
 
            tmp = gnumeric_doc.createElement( "gmr:Expression1" );
328
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.maximumValue() ) ) );
329
 
            val.appendChild( tmp );
 
299
        case Conditional::Between:
 
300
        case Conditional::DifferentTo: {
 
301
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
302
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
303
            val.appendChild(tmp);
 
304
            tmp = gnumeric_doc.createElement("gmr:Expression1");
 
305
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.maximumValue())));
 
306
            val.appendChild(tmp);
330
307
        }
331
308
        break;
332
309
        }
338
315
        //val.setAttribute("Type", "1" );
339
316
        break;
340
317
    case Validity::Time:
341
 
        val.setAttribute("Type", "5" );
342
 
        switch( kspread_validity.condition() )
343
 
        {
344
 
          case Conditional::None:
 
318
        val.setAttribute("Type", "5");
 
319
        switch (kspread_validity.condition()) {
 
320
        case Conditional::None:
345
321
            //Nothing
346
322
            break;
347
 
          case Conditional::Equal:
348
 
          case Conditional::Superior:
349
 
          case Conditional::Inferior:
350
 
          case Conditional::SuperiorEqual:
351
 
          case Conditional::InferiorEqual:
352
 
          case Conditional::Different:
353
 
        {
354
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
355
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.minimumTime().toString() ) );
356
 
            val.appendChild( tmp );
 
323
        case Conditional::Equal:
 
324
        case Conditional::Superior:
 
325
        case Conditional::Inferior:
 
326
        case Conditional::SuperiorEqual:
 
327
        case Conditional::InferiorEqual:
 
328
        case Conditional::Different: {
 
329
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
330
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.minimumTime().toString()));
 
331
            val.appendChild(tmp);
357
332
        }
358
333
        break;
359
 
          case Conditional::Between:
360
 
          case Conditional::DifferentTo:
361
 
        {
362
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
363
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.minimumTime().toString() ) );
364
 
            val.appendChild( tmp );
365
 
            tmp = gnumeric_doc.createElement( "gmr:Expression1" );
366
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.maximumTime().toString() ) );
367
 
            val.appendChild( tmp );
 
334
        case Conditional::Between:
 
335
        case Conditional::DifferentTo: {
 
336
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
337
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.minimumTime().toString()));
 
338
            val.appendChild(tmp);
 
339
            tmp = gnumeric_doc.createElement("gmr:Expression1");
 
340
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.maximumTime().toString()));
 
341
            val.appendChild(tmp);
368
342
        }
369
343
        break;
370
344
        }
371
345
 
372
346
        break;
373
347
    case Validity::Date:
374
 
        val.setAttribute("Type", "4" );
375
 
        switch( kspread_validity.condition() )
376
 
        {
377
 
          case Conditional::None:
 
348
        val.setAttribute("Type", "4");
 
349
        switch (kspread_validity.condition()) {
 
350
        case Conditional::None:
378
351
            //Nothing
379
352
            break;
380
 
          case Conditional::Equal:
381
 
          case Conditional::Superior:
382
 
          case Conditional::Inferior:
383
 
          case Conditional::SuperiorEqual:
384
 
          case Conditional::InferiorEqual:
385
 
          case Conditional::Different:
386
 
        {
387
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
388
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.minimumDate().toString() ) );
389
 
            val.appendChild( tmp );
 
353
        case Conditional::Equal:
 
354
        case Conditional::Superior:
 
355
        case Conditional::Inferior:
 
356
        case Conditional::SuperiorEqual:
 
357
        case Conditional::InferiorEqual:
 
358
        case Conditional::Different: {
 
359
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
360
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.minimumDate().toString()));
 
361
            val.appendChild(tmp);
390
362
        }
391
363
        break;
392
 
          case Conditional::Between:
393
 
          case Conditional::DifferentTo:
394
 
        {
395
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
396
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.minimumDate().toString() ) );
397
 
            val.appendChild( tmp );
398
 
            tmp = gnumeric_doc.createElement( "gmr:Expression1" );
399
 
            tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity.maximumDate().toString() ) );
400
 
            val.appendChild( tmp );
 
364
        case Conditional::Between:
 
365
        case Conditional::DifferentTo: {
 
366
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
367
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.minimumDate().toString()));
 
368
            val.appendChild(tmp);
 
369
            tmp = gnumeric_doc.createElement("gmr:Expression1");
 
370
            tmp.appendChild(gnumeric_doc.createTextNode(kspread_validity.maximumDate().toString()));
 
371
            val.appendChild(tmp);
401
372
        }
402
373
        break;
403
374
        }
404
375
 
405
376
        break;
406
377
    case Validity::Integer:
407
 
        val.setAttribute("Type", "1" );
408
 
        switch( kspread_validity.condition() )
409
 
        {
410
 
          case Conditional::None:
 
378
        val.setAttribute("Type", "1");
 
379
        switch (kspread_validity.condition()) {
 
380
        case Conditional::None:
411
381
            //Nothing
412
382
            break;
413
 
          case Conditional::Equal:
414
 
          case Conditional::Superior:
415
 
          case Conditional::Inferior:
416
 
          case Conditional::SuperiorEqual:
417
 
          case Conditional::InferiorEqual:
418
 
          case Conditional::Different:
419
 
        {
420
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
421
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.minimumValue() ) ) );
422
 
            val.appendChild( tmp );
 
383
        case Conditional::Equal:
 
384
        case Conditional::Superior:
 
385
        case Conditional::Inferior:
 
386
        case Conditional::SuperiorEqual:
 
387
        case Conditional::InferiorEqual:
 
388
        case Conditional::Different: {
 
389
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
390
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
391
            val.appendChild(tmp);
423
392
        }
424
393
        break;
425
 
          case Conditional::Between:
426
 
          case Conditional::DifferentTo:
427
 
        {
428
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
429
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.minimumValue() ) ) );
430
 
            val.appendChild( tmp );
431
 
            tmp = gnumeric_doc.createElement( "gmr:Expression1" );
432
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.maximumValue() ) ) );
433
 
            val.appendChild( tmp );
 
394
        case Conditional::Between:
 
395
        case Conditional::DifferentTo: {
 
396
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
397
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
398
            val.appendChild(tmp);
 
399
            tmp = gnumeric_doc.createElement("gmr:Expression1");
 
400
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.maximumValue())));
 
401
            val.appendChild(tmp);
434
402
        }
435
403
        break;
436
404
        }
437
405
        break;
438
406
    case Validity::TextLength:
439
 
        val.setAttribute("Type", "6" );
440
 
        switch( kspread_validity.condition() )
441
 
        {
442
 
          case Conditional::None:
 
407
        val.setAttribute("Type", "6");
 
408
        switch (kspread_validity.condition()) {
 
409
        case Conditional::None:
443
410
            //Nothing
444
411
            break;
445
 
          case Conditional::Equal:
446
 
          case Conditional::Superior:
447
 
          case Conditional::Inferior:
448
 
          case Conditional::SuperiorEqual:
449
 
          case Conditional::InferiorEqual:
450
 
          case Conditional::Different:
451
 
        {
452
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
453
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.minimumValue() ) ) );
454
 
            val.appendChild( tmp );
 
412
        case Conditional::Equal:
 
413
        case Conditional::Superior:
 
414
        case Conditional::Inferior:
 
415
        case Conditional::SuperiorEqual:
 
416
        case Conditional::InferiorEqual:
 
417
        case Conditional::Different: {
 
418
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
419
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
420
            val.appendChild(tmp);
455
421
        }
456
422
        break;
457
 
          case Conditional::Between:
458
 
          case Conditional::DifferentTo:
459
 
        {
460
 
            QDomElement tmp = gnumeric_doc.createElement( "gmr:Expression0" );
461
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.minimumValue() ) ) );
462
 
            val.appendChild( tmp );
463
 
            tmp = gnumeric_doc.createElement( "gmr:Expression1" );
464
 
            tmp.appendChild( gnumeric_doc.createTextNode( QString::number(kspread_validity.maximumValue() ) ) );
465
 
            val.appendChild( tmp );
 
423
        case Conditional::Between:
 
424
        case Conditional::DifferentTo: {
 
425
            QDomElement tmp = gnumeric_doc.createElement("gmr:Expression0");
 
426
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.minimumValue())));
 
427
            val.appendChild(tmp);
 
428
            tmp = gnumeric_doc.createElement("gmr:Expression1");
 
429
            tmp.appendChild(gnumeric_doc.createTextNode(QString::number(kspread_validity.maximumValue())));
 
430
            val.appendChild(tmp);
466
431
        }
467
432
        break;
468
433
        }
469
434
        break;
470
435
    case Validity::List:
471
 
        val.setAttribute("Type", "3" );
472
 
        switch( kspread_validity.condition() )
473
 
        {
474
 
          case Conditional::None:
 
436
        val.setAttribute("Type", "3");
 
437
        switch (kspread_validity.condition()) {
 
438
        case Conditional::None:
475
439
            //Nothing
476
440
            break;
477
 
          case Conditional::Equal:
478
 
          case Conditional::Superior:
479
 
          case Conditional::Inferior:
480
 
          case Conditional::SuperiorEqual:
481
 
          case Conditional::InferiorEqual:
482
 
          case Conditional::Different:
 
441
        case Conditional::Equal:
 
442
        case Conditional::Superior:
 
443
        case Conditional::Inferior:
 
444
        case Conditional::SuperiorEqual:
 
445
        case Conditional::InferiorEqual:
 
446
        case Conditional::Different:
483
447
            break;
484
 
          case Conditional::Between:
485
 
          case Conditional::DifferentTo:
 
448
        case Conditional::Between:
 
449
        case Conditional::DifferentTo:
486
450
            break;
487
451
        }
488
452
        break;
491
455
    return val;
492
456
}
493
457
 
494
 
QDomElement GNUMERICExport::GetFontStyle( QDomDocument gnumeric_doc,const Cell& cell, int currentcolumn, int currentrow)
 
458
QDomElement GNUMERICExport::GetFontStyle(QDomDocument gnumeric_doc, const Cell& cell, int currentcolumn, int currentrow)
495
459
{
496
460
    QDomElement font_style;
497
461
    const Style style = cell.style();
498
 
    kDebug(30521)<<" currentcolumn :"<<currentcolumn<<" currentrow :"<<currentrow;
 
462
    kDebug(30521) << " currentcolumn :" << currentcolumn << " currentrow :" << currentrow;
499
463
    font_style = gnumeric_doc.createElement("gmr:Font");
500
464
    font_style.appendChild(gnumeric_doc.createTextNode(style.fontFamily()));
501
465
 
502
 
    if (style.italic() || (isLink && isLinkItalic))
503
 
    {
504
 
        font_style.setAttribute("Italic","1");
505
 
    }
506
 
    if (style.bold() || (isLink && isLinkBold))
507
 
    {
508
 
        font_style.setAttribute("Bold","1");
509
 
    }
510
 
    if (style.underline())
511
 
    {
512
 
        font_style.setAttribute("Underline","1");
513
 
    }
514
 
    if (style.strikeOut())
515
 
    {
516
 
        font_style.setAttribute("StrikeThrough","1");
517
 
    }
518
 
    if (style.fontSize())
519
 
    {
520
 
        font_style.setAttribute("Unit",QString::number(style.fontSize()));
 
466
    if (style.italic() || (isLink && isLinkItalic)) {
 
467
        font_style.setAttribute("Italic", "1");
 
468
    }
 
469
    if (style.bold() || (isLink && isLinkBold)) {
 
470
        font_style.setAttribute("Bold", "1");
 
471
    }
 
472
    if (style.underline()) {
 
473
        font_style.setAttribute("Underline", "1");
 
474
    }
 
475
    if (style.strikeOut()) {
 
476
        font_style.setAttribute("StrikeThrough", "1");
 
477
    }
 
478
    if (style.fontSize()) {
 
479
        font_style.setAttribute("Unit", QString::number(style.fontSize()));
521
480
    }
522
481
 
523
482
    return font_style;
533
492
 
534
493
    path = linkUrl;
535
494
 
536
 
    if (path.section(":",0,0).toLower() == "http")
537
 
        link_style.setAttribute("type","GnmHLinkURL");
538
 
    else if (path.section(":",0,0).toLower() == "mailto")
539
 
        link_style.setAttribute("type","GnmHLinkEMail");
540
 
    else if (path.section(":",0,0).toLower() == "file")
541
 
        link_style.setAttribute("type","GnmHLinkExternal");
 
495
    if (path.section(":", 0, 0).toLower() == "http")
 
496
        link_style.setAttribute("type", "GnmHLinkURL");
 
497
    else if (path.section(":", 0, 0).toLower() == "mailto")
 
498
        link_style.setAttribute("type", "GnmHLinkEMail");
 
499
    else if (path.section(":", 0, 0).toLower() == "file")
 
500
        link_style.setAttribute("type", "GnmHLinkExternal");
542
501
    else if (path.left(5).toLower() == "sheet")
543
 
        link_style.setAttribute("type","GnmHLinkCurWB");
 
502
        link_style.setAttribute("type", "GnmHLinkCurWB");
544
503
    else
545
 
        link_style.setAttribute("type","");
 
504
        link_style.setAttribute("type", "");
546
505
 
547
 
    link_style.setAttribute("target",path);
 
506
    link_style.setAttribute("target", path);
548
507
 
549
508
    // KSpread doesn't support link tips.
550
 
    link_style.setAttribute("tip","");
 
509
    link_style.setAttribute("tip", "");
551
510
 
552
511
    return link_style;
553
512
}
554
513
 
555
 
QDomElement GNUMERICExport::GetCellStyle(QDomDocument gnumeric_doc,const Cell& cell, int currentcolumn, int currentrow)
 
514
QDomElement GNUMERICExport::GetCellStyle(QDomDocument gnumeric_doc, const Cell& cell, int currentcolumn, int currentrow)
556
515
{
557
 
    QColorGroup defaultColorGroup = QApplication::palette().active();
558
 
 
559
 
        QDomElement cell_style;
560
 
 
561
 
        cell_style = gnumeric_doc.createElement("gmr:Style");
 
516
    QDomElement cell_style;
 
517
 
 
518
    cell_style = gnumeric_doc.createElement("gmr:Style");
562
519
 
563
520
    int red, green, blue;
564
521
 
565
522
    const Style style = cell.style();
566
523
    QColor bgColor =  style.backgroundColor();
567
524
    if (bgColor.isValid()) {
568
 
        red = bgColor.red()<<8;
569
 
        green = bgColor.green()<<8;
570
 
        blue = bgColor.blue()<<8;
 
525
        red = bgColor.red() << 8;
 
526
        green = bgColor.green() << 8;
 
527
        blue = bgColor.blue() << 8;
571
528
    } else {
572
529
        // Let's use white default for background
573
530
        red = 0xffff;
575
532
        blue = 0xffff;
576
533
    }
577
534
 
578
 
    switch (style.backgroundBrush().style())
579
 
    {
580
 
        case Qt::NoBrush:
581
 
            cell_style.setAttribute("Shade","0");
582
 
            break;
583
 
        case Qt::SolidPattern:
584
 
            // 100%
585
 
            cell_style.setAttribute("Shade","1");
586
 
            break;
587
 
        case Qt::Dense1Pattern:
588
 
            // 87.5%
589
 
            cell_style.setAttribute("Shade","25");
590
 
            break;
591
 
        case Qt::Dense2Pattern:
592
 
            // 75%
593
 
            cell_style.setAttribute("Shade","2");
594
 
            break;
595
 
        case Qt::Dense3Pattern:
596
 
            // 62.5%
597
 
            // Not supported by GNumeric
598
 
            // Fall back to 50%
599
 
            cell_style.setAttribute("Shade","3");
600
 
            break;
601
 
        case Qt::Dense4Pattern:
602
 
            // 50%
603
 
            cell_style.setAttribute("Shade","3");
604
 
            break;
605
 
        case Qt::Dense5Pattern:
606
 
            // 25%
607
 
            cell_style.setAttribute("Shade","4");
608
 
            break;
609
 
        case Qt::Dense6Pattern:
610
 
            // 12.5%
611
 
            cell_style.setAttribute("Shade","5");
612
 
            break;
613
 
        case Qt::Dense7Pattern:
614
 
            // 6.25%
615
 
            cell_style.setAttribute("Shade","6");
616
 
            break;
617
 
        case Qt::HorPattern:
618
 
            cell_style.setAttribute("Shade","13");
619
 
            break;
620
 
        case Qt::VerPattern:
621
 
            cell_style.setAttribute("Shade","14");
622
 
            break;
623
 
        case Qt::CrossPattern:
624
 
            cell_style.setAttribute("Shade","17");
625
 
            break;
626
 
        case Qt::BDiagPattern:
627
 
            cell_style.setAttribute("Shade","16");
628
 
            break;
629
 
        case Qt::FDiagPattern:
630
 
            cell_style.setAttribute("Shade","15");
631
 
            break;
632
 
        case Qt::DiagCrossPattern:
633
 
            cell_style.setAttribute("Shade","18");
634
 
            break;
635
 
        case Qt::TexturePattern:
636
 
            // Not supported by Gnumeric
637
 
            cell_style.setAttribute("Shade","0");
638
 
            break;
639
 
    }
640
 
 
641
 
        cell_style.setAttribute("Back",QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16) );
642
 
 
643
 
 
644
 
        QColor textColor =  style.fontColor();
645
 
        red = textColor.red()<<8;
646
 
        green = textColor.green()<<8;
647
 
        blue = textColor.blue()<<8;
648
 
 
649
 
        cell_style.setAttribute("Fore",QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16) );
650
 
 
651
 
 if (style.halign() ==  Style::HAlignUndefined)
652
 
    {
653
 
        cell_style.setAttribute("HAlign","1");
654
 
    }
655
 
    else if (style.halign() ==  Style::Left)
656
 
        {
657
 
        cell_style.setAttribute("HAlign","2");
658
 
    }
659
 
    else if (style.halign() ==  Style::Right)
660
 
        {
661
 
        cell_style.setAttribute("HAlign","4");
662
 
        }
663
 
 else if (style.halign() ==  Style::Center)
664
 
        {
665
 
        cell_style.setAttribute("HAlign","8");
666
 
    }
667
 
 
668
 
    if (style.valign() ==  Style::Top)
669
 
        {
670
 
            cell_style.setAttribute("VAlign","1");
671
 
        }
672
 
 else if (style.valign() ==  Style::Bottom)
673
 
        {
674
 
        cell_style.setAttribute("VAlign","2");
675
 
    }
676
 
    else if (style.valign() ==  Style::Middle)
677
 
    {
678
 
        cell_style.setAttribute("VAlign","4");
679
 
        }
 
535
    switch (style.backgroundBrush().style()) {
 
536
    case Qt::NoBrush:
 
537
        cell_style.setAttribute("Shade", "0");
 
538
        break;
 
539
    case Qt::SolidPattern:
 
540
        // 100%
 
541
        cell_style.setAttribute("Shade", "1");
 
542
        break;
 
543
    case Qt::Dense1Pattern:
 
544
        // 87.5%
 
545
        cell_style.setAttribute("Shade", "25");
 
546
        break;
 
547
    case Qt::Dense2Pattern:
 
548
        // 75%
 
549
        cell_style.setAttribute("Shade", "2");
 
550
        break;
 
551
    case Qt::Dense3Pattern:
 
552
        // 62.5%
 
553
        // Not supported by GNumeric
 
554
        // Fall back to 50%
 
555
        cell_style.setAttribute("Shade", "3");
 
556
        break;
 
557
    case Qt::Dense4Pattern:
 
558
        // 50%
 
559
        cell_style.setAttribute("Shade", "3");
 
560
        break;
 
561
    case Qt::Dense5Pattern:
 
562
        // 25%
 
563
        cell_style.setAttribute("Shade", "4");
 
564
        break;
 
565
    case Qt::Dense6Pattern:
 
566
        // 12.5%
 
567
        cell_style.setAttribute("Shade", "5");
 
568
        break;
 
569
    case Qt::Dense7Pattern:
 
570
        // 6.25%
 
571
        cell_style.setAttribute("Shade", "6");
 
572
        break;
 
573
    case Qt::HorPattern:
 
574
        cell_style.setAttribute("Shade", "13");
 
575
        break;
 
576
    case Qt::VerPattern:
 
577
        cell_style.setAttribute("Shade", "14");
 
578
        break;
 
579
    case Qt::CrossPattern:
 
580
        cell_style.setAttribute("Shade", "17");
 
581
        break;
 
582
    case Qt::BDiagPattern:
 
583
        cell_style.setAttribute("Shade", "16");
 
584
        break;
 
585
    case Qt::FDiagPattern:
 
586
        cell_style.setAttribute("Shade", "15");
 
587
        break;
 
588
    case Qt::DiagCrossPattern:
 
589
        cell_style.setAttribute("Shade", "18");
 
590
        break;
 
591
    case Qt::TexturePattern:
 
592
    default:
 
593
        // Not supported by Gnumeric
 
594
        cell_style.setAttribute("Shade", "0");
 
595
        break;
 
596
    }
 
597
 
 
598
    cell_style.setAttribute("Back", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
599
 
 
600
 
 
601
    QColor textColor =  style.fontColor();
 
602
    red = textColor.red() << 8;
 
603
    green = textColor.green() << 8;
 
604
    blue = textColor.blue() << 8;
 
605
 
 
606
    cell_style.setAttribute("Fore", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
 
607
 
 
608
    if (style.halign() ==  Style::HAlignUndefined) {
 
609
        cell_style.setAttribute("HAlign", "1");
 
610
    } else if (style.halign() ==  Style::Left) {
 
611
        cell_style.setAttribute("HAlign", "2");
 
612
    } else if (style.halign() ==  Style::Right) {
 
613
        cell_style.setAttribute("HAlign", "4");
 
614
    } else if (style.halign() ==  Style::Center) {
 
615
        cell_style.setAttribute("HAlign", "8");
 
616
    }
 
617
 
 
618
    if (style.valign() ==  Style::Top) {
 
619
        cell_style.setAttribute("VAlign", "1");
 
620
    } else if (style.valign() ==  Style::Bottom) {
 
621
        cell_style.setAttribute("VAlign", "2");
 
622
    } else if (style.valign() ==  Style::Middle) {
 
623
        cell_style.setAttribute("VAlign", "4");
 
624
    }
680
625
 
681
626
    if (style.wrapText())
682
 
        cell_style.setAttribute("WrapText","1");
 
627
        cell_style.setAttribute("WrapText", "1");
683
628
    else
684
 
        cell_style.setAttribute("WrapText","0");
 
629
        cell_style.setAttribute("WrapText", "0");
685
630
 
686
631
    // ShrinkToFit not supported by KSpread (?)
687
 
    cell_style.setAttribute("ShrinkToFit","0");
 
632
    cell_style.setAttribute("ShrinkToFit", "0");
688
633
 
689
634
    // I'm not sure about the rotation values.
690
635
    // I never got it to work in GNumeric.
703
648
    cell_style.setAttribute("Hidden", style.hideAll());
704
649
 
705
650
    QColor patColor =  style.backgroundBrush().color();
706
 
    red = patColor.red()<<8;
707
 
    green = patColor.green()<<8;
708
 
    blue = patColor.blue()<<8;
 
651
    red = patColor.red() << 8;
 
652
    green = patColor.green() << 8;
 
653
    blue = patColor.blue() << 8;
709
654
 
710
 
    cell_style.setAttribute("PatternColor", QString::number(red,16)+':'+QString::number(green,16) +':'+QString::number(blue,16));
 
655
    cell_style.setAttribute("PatternColor", QString::number(red, 16) + ':' + QString::number(green, 16) + ':' + QString::number(blue, 16));
711
656
 
712
657
    if (isLink)
713
658
        cell_style.appendChild(GetLinkStyle(gnumeric_doc));
714
659
 
715
660
    cell_style.appendChild(GetFontStyle(gnumeric_doc, cell, currentcolumn, currentrow));
716
661
 
717
 
    if ( !cell.validity().isEmpty() )
718
 
    {
719
 
        cell_style.appendChild( GetValidity( gnumeric_doc, cell ) );
 
662
    if (!cell.validity().isEmpty()) {
 
663
        cell_style.appendChild(GetValidity(gnumeric_doc, cell));
720
664
    }
721
665
 
722
 
        QString stringFormat;
 
666
    QString stringFormat;
723
667
 
724
668
    Currency currency;
725
669
 
726
 
        switch( style.formatType())
727
 
        {
728
 
        case Format::Generic:
729
 
            stringFormat="General";
730
 
            break;
731
 
        case Format::Number:
732
 
            stringFormat="0.00";
733
 
                        break;
734
 
        case Format::Text:
735
 
            stringFormat="General";
736
 
            break;
737
 
                case Format::Money:
738
 
 
739
 
            if (!style.hasAttribute(Style::CurrencyFormat))
740
 
            {
741
 
                stringFormat = "0.00";
742
 
                break;
743
 
            }
744
 
            currency = style.currency();
745
 
 
746
 
            if (currency.code().isEmpty())
747
 
                stringFormat = "0.00";
748
 
            else if (currency.code() == "$")
749
 
                stringFormat = "$0.00";
750
 
            else if (currency.code() == QString::fromUtf8("€"))
751
 
                stringFormat = "[$€-2]0.00";
752
 
            else if (currency.code() == QString::fromUtf8("£"))
753
 
                stringFormat = "£0.00";
754
 
            else if (currency.code() == QString::fromUtf8("¥"))
755
 
                stringFormat = "¥0.00";
756
 
            else
757
 
                stringFormat="[$" + currency.code() + "]0.00";
758
 
 
759
 
            break;
760
 
                case Format::Percentage:
761
 
                    stringFormat="0.00%";
762
 
                        break;
763
 
                case Format::Scientific:
764
 
                    stringFormat="0.00E+00";
765
 
                        break;
766
 
                case Format::ShortDate:
767
 
                        stringFormat=cell.locale()->dateFormatShort();
768
 
                        break;
769
 
                case Format::TextDate:
770
 
                        stringFormat=cell.locale()->dateFormat();
771
 
                        break;
772
 
                case Format::Date1:
773
 
            stringFormat="dd-mmm-yy";
774
 
            break;
775
 
                case Format::Date2:
776
 
            stringFormat="dd-mmm-yyyy";
777
 
            break;
778
 
                case Format::Date3:
779
 
            stringFormat="dd-mmm";
780
 
            break;
781
 
                case Format::Date4:
782
 
            stringFormat="dd-mm";
783
 
            break;
784
 
                case Format::Date5:
785
 
            stringFormat="dd/mm/yy";
786
 
            break;
787
 
                case Format::Date6:
788
 
            stringFormat="dd/mm/yyyy";
789
 
            break;
790
 
                case Format::Date7:
791
 
            stringFormat="mmm-yy";
792
 
            break;
793
 
                case Format::Date8:
794
 
            stringFormat="mmmm-yy";
795
 
            break;
796
 
                case Format::Date9:
797
 
            stringFormat="mmmm-yyyy";
798
 
            break;
799
 
                case Format::Date10:
800
 
            stringFormat="m-yy";
801
 
            break;
802
 
                case Format::Date11:
803
 
            stringFormat="dd/mmm";
804
 
            break;
805
 
                case Format::Date12:
806
 
            stringFormat="dd/mm";
807
 
            break;
808
 
                case Format::Date13:
809
 
            stringFormat="dd/mmm/yyyy";
810
 
            break;
811
 
                case Format::Date14:
812
 
            stringFormat="yyyy/mmm/dd";
813
 
            break;
814
 
                case Format::Date15:
815
 
            stringFormat="yyyy-mmm-dd";
816
 
            break;
817
 
                case Format::Date16:
818
 
            stringFormat="yyyy-mm-dd";
819
 
            break;
820
 
        case Format::Date17:
821
 
            stringFormat="d mmmm yyyy";
822
 
            break;
823
 
        case Format::Date18:
824
 
            stringFormat="mm/dd/yyyy";
825
 
            break;
826
 
        case Format::Date19:
827
 
            stringFormat="mm/dd/yy";
828
 
            break;
829
 
        case Format::Date20:
830
 
            stringFormat="mmm/dd/yy";
831
 
            break;
832
 
        case Format::Date21:
833
 
            stringFormat="mmm/dd/yyyy";
834
 
            break;
835
 
        case Format::Date22:
836
 
            stringFormat="mmm-yyyy";
837
 
            break;
838
 
        case Format::Date23:
839
 
            stringFormat="yyyy";
840
 
            break;
841
 
        case Format::Date24:
842
 
            stringFormat="yy";
843
 
            break;
844
 
        case Format::Date25:
845
 
            stringFormat="yyyy/mm/dd";
846
 
            break;
847
 
        case Format::Date26:
848
 
                        stringFormat="yyyy/mmm/dd";
849
 
            break;
850
 
                case Format::Time:
851
 
                case Format::SecondeTime:
852
 
                        stringFormat=cell.locale()->timeFormat();
853
 
                        break;
854
 
        case Format::Time1:
855
 
            stringFormat = "h:mm AM/PM";
856
 
            break;
857
 
        case Format::Time2:
858
 
            stringFormat = "h:mm:ss AM/PM";
859
 
            break;
860
 
        case Format::Time3:
861
 
            stringFormat = "h \"h\" mm \"min\" ss \"s\"";
862
 
            break;
863
 
        case Format::Time4:
864
 
            stringFormat = "h:mm";
865
 
            break;
866
 
        case Format::Time5:
867
 
            stringFormat = "h:mm:ss";
868
 
            break;
869
 
        case Format::Time6:
870
 
            stringFormat = "mm:ss";
871
 
            break;
872
 
        case Format::Time7:
873
 
            stringFormat = "[h]:mm:ss";
874
 
            break;
875
 
        case Format::Time8:
876
 
            stringFormat = "[h]:mm";
877
 
            break;
878
 
                case Format::fraction_half:
879
 
                        stringFormat="# ?/2";
880
 
                        break;
881
 
                case Format::fraction_quarter:
882
 
                        stringFormat="# ?/4";
883
 
                        break;
884
 
                case Format::fraction_eighth:
885
 
                        stringFormat="# ?/8";
886
 
                        break;
887
 
                case Format::fraction_sixteenth:
888
 
                        stringFormat="# ?/16";
889
 
                        break;
890
 
                case Format::fraction_tenth:
891
 
                        stringFormat="# ?/10";
892
 
                        break;
893
 
                case Format::fraction_hundredth:
894
 
                        stringFormat="# ?/100";
895
 
                        break;
896
 
                case Format::fraction_one_digit:
897
 
                        stringFormat="# ?/?";
898
 
                        break;
899
 
                case Format::fraction_two_digits:
900
 
                        stringFormat="# ?\?/?\?";
901
 
                        break;
902
 
                case Format::fraction_three_digits:
903
 
                        stringFormat="# ?\?\?/?\?\?";
904
 
                        break;
905
 
        case Format::Custom:
906
 
            stringFormat = style.customFormat();
907
 
            break;
908
 
        default:
909
 
            // This is a required parameter, so let's write a sane default
910
 
            kWarning(30521) << "Unhandled Format value, setting 'General' as default: " << style.formatType();
911
 
            stringFormat = "General";
912
 
            break;
 
670
    switch (style.formatType()) {
 
671
    case Format::Generic:
 
672
        stringFormat = "General";
 
673
        break;
 
674
    case Format::Number:
 
675
        stringFormat = "0.00";
 
676
        break;
 
677
    case Format::Text:
 
678
        stringFormat = "General";
 
679
        break;
 
680
    case Format::Money:
 
681
 
 
682
        if (!style.hasAttribute(Style::CurrencyFormat)) {
 
683
            stringFormat = "0.00";
 
684
            break;
 
685
        }
 
686
        currency = style.currency();
 
687
 
 
688
        if (currency.code().isEmpty())
 
689
            stringFormat = "0.00";
 
690
        else if (currency.code() == "$")
 
691
            stringFormat = "$0.00";
 
692
        else if (currency.code() == QString::fromUtf8("€"))
 
693
            stringFormat = "[$€-2]0.00";
 
694
        else if (currency.code() == QString::fromUtf8("£"))
 
695
            stringFormat = "£0.00";
 
696
        else if (currency.code() == QString::fromUtf8("¥"))
 
697
            stringFormat = "¥0.00";
 
698
        else
 
699
            stringFormat = "[$" + currency.code() + "]0.00";
 
700
 
 
701
        break;
 
702
    case Format::Percentage:
 
703
        stringFormat = "0.00%";
 
704
        break;
 
705
    case Format::Scientific:
 
706
        stringFormat = "0.00E+00";
 
707
        break;
 
708
    case Format::ShortDate:
 
709
        stringFormat = cell.locale()->dateFormatShort();
 
710
        break;
 
711
    case Format::TextDate:
 
712
        stringFormat = cell.locale()->dateFormat();
 
713
        break;
 
714
    case Format::Date1:
 
715
        stringFormat = "dd-mmm-yy";
 
716
        break;
 
717
    case Format::Date2:
 
718
        stringFormat = "dd-mmm-yyyy";
 
719
        break;
 
720
    case Format::Date3:
 
721
        stringFormat = "dd-mmm";
 
722
        break;
 
723
    case Format::Date4:
 
724
        stringFormat = "dd-mm";
 
725
        break;
 
726
    case Format::Date5:
 
727
        stringFormat = "dd/mm/yy";
 
728
        break;
 
729
    case Format::Date6:
 
730
        stringFormat = "dd/mm/yyyy";
 
731
        break;
 
732
    case Format::Date7:
 
733
        stringFormat = "mmm-yy";
 
734
        break;
 
735
    case Format::Date8:
 
736
        stringFormat = "mmmm-yy";
 
737
        break;
 
738
    case Format::Date9:
 
739
        stringFormat = "mmmm-yyyy";
 
740
        break;
 
741
    case Format::Date10:
 
742
        stringFormat = "m-yy";
 
743
        break;
 
744
    case Format::Date11:
 
745
        stringFormat = "dd/mmm";
 
746
        break;
 
747
    case Format::Date12:
 
748
        stringFormat = "dd/mm";
 
749
        break;
 
750
    case Format::Date13:
 
751
        stringFormat = "dd/mmm/yyyy";
 
752
        break;
 
753
    case Format::Date14:
 
754
        stringFormat = "yyyy/mmm/dd";
 
755
        break;
 
756
    case Format::Date15:
 
757
        stringFormat = "yyyy-mmm-dd";
 
758
        break;
 
759
    case Format::Date16:
 
760
        stringFormat = "yyyy-mm-dd";
 
761
        break;
 
762
    case Format::Date17:
 
763
        stringFormat = "d mmmm yyyy";
 
764
        break;
 
765
    case Format::Date18:
 
766
        stringFormat = "mm/dd/yyyy";
 
767
        break;
 
768
    case Format::Date19:
 
769
        stringFormat = "mm/dd/yy";
 
770
        break;
 
771
    case Format::Date20:
 
772
        stringFormat = "mmm/dd/yy";
 
773
        break;
 
774
    case Format::Date21:
 
775
        stringFormat = "mmm/dd/yyyy";
 
776
        break;
 
777
    case Format::Date22:
 
778
        stringFormat = "mmm-yyyy";
 
779
        break;
 
780
    case Format::Date23:
 
781
        stringFormat = "yyyy";
 
782
        break;
 
783
    case Format::Date24:
 
784
        stringFormat = "yy";
 
785
        break;
 
786
    case Format::Date25:
 
787
        stringFormat = "yyyy/mm/dd";
 
788
        break;
 
789
    case Format::Date26:
 
790
        stringFormat = "yyyy/mmm/dd";
 
791
        break;
 
792
    case Format::Time:
 
793
    case Format::SecondeTime:
 
794
        stringFormat = cell.locale()->timeFormat();
 
795
        break;
 
796
    case Format::Time1:
 
797
        stringFormat = "h:mm AM/PM";
 
798
        break;
 
799
    case Format::Time2:
 
800
        stringFormat = "h:mm:ss AM/PM";
 
801
        break;
 
802
    case Format::Time3:
 
803
        stringFormat = "h \"h\" mm \"min\" ss \"s\"";
 
804
        break;
 
805
    case Format::Time4:
 
806
        stringFormat = "h:mm";
 
807
        break;
 
808
    case Format::Time5:
 
809
        stringFormat = "h:mm:ss";
 
810
        break;
 
811
    case Format::Time6:
 
812
        stringFormat = "mm:ss";
 
813
        break;
 
814
    case Format::Time7:
 
815
        stringFormat = "[h]:mm:ss";
 
816
        break;
 
817
    case Format::Time8:
 
818
        stringFormat = "[h]:mm";
 
819
        break;
 
820
    case Format::fraction_half:
 
821
        stringFormat = "# ?/2";
 
822
        break;
 
823
    case Format::fraction_quarter:
 
824
        stringFormat = "# ?/4";
 
825
        break;
 
826
    case Format::fraction_eighth:
 
827
        stringFormat = "# ?/8";
 
828
        break;
 
829
    case Format::fraction_sixteenth:
 
830
        stringFormat = "# ?/16";
 
831
        break;
 
832
    case Format::fraction_tenth:
 
833
        stringFormat = "# ?/10";
 
834
        break;
 
835
    case Format::fraction_hundredth:
 
836
        stringFormat = "# ?/100";
 
837
        break;
 
838
    case Format::fraction_one_digit:
 
839
        stringFormat = "# ?/?";
 
840
        break;
 
841
    case Format::fraction_two_digits:
 
842
        stringFormat = "# ?\?/?\?";
 
843
        break;
 
844
    case Format::fraction_three_digits:
 
845
        stringFormat = "# ?\?\?/?\?\?";
 
846
        break;
 
847
    case Format::Custom:
 
848
        stringFormat = style.customFormat();
 
849
        break;
 
850
    default:
 
851
        // This is a required parameter, so let's write a sane default
 
852
        kWarning(30521) << "Unhandled Format value, setting 'General' as default: " << style.formatType();
 
853
        stringFormat = "General";
 
854
        break;
913
855
    }
914
 
    cell_style.setAttribute("Format",stringFormat);
 
856
    cell_style.setAttribute("Format", stringFormat);
915
857
 
916
 
    if(hasBorder(cell, currentcolumn, currentrow))
 
858
    if (hasBorder(cell, currentcolumn, currentrow))
917
859
        cell_style.appendChild(GetBorderStyle(gnumeric_doc, cell, currentcolumn, currentrow));
918
860
 
919
 
        return cell_style;
 
861
    return cell_style;
920
862
}
921
863
 
922
864
 
948
890
 
949
891
void GNUMERICExport::addSummaryItem(QDomDocument gnumeric_doc, QDomElement summary, const QString& name, const QString& value)
950
892
{
951
 
    if ( value.isEmpty() )
 
893
    if (value.isEmpty())
952
894
        return;
953
895
    QDomElement gmr_item, gmr_name, gmr_val_string;
954
896
 
966
908
 
967
909
// The reason why we use the KoDocument* approach and not the QDomDocument
968
910
// approach is because we don't want to export formulas but values !
969
 
KoFilter::ConversionStatus GNUMERICExport::convert( const QByteArray& from, const QByteArray& to )
 
911
KoFilter::ConversionStatus GNUMERICExport::convert(const QByteArray& from, const QByteArray& to)
970
912
{
971
 
    kDebug(30521) <<"Exporting GNUmeric";
 
913
    kDebug(30521) << "Exporting GNUmeric";
972
914
 
973
 
    QDomDocument gnumeric_doc=QDomDocument();
 
915
    QDomDocument gnumeric_doc = QDomDocument();
974
916
 
975
917
    KoDocument* document = m_chain->inputDocument();
976
918
 
977
919
    if (!document)
978
920
        return KoFilter::StupidError;
979
921
 
980
 
    if ( !qobject_cast<const KSpread::Doc *>( document ) )  // it's safer that way :)
981
 
    {
982
 
      kWarning(30521) << "document isn't a KSpread::Doc but a " << document->metaObject()->className();
 
922
    if (!qobject_cast<const KSpread::Doc *>(document)) {    // it's safer that way :)
 
923
        kWarning(30521) << "document isn't a KSpread::Doc but a " << document->metaObject()->className();
983
924
        return KoFilter::NotImplemented;
984
925
    }
985
 
    if (to != "application/x-gnumeric" || from != "application/x-kspread")
986
 
    {
 
926
    if (to != "application/x-gnumeric" || from != "application/x-kspread") {
987
927
        kWarning(30521) << "Invalid mimetypes " << to << " " << from;
988
928
        return KoFilter::NotImplemented;
989
929
    }
990
930
 
991
931
    Doc* ksdoc = (Doc*)document;
992
932
 
993
 
    if (ksdoc->mimeType() != "application/x-kspread")
994
 
    {
 
933
    if (ksdoc->mimeType() != "application/x-kspread") {
995
934
        kWarning(30521) << "Invalid document mimetype " << ksdoc->mimeType();
996
935
        return KoFilter::NotImplemented;
997
936
    }
998
937
 
999
938
    /* This could be Made into a function */
1000
939
 
1001
 
    gnumeric_doc.appendChild( gnumeric_doc.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
 
940
    gnumeric_doc.appendChild(gnumeric_doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
1002
941
 
1003
942
    QDomElement workbook = gnumeric_doc.createElement("gmr:Workbook");
1004
 
    workbook.setAttribute("xmlns:gmr","http://www.gnumeric.org/v10.dtd");
1005
 
    workbook.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
 
943
    workbook.setAttribute("xmlns:gmr", "http://www.gnumeric.org/v10.dtd");
 
944
    workbook.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
1006
945
    workbook.setAttribute("xmlns:schemaLocation", "http://www.gnumeric.org/v8.xsd");
1007
946
    gnumeric_doc.appendChild(workbook);
1008
947
 
1009
948
    /* End Made into a function */
1010
949
 
1011
 
    QDomElement sheets,sheet,tmp,cells,selections, cols,rows,styles,merged, margins, top, left, bottom, right, orientation, paper, header, footer, customSize, cellComment, objects, repeatColumns, repeatRows;
 
950
    QDomElement sheets, sheet, tmp, cells, selections, cols, rows, styles, merged, margins, topMargin, leftMargin, bottomMargin, rightMargin, orientation, paper, header, footer, customSize, cellComment, objects, repeatColumns, repeatRows;
1012
951
 
1013
952
    KoDocumentInfo *DocumentInfo = document->documentInfo();
1014
953
 
1047
986
    QDomElement sheetNameIndex = gnumeric_doc.createElement("gmr:SheetNameIndex");
1048
987
    workbook.appendChild(sheetNameIndex);
1049
988
 
1050
 
    foreach(Sheet* table, ksdoc->map()->sheetList())
1051
 
    {
 
989
    foreach(Sheet* table, ksdoc->map()->sheetList()) {
1052
990
        QDomElement sheetName = gnumeric_doc.createElement("gmr:SheetName");
1053
991
        sheetName.appendChild(gnumeric_doc.createTextNode(table->sheetName()));
1054
992
        sheetNameIndex.appendChild(sheetName);
1069
1007
      <gmr:value>Sheet2!$A$2:$D$8</gmr:value>
1070
1008
      <gmr:position>A1</gmr:position>
1071
1009
    </gmr:Name>
1072
 
  </gmr:Names>
 
1010
    </gmr:Names>
1073
1011
    */
1074
1012
    const QList<QString> namedAreas = ksdoc->map()->namedAreaManager()->areaNames();
1075
 
    if (namedAreas.count() > 0)
1076
 
    {
 
1013
    if (namedAreas.count() > 0) {
1077
1014
        Sheet* sheet = 0;
1078
1015
        QRect range;
1079
1016
        QDomElement areaNames = gnumeric_doc.createElement("gmr:Names");
1080
 
        for (int i = 0; i < namedAreas.count(); ++i)
1081
 
        {
 
1017
        for (int i = 0; i < namedAreas.count(); ++i) {
1082
1018
            sheet = ksdoc->map()->namedAreaManager()->sheet(namedAreas[i]);
1083
1019
            if (!sheet)
1084
1020
                continue;
1086
1022
            QDomElement areaName = gnumeric_doc.createElement("gmr:Name");
1087
1023
            QDomElement areaNameElement = gnumeric_doc.createElement("gmr:name");
1088
1024
            areaNameElement.appendChild(gnumeric_doc.createTextNode(namedAreas[i]));
1089
 
            areaName.appendChild( areaNameElement );
 
1025
            areaName.appendChild(areaNameElement);
1090
1026
            QDomElement areaNameValue = gnumeric_doc.createElement("gmr:value");
1091
1027
            areaNameValue.appendChild(gnumeric_doc.createTextNode(convertRefToRange(sheet->sheetName(), range)));
1092
 
            areaName.appendChild( areaNameValue );
1093
 
            areaNames.appendChild( areaName );
 
1028
            areaName.appendChild(areaNameValue);
 
1029
            areaNames.appendChild(areaName);
1094
1030
            //TODO <gmr:position>A1</gmr:position> I don't know what is it.
1095
1031
        }
1096
1032
        workbook.appendChild(areaNames);
1105
1041
 
1106
1042
    QString str;
1107
1043
 
1108
 
    View * view = ksdoc->views().isEmpty() ? 0 : static_cast<View*>( ksdoc->views().first() );
1109
 
    Canvas * canvas=0L;
 
1044
    View * view = ksdoc->views().isEmpty() ? 0 : static_cast<View*>(ksdoc->views().first());
 
1045
    Canvas * canvas = 0L;
1110
1046
    QString activeTableName;
1111
 
    if (view)
1112
 
    {
 
1047
    if (view) {
1113
1048
        canvas = view->canvasWidget();
1114
1049
        activeTableName =  canvas->activeSheet()->sheetName();
1115
1050
    }
1116
1051
    int i = 0;
1117
 
    int indexActiveTable=0;
1118
 
    foreach(Sheet* table, ksdoc->map()->sheetList())
1119
 
    {
1120
 
        if ( table->print()->settings()->pageLayout().format == KoPageFormat::CustomSize )
1121
 
        {
1122
 
            customSize = gnumeric_doc.createElement( "gmr:Geometry" );
1123
 
            customSize.setAttribute( "Width", POINT_TO_MM ( table->print()->settings()->pageLayout().width ));
1124
 
            customSize.setAttribute( "Height", POINT_TO_MM (table->print()->settings()->pageLayout().width ));
 
1052
    int indexActiveTable = 0;
 
1053
    foreach(Sheet* table, ksdoc->map()->sheetList()) {
 
1054
        if (table->print()->settings()->pageLayout().format == KoPageFormat::CustomSize) {
 
1055
            customSize = gnumeric_doc.createElement("gmr:Geometry");
 
1056
            customSize.setAttribute("Width", POINT_TO_MM(table->print()->settings()->pageLayout().width));
 
1057
            customSize.setAttribute("Height", POINT_TO_MM(table->print()->settings()->pageLayout().width));
1125
1058
            sheets.appendChild(customSize);
1126
1059
            //<gmr:Geometry Width="768" Height="365"/>
1127
1060
        }
1129
1062
        sheet = gnumeric_doc.createElement("gmr:Sheet");
1130
1063
        sheets.appendChild(sheet);
1131
1064
 
1132
 
        sheet.setAttribute("DisplayFormulas", table->getShowFormula() ? "true" : "false" );
1133
 
        sheet.setAttribute("HideZero", table->getHideZero()? "true" : "false");
1134
 
        sheet.setAttribute("HideGrid", !table->getShowGrid()? "true" : "false");
1135
 
        sheet.setAttribute("HideColHeader", ( !ksdoc->map()->settings()->showColumnHeader() ? "true" : "false" ));
1136
 
        sheet.setAttribute("HideRowHeader", ( !ksdoc->map()->settings()->showRowHeader()? "true" : "false" ));
 
1065
        sheet.setAttribute("DisplayFormulas", table->getShowFormula() ? "true" : "false");
 
1066
        sheet.setAttribute("HideZero", table->getHideZero() ? "true" : "false");
 
1067
        sheet.setAttribute("HideGrid", !table->getShowGrid() ? "true" : "false");
 
1068
        sheet.setAttribute("HideColHeader", (!ksdoc->map()->settings()->showColumnHeader() ? "true" : "false"));
 
1069
        sheet.setAttribute("HideRowHeader", (!ksdoc->map()->settings()->showRowHeader() ? "true" : "false"));
1137
1070
        /* Not available in KSpread ?
1138
1071
         * sheet.setAttribute("DisplayOutlines", "true");
1139
1072
         * sheet.setAttribute("OutlineSymbolsBelow", "true");
1143
1076
         */
1144
1077
 
1145
1078
        tmp = gnumeric_doc.createElement("gmr:Name");
1146
 
        if ( table->sheetName()==activeTableName )
 
1079
        if (table->sheetName() == activeTableName)
1147
1080
            indexActiveTable = i;
1148
1081
 
1149
1082
        tmp.appendChild(gnumeric_doc.createTextNode(table->sheetName()));
1169
1102
        sheet.appendChild(tmp);
1170
1103
 
1171
1104
        //Print Info
1172
 
        tmp = gnumeric_doc.createElement( "gmr:PrintInformation" );
1173
 
        margins = gnumeric_doc.createElement( "gmr:Margins" );
1174
 
 
1175
 
        top = gnumeric_doc.createElement( "gmr:top" );
1176
 
        top.setAttribute("Points", table->print()->settings()->pageLayout().top);
1177
 
        top.setAttribute("PrefUnit", "mm");
1178
 
        margins.appendChild( top );
1179
 
 
1180
 
        bottom = gnumeric_doc.createElement( "gmr:bottom" );
1181
 
        bottom.setAttribute("Points", table->print()->settings()->pageLayout().bottom);
1182
 
        bottom.setAttribute("PrefUnit", "mm");
1183
 
        margins.appendChild( bottom );
1184
 
 
1185
 
        left = gnumeric_doc.createElement( "gmr:left" );
1186
 
        left.setAttribute("Points", table->print()->settings()->pageLayout().left);
1187
 
        left.setAttribute("PrefUnit", "mm");
1188
 
        margins.appendChild( left );
1189
 
 
1190
 
        right = gnumeric_doc.createElement( "gmr:right" );
1191
 
        right.setAttribute("Points", table->print()->settings()->pageLayout().right);
1192
 
        right.setAttribute("PrefUnit", "mm");
1193
 
        margins.appendChild( right );
1194
 
 
1195
 
        tmp.appendChild( margins );
 
1105
        tmp = gnumeric_doc.createElement("gmr:PrintInformation");
 
1106
        margins = gnumeric_doc.createElement("gmr:Margins");
 
1107
 
 
1108
        topMargin = gnumeric_doc.createElement("gmr:top");
 
1109
        topMargin.setAttribute("Points", table->print()->settings()->pageLayout().topMargin);
 
1110
        topMargin.setAttribute("PrefUnit", "mm");
 
1111
        margins.appendChild(topMargin);
 
1112
 
 
1113
        bottomMargin = gnumeric_doc.createElement("gmr:bottom");
 
1114
        bottomMargin.setAttribute("Points", table->print()->settings()->pageLayout().bottomMargin);
 
1115
        bottomMargin.setAttribute("PrefUnit", "mm");
 
1116
        margins.appendChild(bottomMargin);
 
1117
 
 
1118
        leftMargin = gnumeric_doc.createElement("gmr:left");
 
1119
        leftMargin.setAttribute("Points", table->print()->settings()->pageLayout().leftMargin);
 
1120
        leftMargin.setAttribute("PrefUnit", "mm");
 
1121
        margins.appendChild(leftMargin);
 
1122
 
 
1123
        rightMargin = gnumeric_doc.createElement("gmr:right");
 
1124
        rightMargin.setAttribute("Points", table->print()->settings()->pageLayout().rightMargin);
 
1125
        rightMargin.setAttribute("PrefUnit", "mm");
 
1126
        margins.appendChild(rightMargin);
 
1127
 
 
1128
        tmp.appendChild(margins);
1196
1129
        sheet.appendChild(tmp);
1197
1130
 
1198
 
        orientation = gnumeric_doc.createElement( "gmr:orientation" );
 
1131
        orientation = gnumeric_doc.createElement("gmr:orientation");
1199
1132
        QString orientString = table->print()->settings()->pageLayout().orientation == KoPageFormat::Landscape ? "landscape" : "portrait";
1200
 
        orientation.appendChild( gnumeric_doc.createTextNode(orientString) );
1201
 
        tmp.appendChild( orientation );
 
1133
        orientation.appendChild(gnumeric_doc.createTextNode(orientString));
 
1134
        tmp.appendChild(orientation);
1202
1135
 
1203
1136
        //TODO for future
1204
1137
        //<gmr:repeat_top value="A1:IV5"/>
1206
1139
 
1207
1140
        int _tmpRepeatColumnStart = table->print()->printRepeatColumns().first;
1208
1141
        int _tmpRepeatColumnEnd = table->print()->printRepeatColumns().second;
1209
 
        if ( _tmpRepeatColumnStart!=0 )
1210
 
        {
1211
 
            repeatColumns = gnumeric_doc.createElement( "gmr:repeat_left" );
1212
 
            QString value = Cell::columnName( _tmpRepeatColumnStart )+"1:"+Cell::columnName(_tmpRepeatColumnEnd )+"65536";
1213
 
            repeatColumns.setAttribute( "value", value );
1214
 
            tmp.appendChild( repeatColumns );
 
1142
        if (_tmpRepeatColumnStart != 0) {
 
1143
            repeatColumns = gnumeric_doc.createElement("gmr:repeat_left");
 
1144
            QString value = Cell::columnName(_tmpRepeatColumnStart) + "1:" + Cell::columnName(_tmpRepeatColumnEnd) + "65536";
 
1145
            repeatColumns.setAttribute("value", value);
 
1146
            tmp.appendChild(repeatColumns);
1215
1147
        }
1216
1148
        int _tmpRepeatRowStart = table->print()->printRepeatRows().first;
1217
1149
        int _tmpRepeatRowEnd = table->print()->printRepeatRows().second;
1218
 
        if ( _tmpRepeatRowStart!=0 )
1219
 
        {
1220
 
            repeatRows = gnumeric_doc.createElement( "gmr:repeat_top" );
1221
 
            QString value = 'A'+ QString::number(_tmpRepeatRowStart ) +":IV"+QString::number( _tmpRepeatRowEnd );
1222
 
            repeatRows.setAttribute( "value", value );
1223
 
            tmp.appendChild( repeatRows );
 
1150
        if (_tmpRepeatRowStart != 0) {
 
1151
            repeatRows = gnumeric_doc.createElement("gmr:repeat_top");
 
1152
            QString value = 'A' + QString::number(_tmpRepeatRowStart) + ":IV" + QString::number(_tmpRepeatRowEnd);
 
1153
            repeatRows.setAttribute("value", value);
 
1154
            tmp.appendChild(repeatRows);
1224
1155
        }
1225
1156
 
1226
 
        header = gnumeric_doc.createElement( "gmr:Header" );
1227
 
        header.setAttribute( "Left", convertVariable(table->print()->headLeft() ) );
1228
 
        header.setAttribute( "Middle", convertVariable(table->print()->headMid() ) );
1229
 
        header.setAttribute( "Right", convertVariable(table->print()->headRight() ) );
1230
 
        tmp.appendChild( header );
1231
 
 
1232
 
        footer = gnumeric_doc.createElement( "gmr:Footer" );
1233
 
        footer.setAttribute( "Left", convertVariable( table->print()->footLeft() ) );
1234
 
        footer.setAttribute( "Middle", convertVariable( table->print()->footMid() ) );
1235
 
        footer.setAttribute( "Right", convertVariable( table->print()->footRight() ));
1236
 
        tmp.appendChild( footer );
1237
 
 
1238
 
        paper = gnumeric_doc.createElement( "gmr:paper" );
1239
 
        paper.appendChild( gnumeric_doc.createTextNode( table->print()->paperFormatString() ) );
1240
 
        tmp.appendChild( paper );
 
1157
        header = gnumeric_doc.createElement("gmr:Header");
 
1158
        header.setAttribute("Left", convertVariable(table->print()->headLeft()));
 
1159
        header.setAttribute("Middle", convertVariable(table->print()->headMid()));
 
1160
        header.setAttribute("Right", convertVariable(table->print()->headRight()));
 
1161
        tmp.appendChild(header);
 
1162
 
 
1163
        footer = gnumeric_doc.createElement("gmr:Footer");
 
1164
        footer.setAttribute("Left", convertVariable(table->print()->footLeft()));
 
1165
        footer.setAttribute("Middle", convertVariable(table->print()->footMid()));
 
1166
        footer.setAttribute("Right", convertVariable(table->print()->footRight()));
 
1167
        tmp.appendChild(footer);
 
1168
 
 
1169
        paper = gnumeric_doc.createElement("gmr:paper");
 
1170
        paper.appendChild(gnumeric_doc.createTextNode(table->print()->paperFormatString()));
 
1171
        tmp.appendChild(paper);
1241
1172
 
1242
1173
        styles = gnumeric_doc.createElement("gmr:Styles");
1243
1174
        sheet.appendChild(styles);
1273
1204
 
1274
1205
        // this is just a bad approximation which fails for documents with less than 50 rows, but
1275
1206
        // we don't need any progress stuff there anyway :) (Werner)
1276
 
        int value=0;
1277
 
        int step=iMaxRow > 50 ? iMaxRow/50 : 1;
1278
 
        int i=1;
 
1207
        int value = 0;
 
1208
        int step = iMaxRow > 50 ? iMaxRow / 50 : 1;
 
1209
        int i = 1;
1279
1210
 
1280
1211
        QString emptyLines;
1281
1212
 
1300
1231
 
1301
1232
 
1302
1233
        /* Start COLS */
1303
 
        ColumnFormat *cl=table->firstCol();
1304
 
        while (cl)
1305
 
        {
 
1234
        ColumnFormat *cl = table->firstCol();
 
1235
        while (cl) {
1306
1236
            QDomElement colinfo = gnumeric_doc.createElement("gmr:ColInfo");
1307
1237
            cols.appendChild(colinfo);
1308
 
            colinfo.setAttribute("No", QString::number(cl->column()-1));
 
1238
            colinfo.setAttribute("No", QString::number(cl->column() - 1));
1309
1239
            colinfo.setAttribute("Hidden", QString::number(cl->isHidden()));
1310
1240
            colinfo.setAttribute("Unit", QString::number(cl->width()));
1311
1241
 
1312
 
            cl=cl->next();
 
1242
            cl = cl->next();
1313
1243
        }
1314
1244
 
1315
1245
        /* End COLS */
1316
1246
 
1317
 
        //       RowFormat *rl=table->m_cells.firstCell;
 
1247
        //  RowFormat *rl=table->m_cells.firstCell;
1318
1248
        //   <gmr:ColInfo No="1" Unit="96.75" MarginA="2" MarginB="2" HardSize="-1" Hidden="0"/>
1319
1249
 
1320
1250
        /* Start ROWS */
1321
 
        RowFormat *rl=table->firstRow();
1322
 
        while (rl)
1323
 
        {
 
1251
        RowFormat *rl = table->firstRow();
 
1252
        while (rl) {
1324
1253
            QDomElement rowinfo = gnumeric_doc.createElement("gmr:RowInfo");
1325
1254
            rows.appendChild(rowinfo);
1326
 
            rowinfo.setAttribute("No", QString::number(rl->row()-1));
 
1255
            rowinfo.setAttribute("No", QString::number(rl->row() - 1));
1327
1256
            rowinfo.setAttribute("Hidden", QString::number(rl->isHidden()));
1328
1257
            rowinfo.setAttribute("Unit", QString::number(rl->height()));
1329
1258
 
1330
 
            rl=rl->next();
 
1259
            rl = rl->next();
1331
1260
        }
1332
1261
 
1333
1262
        /* End ROWS */
1334
1263
 
1335
1264
        //rl->setHeight
1336
 
        //       colinfo.info();
 
1265
        //  colinfo.info();
1337
1266
        /*
1338
1267
          <gmr:ColInfo No="1" Unit="96.75" MarginA="2" MarginB="2" HardSize="-1" Hidden="0"/>
1339
1268
          <gmr:ColInfo No="3" Unit="113.25" MarginA="2" MarginB="2" HardSize="-1"
1342
1271
 
1343
1272
        /* End COLS */
1344
1273
 
1345
 
        for (int currentrow = 1; currentrow <= iMaxRow; ++currentrow, ++i)
1346
 
        {
1347
 
            if(i>step)
1348
 
            {
1349
 
                value+=2;
 
1274
        for (int currentrow = 1; currentrow <= iMaxRow; ++currentrow, ++i) {
 
1275
            if (i > step) {
 
1276
                value += 2;
1350
1277
                emit sigProgress(value);
1351
 
                i=0;
 
1278
                i = 0;
1352
1279
            }
1353
1280
 
1354
1281
            QString line;
1355
 
            for (int currentcolumn = 1; currentcolumn <= iMaxColumn; currentcolumn++)
1356
 
            {
 
1282
            for (int currentcolumn = 1; currentcolumn <= iMaxColumn; currentcolumn++) {
1357
1283
                QDomElement cell_contents;
1358
 
                Cell cell( table, currentcolumn, currentrow );
 
1284
                Cell cell(table, currentcolumn, currentrow);
1359
1285
 
1360
1286
                QString text, style;
1361
1287
                QDomDocument domLink;
1363
1289
                QDomNode domNode;
1364
1290
                QDomNodeList childNodes;
1365
1291
 
1366
 
                if (!cell.isDefault() && !cell.isEmpty())
1367
 
                {
1368
 
                    if ( cell.isFormula() )
1369
 
                    {
 
1292
                if (!cell.isDefault() && !cell.isEmpty()) {
 
1293
                    if (cell.isFormula()) {
1370
1294
                        QString tmp = cell.userInput();
1371
 
                        if ( tmp.contains( "==" ) )
1372
 
                            tmp=tmp.replace( "==", "=" );
 
1295
                        if (tmp.contains("=="))
 
1296
                            tmp = tmp.replace("==", "=");
1373
1297
                        text = tmp;
1374
1298
                        isLink = false;
1375
 
                    }
1376
 
                    else if ( !cell.link().isEmpty() )
1377
 
                    {
 
1299
                    } else if (!cell.link().isEmpty()) {
1378
1300
                        isLink = true;
1379
1301
                        isLinkBold = false;
1380
1302
                        isLinkItalic = false;
1382
1304
                        linkUrl = cell.link();
1383
1305
                        linkText = cell.userInput();
1384
1306
 
1385
 
                    }
1386
 
                    else
1387
 
                    {
 
1307
                    } else {
1388
1308
                        text = cell.userInput();
1389
1309
                        isLink = false;
1390
1310
                    }
1391
1311
#if 0
1392
 
                    switch (cell.content())
1393
 
                    {
 
1312
                    switch (cell.content()) {
1394
1313
                    case Cell::Text:
1395
1314
                        text = cell.userInput();
1396
1315
                        isLink = false;
1401
1320
                        isLink = true;
1402
1321
                        isLinkBold = false;
1403
1322
                        isLinkItalic = false;
1404
 
                        domLink.setContent(cell.userInput().section("!",1,1));
 
1323
                        domLink.setContent(cell.userInput().section("!", 1, 1));
1405
1324
 
1406
1325
                        domNode = domLink.firstChild();
1407
1326
                        domRoot = domNode.toElement();
1408
1327
                        text = domNode.toElement().text();
1409
1328
 
1410
 
                        while (!domNode.isNull())
1411
 
                        {
 
1329
                        while (!domNode.isNull()) {
1412
1330
                            style = domNode.toElement().tagName();
1413
1331
 
1414
1332
                            if (style == "b")
1433
1351
                    case Cell::Formula:
1434
1352
                        isLink = false;
1435
1353
                        QString tmp = cell.userInput();
1436
 
                        if ( tmp =="==" )
1437
 
                            tmp=replace( "==", "=" );
 
1354
                        if (tmp == "==")
 
1355
                            tmp = replace("==", "=");
1438
1356
                        /* cell.calc( true ); // Incredible, cells are not calculated if the document was just opened text = cell.valueString(); */
1439
1357
                        text = tmp;
1440
1358
                        break;
1442
1360
#endif
1443
1361
                }
1444
1362
 
1445
 
                if (!cell.isDefault())
1446
 
                {
 
1363
                if (!cell.isDefault()) {
1447
1364
 
1448
1365
                    // Check if the cell is merged
1449
1366
                    // Only cells with content are interesting?
1450
1367
                    // Otherwise it can take a while to parse a large sheet
1451
1368
 
1452
 
                    if (cell.doesMergeCells())
1453
 
                    {
 
1369
                    if (cell.doesMergeCells()) {
1454
1370
                        // The cell is forced to occupy other cells
1455
1371
                        QDomElement merge = gnumeric_doc.createElement("gmr:Merge");
1456
1372
 
1466
1382
                        merged.appendChild(merge);
1467
1383
                    }
1468
1384
                    // ---
1469
 
                    if ( !cell.comment().isEmpty() )
1470
 
                    {
 
1385
                    if (!cell.comment().isEmpty()) {
1471
1386
                        //<gmr:CellComment Author="" Text="cvbcvbxcvb&#10;cb&#10;xc&#10;vbxcv&#10;" ObjectBound="A1" ObjectOffset="0 0 0 0" ObjectAnchorType="17 16 17 16" Direction="17"/>
1472
1387
                        cellComment = gnumeric_doc.createElement("gmr:CellComment");
1473
 
                        cellComment.setAttribute( "Text", cell.comment() );
1474
 
                        QString sCell=QString( "%1%2" ).arg( Cell::columnName(currentcolumn ) ).arg( currentrow );
 
1388
                        cellComment.setAttribute("Text", cell.comment());
 
1389
                        QString sCell = QString("%1%2").arg(Cell::columnName(currentcolumn)).arg(currentrow);
1475
1390
 
1476
 
                        cellComment.setAttribute("ObjectBound", sCell );
 
1391
                        cellComment.setAttribute("ObjectBound", sCell);
1477
1392
                        objects.appendChild(cellComment);
1478
1393
 
1479
1394
                    }
1484
1399
 
1485
1400
                    cells.appendChild(gnumeric_cell);
1486
1401
 
1487
 
                    gnumeric_cell.setAttribute("Col", QString::number(currentcolumn-1));
1488
 
                    gnumeric_cell.setAttribute("Row", QString::number(currentrow-1));
 
1402
                    gnumeric_cell.setAttribute("Col", QString::number(currentcolumn - 1));
 
1403
                    gnumeric_cell.setAttribute("Row", QString::number(currentrow - 1));
1489
1404
 
1490
1405
                    /* Right now, we create a single region for each cell.. This is inefficient,
1491
1406
                     * but the implementation is quicker.. Probably later we will have to
1492
1407
                     * consolidate styles into style regions.
1493
1408
                     */
1494
1409
 
1495
 
                    style_region.setAttribute("startCol", QString::number(currentcolumn-1));
1496
 
                    style_region.setAttribute("startRow", QString::number(currentrow-1));
1497
 
                    style_region.setAttribute("endCol", QString::number(currentcolumn-1));
1498
 
                    style_region.setAttribute("endRow", QString::number(currentrow-1));
 
1410
                    style_region.setAttribute("startCol", QString::number(currentcolumn - 1));
 
1411
                    style_region.setAttribute("startRow", QString::number(currentrow - 1));
 
1412
                    style_region.setAttribute("endCol", QString::number(currentcolumn - 1));
 
1413
                    style_region.setAttribute("endRow", QString::number(currentrow - 1));
1499
1414
 
1500
 
                    cell_style = GetCellStyle(gnumeric_doc,cell,currentcolumn,currentrow);
 
1415
                    cell_style = GetCellStyle(gnumeric_doc, cell, currentcolumn, currentrow);
1501
1416
 
1502
1417
                    style_region.appendChild(cell_style);
1503
1418
 
1517
1432
            sheet.appendChild(merged);
1518
1433
    }
1519
1434
    QDomElement uidata = gnumeric_doc.createElement("gmr:UIData");
1520
 
    uidata.setAttribute( "SelectedTab", indexActiveTable );
 
1435
    uidata.setAttribute("SelectedTab", indexActiveTable);
1521
1436
    workbook.appendChild(uidata);
1522
1437
 
1523
 
    str = gnumeric_doc.toString ();
 
1438
    str = gnumeric_doc.toString();
1524
1439
 
1525
1440
    emit sigProgress(100);
1526
1441
 
1527
1442
    // Ok, now write to export file
1528
1443
 
1529
 
    QIODevice* out = KFilterDev::deviceForFile(m_chain->outputFile(),"application/x-gzip");
 
1444
    QIODevice* out = KFilterDev::deviceForFile(m_chain->outputFile(), "application/x-gzip");
1530
1445
 
1531
 
    if (!out)
1532
 
    {
 
1446
    if (!out) {
1533
1447
        kError(30521) << "No output file! Aborting!" << endl;
1534
1448
        return KoFilter::FileNotFound;
1535
1449
    }
1536
1450
 
1537
 
    if (!out->open(QIODevice::WriteOnly))
1538
 
    {
 
1451
    if (!out->open(QIODevice::WriteOnly)) {
1539
1452
        kError(30521) << "Unable to open output file! Aborting!" << endl;
1540
1453
        delete out;
1541
1454
        return KoFilter::FileNotFound;
1553
1466
}
1554
1467
 
1555
1468
 
1556
 
QString GNUMERICExport::convertRefToRange( const QString & table, const QRect & rect )
1557
 
{
1558
 
  QPoint topLeft( rect.topLeft() );
1559
 
  QPoint bottomRight( rect.bottomRight() );
1560
 
  if ( topLeft == bottomRight )
1561
 
    return convertRefToBase( table, rect );
1562
 
  QString s;
1563
 
  s += table;
1564
 
  s += "!$";
1565
 
  s += Cell::columnName( topLeft.x() );
1566
 
  s += '$';
1567
 
  s += QString::number( topLeft.y() );
1568
 
  s += ":$";
1569
 
  s += Cell::columnName( bottomRight.x() );
1570
 
  s += '$';
1571
 
  s += QString::number( bottomRight.y() );
1572
 
 
1573
 
  return s;
1574
 
}
1575
 
 
1576
 
 
1577
 
QString GNUMERICExport::convertRefToBase( const QString & table, const QRect & rect )
1578
 
{
1579
 
  QPoint bottomRight( rect.bottomRight() );
1580
 
 
1581
 
  QString s;
1582
 
  s = table;
1583
 
  s += "!$";
1584
 
  s += Cell::columnName( bottomRight.x() );
1585
 
  s += '$';
1586
 
  s += QString::number( bottomRight.y() );
1587
 
 
1588
 
  return s;
1589
 
}
1590
 
 
1591
 
QString GNUMERICExport::convertVariable( QString headerFooter )
1592
 
{
1593
 
    headerFooter = headerFooter.replace( "<sheet>", "&[TAB]" );
1594
 
    headerFooter = headerFooter.replace( "<date>", "&[DATE]" );
1595
 
    headerFooter = headerFooter.replace( "<page>", "&[PAGE]" );
1596
 
    headerFooter = headerFooter.replace( "<pages>", "&[PAGES]" );
1597
 
    headerFooter = headerFooter.replace( "<time>", "&[TIME]" );
1598
 
    headerFooter = headerFooter.replace( "<file>", "&[FILE]" );
 
1469
QString GNUMERICExport::convertRefToRange(const QString & table, const QRect & rect)
 
1470
{
 
1471
    QPoint topLeft(rect.topLeft());
 
1472
    QPoint bottomRight(rect.bottomRight());
 
1473
    if (topLeft == bottomRight)
 
1474
        return convertRefToBase(table, rect);
 
1475
    QString s;
 
1476
    s += table;
 
1477
    s += "!$";
 
1478
    s += Cell::columnName(topLeft.x());
 
1479
    s += '$';
 
1480
    s += QString::number(topLeft.y());
 
1481
    s += ":$";
 
1482
    s += Cell::columnName(bottomRight.x());
 
1483
    s += '$';
 
1484
    s += QString::number(bottomRight.y());
 
1485
 
 
1486
    return s;
 
1487
}
 
1488
 
 
1489
 
 
1490
QString GNUMERICExport::convertRefToBase(const QString & table, const QRect & rect)
 
1491
{
 
1492
    QPoint bottomRight(rect.bottomRight());
 
1493
 
 
1494
    QString s;
 
1495
    s = table;
 
1496
    s += "!$";
 
1497
    s += Cell::columnName(bottomRight.x());
 
1498
    s += '$';
 
1499
    s += QString::number(bottomRight.y());
 
1500
 
 
1501
    return s;
 
1502
}
 
1503
 
 
1504
QString GNUMERICExport::convertVariable(QString headerFooter)
 
1505
{
 
1506
    headerFooter = headerFooter.replace("<sheet>", "&[TAB]");
 
1507
    headerFooter = headerFooter.replace("<date>", "&[DATE]");
 
1508
    headerFooter = headerFooter.replace("<page>", "&[PAGE]");
 
1509
    headerFooter = headerFooter.replace("<pages>", "&[PAGES]");
 
1510
    headerFooter = headerFooter.replace("<time>", "&[TIME]");
 
1511
    headerFooter = headerFooter.replace("<file>", "&[FILE]");
1599
1512
 
1600
1513
    return headerFooter;
1601
1514
}