~ubuntu-branches/ubuntu/lucid/skrooge/lucid

« back to all changes in this revision

Viewing changes to skrooge_report/skgreportpluginwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-07-28 15:38:43 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090728153843-91b74m0vcam50krt
Tags: 0.2.9-0ubuntu1
* New upstream release
* Added kubuntu_01_cmake_fix.patch:
  Fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        ui.kLines->addItem(i18n("Accounts"));
63
63
        ui.kLines->addItem(i18n("Units"));
64
64
 
 
65
        ui.kMode->addItem(i18n("Sum"));
 
66
        ui.kMode->addItem(i18n("History"));
 
67
 
65
68
        ui.kPeriod->addItem(i18n("All dates"));
66
69
        ui.kPeriod->addItem(i18n("Current month"));
67
70
        ui.kPeriod->addItem(i18n("Previous month"));
78
81
 
79
82
        ui.kType->addItem(i18n("All without transfer"));
80
83
        ui.kType->addItem(i18n("Income without transfer"));
81
 
        ui.kType->addItem(i18n("Expense without transfer"));
 
84
        ui.kType->addItem(i18n("Expenditure without transfer"));
82
85
        ui.kType->addItem(i18n("All with transfers"));
83
86
        ui.kType->addItem(i18n("Income with transfers"));
84
 
        ui.kType->addItem(i18n("Expense with transfers"));
 
87
        ui.kType->addItem(i18n("Expenditure with transfers"));
85
88
 
86
89
        connect(ui.kTableWithGraph->table(), SIGNAL(currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)), this, SLOT(onSelectionChanged()));
87
90
 
88
91
        //Refresh
89
92
        connect(ui.kColumns, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()), Qt::QueuedConnection);
90
93
        connect(ui.kLines, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()), Qt::QueuedConnection);
 
94
        connect(ui.kMode, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()), Qt::QueuedConnection);
91
95
        connect(ui.kPeriod, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()), Qt::QueuedConnection);
92
96
        connect(ui.kType, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()), Qt::QueuedConnection);
93
97
        connect((const QObject*) getDocument(), SIGNAL(tableModified(QString, int)), this, SLOT(dataModified(QString, int)));
115
119
 
116
120
        root.setAttribute("columns", ui.kColumns->currentIndex());
117
121
        root.setAttribute("lines", ui.kLines->currentIndex());
 
122
        root.setAttribute("mode", ui.kMode->currentIndex());
118
123
        root.setAttribute("period", ui.kPeriod->currentIndex());
119
124
        root.setAttribute("type", ui.kType->currentIndex());
120
125
        root.setAttribute("tableAndGraphState", ui.kTableWithGraph->getState());
132
137
 
133
138
                QString columns=root.attribute ( "columns");
134
139
                QString lines=root.attribute ( "lines");
 
140
                QString mode=root.attribute ( "mode");
135
141
                QString period=root.attribute ( "period");
136
142
                QString type=root.attribute ( "type");
137
143
                QString tableAndGraphState=root.attribute ( "tableAndGraphState");
140
146
                operationWhereClause=root.attribute ( "operationWhereClause");
141
147
                if (!columns.isEmpty()) ui.kColumns->setCurrentIndex(SKGServices::stringToInt(columns));
142
148
                if (!lines.isEmpty()) ui.kLines->setCurrentIndex(SKGServices::stringToInt(lines));
 
149
                if (!mode.isEmpty()) ui.kMode->setCurrentIndex(SKGServices::stringToInt(mode));
143
150
                if (!period.isEmpty()) ui.kPeriod->setCurrentIndex(SKGServices::stringToInt(period));
144
151
                if (!type.isEmpty()) ui.kType->setCurrentIndex(SKGServices::stringToInt(type));
145
152
                ui.kTableWithGraph->setState(tableAndGraphState);
146
153
                if (!title.isEmpty()) {
147
 
                        ui.kTitle->setText(title);
 
154
                        ui.kTitle->setComment("<html><body><b>"+title+"</b></body></html>");
148
155
                        ui.kTitle->show();
149
156
                } else {
150
157
                        ui.kTitle->hide();
158
165
        } else ui.kTableWithGraph->setState("");
159
166
}
160
167
 
 
168
QString SKGReportPluginWidget::getDefaultStateAttibute()
 
169
{
 
170
        return "SKGREPORT_DEFAULT_PARAMETERS";
 
171
}
 
172
 
