From 7440c632dd9bfb985f0c22c835e97d24dd9cbff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 20 Feb 2012 21:27:51 +0100 Subject: [PATCH] Add ImportPanel Throw exception when category/account are not found in User Fix a bug in GrisbiImportEngine with QDate::fromString Try to search an account also with its name Remove categories number limit (only used for pie color) --- Makefile | 1 - src/controller/KissCount.cpp | 13 +- src/controller/KissCount.hpp | 2 +- src/model/User.cpp | 12 +- src/model/User.hpp | 7 +- src/model/import/GrisbiImportEngine.cpp | 4 +- src/model/import/XMLImportEngine.cpp | 18 +- src/view/AccountPanel.cpp | 6 +- src/view/ImportPanel.cpp | 440 ++++++++++++++++++++++++ src/view/ImportPanel.hpp | 68 ++++ src/view/StatsPanel.cpp | 12 +- src/view/grid/GridAccount.cpp | 3 - src/view/grid/GridAccount.hpp | 2 + src/view/wxUI.cpp | 5 +- 14 files changed, 553 insertions(+), 40 deletions(-) create mode 100644 src/view/ImportPanel.cpp create mode 100644 src/view/ImportPanel.hpp diff --git a/Makefile b/Makefile index 5aff438..e24d342 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ BIN_DIR=$(DESTDIR)$(ROOT_DIR)"/bin/" QT_PACKAGES="QtCore QtGui QtSql QtXml" CXXFLAGS=`pkg-config --cflags $(QT_PACKAGES)` CXXFLAGS+=-Wall -Isrc -ggdb -fPIC -CXXFLAGS+=-I/usr/include/libxml2 CXXFLAGS+=-DRESSOURCES_ROOT="\"$(SHARE_DIR)\"" # For developpers #CXXFLAGS+=-DRESSOURCES_ROOT="\"./ressources/\"" diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 1bc177a..1ac9433 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -546,22 +546,15 @@ QString KissCount::GetImportEngineExtensions() return res; } -ImportEngine* KissCount::GetImportEngine(QString path, QString filter) +ImportEngine* KissCount::GetImportEngine(QString path) { std::vector::iterator it; std::vector* importEngines = KissCount::GetImportEngines(); - QString tmp; for(it=importEngines->begin(); it!=importEngines->end(); it++) { - if (filter == (*it)->GetFileExt()) - { - tmp = path; - if (!tmp.endsWith((*it)->GetShortExt())) - tmp += (*it)->GetShortExt(); - if ((*it)->HandleFile(path, _user, _db, this)) - return *it; - } + if ((*it)->HandleFile(path, _user, _db, this)) + return *it; } return 0; diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index 1041d07..f1860a6 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -125,7 +125,7 @@ public: static void UnRegisterImportEngine(ImportEngine* engine); QString GetImportEngineExtensions(); - ImportEngine* GetImportEngine(QString path, QString filter); + ImportEngine* GetImportEngine(QString path); static void RegisterExportEngine(ExportEngine* engine); static void UnRegisterExportEngine(ExportEngine* engine); diff --git a/src/model/User.cpp b/src/model/User.cpp index e967ca7..dd6fa5d 100644 --- a/src/model/User.cpp +++ b/src/model/User.cpp @@ -80,7 +80,7 @@ QString User::GetCategoryName(int catId) return _("Unknown") ; } -int User::GetCategoryId(const QString& catName) +int User::GetCategoryId(const QString& catName) throw (CategoryNotFound) { std::vector::iterator it; Category cat; @@ -92,7 +92,7 @@ int User::GetCategoryId(const QString& catName) if ( _db->LoadCategory(0, catName, cat)) return cat.id; - return 0 ; + throw CategoryNotFound(); } const QFont User::GetCategoryFont(int catId) @@ -158,24 +158,24 @@ QString User::GetAccountName(int accountId) return _("Unknown") ; } -int User::GetAccountId(const QString& accountName) +int User::GetAccountId(const QString& accountName) throw (AccountNotFound) { std::vector::iterator it; for (it=_accounts.begin(); it !=_accounts.end(); it++) if (it->name == accountName) return it->id; - return 0 ; + throw AccountNotFound(); } -int User::GetAccountIdFromAccountNumber(const QString& accountNumber) +int User::GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound) { std::vector::iterator it; for (it=_accounts.begin(); it !=_accounts.end(); it++) if (it->number == accountNumber) return it->id; - return 0 ; + throw AccountNotFound(); } void User::AddAccount(Account& ac) diff --git a/src/model/User.hpp b/src/model/User.hpp index 7fa1cb3..f40f5e6 100644 --- a/src/model/User.hpp +++ b/src/model/User.hpp @@ -52,10 +52,11 @@ public: std::map _importPatterns; class AccountNotFound {}; + class CategoryNotFound {}; Category GetCategory(int catId); QString GetCategoryName(int catId); - int GetCategoryId(const QString& catName); + int GetCategoryId(const QString& catName) throw (CategoryNotFound); const QFont GetCategoryFont(int catId); void AddCategory(const Category& cat); void UpdateCategory(const Category& cat); @@ -64,8 +65,8 @@ public: Account GetAccount(int accountId) throw (AccountNotFound); QString GetAccountName(int accountId); - int GetAccountId(const QString& accountName); - int GetAccountIdFromAccountNumber(const QString& accountNumber); + int GetAccountId(const QString& accountName) throw (AccountNotFound); + int GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound); void AddAccount(Account& ac); void UpdateAccount(Account& ac); void DeleteAccount(Account& ac); diff --git a/src/model/import/GrisbiImportEngine.cpp b/src/model/import/GrisbiImportEngine.cpp index e903f0c..07fe18e 100644 --- a/src/model/import/GrisbiImportEngine.cpp +++ b/src/model/import/GrisbiImportEngine.cpp @@ -110,10 +110,10 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs) op.account = _accounts[attrs.value("Ac").toInt()]; - date.fromString(attrs.value("Dt"), "MM/%dd/%yyyy"); + date = QDate::fromString(attrs.value("Dt"), "MM/dd/yyyy"); op.day = date.day(); op.month = date.month(); - op.year = date.year(); + op.year = date.year(); op.amount = attrs.value("Am").toDouble(); op.category = _categories[attrs.value("Ca").toInt()]; op.description = attrs.value("No"); diff --git a/src/model/import/XMLImportEngine.cpp b/src/model/import/XMLImportEngine.cpp index 9daef56..dc0ceba 100644 --- a/src/model/import/XMLImportEngine.cpp +++ b/src/model/import/XMLImportEngine.cpp @@ -93,7 +93,6 @@ bool XMLImportEngine::startElement (const QString& namespaceURI, const QString& void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs) { int id; - QString account_number, name; Account ac; static int unknownAccount = 0; @@ -101,7 +100,7 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs) ac.name = attrs.value("name"); ac.id = id = attrs.value("id").toInt(); - ac.number = account_number = attrs.value("number"); + ac.number = attrs.value("number"); ac.blocked = (attrs.value("blocked") == "1"); ac._virtual = (attrs.value("virtual") == "1"); ac.hidden = (attrs.value("hidden") == "1"); @@ -113,10 +112,21 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs) ac.shared = false; ac.is_owner = true; - if (account_number.size()) + if (ac.number.size()) { try { - _accounts[ac.id] = _user->GetAccountIdFromAccountNumber(account_number); + _accounts[ac.id] = _user->GetAccountIdFromAccountNumber(ac.number); + return; + } + catch (User::AccountNotFound) + { + } + } + + if (ac.name.size()) + { + try { + _accounts[ac.id] = _user->GetAccountId(ac.name); return; } catch (User::AccountNotFound) diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index b0748c2..6350782 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -81,7 +81,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare _categoriesIndexes[categoryIt->name] = i; } - nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY; + nbCategories = user->GetCategoriesNumber(); + // nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY; _pie = new KDChart::Widget(); _pie->setType( KDChart::Widget::Pie ); @@ -107,7 +108,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare legend->setText( i, _categories[i] ); _dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]); _dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0); - _dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole); + if (i < wxUI::MAX_CATEGORY) + _dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole); } _pie->setMaximumSize( 200, 400 ); diff --git a/src/view/ImportPanel.cpp b/src/view/ImportPanel.cpp new file mode 100644 index 0000000..73858d7 --- /dev/null +++ b/src/view/ImportPanel.cpp @@ -0,0 +1,440 @@ +/* + Copyright 2010-2011 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#include + +#include "ImportPanel.hpp" +#include "grid/ChoiceDelegate.hpp" + +ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent) +{ + QVBoxLayout *vbox = new QVBoxLayout; + QVBoxLayout *vbox2 = new QVBoxLayout; + QHBoxLayout *hbox = new QHBoxLayout; + _hbox = new QHBoxLayout; + QPushButton* buttonOpen; + QGroupBox* staticAccount = new QGroupBox(_("Unresolved accounts")); + QGroupBox* staticCategory = new QGroupBox(_("Unresolved categories")); + + setLayout(vbox); + + _fileTxt = new QLineEdit; + buttonOpen = new QPushButton("..."); + + connect(buttonOpen, SIGNAL(clicked()), this, SLOT(OnFile())); + connect(_fileTxt, SIGNAL(returnPressed()), this, SLOT(OnFileEnter())); + + _buttonLoadOperations = new QPushButton(_("Load operations")); + _buttonLoadOperations->setEnabled(false); + connect(_buttonLoadOperations, SIGNAL(clicked()), this, SLOT(OnLoadOperations())); + + _buttonIntegrate = new QPushButton(_("Integrate operations")); + _buttonIntegrate->setEnabled(false); + connect(_buttonIntegrate, SIGNAL(clicked()), this, SLOT(OnIntegrate())); + + _checkSaveImportPatterns = new QCheckBox(_("Save import patterns")); + + hbox->addWidget(_fileTxt); + hbox->addWidget(buttonOpen); + hbox->addWidget(_buttonLoadOperations); + hbox->addWidget(_buttonIntegrate); + hbox->addWidget(_checkSaveImportPatterns); + + vbox->addLayout(hbox); + + _accountsGrid = new QTableWidget(0, 3); + _accountsGrid->verticalHeader()->setHidden(true); + QStringList labels; + labels << _("File account") << _("Account name") << _("Internal account"); + _accountsGrid->setHorizontalHeaderLabels(labels); + _accountsGrid->resizeColumnsToContents(); + + _categoriesGrid = new QTableWidget(0, 3); + _categoriesGrid->verticalHeader()->setHidden(true); + labels.clear(); + labels << _("File category") << _("Category name") << _("Internal category"); + _categoriesGrid->setHorizontalHeaderLabels(labels); + _categoriesGrid->resizeColumnsToContents(); + + { + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(_accountsGrid); + staticAccount->setLayout(vbox); + } + + vbox2->addWidget(staticAccount); + + { + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(_categoriesGrid); + staticCategory->setLayout(vbox); + } + + vbox2->addWidget(staticCategory); + + _operationsGrid = new GridAccount(kiss, this, false, false, false); + connect(_operationsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnOperationModified(int, int))); + + _hbox->addLayout(vbox2); + _hbox->addWidget(_operationsGrid); + + vbox->addLayout(_hbox); + + layout(); +} + +KissPanel* ImportPanel::CreatePanel() +{ + return new ImportPanel(_kiss, _wxUI); +} + +QPushButton* ImportPanel::GetButton() +{ + if (!_KissButton) + { + _KissButton = new QPushButton(QIcon(IMPORT_ICON), "", this); + _KissButton->setFixedSize(128, 128); + _KissButton->setIconSize(QSize(128, 128)); + } + + return _KissButton; +} + +QString ImportPanel::GetToolTip() +{ + return _("Import"); +} + +void ImportPanel::OnShow() +{ + _wxUI->setWindowTitle(_("KissCount - Import")); +} + +void ImportPanel::OnFile() +{ + QString path; + + path = QFileDialog::getOpenFileName(0, _("Choose a database to open"), "", _kiss->GetImportEngineExtensions()); + + if (!path.size()) + return; + + _fileTxt->setText(path); + + ProcessFile(); +} + +void ImportPanel::OnFileEnter() +{ + ProcessFile(); +} + +void ImportPanel::ProcessFile() +{ + User* user = _kiss->GetUser(); + int i; + QString* userAccounts; + std::map resolvedAccounts; + QString* userCategories; + std::map resolvedCategories; + QTableWidgetItem* item; + + QString path = _fileTxt->text(); + + _buttonLoadOperations->setEnabled(false); + _buttonIntegrate->setEnabled(false); + _accountsGrid->setRowCount(0); + _categoriesGrid->setRowCount(0); + _operationsGrid->setRowCount(0); + + _importEngine = _kiss->GetImportEngine(path); + + if (!_importEngine) + { + QMessageBox::critical(0, _("Error"), _("Any engine can process this file !")); + return ; + } + + _importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories); + + if (_unresolvedAccounts.size()) + { + int nb_accounts = user->GetAccountsNumber(); + userAccounts = new QString[nb_accounts+1]; + + userAccounts[0] = _("Create one"); + + for(i=0; i_accounts[i].name; + + ChoiceDelegate* accountEditor = new ChoiceDelegate(this, userAccounts, nb_accounts+1); + _accountsGrid->setItemDelegateForColumn(2, accountEditor); + + _buttonLoadOperations->setEnabled(true); + + _accountsGrid->setRowCount(_unresolvedAccounts.size()); + + for (i=0; i<(int)_unresolvedAccounts.size(); i++) + { + item = new QTableWidgetItem(_unresolvedAccounts[i].number); + item->setFlags(item->flags() & ~Qt::ItemIsEditable); + _accountsGrid->setItem(i, 0, item); + _accountsGrid->setItem(i, 1, new QTableWidgetItem(_unresolvedAccounts[i].name)); + _accountsGrid->setItem(i, 2, new QTableWidgetItem(userAccounts[0])); + } + + _accountsGrid->resizeColumnsToContents(); + _accountsGrid->layout(); + } + + if (_unresolvedCategories.size()) + { + int nb_categories = user->GetCategoriesNumber(); + userCategories = new QString[nb_categories+1]; + + userCategories[0] = _("Create one"); + + for(i=0; i_categories[i].name; + + ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, userCategories, nb_categories+1); + _categoriesGrid->setItemDelegateForColumn(2, categoryEditor); + + _buttonLoadOperations->setEnabled(true); + + _categoriesGrid->setRowCount(_unresolvedCategories.size()); + + for (i=0; i<(int)_unresolvedCategories.size(); i++) + { + item = new QTableWidgetItem(_unresolvedCategories[i].name); + item->setFlags(item->flags() & ~Qt::ItemIsEditable); + _categoriesGrid->setItem(i, 0, item); + _categoriesGrid->setItem(i, 1, new QTableWidgetItem("")); + _categoriesGrid->setItem(i, 2, new QTableWidgetItem(userCategories[0])); + } + + _categoriesGrid->resizeColumnsToContents(); + _categoriesGrid->layout(); + } + + if (!_unresolvedAccounts.size() && !_unresolvedCategories.size()) + { + OnLoadOperations(); + } + layout(); +} + +void ImportPanel::OnLoadOperations() +{ + int i, nbAccounts=0, nbCategories=0; + User* user = _kiss->GetUser(); + Account account; + Category category; + std::map accounts; + std::map categories; + int oldid; + + for(i=0; i<_accountsGrid->rowCount(); i++) + { + if (_accountsGrid->item(i, 2)->text() == _("Create one")) + nbAccounts++; + else + accounts[_accountsGrid->item(i, 0)->text().toInt()] = + user->GetAccountId(_accountsGrid->item(i, 1)->text()); + } + + for(i=0; i<_categoriesGrid->rowCount(); i++) + { + if (_categoriesGrid->item(i, 2)->text() == _("Create one")) + nbCategories++; + else + categories[_categoriesGrid->item(i, 0)->text().toInt()] = + user->GetAccountId(_categoriesGrid->item(i, 1)->text()); + } + + if (nbAccounts || nbCategories) + { + QString message, v; + + if (nbAccounts) + { + message += v.sprintf(_("%d accounts").toStdString().c_str(), nbAccounts); + if (nbCategories) message += _(" and "); + } + + if (nbCategories) + message += v.sprintf(_("%d categories").toStdString().c_str(), nbCategories); + + message += _(" will be created, is it ok ?"); + + if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) + return; + + for(i=0; i<_accountsGrid->rowCount(); i++) + { + if (_accountsGrid->item(i, 2)->text() == _("Create one")) + { + account = _unresolvedAccounts[i] ; + if (_accountsGrid->item(i, 1)->text().length()) + account.name = _accountsGrid->item(i, 1)->text(); + else + account.name = _accountsGrid->item(i, 0)->text(); + account.number = _accountsGrid->item(i, 0)->text(); + + oldid = account.id; + _resolvedAccounts[oldid] = accounts[_accountsGrid->item(i, 0)->text().toInt()] = _kiss->AddAccount(account); + } + } + + _accountsGrid->setRowCount(0); + + for(i=0; i<_categoriesGrid->rowCount(); i++) + { + if (_categoriesGrid->item(i, 2)->text() == _("Create one")) + { + category = _unresolvedCategories[i] ; + if (_categoriesGrid->item(i, 1)->text().length()) + category.name = _categoriesGrid->item(i, 1)->text(); + else + category.name = _categoriesGrid->item(i, 0)->text(); + + oldid = category.id; + _resolvedCategories[oldid] = categories[_categoriesGrid->item(i, 0)->text().toInt()] = category.id = _kiss->AddCategory(category); + } + } + + _categoriesGrid->setRowCount(0); + + _wxUI->NeedReload(); + } + + _operations = _importEngine->GetOperations(accounts, categories); + + if (_operations->size()) + { + _hbox->removeWidget(_operationsGrid); + delete _operationsGrid; + _operationsGrid = new GridAccount(_kiss, this, false, false, false); + _hbox->addWidget(_operationsGrid); + + _operationsGrid->LoadOperations(_operations, 0, 0); + _buttonIntegrate->setEnabled(true); + + _buttonLoadOperations->setEnabled(false); + + layout(); + } + else + { + QMessageBox::information(0, "KissCount", _("No operation found into this file")); + } +} + +void ImportPanel::OnIntegrate() +{ + int i; + std::map mapid; + int oldid, account; + bool update; + std::map accountAmounts; + std::map::iterator it; + double amount; + + if (!_operations->size()) return; + + if (QMessageBox::question(0, "KissCount", _("Are you sure want to integrate these operations ?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) + return; + + _buttonIntegrate->setEnabled(false); + + for(i=0; i<(int)_operations->size(); i++) + { + oldid = (*_operations)[i].id; + _kiss->AddOperation((*_operations)[i], false); + mapid[oldid] = (*_operations)[i].id; + } + + for(i=0; i<(int)_operations->size(); i++) + { + update = false; + + if ((*_operations)[i].parent) + { + (*_operations)[i].parent = mapid[(*_operations)[i].parent]; + update = true; + } + + if ((*_operations)[i].transfert) + { + (*_operations)[i].transfert = mapid[(*_operations)[i].transfert]; + update = true; + } + + if (update) + _kiss->UpdateOperation((*_operations)[i], false); + } + + accountAmounts = _importEngine->GetAccountAmounts(); + + for(it=accountAmounts.begin(); it!=accountAmounts.end(); it++) + { + account = it->first.account; + + if (_resolvedAccounts.count(account)) + account = _resolvedAccounts[account]; + + amount = _kiss->GetAccountAmount(account, it->first.month, it->first.year); + + if (!amount) + _kiss->SetAccountAmount(account, it->first.month, it->first.year, it->second); + } + + if (_checkSaveImportPatterns->checkState() == Qt::Checked) + _kiss->UpdateImportPattern(); + + _operations->clear(); + _operationsGrid->ClearGrid(); + + QMessageBox::information(0, "KissCount", _("Operations successfully imported")); + + _wxUI->NeedReload(); +} + +void ImportPanel::OnOperationModified(int row, int col) +{ + static bool update = false; + + if (col != GridAccount::DESCRIPTION && + col != GridAccount::CATEGORY && + col != GridAccount::ACCOUNT) + return ; + + if (update) return; + + update = true; + + _operationsGrid->ClearGrid(); + + if (_importEngine->UpdatePattern(row-1) > 1) + _operationsGrid->LoadOperations(_operations, 0, 0); + + layout(); + + update = false; +} diff --git a/src/view/ImportPanel.hpp b/src/view/ImportPanel.hpp new file mode 100644 index 0000000..a41a79f --- /dev/null +++ b/src/view/ImportPanel.hpp @@ -0,0 +1,68 @@ +/* + Copyright 2010-2012 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#ifndef IMPORTPANEL_H +#define IMPORTPANEL_H + +#include + +#include "view.hpp" +#include +#include + +#include "grid/GridAccount.hpp" + +class ImportPanel: public KissPanel +{ + Q_OBJECT; + +public: + ImportPanel(KissCount* kiss, wxUI *parent); + + KissPanel* CreatePanel(); + QPushButton* GetButton(); + QString GetToolTip(); + void OnShow(); + +private slots: + void OnFile(); + void OnFileEnter(); + void OnLoadOperations(); + void OnIntegrate(); + void OnOperationModified(int row, int col); + +private: + QHBoxLayout *_hbox; + QTableWidget* _accountsGrid, *_categoriesGrid; + QLineEdit* _fileTxt; + GridAccount* _operationsGrid; + ImportEngine* _importEngine; + QPushButton* _buttonLoadOperations, *_buttonIntegrate; + QCheckBox *_checkSaveImportPatterns; + std::vector* _operations; + + std::vector _unresolvedAccounts; + std::vector _unresolvedCategories; + std::map _resolvedAccounts; + std::map _resolvedCategories; + + void ProcessFile(); +}; + +#endif diff --git a/src/view/StatsPanel.cpp b/src/view/StatsPanel.cpp index 3f65c7b..299363e 100644 --- a/src/view/StatsPanel.cpp +++ b/src/view/StatsPanel.cpp @@ -135,7 +135,8 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _vbox3->addWidget(_account); _vbox3->addWidget(_statsGrid); - nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY; + nbCategories = user->GetCategoriesNumber(); + // nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY; _categoriesValues = new double[user->GetCategoriesNumber()]; for(i=0; iGetCategoriesNumber(); i++) @@ -159,7 +160,8 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), { _categoriesValues[i] = 0.0; _pie->setDataset(i, vec, _categories[i]); - _pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i])); + if (i < wxUI::MAX_CATEGORY) + _pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i])); legend->setText(i, _categories[i]); } @@ -217,7 +219,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT std::map >::iterator accountYearIt; double total, non_fix; int account, size, i, a, b, percents, nbDays; - QString value; + QString value, v; User* user = _kiss->GetUser(); QDate date; bool failed; @@ -372,7 +374,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT percents = ((double) (categoriesIt->second*100))/total; else percents = 0; - value = value.sprintf("%0.2lf (%02d%%)", categoriesIt->second, percents); + value = v.sprintf("%0.2lf (%02d%%)", categoriesIt->second, percents); if (i) { _statsGrid->setItem(_categoriesIndexes[categoriesIt->first]+1, 1, new QTableWidgetItem(value)); @@ -394,7 +396,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT percents = ((double) (non_fix*100))/total; else percents = 0; - value = value.sprintf("%0.2lf (%02d%%)", non_fix, percents); + value = v.sprintf("%0.2lf (%02d%%)", non_fix, percents); _statsGrid->setItem(1, 1, new QTableWidgetItem(value)); _statsGrid->resizeColumnsToContents(); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 239e0fb..4182bc3 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -27,8 +27,6 @@ #include "FormulaDelegate.hpp" #include "TabDelegate.hpp" -enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS}; - #define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; iitem(row, i)) setItem(row, i, new QTableWidgetItem("")); \ @@ -75,7 +73,6 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, for(i=0; isetText(colsName[i]); item->setBackground(view::OWN_CYAN); item->setFont(font); SET_READ_ONLY(item); diff --git a/src/view/grid/GridAccount.hpp b/src/view/grid/GridAccount.hpp index f8d52b7..c30df5d 100644 --- a/src/view/grid/GridAccount.hpp +++ b/src/view/grid/GridAccount.hpp @@ -41,6 +41,8 @@ class GridAccount : public QTableWidget public: class OperationNotFound {}; + enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS}; + GridAccount(KissCount* kiss, QWidget *parent, bool canAddOperation, bool setWeek, bool synchronizeWithDatabase); ~GridAccount(); diff --git a/src/view/wxUI.cpp b/src/view/wxUI.cpp index e7c2f5a..c7bd32a 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -22,9 +22,8 @@ #include "AccountPanel.hpp" #include "SearchPanel.hpp" #include "PreferencesPanel.hpp" -//#include "UsersDialog.hpp" #include "StatsPanel.hpp" -//#include "ImportPanel.hpp" +#include "ImportPanel.hpp" #include "ExportPanel.hpp" #include "wxUI.hpp" @@ -168,7 +167,7 @@ void wxUI::InitPanels() ADD_PANEL(StatsPanel); ADD_PANEL(SearchPanel); ADD_PANEL(PreferencesPanel); - // ADD_PANEL(ImportPanel, 4); + ADD_PANEL(ImportPanel); ADD_PANEL(ExportPanel); }