diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 42268a3..d4c55cd 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -454,6 +454,18 @@ bool KissCount::SearchPreviousOperation(Operation* res, Operation& op, int month return false; } +void KissCount::GetHistory(int month, int year, QStringList& list) +{ + month -= 3; + if (month < 0) + { + year -= 1; + month += 12; + } + + _db->GetHistory(month, year, list); +} + void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo, std::map > >* accountAmounts, std::map* categories) diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index f1860a6..567b2b8 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -135,6 +135,8 @@ public: void UpdateImportPattern(); + void GetHistory(int month, int year, QStringList& list); + private: wxUI* _wxUI; Database* _db; diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 7c4d211..94406b9 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1727,3 +1727,24 @@ void Database::UpdateImportPattern(User* user) } } } + +void Database::GetHistory(int month, int year, QStringList& list) +{ + QSqlRecord set ; + QSqlQuery query(_db); + QString req; + + req = QString("SELECT DISTINCT description AS d FROM operation"); + req += " WHERE (year > '" + QString::number(year) + "' OR (year == '" + QString::number(year) + "' AND month >= '" + QString::number(month) + "'))"; + req += " ORDER by description"; + + EXECUTE_SQL_QUERY(req, ); + + while (query.next()) + { + set = query.record(); + + list << set.value("d").toString(); + } +} + diff --git a/src/model/Database.hpp b/src/model/Database.hpp index a685234..c80715c 100644 --- a/src/model/Database.hpp +++ b/src/model/Database.hpp @@ -28,7 +28,7 @@ #include #include "model.hpp" -#define BDD_FILE "/.kisscount/kc.bdd" +#define BDD_FILE "kc.bdd" #define INIT_SCRIPT RESSOURCES_ROOT "init.sql" @@ -146,6 +146,8 @@ public: void UpdateImportPattern(User* user); + void GetHistory(int month, int year, QStringList& list); + /* Database Update */ void CheckDatabaseVersion(); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 4182bc3..58a3962 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -49,7 +49,7 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, _parent(parent), _kiss(kiss), _setWeek(setWeek), _databaseSynchronization(synchronizeWithDatabase), _loadOperations(false), _curMonth(0), _curYear(0), _treeSignalMapper(this), _checkSignalMapper(this), - _deleteSignalMapper(this), _inModification(false) + _deleteSignalMapper(this), _inModification(false), _completer(0) { DEFAULT_FONT(font); int i; @@ -136,6 +136,8 @@ GridAccount::~GridAccount() { delete[] _categories; delete[] _accounts; + if (_completer) + delete _completer; } void GridAccount::ResetWeeks() @@ -196,6 +198,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, User* user = _kiss->GetUser(); int curLine = 0; Operation NULLop; + QStringList list; NULLop.id = 0; @@ -211,7 +214,20 @@ void GridAccount::LoadOperations(std::vector* operations, int month, if (rowCount() > 1) setRowCount(1); - TabDelegate* descriptionEditor = new TabDelegate(this, &_displayedOperations); + if (_completer) + { + delete _completer; + _completer = 0; + } + + if (_canAddOperation) + { + _kiss->GetHistory(month, year, list); + _completer = new QCompleter(list); + _completer->setCaseSensitivity(Qt::CaseInsensitive); + } + + TabDelegate* descriptionEditor = new TabDelegate(this, &_displayedOperations, _completer); setItemDelegateForColumn(DESCRIPTION, descriptionEditor); ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()-1); diff --git a/src/view/grid/GridAccount.hpp b/src/view/grid/GridAccount.hpp index c30df5d..54bf5c1 100644 --- a/src/view/grid/GridAccount.hpp +++ b/src/view/grid/GridAccount.hpp @@ -29,6 +29,7 @@ #include #include +#include class KissCount; @@ -83,6 +84,7 @@ private: int _curMonth, _curYear; QSignalMapper _treeSignalMapper, _checkSignalMapper, _deleteSignalMapper; bool _inModification; + QCompleter* _completer; void SetWeek(int week, int line); void ResetWeeks(); diff --git a/src/view/grid/TabDelegate.cpp b/src/view/grid/TabDelegate.cpp index ed9e56a..44abac6 100644 --- a/src/view/grid/TabDelegate.cpp +++ b/src/view/grid/TabDelegate.cpp @@ -24,7 +24,12 @@ QWidget * TabDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const { - return new QLineEdit(parent); + QLineEdit* lineEdit = new QLineEdit(parent); + + if (_completer) + lineEdit->setCompleter(_completer); + + return lineEdit; } void TabDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, diff --git a/src/view/grid/TabDelegate.hpp b/src/view/grid/TabDelegate.hpp index 869ddcc..b198687 100644 --- a/src/view/grid/TabDelegate.hpp +++ b/src/view/grid/TabDelegate.hpp @@ -28,7 +28,10 @@ class TabDelegate : public TableViewDelegate Q_OBJECT; public: - TabDelegate(QWidget *parent = 0, std::vector* operations=0) : TableViewDelegate(parent), _operations(operations) {} + TabDelegate(QWidget *parent = 0, std::vector* operations=0, QCompleter* completer=0) : + TableViewDelegate(parent), _operations(operations), + _completer(completer) + {} QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; @@ -37,6 +40,7 @@ public: private: std::vector* _operations; + QCompleter* _completer; }; #endif