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

« back to all changes in this revision

Viewing changes to skrooge_bank/skgbankpluginwidget.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:
28
28
#include "skgaccountobject.h"
29
29
#include "skgdocumentbank.h"
30
30
#include "skgtraces.h"
31
 
#include "skgautohide.h"
32
31
 
33
32
#include <kstandarddirs.h>
34
33
 
46
45
        ui.kAccountCreatorUpdate->setIcon ( KIcon ( "dialog-ok-apply" ) );
47
46
        ui.kAccountCreatorAdd->setIcon ( KIcon ( "list-add" ) );
48
47
 
 
48
        ui.kStandardBtn->setIcon (KIcon ( "flag-blue" ) );
 
49
        ui.kIntermediateBtn->setIcon (KIcon ( "flag-green" ) );
 
50
        ui.kAllBtn->setIcon (KIcon ( "flag-yellow" ) );
 
51
 
49
52
        //Add NLS values for type of account
50
53
        //C=current D=credit card P=passif (for objects) I=Investment O=other
51
54
        ui.kAccountCreatorType->addItem ( i18n ( "Current" ) );
52
55
        ui.kAccountCreatorType->addItem ( i18n ( "Credit card" ) );
53
56
        ui.kAccountCreatorType->addItem ( i18n ( "Investment" ) );
54
 
        ui.kAccountCreatorType->addItem ( i18n ( "Actif" ) );
 
57
        ui.kAccountCreatorType->addItem ( i18n ( "Assets" ) );
55
58
        ui.kAccountCreatorType->addItem ( i18n ( "Other" ) );
56
59
 
57
60
        //Bind account creation view
63
66
 
64
67
        ui.kAccountTableViewEdition->setModel ( modelProxy );
65
68
        ui.kAccountTableViewEdition->setWindowTitle ( i18n ( "Accounts" ) );
66
 
        ui.kAccountTableViewEdition->setDefaultSaveParameters ( getDocument(), "SKG_DEFAULT_ACCOUNT" );
67
 
 
68
 
        //Addition of auto hidder
69
 
        autoHidder=new SKGAutoHide ( ui.kAutoHiddenFrame, ui.kInfo );
70
69
 
71
70
        //Add registered global action in contextual menu
72
71
        if ( iParent ) {
77
76
                ui.kAccountTableViewEdition->insertAction ( 0, iParent->getGlobalAction ( "open_report" ) );
78
77
        }
79
78
        connect ( ui.kAccountTableViewEdition->selectionModel(), SIGNAL ( selectionChanged ( QItemSelection,QItemSelection ) ), this, SLOT ( onSelectionChanged() ) );
80
 
        connect ( objectModel, SIGNAL ( modelAboutToBeReset() ), ui.kAccountTableViewEdition, SLOT ( saveSelection() ) );
81
 
        connect ( objectModel, SIGNAL ( modelReset() ), ui.kAccountTableViewEdition, SLOT ( resetSelection() ) );
 
79
        connect ( objectModel, SIGNAL ( beforeReset() ), ui.kAccountTableViewEdition, SLOT ( saveSelection() ) );
 
80
        connect ( objectModel, SIGNAL ( afterReset() ), ui.kAccountTableViewEdition, SLOT ( resetSelection() ) );
82
81
 
83
82
        ui.kAccountTableViewEdition->sortByColumn ( 0, Qt::AscendingOrder );
84
83
 
112
111
                file.close();
113
112
        }
114
113
 
 
114
        setCurrentMode(-1);
 
115
 
115
116
        //Refresh
116
 
        connect ( ( const QObject* ) getDocument(), SIGNAL ( transactionSuccessfullyEnded ( int ) ), this, SLOT ( refresh() ), Qt::QueuedConnection );
117
 
 
118
 
        refresh();
 
117
        connect ( ( const QObject* ) getDocument(), SIGNAL(tableModified(QString, int)), this, SLOT(dataModified(QString, int)), Qt::QueuedConnection );
 
118
        dataModified("", 0);
119
119
}
120
120
 
121
121
SKGBankPluginWidget::~SKGBankPluginWidget()
122
122
{
123
123
        SKGTRACEIN ( 10, "SKGBankPluginWidget::~SKGBankPluginWidget" );
124
124
        objectModel=NULL;
125
 
 
126
 
        if ( autoHidder ) {
127
 
                delete autoHidder;
128
 
                autoHidder=NULL;
129
 
        }
130
125
}
131
126
 
132
127
void SKGBankPluginWidget::onSelectionChanged()
166
161
                        ui.kAccountCreatorType->setText ( account.getAttribute ( "t_TYPENLS" ) );
167
162
                        ui.kAccountCreatorAddress->setText ( account.getAttribute ( "t_agency_address" ) );
168
163
                        ui.kAccountCreatorComment->setText ( account.getAttribute ( "t_comment" ) );
169
 
 
170
 
                        if ( autoHidder ) autoHidder->resetTimer();
