Add auto-completion for description field in GridAccount
This commit is contained in:
parent
37626b09e1
commit
88e06dacce
|
@ -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<int, std::map<int, std::map<int, double> > >* accountAmounts,
|
||||
std::map<int, double>* categories)
|
||||
|
|
|
@ -135,6 +135,8 @@ public:
|
|||
|
||||
void UpdateImportPattern();
|
||||
|
||||
void GetHistory(int month, int year, QStringList& list);
|
||||
|
||||
private:
|
||||
wxUI* _wxUI;
|
||||
Database* _db;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <controller/KissCount.hpp>
|
||||
#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();
|
||||
|
|
|
@ -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<Operation>* 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<Operation>* 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);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <QTableWidget>
|
||||
#include <QSignalMapper>
|
||||
#include <QCompleter>
|
||||
|
||||
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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -28,7 +28,10 @@ class TabDelegate : public TableViewDelegate
|
|||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
TabDelegate(QWidget *parent = 0, std::vector<Operation>* operations=0) : TableViewDelegate(parent), _operations(operations) {}
|
||||
TabDelegate(QWidget *parent = 0, std::vector<Operation>* 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<Operation>* _operations;
|
||||
QCompleter* _completer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user