Tag management : first version
This commit is contained in:
@@ -32,6 +32,7 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
||||
QPushButton* buttonOpen;
|
||||
QGroupBox* staticAccount = new QGroupBox(_("Unresolved accounts"));
|
||||
QGroupBox* staticCategory = new QGroupBox(_("Unresolved categories"));
|
||||
QGroupBox* staticTag = new QGroupBox(_("Unresolved tags"));
|
||||
|
||||
_icons[KissPanel::LOW_RES_ICON] = IMPORT_LOW_ICON;
|
||||
_icons[KissPanel::HIGH_RES_ICON] = IMPORT_ICON;
|
||||
@@ -76,6 +77,13 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
||||
_categoriesGrid->setHorizontalHeaderLabels(labels);
|
||||
_categoriesGrid->resizeColumnsToContents();
|
||||
|
||||
_tagsGrid = new QTableWidget(0, 3);
|
||||
_tagsGrid->verticalHeader()->setHidden(true);
|
||||
labels.clear();
|
||||
labels << _("File tag") << _("Tag name") << _("Internal tag");
|
||||
_tagsGrid->setHorizontalHeaderLabels(labels);
|
||||
_tagsGrid->resizeColumnsToContents();
|
||||
|
||||
{
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(_accountsGrid);
|
||||
@@ -90,7 +98,14 @@ ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
||||
staticCategory->setLayout(vbox);
|
||||
}
|
||||
|
||||
{
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(_tagsGrid);
|
||||
staticTag->setLayout(vbox);
|
||||
}
|
||||
|
||||
vbox2->addWidget(staticCategory);
|
||||
vbox2->addWidget(staticTag);
|
||||
|
||||
_operationsGrid = new GridAccount(kiss, this, false, false, false);
|
||||
connect(_operationsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnOperationModified(int, int)));
|
||||
@@ -145,6 +160,8 @@ void ImportPanel::ProcessFile()
|
||||
std::map<int, int> resolvedAccounts;
|
||||
QString* userCategories;
|
||||
std::map<int, int> resolvedCategories;
|
||||
QString* userTags;
|
||||
std::map<int, int> resolvedTags;
|
||||
QTableWidgetItem* item;
|
||||
|
||||
QString path = _fileTxt->text();
|
||||
@@ -153,6 +170,7 @@ void ImportPanel::ProcessFile()
|
||||
_buttonIntegrate->setEnabled(false);
|
||||
_accountsGrid->setRowCount(0);
|
||||
_categoriesGrid->setRowCount(0);
|
||||
_tagsGrid->setRowCount(0);
|
||||
_operationsGrid->setRowCount(0);
|
||||
|
||||
_importEngine = _kiss->GetImportEngine(path);
|
||||
@@ -163,7 +181,7 @@ void ImportPanel::ProcessFile()
|
||||
return ;
|
||||
}
|
||||
|
||||
_importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories);
|
||||
_importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories, _unresolvedTags);
|
||||
|
||||
if (_unresolvedAccounts.size())
|
||||
{
|
||||
@@ -225,7 +243,37 @@ void ImportPanel::ProcessFile()
|
||||
_categoriesGrid->layout();
|
||||
}
|
||||
|
||||
if (!_unresolvedAccounts.size() && !_unresolvedCategories.size())
|
||||
if (_unresolvedTags.size())
|
||||
{
|
||||
int nb_tags = user->GetTagsNumber();
|
||||
userTags = new QString[nb_tags+1];
|
||||
|
||||
userTags[0] = _("Create one");
|
||||
|
||||
for(i=0; i<nb_tags; i++)
|
||||
userTags[i+1] = user->_tags[i].name;
|
||||
|
||||
ChoiceDelegate* tagEditor = new ChoiceDelegate(this, userTags, nb_tags+1);
|
||||
_tagsGrid->setItemDelegateForColumn(2, tagEditor);
|
||||
|
||||
_buttonLoadOperations->setEnabled(true);
|
||||
|
||||
_tagsGrid->setRowCount(_unresolvedTags.size());
|
||||
|
||||
for (i=0; i<(int)_unresolvedTags.size(); i++)
|
||||
{
|
||||
item = new QTableWidgetItem(_unresolvedTags[i].name);
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||
_tagsGrid->setItem(i, 0, item);
|
||||
_tagsGrid->setItem(i, 1, new QTableWidgetItem(""));
|
||||
_tagsGrid->setItem(i, 2, new QTableWidgetItem(userTags[0]));
|
||||
}
|
||||
|
||||
_tagsGrid->resizeColumnsToContents();
|
||||
_tagsGrid->layout();
|
||||
}
|
||||
|
||||
if (!_unresolvedAccounts.size() && !_unresolvedCategories.size() && !_unresolvedTags.size())
|
||||
{
|
||||
OnLoadOperations();
|
||||
}
|
||||
@@ -234,12 +282,14 @@ void ImportPanel::ProcessFile()
|
||||
|
||||
void ImportPanel::OnLoadOperations()
|
||||
{
|
||||
int i, nbAccounts=0, nbCategories=0;
|
||||
int i, nbAccounts=0, nbCategories=0, nbTags=0;
|
||||
User* user = _kiss->GetUser();
|
||||
Account account;
|
||||
Category category;
|
||||
Tag tag;
|
||||
std::map<int, int> accounts;
|
||||
std::map<int, int> categories;
|
||||
std::map<int, int> tags;
|
||||
int oldid;
|
||||
|
||||
for(i=0; i<_accountsGrid->rowCount(); i++)
|
||||
@@ -264,7 +314,18 @@ void ImportPanel::OnLoadOperations()
|
||||
}
|
||||
}
|
||||
|
||||
if (nbAccounts || nbCategories)
|
||||
for(i=0; i<_tagsGrid->rowCount(); i++)
|
||||
{
|
||||
if (_tagsGrid->item(i, 2)->text() == _("Create one"))
|
||||
nbTags++;
|
||||
else
|
||||
{
|
||||
oldid = _unresolvedTags[i].id;
|
||||
tags[oldid] = user->GetTagId(_tagsGrid->item(i, 2)->text());;
|
||||
}
|
||||
}
|
||||
|
||||
if (nbAccounts || nbCategories || nbTags)
|
||||
{
|
||||
QString message, v;
|
||||
|
||||
@@ -277,6 +338,9 @@ void ImportPanel::OnLoadOperations()
|
||||
if (nbCategories)
|
||||
message += v.sprintf(_("%d categories").toStdString().c_str(), nbCategories);
|
||||
|
||||
if (nbTags)
|
||||
message += v.sprintf(_("%d tags").toStdString().c_str(), nbTags);
|
||||
|
||||
message += _(" will be created, is it ok ?");
|
||||
|
||||
if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
|
||||
@@ -328,10 +392,33 @@ void ImportPanel::OnLoadOperations()
|
||||
|
||||
_categoriesGrid->setRowCount(0);
|
||||
|
||||
for(i=0; i<_tagsGrid->rowCount(); i++)
|
||||
{
|
||||
if (_tagsGrid->item(i, 2)->text() == _("Create one"))
|
||||
{
|
||||
tag = _unresolvedTags[i] ;
|
||||
if (_tagsGrid->item(i, 1)->text().length())
|
||||
tag.name = _tagsGrid->item(i, 1)->text();
|
||||
else
|
||||
tag.name = _tagsGrid->item(i, 0)->text();
|
||||
|
||||
if (tag.name.length() == 0)
|
||||
{
|
||||
QMessageBox::critical(0, _("Error"), _("Tag ") + QString::number(i) + _(" must have a name"));
|
||||
return;
|
||||
}
|
||||
|
||||
oldid = tag.id;
|
||||
tags[oldid] = tag.id = _kiss->AddTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
_tagsGrid->setRowCount(0);
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
_operations = _importEngine->GetOperations(accounts, categories);
|
||||
_operations = _importEngine->GetOperations(accounts, categories, tags);
|
||||
|
||||
if (_operations->size())
|
||||
{
|
||||
@@ -431,8 +518,9 @@ void ImportPanel::OnOperationModified(int row, int col)
|
||||
{
|
||||
static bool update = false;
|
||||
|
||||
if (col != GridAccount::DESCRIPTION &&
|
||||
col != GridAccount::CATEGORY &&
|
||||
if (col != GridAccount::DESCRIPTION &&
|
||||
col != GridAccount::CATEGORY &&
|
||||
col != GridAccount::TAG &&
|
||||
col != GridAccount::ACCOUNT)
|
||||
return ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user