171
164
                } else {
172
165
                        ui.kAccountCreatorIcon->setText ( "" );
173
166
                        ui.kAccountCreatorBank->setText ( "" );
185
178
        }
186
179
}
187
180
 
 
181
int SKGBankPluginWidget::getCurrentMode()
 
182
{
 
183
        if (ui.kAllFrm->isVisible()) return 2;
 
184
        else if (ui.kIntermediateFrm->isVisible()) return 1;
 
185
        else if (ui.kCommonFrm->isVisible()) return 0;
 
186
        return -1;
 
187
}
 
188
 
 
189
void SKGBankPluginWidget::onBtnModeClicked()
 
190
{
 
191
        QWidget* sender=static_cast<QWidget*> ( this->sender() );
 
192
 
 
193
        int currentMode=getCurrentMode();
 
194
        int newMode=0;
 
195
 
 
196
        if (sender==ui.kStandardBtn) newMode=0;
 
197
        else if (sender==ui.kIntermediateBtn) newMode=1;
 
198
        else if (sender==ui.kAllBtn) newMode=2;
 
199
 
 
200
        if (currentMode==newMode) newMode=-1;
 
201
        setCurrentMode(newMode);
 
202
}
 
203
 
 
204
void SKGBankPluginWidget::setCurrentMode(int iMode)
 
205
{
 
206
        ui.kAllFrm->hide();
 
207
        ui.kIntermediateFrm->hide();
 
208
        ui.kCommonFrm->setVisible(iMode>=0);
 
209
        ui.kBtnFrm->setVisible(iMode>=0);
 
210
 
 
211
        ui.kStandardBtn->setChecked(false);
 
212
        ui.kIntermediateBtn->setChecked(false);
 
213
        ui.kAllBtn->setChecked(false);
 
214
 
 
215
        if (iMode==0) {
 
216
                ui.kStandardBtn->setChecked(true);
 
217
        } else if (iMode==1) {
 
218
                ui.kIntermediateFrm->show();
 
219
                ui.kIntermediateBtn->setChecked(true);
 
220
        } else if (iMode==2) {
 
221
                ui.kIntermediateFrm->show();
 
222
                ui.kAllFrm->show();
 
223
                ui.kAllBtn->setChecked(true);
 
224
        }
 
225
 
 
226
        onAccountCreatorModified();
 
227
}
 
228
 
