diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 594b22d..a433410 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1419,7 +1419,7 @@ std::vector* Database::Search(User* user, QString* description, QDate if (tags.size()) { if (firstCond) req += " AND " ; else firstCond = true; - req += "category IN ('"; + req += "tag IN ('"; it = tags.begin(); req += QString::number(*it); it++; diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 2430f27..8e6bee8 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -191,8 +191,10 @@ AccountPanel::~AccountPanel() { delete[] _categoriesValues; delete[] _categories; - delete[] _tagsValues; - delete[] _tags; + if (_tagsValues) + delete[] _tagsValues; + if (_tags) + delete[] _tags; delete[] _accounts; } diff --git a/src/view/SearchBanner.cpp b/src/view/SearchBanner.cpp index e58f344..077abbe 100644 --- a/src/view/SearchBanner.cpp +++ b/src/view/SearchBanner.cpp @@ -228,9 +228,9 @@ std::vector * SearchBanner::Search() if (_category->item(i)->checkState() == Qt::Checked) categories.push_back((i) ? user->_categories[i-1].id : 0); - for(i=0; iGetTagsNumber()+1; i++) - if (_tag->item(i)->checkState() == Qt::Checked) - tags.push_back((i) ? user->_tags[i-1].id : 0); + for(i=0; iGetTagsNumber(); i++) + if (_tag->item(i+1)->checkState() == Qt::Checked) + tags.push_back(user->_tags[i].id); types |= (_optype->item(0)->checkState() == Qt::Checked) ? Database::FIX_OP : 0; types |= (_optype->item(1)->checkState() == Qt::Checked) ? Database::NON_FIX_OP : 0; diff --git a/src/view/SearchPanel.cpp b/src/view/SearchPanel.cpp index 1b5535b..6a6fac5 100644 --- a/src/view/SearchPanel.cpp +++ b/src/view/SearchPanel.cpp @@ -52,10 +52,12 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) : _changeAccountButton = new QPushButton(_("Change account")); _changeCategoryButton = new QPushButton(_("Change category")); + _changeTagButton = new QPushButton(_("Change tag")); _renameButton = new QPushButton(_("Rename")); connect(_changeAccountButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeAccount())); connect(_changeCategoryButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeCategory())); + connect(_changeTagButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeTag())); connect(_renameButton, SIGNAL(clicked()), this, SLOT(OnButtonRename())); _categories = new QString[user->GetCategoriesNumber()] ; @@ -72,6 +74,7 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) : vbox2->addWidget(_changeAccountButton); vbox2->addWidget(_changeCategoryButton); + vbox2->addWidget(_changeTagButton); vbox2->addWidget(_renameButton); hbox->addLayout(vbox2); @@ -255,6 +258,51 @@ void SearchPanel::OnButtonChangeCategory() _wxUI->NeedReload(); } +static void ChangeTag(Operation* op, void** params) +{ + int* tag = (int*) params[0]; + + op->tag = *tag; +} + +void SearchPanel::OnButtonChangeTag() +{ + int i, a; + std::vector rows; + User* user = _kiss->GetUser(); + QStringList tags; + std::vector::iterator it; + QString res; + int tag; + void * params[] = {&tag}; + + if (!_operations) return; + + _grid->GetSelectedOperations(&rows); + + tags << _("None"); + for(i=0; i < user->GetTagsNumber(); i++) + tags << _(user->_tags[i].name.toStdString().c_str()); + + res = QInputDialog::getItem(0, "KissCount", _("Choose a new tag"), tags, 0, false); + + if (res.length()) + { + a = tags.indexOf(res); + tag = user->_tags[a].id ; + } + else + { + tag = 0; + } + + _grid->MassUpdate(rows, true, ChangeTag, params); + + UpdateCostRepartition(); + + _wxUI->NeedReload(); +} + static void ChangeName(Operation* op, void** params) { QString* description = (QString*) params[0]; diff --git a/src/view/SearchPanel.hpp b/src/view/SearchPanel.hpp index da643fe..ecd3758 100644 --- a/src/view/SearchPanel.hpp +++ b/src/view/SearchPanel.hpp @@ -45,12 +45,12 @@ public: void OnShow(); private slots: - /* void OnEnter(wxCommandEvent& event); */ void OnButtonSearch(); void OnOperationModified(); void OnButtonChangeAccount(); void OnButtonChangeCategory(); + void OnButtonChangeTag(); void OnButtonRename(); private: @@ -63,7 +63,7 @@ private: QString* _categories; int *_categoriesValues; std::map _categoriesIndexes; - QPushButton* _searchButton, *_renameButton, *_changeAccountButton, *_changeCategoryButton; + QPushButton* _searchButton, *_renameButton, *_changeAccountButton, *_changeCategoryButton, *_changeTagButton; static void OnEnter(void* caller); }; diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 0dbec39..1234eba 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -121,7 +121,8 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, } _tags = new QString[user->GetTagsNumber()] ; - for(i=0, tagIt = user->_tags.begin(); + _tags[0] = _("No Tag"); + for(i=1, tagIt = user->_tags.begin(); tagIt != user->_tags.end(); tagIt++, i++) { @@ -246,7 +247,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()-1); setItemDelegateForColumn(CATEGORY, categoryEditor); - ChoiceDelegate* tagEditor = new ChoiceDelegate(this, _tags, user->GetTagsNumber()); + ChoiceDelegate* tagEditor = new ChoiceDelegate(this, _tags, user->GetTagsNumber()+1); setItemDelegateForColumn(TAG, tagEditor); ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts); @@ -405,7 +406,10 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (!fix && !op.meta) setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str()))); - setItem(line, TAG, new QTableWidgetItem(_(tag.name.toStdString().c_str()))); + if (tag.id) + setItem(line, TAG, new QTableWidgetItem(_(tag.name.toStdString().c_str()))); + else + setItem(line, TAG, new QTableWidgetItem("")); checkBox = new QCheckBox(); checkBox->setCheckState(Qt::Unchecked); @@ -448,6 +452,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (op.meta) resizeColumnToContents(TREE); resizeColumnToContents(CATEGORY); + resizeColumnToContents(TAG); resizeColumnToContents(ACCOUNT); } } @@ -1034,6 +1039,7 @@ void GridAccount::OnOperationModified(int row, int col) catch (User::TagNotFound e) { op_complete++; + setItem(row, TAG, new QTableWidgetItem("")); } op_complete--; } @@ -1117,6 +1123,11 @@ void GridAccount::OnOperationModified(int row, int col) if (need_insertion) InsertIntoGrid(new_op); + else + { + resizeColumnToContents(CATEGORY); + resizeColumnToContents(TAG); + } if (new_op.parent) {