161
173
QWidget* SKGReportPluginWidget::getWidgetForPrint()
162
174
{
163
175
        return this;
170
182
        QString title;
171
183
        if (ui.kTitle->isVisible()) oTitle=ui.kTitle->text()+'\n';
172
184
 
 
185
        bool modeHistory=(ui.kMode->currentIndex()==1);
 
186
 
173
187
        //Condition on line attribute
174
188
        oTitle+=i18n("Operations with ");
175
 
        if (row+1!=ui.kTableWithGraph->table()->rowCount()) {
 
189
        if (modeHistory || row+1!=ui.kTableWithGraph->table()->rowCount()) {
176
190
                QString att=AttsForLines[ui.kLines->currentIndex()];
177
191
                oWc=att;
178
192
                QString lineVal=ui.kTableWithGraph->table()->item(row, 0)->text();
189
203
        }
190
204
        //Condition on column attribute
191
205
        int nbCol=ui.kTableWithGraph->table()->columnCount();
192
 
        if (column!=0 && (nbCol==2 || (nbCol>=4 && column<nbCol-2))) {
 
206
        if (modeHistory || (column!=0 && (nbCol==2 || (nbCol>=4 && column<nbCol-2)))) {
193
207
                if (!AttsForColumns[ui.kColumns->currentIndex()].isEmpty()) {
194
208
                        if (!oWc.isEmpty()) {
195
209
                                oWc+=" AND ";
231
245
        } else {
232
246
                //Call operation plugin
233
247
                QDomDocument doc("SKGML");
234
 
                QDomElement root = doc.createElement("parameters");
235
 
                doc.appendChild(root);
 
248
                doc.setContent ( getDocument()->getParameter("SKGOPERATION_DEFAULT_PARAMETERS") );
 
249
                QDomElement root = doc.documentElement();
 
250
                if (root.isNull()) {
 
251
                        root=doc.createElement("parameters");
 
252
                        doc.appendChild(root);
 
253
                }
 
254
 
236
255
                root.setAttribute("operationTable", "v_operation_consolidated");
237
256
                root.setAttribute("operationWhereClause", wc);
238
257
                root.setAttribute("title", title);
239
258
                root.setAttribute("title_icon", "view-statistics");
240
 
 
 
259
                root.setAttribute ( "currentPage", "-1" );
241
260
 
242
261
                getMainPanel()->setNewTabContent(getMainPanel()->getPluginByName("Skrooge operation plugin"), -1, doc.toString());
243
262
        }
255
274
 
256
275
                //Call report plugin
257
276
                QDomDocument doc("SKGML");
258
 
                QDomElement root = doc.createElement("parameters");
259
 
                doc.appendChild(root);
 
277
                doc.setContent(getState());
 
278
                QDomElement root = doc.documentElement();
260
279
                root.setAttribute("operationWhereClause", wc);
261
280
                root.setAttribute("title", title);
262
281
                root.setAttribute("title_icon", "view-statistics");
271
290
        switch ( ui.kPeriod->currentIndex() ) {
272
291
        case 1:
273
292
                //Current month
274
 
                wc="d_DATEMONTH=STRFTIME('%Y-%m',date('now'))";
 
293
                wc="d_DATEMONTH=STRFTIME('%Y-%m',date('now'))";
275
294
                break;
276
295
 
277
296
        case 2:
278
297
                //Previous month
279
 
                wc="d_DATEMONTH=STRFTIME('%Y-%m',date('now','-1 month'))";
 
298
                wc="d_DATEMONTH=STRFTIME('%Y-%m',date('now','-1 month'))";
280
299
                break;
281
300
 
282
301
        case 3:
283
302
                //Current year
284
 
                wc="d_DATEYEAR=STRFTIME('%Y',date('now'))";
 
303
                wc="d_DATEYEAR=STRFTIME('%Y',date('now'))";
285
304
                break;
286
305
 
287
306
        case 4:
288
307
                //Previous year
289
 
                wc="d_DATEYEAR=STRFTIME('%Y',date('now','-1 year'))";
 
308
                wc="d_DATEYEAR=STRFTIME('%Y',date('now','-1 year'))";
290
309
                break;
291
310
        case 5:
292
311
                //30 last days
330
349
 
331
350
        case 2:
332
351
        case 5:
333
 
                //Expense
 
352
                //Expenditure
334
353
                wc+=" AND t_TYPEEXPENSE='-'";
335
354
                break;
336
355
 
409
428
                                                table.replace(0, line1);
410
429
                                        }
411
430
 
 
431
                                        bool modeHistory=(ui.kMode->currentIndex()==1);
 
432
                                        if (modeHistory) {
 
433
                                                //Build history
 
434
                                                SKGStringListList historizedTable;
 
435
 
 
436
                                                historizedTable.push_back(table.at(0));
 
437
 
 
438
                                                QStringList newLine;
 
439
                                                int nblines=table.count();
 
440
                                                int nbCols=0;
 
441
                                                if (nblines) {
 
442
                                                        nbCols=table.at(0).count();
 
443
                                                }
 
444
                                                for (int i=1; i<nblines; ++i) {
 
445
                                                        QStringList newLine;
 
446
                                                        newLine.push_back(table.at(i).at(0));
 
447
 
 
448
                                                        double sum=0;
 
449
                                                        for (int j=1; j<nbCols; ++j) {
 
450
                                                                sum+=SKGServices::stringToDouble(table.at(i).at(j));
 
451
                                                                newLine.push_back(SKGServices::doubleToString(sum));
 
452
                                                        }
 
453
                                                        historizedTable.push_back(newLine);
 
454
                                                }
 
455
 
 
456
                                                table=historizedTable;
 
457
                                        }
 
458
 
412
459
                                        QString primaryUnit=((SKGDocumentBank*) getDocument())->getPrimaryUnit();
413
460
                                        QString secondaryUnit=((SKGDocumentBank*) getDocument())->getSecondaryUnit();
414
461
                                        double secondaryUnitValue=((SKGDocumentBank*) getDocument())->getSecondaryUnitValue();
415
 
                                        ui.kTableWithGraph->setData(table, primaryUnit, secondaryUnit, secondaryUnitValue);
 
462
                                        ui.kTableWithGraph->setData(table, primaryUnit, secondaryUnit, secondaryUnitValue, !modeHistory);
416
463
                                }
417
464
                        }
418
465