188
229
void SKGBankPluginWidget::onAccountCreatorModified()
189
230
{
190
231
        SKGTRACEIN ( 10, "SKGBankPluginWidget::onAccountCreatorModified" );
272
313
 
273
314
SKGObjectBase::SKGListSKGObjectBase SKGBankPluginWidget::getSelectedObjects()
274
315
{
275
 
        //Get Selection
276
 
        SKGObjectBase::SKGListSKGObjectBase selection;
277
 
        QItemSelectionModel *selModel=ui.kAccountTableViewEdition->selectionModel();
278
 
        QSortFilterProxyModel* proxyModel= ( QSortFilterProxyModel* ) ui.kAccountTableViewEdition->model();
279
 
        SKGObjectModel* model= ( SKGObjectModel* ) proxyModel->sourceModel();
280
 
        if ( model ) {
281
 
                QModelIndexList indexes=selModel->selectedRows();
282
 
                foreach ( const QModelIndex& index, indexes ) {
283
 
                        SKGObjectBase obj=model->getObject ( proxyModel->mapToSource ( index ) );
284
 
                        selection.push_back ( obj );
285
 
                }
286
 
        }
287
 
        return selection;
 
316
        return ui.kAccountTableViewEdition->getSelectedObjects();
288
317
}
289
318
 
290
319
int SKGBankPluginWidget::getNbSelectedObjects()
291
320
{
292
 
        QItemSelectionModel *selModel=ui.kAccountTableViewEdition->selectionModel();
293
 
        return ( selModel ? selModel->selectedRows().count() : 0 );
 
321
        return ui.kAccountTableViewEdition->getNbSelectedObjects();
294
322
}
295
323
 
296
324
void SKGBankPluginWidget::onModifyAccountClicked()
371
399
        for ( int i=0; i<nb; ++i ) {
372
400
                SKGAccountObject accountObj=selection[i];
373
401
 
374
 
                QDomDocument doc ( "SKGML" );
375
 
                QDomElement root = doc.createElement ( "parameters" );
376
 
                doc.appendChild ( root );
 
402
                QDomDocument doc("SKGML");
 
403
                doc.setContent ( getDocument()->getParameter("SKGOPERATION_DEFAULT_PARAMETERS") );
 
404
                QDomElement root = doc.documentElement();
 
405
                if (root.isNull()) {
 
406
                        root=doc.createElement("parameters");
 
407
                        doc.appendChild(root);
 
408
                }
 
409
 
377
410
                root.setAttribute ( "account", accountObj.getName() );
378
411
                getMainPanel()->setNewTabContent ( getMainPanel()->getPluginByName ( "Skrooge operation plugin" ), -1, doc.toString() );
379
412
 
442
475
        doc.appendChild ( root );
443
476
 
444
477
        root.setAttribute ( "hideUseless", ui.kHideUseless->checkState() ==Qt::Checked ? "Y" : "N" );
445
 
        if (autoHidder) root.setAttribute ( "autoHide", autoHidder->autoHideMode() ? "Y" : "N" );
446
 
 
447
478
        root.setAttribute ( "filter", ui.kFilterEdit->text() );
 
479
        root.setAttribute ( "currentPage", getCurrentMode() );
448
480
 
449
481
        //Memorize table settings
450
482
        root.setAttribute ( "view", ui.kAccountTableViewEdition->getState() );
460
492
 
461
493
        QString hideUseless=root.attribute ( "hideUseless" );
462
494
        QString filter=root.attribute ( "filter" );
 
495
        QString currentPage=root.attribute ( "currentPage" );
463
496
 
464
497
        if ( !hideUseless.isEmpty() ) ui.kHideUseless->setCheckState ( hideUseless=="Y" ? Qt::Checked : Qt::Unchecked );
465
498
        if ( !filter.isEmpty() ) ui.kFilterEdit->setText ( filter );
466
 
        if (autoHidder) autoHidder->setAutoHideMode ( root.attribute ( "autoHide" )=="Y");
 
499
        if ( !currentPage.isEmpty() ) setCurrentMode ( SKGServices::stringToInt ( currentPage ) );
467
500
 
468
501
        onFilterChanged();
469
502
 
471
504
        ui.kAccountTableViewEdition->setState ( root.attribute ( "view" ) );
472
505
}
473
506
 
474
 
void SKGBankPluginWidget::refresh()
475
 
 
476
 
{
477
 
        SKGTRACEIN ( 10, "SKGBankPluginWidget::refresh" );
 
507
QString SKGBankPluginWidget::getDefaultStateAttibute()
 
508
{
 
509
        return "SKGBANK_DEFAULT_PARAMETERS";
 
510
}
 
511
 
 
512
void SKGBankPluginWidget::dataModified(const QString& iTableName, int iIdTransaction)
 
513
 
 
514
{
 
515
        SKGTRACEIN ( 10, "SKGBankPluginWidget::dataModified" );
478
516
 
479
517
        //Refresh widgets
480
518
        QSqlDatabase* db = getDocument()->getDatabase();
481
519
        setEnabled ( db!=NULL );
482
 
        if ( db!=NULL ) {
 
520
        if ( db!=NULL && (iTableName=="account" || iTableName.isEmpty())) {
483
521
                //Correction bug 2299394 vvv
484
522
                if ( ui.kAccountTableViewEdition->isAutoResized() ) ui.kAccountTableViewEdition->resizeColumnsToContents();
485
523
                //Correction bug 2299394 ^^^
508
546
                QString s1=QString ( "<font color=\"" ) + ( v1<0 ? "red" : "black" ) +"\">"+locale->formatMoney ( v1, pUnit,2 ) +"</font>";
509
547
                QString s2=QString ( "<font color=\"" ) + ( v2<0 ? "red" : "black" ) +"\">"+locale->formatMoney ( v2, pUnit,2 ) +"</font>";
510
548
                QString s3=QString ( "<font color=\"" ) + ( v3<0 ? "red" : "black" ) +"\">"+locale->formatMoney ( v3, pUnit,2 ) +"</font>";
511
 
                ui.kInfo->setText ( i18n ( "Balance: %1     Checked: %2     Foreseen: %3", s1, s2, s3 ) );
 
549
                ui.kInfo->setText ( i18n ( "Balance: %1     Cleared: %2     In Transit: %3", s1, s2, s3 ) );
512
550
 
513
551
                QString secondaryUnit= ( ( SKGDocumentBank* ) getDocument() )->getSecondaryUnit();
514
552
                double secondaryUnitValue= ( ( SKGDocumentBank* ) getDocument() )->getSecondaryUnitValue();
517
555
                        s2=QString ( "<font color=\"" ) + ( v2<0 ? "red" : "black" ) +"\">"+locale->formatMoney ( v2/secondaryUnitValue, secondaryUnit,2 ) +"</font>";
518
556
                        s3=QString ( "<font color=\"" ) + ( v3<0 ? "red" : "black" ) +"\">"+locale->formatMoney ( v3/secondaryUnitValue, secondaryUnit,2 ) +"</font>";
519
557
                }
520
 
                ui.kInfo->setToolTip ( i18n ( "<p>Balance: %1</p><p>Checked: %2</p><p>Foreseen: %3</p>", s1, s2, s3 ) );
 
558
                ui.kInfo->setToolTip ( i18n ( "<p>Balance: %1</p><p>Cleared: %2</p><p>In Transit: %3</p>", s1, s2, s3 ) );
521
559
        }
522
560
}
523
561