Updates for Qt6 + some fixes

This commit is contained in:
Grégory Soutadé 2023-03-06 20:32:17 +01:00
parent 259b163b11
commit 9677a077c6
30 changed files with 241 additions and 184 deletions

4
debian/changelog vendored
View File

@ -1,5 +1,5 @@
kisscount (0.8-1) unstable; urgency=low kisscount (0.9-1) unstable; urgency=low
* Initial release * Initial release
-- Grégory Soutadé <soutade@gmail.com> Sat, 8 Oct 2016 20:26:00 +0200 -- Grégory Soutadé <soutade@gmail.com> Sat, 3 Dec 2022 20:26:00 +0200

View File

@ -51,7 +51,7 @@ KissCount::KissCount(int& argc, char** argv) : QApplication(argc, argv), _user(0
_wxUI->close(); _wxUI->close();
throw s; throw s;
} }
_wxUI->ChangeUser(); _wxUI->ChangeUser();
_wxUI->setDisabled(false); _wxUI->setDisabled(false);
} }
@ -691,7 +691,7 @@ QFont KissCount::ExtractFont(QString strFont)
QString KissCount::CompactFont(const QFont& font) QString KissCount::CompactFont(const QFont& font)
{ {
QString res ; QString res ;
res = res.sprintf("%d;%d;%d;%d;", font.pointSize(), 0, 0, font.weight()); res = res.asprintf("%d;%d;%d;%d;", font.pointSize(), 0, 0, font.weight());
res += font.family(); res += font.family();
return res; return res;

View File

@ -30,24 +30,11 @@
#include <view/wxUI.hpp> #include <view/wxUI.hpp>
#define APP_VERSION "0.8" #define APP_VERSION "0.9"
#define ESCAPE_CHARS(s) s = s.replace("\"", " "); #define ESCAPE_CHARS(s) s = s.replace("\"", " ");
// #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'");
/*{ \
if (s.Find(wxT("\\\"")) == wxNOT_FOUND) \
s.Replace(wxT("\""), wxT("\\\""), true); \
if (s.Find(wxT("\\\'")) == wxNOT_FOUND) \
s.Replace(wxT("\'"), wxT("\\\'"), true); \
}
*/
#define UNESCAPE_CHARS(s) s = s.replace("\\\"", " "); #define UNESCAPE_CHARS(s) s = s.replace("\\\"", " ");
// #define UNESCAPE_CHARS(s) s = s.replace("\\\"", "\""); s = s.replace("\\\'", "\'");
/*{ \
s.Replace(wxT("\\\""), wxT("\""), true); \
s.Replace(wxT("\\\'"), wxT("\'"), true); \
}
*/
class wxUI; class wxUI;
class Database; class Database;
class ImportEngine; class ImportEngine;

View File

@ -529,7 +529,7 @@ void Database::LinkOrUnlinkOperation(User* user, Operation& op)
query.clear(); query.clear();
req = QString("SELECT id, account FROM operation WHERE description=\"%1\" AND month='%2' AND year='%3' AND amount='%4' AND meta='0' AND account !='%5' AND transfert=''") req = QString("SELECT id, account FROM operation WHERE description=\"%1\" AND month='%2' AND year='%3' AND amount='%4' AND meta='0' AND account !='%5' AND transfert=''")
.arg(op.description, QString::number(op.month), QString::number(op.year), v.sprintf("%d", -op.amount), QString::number(op.account)); .arg(op.description, QString::number(op.month), QString::number(op.year), v.asprintf("%d", -op.amount), QString::number(op.account));
EXECUTE_SQL_QUERY(req, ); EXECUTE_SQL_QUERY(req, );
@ -578,7 +578,7 @@ void Database::UpdateOperation(User* user, Operation& op, bool checkTransfert)
req = "UPDATE operation SET parent='%1', account='%2', year='%3', month='%4', day='%5', amount='%6', description=:description, category='%8', tag='%9'" ; req = "UPDATE operation SET parent='%1', account='%2', year='%3', month='%4', day='%5', amount='%6', description=:description, category='%8', tag='%9'" ;
req = req.arg((op.parent) ? QString::number(op.parent) : "", QString::number(op.account), QString::number(op.year), QString::number(op.month), req = req.arg((op.parent) ? QString::number(op.parent) : "", QString::number(op.account), QString::number(op.year), QString::number(op.month),
QString::number(op.day), v.sprintf("%d", op.amount), QString::number(op.category), QString::number(op.tag)); QString::number(op.day), v.asprintf("%d", op.amount), QString::number(op.category), QString::number(op.tag));
req += ", fix_cost='%1', checked='%2', transfert='%3', meta='%4', virtual='%5', formula=:formula WHERE id='%7'"; req += ", fix_cost='%1', checked='%2', transfert='%3', meta='%4', virtual='%5', formula=:formula WHERE id='%7'";
req = req.arg(QString::number(op.fix_cost), QString::number(op.checked), (op.transfert) ? QString::number(op.transfert): "", req = req.arg(QString::number(op.fix_cost), QString::number(op.checked), (op.transfert) ? QString::number(op.transfert): "",
QString::number(op.meta), QString::number(op._virtual), QString::number(op.id)); QString::number(op.meta), QString::number(op._virtual), QString::number(op.id));
@ -604,7 +604,7 @@ int Database::AddOperation(User* user, Operation& op, bool checkTransfert)
req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'tag', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual', 'checked') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', :description" ; req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'tag', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual', 'checked') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', :description" ;
req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year), req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year),
QString::number(op.month), QString::number(op.day), v.sprintf("%d", op.amount)); QString::number(op.month), QString::number(op.day), v.asprintf("%d", op.amount));
req += ", '%1', '%2', '%3', :formula, '%4', '%5', '%6', '%7')"; req += ", '%1', '%2', '%3', :formula, '%4', '%5', '%6', '%7')";
req = req.arg(QString::number(op.category), QString::number(op.tag), QString::number(op.fix_cost), (op.transfert) ? QString::number(op.transfert): "", req = req.arg(QString::number(op.category), QString::number(op.tag), QString::number(op.fix_cost), (op.transfert) ? QString::number(op.transfert): "",
QString::number(op.meta), QString::number(op._virtual), QString::number(op.checked)); QString::number(op.meta), QString::number(op._virtual), QString::number(op.checked));
@ -775,7 +775,7 @@ void Database::SetAccountAmount(int accountId, int month, int year, int amount)
QSqlQuery query(_db); QSqlQuery query(_db);
req = "INSERT or REPLACE INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('%1', '%2', '%3', '%4')" ; req = "INSERT or REPLACE INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('%1', '%2', '%3', '%4')" ;
req = req.arg(QString::number(accountId), QString::number(year), QString::number(month), v.sprintf("%d", amount)); req = req.arg(QString::number(accountId), QString::number(year), QString::number(month), v.asprintf("%d", amount));
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
@ -1271,7 +1271,7 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT
req = "INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES " ; req = "INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES " ;
req += "('%1', '%2', '%3', '%4')"; req += "('%1', '%2', '%3', '%4')";
req = req.arg(QString::number(it->id), QString::number(yearTo), QString::number(monthTo), v.sprintf("%d", amount)); req = req.arg(QString::number(it->id), QString::number(yearTo), QString::number(monthTo), v.asprintf("%d", amount));
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
@ -1397,9 +1397,12 @@ void Database::UpdatePreference(User* user, const QString& preference)
EXECUTE_SQL_UPDATE(req, ); EXECUTE_SQL_UPDATE(req, );
} }
std::vector<Operation>* Database::Search(User* user, QString* description, QDate* dateFrom, QDate* dateTo, std::vector<Operation>* Database::Search(User* user, QString* description,
int* amountFrom, int* amountTo, QDate* dateFrom, QDate* dateTo,
std::vector<int> categories, int types, std::vector<int> accounts, bool wildcards, std::vector<int> tags) int* amountFrom, int* amountTo,
std::vector<int> categories, int types,
std::vector<int> accounts, bool wildcards,
std::vector<int> tags)
{ {
QSqlRecord set; QSqlRecord set;
QSqlQuery query(_db); QSqlQuery query(_db);
@ -1466,13 +1469,13 @@ std::vector<Operation>* Database::Search(User* user, QString* description, QDate
if (amountFrom) if (amountFrom)
{ {
if (firstCond) req += " AND " ; else firstCond = true; if (firstCond) req += " AND " ; else firstCond = true;
req += "ABS(amount) >= " + v.sprintf("%d", *amountFrom); req += "ABS(amount) >= " + v.asprintf("%d", *amountFrom);
} }
if (amountTo) if (amountTo)
{ {
if (firstCond) req += " AND " ; else firstCond = true; if (firstCond) req += " AND " ; else firstCond = true;
req += "ABS(amount) <= " + v.sprintf("%d", *amountTo); req += "ABS(amount) <= " + v.asprintf("%d", *amountTo);
} }
if (categories.size()) if (categories.size())

View File

@ -179,7 +179,8 @@ public:
std::vector<Operation>* Search(User* user, QString* description, QDate* dateFrom, QDate* dateTo, std::vector<Operation>* Search(User* user, QString* description, QDate* dateFrom, QDate* dateTo,
int* amountFrom, int* amountTo, int* amountFrom, int* amountTo,
std::vector<int> categories, int types, std::vector<int> accounts, bool wildcards, std::vector<int> tags); std::vector<int> categories, int types, std::vector<int> accounts,
bool wildcards, std::vector<int> tags);
void GetStats(User* user, int monthFrom, int yearFrom, int monthTo, void GetStats(User* user, int monthFrom, int yearFrom, int monthTo,
int yearTo, std::map<int, std::map<int, std::map<int, int> > >* accountAmounts, int yearTo, std::map<int, std::map<int, std::map<int, int> > >* accountAmounts,

View File

@ -48,8 +48,8 @@ bool CSVExportEngine::SaveAccounts()
Account account; Account account;
std::map<int, int>::iterator it; std::map<int, int>::iterator it;
*_writer << "Accounts" << endl << endl; *_writer << "Accounts" << Qt::endl << Qt::endl;
*_writer << "id;name;number;blocked;virtual;hidden" << endl; *_writer << "id;name;number;blocked;virtual;hidden" << Qt::endl;
for(it=_accounts.begin(); it!=_accounts.end(); it++) for(it=_accounts.begin(); it!=_accounts.end(); it++)
{ {
@ -78,10 +78,10 @@ bool CSVExportEngine::SaveAccounts()
// *_writer << (account.is_owner ? "1" : "0") << ";"; // *_writer << (account.is_owner ? "1" : "0") << ";";
*_writer << (account._virtual ? "1" : "0") << ";"; *_writer << (account._virtual ? "1" : "0") << ";";
*_writer << (account.hidden ? "1" : "0"); *_writer << (account.hidden ? "1" : "0");
*_writer << endl; *_writer << Qt::endl;
} }
*_writer << endl << endl; *_writer << Qt::endl << Qt::endl;
return true; return true;
} }
@ -91,19 +91,19 @@ bool CSVExportEngine::SaveAccountAmounts()
std::map<AccountAmount, int, AccountAmount>::iterator it; std::map<AccountAmount, int, AccountAmount>::iterator it;
QString v; QString v;
*_writer << "Account Amounts" << endl << endl; *_writer << "Account Amounts" << Qt::endl << Qt::endl;
*_writer << "id;month;year;amount" << endl; *_writer << "id;month;year;amount" << Qt::endl;
for(it=_accountAmounts.begin(); it!=_accountAmounts.end(); it++) for(it=_accountAmounts.begin(); it!=_accountAmounts.end(); it++)
{ {
*_writer << QString::number(it->first.account) << ";"; *_writer << QString::number(it->first.account) << ";";
*_writer << QString::number(it->first.month+1) << ";"; *_writer << QString::number(it->first.month+1) << ";";
*_writer << QString::number(it->first.year) << ";"; *_writer << QString::number(it->first.year) << ";";
*_writer << v.sprintf("%d", it->second); *_writer << v.asprintf("%d", it->second);
*_writer << endl; *_writer << Qt::endl;
} }
*_writer << endl << endl; *_writer << Qt::endl << Qt::endl;
return true; return true;
} }
@ -115,8 +115,8 @@ bool CSVExportEngine::SaveCategories()
int rgb; int rgb;
QString v; QString v;
*_writer << "Categories" << endl << endl; *_writer << "Categories" << Qt::endl << Qt::endl;
*_writer << "id;parent;name;font;backcolor;forecolor;fix_cost" << endl; *_writer << "id;parent;name;font;backcolor;forecolor;fix_cost" << Qt::endl;
for(it=_categories.begin(); it!=_categories.end(); it++) for(it=_categories.begin(); it!=_categories.end(); it++)
{ {
@ -131,16 +131,16 @@ bool CSVExportEngine::SaveCategories()
rgb = category.backcolor.blue(); rgb = category.backcolor.blue();
rgb |= category.backcolor.green() << 8; rgb |= category.backcolor.green() << 8;
rgb |= category.backcolor.red() << 16; rgb |= category.backcolor.red() << 16;
*_writer << v.sprintf("0x%08X", rgb) << ";"; *_writer << v.asprintf("0x%08X", rgb) << ";";
rgb = category.forecolor.blue(); rgb = category.forecolor.blue();
rgb |= category.forecolor.green() << 8; rgb |= category.forecolor.green() << 8;
rgb |= category.forecolor.red() << 16; rgb |= category.forecolor.red() << 16;
*_writer << v.sprintf("0x%08X", rgb) << ";"; *_writer << v.asprintf("0x%08X", rgb) << ";";
*_writer << (category.fix_cost ? "1" : "0"); *_writer << (category.fix_cost ? "1" : "0");
*_writer << endl; *_writer << Qt::endl;
} }
*_writer << endl << endl; *_writer << Qt::endl << Qt::endl;
return true; return true;
} }
@ -151,8 +151,8 @@ bool CSVExportEngine::SaveTags()
std::map<int, int>::iterator it; std::map<int, int>::iterator it;
QString v; QString v;
*_writer << "Tags" << endl << endl; *_writer << "Tags" << Qt::endl << Qt::endl;
*_writer << "id;name" << endl; *_writer << "id;name" << Qt::endl;
for(it=_tags.begin(); it!=_tags.end(); it++) for(it=_tags.begin(); it!=_tags.end(); it++)
{ {
@ -162,10 +162,10 @@ bool CSVExportEngine::SaveTags()
*_writer << QString::number(tag.id) << ";"; *_writer << QString::number(tag.id) << ";";
*_writer << "\"" << tag.name << "\""; *_writer << "\"" << tag.name << "\"";
*_writer << endl; *_writer << Qt::endl;
} }
*_writer << endl << endl; *_writer << Qt::endl << Qt::endl;
return true; return true;
} }
@ -175,8 +175,8 @@ bool CSVExportEngine::SaveOperations(std::vector<Operation>* operations)
std::vector<Operation>::iterator it; std::vector<Operation>::iterator it;
QString v; QString v;
*_writer << "Operations" << endl << endl; *_writer << "Operations" << Qt::endl << Qt::endl;
*_writer << "id;parent;day;month;year;amount;description;category;fix_cost;account;checked;transfert;formula;meta;virtual;tag" << endl; *_writer << "id;parent;day;month;year;amount;description;category;fix_cost;account;checked;transfert;formula;meta;virtual;tag" << Qt::endl;
for(it=operations->begin(); it!=operations->end(); it++) for(it=operations->begin(); it!=operations->end(); it++)
{ {
@ -187,7 +187,7 @@ bool CSVExportEngine::SaveOperations(std::vector<Operation>* operations)
*_writer << QString::number(it->day+1) << ";"; *_writer << QString::number(it->day+1) << ";";
*_writer << QString::number(it->month+1) << ";"; *_writer << QString::number(it->month+1) << ";";
*_writer << QString::number(it->year) << ";"; *_writer << QString::number(it->year) << ";";
*_writer << v.sprintf("%d", it->amount) << ";"; *_writer << v.asprintf("%d", it->amount) << ";";
*_writer << "\"" << it->description << "\"" << ";"; *_writer << "\"" << it->description << "\"" << ";";
*_writer << QString::number(it->category) << ";"; *_writer << QString::number(it->category) << ";";
*_writer << (it->fix_cost ? "1" : "0") << ";"; *_writer << (it->fix_cost ? "1" : "0") << ";";
@ -198,10 +198,10 @@ bool CSVExportEngine::SaveOperations(std::vector<Operation>* operations)
*_writer << (it->meta ? "1" : "0") << ";"; *_writer << (it->meta ? "1" : "0") << ";";
*_writer << (it->_virtual ? "1" : "0") << ";"; *_writer << (it->_virtual ? "1" : "0") << ";";
*_writer << QString::number(it->tag); *_writer << QString::number(it->tag);
*_writer << endl; *_writer << Qt::endl;
} }
*_writer << endl << endl; *_writer << Qt::endl << Qt::endl;
return true; return true;
} }

View File

@ -95,7 +95,7 @@ bool XMLExportEngine::SaveAccountAmounts()
_writer->writeAttribute("account", QString::number(it->first.account)); _writer->writeAttribute("account", QString::number(it->first.account));
_writer->writeAttribute("month", QString::number(it->first.month)); _writer->writeAttribute("month", QString::number(it->first.month));
_writer->writeAttribute("year", QString::number(it->first.year)); _writer->writeAttribute("year", QString::number(it->first.year));
_writer->writeAttribute("amount", v.sprintf("%d", it->second)); _writer->writeAttribute("amount", v.asprintf("%d", it->second));
_writer->writeEndElement(); _writer->writeEndElement();
} }
@ -123,11 +123,11 @@ bool XMLExportEngine::SaveCategories()
rgb = category.backcolor.blue(); rgb = category.backcolor.blue();
rgb |= category.backcolor.green() << 8; rgb |= category.backcolor.green() << 8;
rgb |= category.backcolor.red() << 16; rgb |= category.backcolor.red() << 16;
_writer->writeAttribute("backcolor", v.sprintf("0x%08X", rgb)); _writer->writeAttribute("backcolor", v.asprintf("0x%08X", rgb));
rgb = category.forecolor.blue(); rgb = category.forecolor.blue();
rgb |= category.forecolor.green() << 8; rgb |= category.forecolor.green() << 8;
rgb |= category.forecolor.red() << 16; rgb |= category.forecolor.red() << 16;
_writer->writeAttribute("forecolor", v.sprintf("0x%08X", rgb)); _writer->writeAttribute("forecolor", v.asprintf("0x%08X", rgb));
_writer->writeAttribute("fix_cost", (category.fix_cost ? "1" : "0")); _writer->writeAttribute("fix_cost", (category.fix_cost ? "1" : "0"));
_writer->writeEndElement(); _writer->writeEndElement();
} }
@ -171,7 +171,7 @@ bool XMLExportEngine::SaveOperations(std::vector<Operation>* operations)
_writer->writeAttribute("day", QString::number(it->day)); _writer->writeAttribute("day", QString::number(it->day));
_writer->writeAttribute("month", QString::number(it->month)); _writer->writeAttribute("month", QString::number(it->month));
_writer->writeAttribute("year", QString::number(it->year)); _writer->writeAttribute("year", QString::number(it->year));
_writer->writeAttribute("amount", v.sprintf("%d", it->amount)); _writer->writeAttribute("amount", v.asprintf("%d", it->amount));
_writer->writeAttribute("description", it->description); _writer->writeAttribute("description", it->description);
_writer->writeAttribute("category", QString::number(it->category)); _writer->writeAttribute("category", QString::number(it->category));
_writer->writeAttribute("tag", QString::number(it->tag)); _writer->writeAttribute("tag", QString::number(it->tag));

View File

@ -24,16 +24,16 @@
static GrisbiImportEngine grisbiImportEngine; static GrisbiImportEngine grisbiImportEngine;
void GrisbiImportEngine::LoadAccount(const QXmlAttributes& attrs) void GrisbiImportEngine::LoadAccount(const QXmlStreamAttributes& attrs)
{ {
int id, i; int id, i;
QString account_number, name, key; QString account_number, name, key;
Account ac; Account ac;
name = attrs.value("name"); name = *attrs.value("name").string();
id = attrs.value("Number").toInt(); id = attrs.value("Number").toInt();
account_number = attrs.value("Bank_account_number"); account_number = *attrs.value("Bank_account_number").string();
key = attrs.value("Key"); key = *attrs.value("Key").string();
account_number += key; account_number += key;
@ -61,13 +61,13 @@ void GrisbiImportEngine::LoadAccount(const QXmlAttributes& attrs)
_unresolvedAccounts.push_back(ac); _unresolvedAccounts.push_back(ac);
} }
void GrisbiImportEngine::LoadCategory(const QXmlAttributes& attrs) void GrisbiImportEngine::LoadCategory(const QXmlStreamAttributes& attrs)
{ {
QString name; QString name;
int id, i; int id, i;
Category cat; Category cat;
name = attrs.value("Na"); name = *attrs.value("Na").string();
id = attrs.value("Nb").toInt(); id = attrs.value("Nb").toInt();
UNESCAPE_CHARS(name); UNESCAPE_CHARS(name);
@ -91,7 +91,7 @@ void GrisbiImportEngine::LoadCategory(const QXmlAttributes& attrs)
_unresolvedCategories.push_back(cat); _unresolvedCategories.push_back(cat);
} }
void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs) void GrisbiImportEngine::LoadOperation(const QXmlStreamAttributes& attrs)
{ {
static int id=0; static int id=0;
Operation op; Operation op;
@ -111,13 +111,13 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs)
op.account = _accounts[attrs.value("Ac").toInt()]; op.account = _accounts[attrs.value("Ac").toInt()];
date = QDate::fromString(attrs.value("Dt"), "MM/dd/yyyy"); date = QDate::fromString(*attrs.value("Dt").string(), QString("MM/dd/yyyy"));
op.day = date.day(); op.day = date.day();
op.month = date.month(); op.month = date.month();
op.year = date.year(); op.year = date.year();
op.amount = attrs.value("Am").toInt(); op.amount = attrs.value("Am").toInt();
op.category = _categories[attrs.value("Ca").toInt()]; op.category = _categories[attrs.value("Ca").toInt()];
op.description = attrs.value("No"); op.description = *attrs.value("No").string();
UNESCAPE_CHARS(op.description); UNESCAPE_CHARS(op.description);
@ -127,7 +127,7 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs)
MatchPattern(op.description, op); MatchPattern(op.description, op);
} }
bool GrisbiImportEngine::startElement (const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& attrs) bool GrisbiImportEngine::startElement (QStringRef qName, const QXmlStreamAttributes& attrs)
{ {
static char first = 0; static char first = 0;
@ -140,10 +140,10 @@ bool GrisbiImportEngine::startElement (const QString& namespaceURI, const QStrin
if (qName == "General") if (qName == "General")
{ {
if (attrs.value("File_version") < "0.6.0") if (*attrs.value("File_version").string() < "0.6.0")
throw "Unsupported version !"; throw "Unsupported version !";
if (attrs.value("Crypt_file") == "1") if (*attrs.value("Crypt_file").string() == "1")
throw "Crypted file !"; throw "Crypted file !";
} }
@ -165,8 +165,6 @@ GrisbiImportEngine::GrisbiImportEngine()
_shortExt = ".gsb"; _shortExt = ".gsb";
_longExt = _("Grisbi files (*.gsb)"); _longExt = _("Grisbi files (*.gsb)");
_sax.setContentHandler(this);
} }
GrisbiImportEngine::~GrisbiImportEngine() GrisbiImportEngine::~GrisbiImportEngine()
@ -177,23 +175,35 @@ bool GrisbiImportEngine::HandleFile(const QString& path, User* user, Database* d
{ {
bool res = false; bool res = false;
QFile file(path); QFile file(path);
QXmlStreamReader::TokenType token;
if (!ImportEngine::HandleFile(path, user, db, kiss)) return false; if (!ImportEngine::HandleFile(path, user, db, kiss)) return false;
QXmlInputSource *source = new QXmlInputSource(&file); QXmlStreamReader reader(&file);
try try
{ {
res = _sax.parse(source, false); while (!reader.atEnd()) {
token = reader.readNext();
if (token == QXmlStreamReader::StartElement)
startElement(reader.name(), reader.attributes());
}
if (reader.hasError()) {
throw reader.errorString();
}
LinkChilds(); LinkChilds();
} }
catch (const char* s) catch (const char* s)
{ {
std::cout << "GrisbiImportEngine :: " << s << std::endl; std::cout << "GrisbiImportEngine : " << s << std::endl;
res = false;
}
catch (QString& e)
{
std::cout << "GrisbiImportEngine : " << e.toStdString() << std::endl;
res = false; res = false;
} }
file.close(); file.close();
delete source;
return res; return res;
} }

View File

@ -20,12 +20,11 @@
#ifndef GRISBIIMPORTENGINE_H #ifndef GRISBIIMPORTENGINE_H
#define GRISBIIMPORTENGINE_H #define GRISBIIMPORTENGINE_H
#include <QXmlDefaultHandler> #include <QXmlStreamAttributes>
#include <QXmlAttributes>
#include "ImportEngine.hpp" #include "ImportEngine.hpp"
class GrisbiImportEngine : public ImportEngine, public QXmlDefaultHandler { class GrisbiImportEngine : public ImportEngine {
public: public:
GrisbiImportEngine(); GrisbiImportEngine();
~GrisbiImportEngine(); ~GrisbiImportEngine();
@ -33,13 +32,12 @@ public:
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss); virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss);
private: private:
QXmlSimpleReader _sax;
bool startElement (const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); bool startElement (QStringRef qName, const QXmlStreamAttributes& atts);
void LoadAccount(const QXmlAttributes& atts); void LoadAccount(const QXmlStreamAttributes& atts);
void LoadCategory(const QXmlAttributes& atts); void LoadCategory(const QXmlStreamAttributes& atts);
void LoadOperation(const QXmlAttributes& atts); void LoadOperation(const QXmlStreamAttributes& atts);
}; };
#endif #endif

View File

@ -30,8 +30,6 @@ XMLImportEngine::XMLImportEngine()
_shortExt = ".xml"; _shortExt = ".xml";
_longExt = _("KissCount xml files (*.xml)"); _longExt = _("KissCount xml files (*.xml)");
_sax.setContentHandler(this);
} }
XMLImportEngine::~XMLImportEngine() XMLImportEngine::~XMLImportEngine()
@ -42,7 +40,8 @@ bool XMLImportEngine::HandleFile(const QString& path, User* user, Database* db,
{ {
bool res = false; bool res = false;
QFile file(path); QFile file(path);
QXmlStreamReader::TokenType token;
if (!ImportEngine::HandleFile(path, user, db, kiss)) return false; if (!ImportEngine::HandleFile(path, user, db, kiss)) return false;
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
@ -51,26 +50,37 @@ bool XMLImportEngine::HandleFile(const QString& path, User* user, Database* db,
return false; return false;
} }
QXmlInputSource *source = new QXmlInputSource(&file); QXmlStreamReader reader(&file);
try try
{ {
res = _sax.parse(source, false); while (!reader.atEnd()) {
token = reader.readNext();
if (token == QXmlStreamReader::StartElement)
startElement(reader.name(), reader.attributes());
}
if (reader.hasError()) {
throw reader.errorString();
}
LinkChilds(); LinkChilds();
} }
catch (const char* s) catch (const char* s)
{ {
std::cout << "XMLImportEngine :: " << s << std::endl; std::cout << "XMLImportEngine : " << s << std::endl;
res = false;
}
catch (QString& e)
{
std::cout << "XMLImportEngine : " << e.toStdString() << std::endl;
res = false; res = false;
} }
file.close(); file.close();
delete source;
return res; return res;
} }
bool XMLImportEngine::startElement (const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& attrs) bool XMLImportEngine::startElement (QStringRef qName, const QXmlStreamAttributes& attrs)
{ {
if (qName == "kisscount") if (qName == "kisscount")
{ {
@ -93,11 +103,11 @@ bool XMLImportEngine::startElement (const QString& namespaceURI, const QString&
else if (qName == "operation") else if (qName == "operation")
LoadOperation(attrs); LoadOperation(attrs);
else else
std::cout << "Unknown element : '" << qName.toStdString() << "'" << std::endl; std::cout << "Unknown element : '" << qName.toString().toStdString() << "'" << std::endl;
return true; return true;
} }
void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs) void XMLImportEngine::LoadAccount(const QXmlStreamAttributes& attrs)
{ {
int id; int id;
Account ac; Account ac;
@ -105,15 +115,15 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
ac.id = 0; ac.id = 0;
ac.name = attrs.value("name"); ac.name = *attrs.value("name").string();
ac.id = id = attrs.value("id").toInt(); ac.id = id = attrs.value("id").toInt();
ac.number = attrs.value("number"); ac.number = *attrs.value("number").string();
ac.blocked = (attrs.value("blocked") == "1"); ac.blocked = (attrs.value("blocked") == "1");
ac._virtual = (attrs.value("virtual") == "1"); ac._virtual = (attrs.value("virtual") == "1");
ac.hidden = (attrs.value("hidden") == "1"); ac.hidden = (attrs.value("hidden") == "1");
ac._default = (attrs.value("default") == "1"); ac._default = (attrs.value("default") == "1");
ac.start_date = (QDate::fromString("dd/MM/yyyy", attrs.value("start"))); ac.start_date = (QDate::fromString(*attrs.value("start").string(), QString("dd/MM/yyyy")));
ac.end_date = (QDate::fromString("dd/MM/yyyy", attrs.value("start"))); ac.end_date = (QDate::fromString(*attrs.value("start").string(), QString("dd/MM/yyyy")));
UNESCAPE_CHARS(ac.name); UNESCAPE_CHARS(ac.name);
UNESCAPE_CHARS(ac.number); UNESCAPE_CHARS(ac.number);
@ -148,7 +158,7 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
_unresolvedAccounts.push_back(ac); _unresolvedAccounts.push_back(ac);
} }
void XMLImportEngine::LoadAccountAmount(const QXmlAttributes& attrs) void XMLImportEngine::LoadAccountAmount(const QXmlStreamAttributes& attrs)
{ {
AccountAmount accountAmount; AccountAmount accountAmount;
int amount; int amount;
@ -161,7 +171,7 @@ void XMLImportEngine::LoadAccountAmount(const QXmlAttributes& attrs)
_accountAmounts[accountAmount] = amount; _accountAmounts[accountAmount] = amount;
} }
void XMLImportEngine::LoadCategory(const QXmlAttributes& attrs) void XMLImportEngine::LoadCategory(const QXmlStreamAttributes& attrs)
{ {
QString name; QString name;
int id; int id;
@ -171,10 +181,10 @@ void XMLImportEngine::LoadCategory(const QXmlAttributes& attrs)
cat.fix_cost = false; cat.fix_cost = false;
cat.name = name = attrs.value("name"); cat.name = name = *attrs.value("name").string();
cat.id = id = attrs.value("id").toInt(); cat.id = id = attrs.value("id").toInt();
cat.parent = attrs.value("parent").toInt(); cat.parent = attrs.value("parent").toInt();
cat.font = attrs.value("font"); cat.font = *attrs.value("font").string();
if (attrs.value("backcolor") != "") if (attrs.value("backcolor") != "")
{ {
@ -210,14 +220,14 @@ void XMLImportEngine::LoadCategory(const QXmlAttributes& attrs)
_unresolvedCategories.push_back(cat); _unresolvedCategories.push_back(cat);
} }
void XMLImportEngine::LoadTag(const QXmlAttributes& attrs) void XMLImportEngine::LoadTag(const QXmlStreamAttributes& attrs)
{ {
QString name; QString name;
int id; int id;
Tag tag; Tag tag;
static int unknownTag = 0; static int unknownTag = 0;
tag.name = name = attrs.value("name"); tag.name = name = *attrs.value("name").string();
tag.id = id = attrs.value("id").toInt(); tag.id = id = attrs.value("id").toInt();
UNESCAPE_CHARS(tag.name); UNESCAPE_CHARS(tag.name);
@ -236,7 +246,7 @@ void XMLImportEngine::LoadTag(const QXmlAttributes& attrs)
_unresolvedTags.push_back(tag); _unresolvedTags.push_back(tag);
} }
void XMLImportEngine::LoadOperation(const QXmlAttributes& attrs) void XMLImportEngine::LoadOperation(const QXmlStreamAttributes& attrs)
{ {
Operation op; Operation op;
@ -246,14 +256,14 @@ void XMLImportEngine::LoadOperation(const QXmlAttributes& attrs)
op.month = attrs.value("month").toInt(); op.month = attrs.value("month").toInt();
op.year = attrs.value("year").toInt(); op.year = attrs.value("year").toInt();
op.amount = attrs.value("amount").toInt(); op.amount = attrs.value("amount").toInt();
op.description = attrs.value("description"); op.description = *attrs.value("description").string();
op.category = attrs.value("category").toInt(); op.category = attrs.value("category").toInt();
op.tag = attrs.value("tag").toInt(); op.tag = attrs.value("tag").toInt();
op.fix_cost = (attrs.value("fix_cost") == "1"); op.fix_cost = (attrs.value("fix_cost") == "1");
op.account = attrs.value("account").toInt(); op.account = attrs.value("account").toInt();
op.checked = (attrs.value("checked") == "1"); op.checked = (attrs.value("checked") == "1");
op.transfert = attrs.value("transfert").toInt(); op.transfert = attrs.value("transfert").toInt();
op.formula = attrs.value("formula"); op.formula = *attrs.value("formula").string();
op.meta = (attrs.value("meta") == "1"); op.meta = (attrs.value("meta") == "1");
op._virtual = (attrs.value("virtual") == "1"); op._virtual = (attrs.value("virtual") == "1");

View File

@ -20,12 +20,11 @@
#ifndef XMLIMPORTENGINE_H #ifndef XMLIMPORTENGINE_H
#define XMLIMPORTENGINE_H #define XMLIMPORTENGINE_H
#include <QXmlDefaultHandler> #include <QXmlStreamAttributes>
#include <QXmlAttributes>
#include "ImportEngine.hpp" #include "ImportEngine.hpp"
class XMLImportEngine : public ImportEngine, public QXmlDefaultHandler { class XMLImportEngine : public ImportEngine {
public: public:
XMLImportEngine(); XMLImportEngine();
~XMLImportEngine(); ~XMLImportEngine();
@ -33,15 +32,14 @@ public:
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss); virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss);
private: private:
QXmlSimpleReader _sax;
bool startElement (const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts); bool startElement (QStringRef qName, const QXmlStreamAttributes& atts);
void LoadAccount(const QXmlAttributes& atts); void LoadAccount(const QXmlStreamAttributes& atts);
void LoadAccountAmount(const QXmlAttributes& atts); void LoadAccountAmount(const QXmlStreamAttributes& atts);
void LoadCategory(const QXmlAttributes& atts); void LoadCategory(const QXmlStreamAttributes& atts);
void LoadTag(const QXmlAttributes& atts); void LoadTag(const QXmlStreamAttributes& atts);
void LoadOperation(const QXmlAttributes& atts); void LoadOperation(const QXmlStreamAttributes& atts);
}; };
#endif #endif

View File

@ -521,7 +521,7 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
_accountsGrid->setItem(curLine, ACCOUNT_NAME, new QTableWidgetItem(it->name)); _accountsGrid->setItem(curLine, ACCOUNT_NAME, new QTableWidgetItem(it->name));
value = _kiss->GetAccountAmount(it->id, month, year); value = _kiss->GetAccountAmount(it->id, month, year);
_accountsGrid->setItem(curLine, ACCOUNT_INIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)value/100))); _accountsGrid->setItem(curLine, ACCOUNT_INIT, new QTableWidgetItem(v.asprintf("%.2lf", (double)value/100)));
_accountsGrid->setItem(curLine, ACCOUNT_CUR, new QTableWidgetItem("")); _accountsGrid->setItem(curLine, ACCOUNT_CUR, new QTableWidgetItem(""));
_accountsGrid->setItem(curLine, ACCOUNT_FINAL, new QTableWidgetItem("")); _accountsGrid->setItem(curLine, ACCOUNT_FINAL, new QTableWidgetItem(""));
for (i=0; i<NUMBER_COLS_ACCOUNTS; i++) for (i=0; i<NUMBER_COLS_ACCOUNTS; i++)
@ -723,12 +723,12 @@ void AccountPanel::UpdateStats()
} }
balance = totalCredit - totalDebit; balance = totalCredit - totalDebit;
_statsGrid->item(CUR_CREDIT, 1)->setText(v.sprintf("%.2lf", (double)curCredit/100)); _statsGrid->item(CUR_CREDIT, 1)->setText(v.asprintf("%.2lf", (double)curCredit/100));
_statsGrid->item(CUR_DEBIT, 1)->setText(v.sprintf("%.2lf", (double)curDebit/100)); _statsGrid->item(CUR_DEBIT, 1)->setText(v.asprintf("%.2lf", (double)curDebit/100));
_statsGrid->item(TOTAL_CREDIT, 1)->setText(v.sprintf("%.2lf", (double)totalCredit/100)); _statsGrid->item(TOTAL_CREDIT, 1)->setText(v.asprintf("%.2lf", (double)totalCredit/100));
_statsGrid->item(TOTAL_DEBIT, 1)->setText(v.sprintf("%.2lf", (double)totalDebit/100)); _statsGrid->item(TOTAL_DEBIT, 1)->setText(v.asprintf("%.2lf", (double)totalDebit/100));
_statsGrid->item(BALANCE, 1)->setText(v.sprintf("%.2lf", (double)balance/100)); _statsGrid->item(BALANCE, 1)->setText(v.asprintf("%.2lf", (double)balance/100));
_statsGrid->item(BALANCE, 1)->setForeground((balance >= 0) ? QBrush(Qt::green) : QBrush(Qt::red)); _statsGrid->item(BALANCE, 1)->setForeground((balance >= 0) ? QBrush(Qt::green) : QBrush(Qt::red));
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++) for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
@ -744,13 +744,13 @@ void AccountPanel::UpdateStats()
value = _accountsInitValues[accountIt->id]; value = _accountsInitValues[accountIt->id];
if (mode == REAL_MODE) if (mode == REAL_MODE)
value -= (*virtuals)[accountIt->id]; value -= (*virtuals)[accountIt->id];
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf", (double)value/100)); _accountsGrid->item(i, ACCOUNT_INIT)->setText(v.asprintf("%.2lf", (double)value/100));
_accountsGrid->item(i, ACCOUNT_INIT)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_INIT)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = curAccountAmounts[day][accountIt->id]; value = curAccountAmounts[day][accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf", (double)value/100)); _accountsGrid->item(i, ACCOUNT_CUR)->setText(v.asprintf("%.2lf", (double)value/100));
_accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = finalAccountAmount[accountIt->id]; value = finalAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.sprintf("%.2lf", (double)value/100)); _accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.asprintf("%.2lf", (double)value/100));
_accountsGrid->item(i, ACCOUNT_FINAL)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_FINAL)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
} }
else else
@ -758,13 +758,13 @@ void AccountPanel::UpdateStats()
value = _accountsInitValues[accountIt->id] - (*virtuals)[accountIt->id]; value = _accountsInitValues[accountIt->id] - (*virtuals)[accountIt->id];
value2 = (*notChecked)[accountIt->id]; value2 = (*notChecked)[accountIt->id];
_accountsGrid->item(i, ACCOUNT_INIT)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100)); _accountsGrid->item(i, ACCOUNT_INIT)->setText(v.asprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100));
_accountsGrid->item(i, ACCOUNT_INIT)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_INIT)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = curAccountAmounts[day][accountIt->id]; value = curAccountAmounts[day][accountIt->id];
_accountsGrid->item(i, ACCOUNT_CUR)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100)); _accountsGrid->item(i, ACCOUNT_CUR)->setText(v.asprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100));
_accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_CUR)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
value = finalAccountAmount[accountIt->id]; value = finalAccountAmount[accountIt->id];
_accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.sprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100)); _accountsGrid->item(i, ACCOUNT_FINAL)->setText(v.asprintf("%.2lf (%.2lf)", (double)value/100, (double)(value-value2)/100));
_accountsGrid->item(i, ACCOUNT_FINAL)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red)); _accountsGrid->item(i, ACCOUNT_FINAL)->setForeground((value >= 0) ? QBrush(Qt::black) : QBrush(Qt::red));
} }
} }
@ -1013,7 +1013,7 @@ void AccountPanel::OnMenuDelete()
void AccountPanel::GenerateMonth(int month, int year) void AccountPanel::GenerateMonth(int month, int year)
{ {
QString s; QString s;
const QString syear = s.sprintf("%d", year); const QString syear = s.asprintf("%d", year);
QList<QTreeWidgetItem *> items = _tree->findItems(syear, Qt::MatchExactly|Qt::MatchRecursive); QList<QTreeWidgetItem *> items = _tree->findItems(syear, Qt::MatchExactly|Qt::MatchRecursive);
QTreeWidgetItem *root, *itemYear = 0, *itemMonth; QTreeWidgetItem *root, *itemYear = 0, *itemMonth;
std::map<int, std::vector<int> > ops ; std::map<int, std::vector<int> > ops ;

View File

@ -135,30 +135,32 @@ void CostRepartitionBanner::Reset()
void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit) void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit)
{ {
int i; int i, curVal;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
unsigned long value, percents, utotalDebit = totalDebit; unsigned long value = 0, percents, utotalDebit = totalDebit;
QString v; QString v;
QPieSeries* series = (QPieSeries*) (_pie->series()[0]); QPieSeries* series = (QPieSeries*) (_pie->series()[0]);
QList<QtCharts::QPieSlice*> slices = series->slices(); QList<QtCharts::QPieSlice*> slices = series->slices();
for(i=0; i<user->GetCategoriesNumber(); i++) for(i=0; i<user->GetCategoriesNumber(); i++)
{ {
curVal = abs(categoriesValues[i]);
if (totalDebit != 0) if (totalDebit != 0)
{ {
percents = ((categoriesValues[i]*(unsigned long)100))/utotalDebit; percents = ((curVal*(unsigned long)100))/utotalDebit;
} }
else else
percents = 0.0; percents = 0.0;
if (!i) if (!i)
_statsGrid->item(i, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents)); _statsGrid->item(i, 1)->setText(v.asprintf("%.2lf (%02d %%)", (double)curVal/100, (int)percents));
else else
{ {
_statsGrid->item(i+1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents)); _statsGrid->item(i+1, 1)->setText(v.asprintf("%.2lf (%02d %%)", (double)curVal/100, (int)percents));
slices[i-1]->setValue(categoriesValues[i] / 100); slices[i-1]->setValue(curVal / 100);
slices[i-1]->setLabelVisible(categoriesValues[i] != 0.0); slices[i-1]->setLabelVisible(curVal != 0.0);
} }
} }
@ -167,7 +169,7 @@ void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit)
percents = (value*100)/totalDebit; percents = (value*100)/totalDebit;
else else
percents = 0.0; percents = 0.0;
_statsGrid->item(1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)value/100, (int)percents)); _statsGrid->item(1, 1)->setText(v.asprintf("%.2lf (%02d %%)", (double)value/100, (int)percents));
_statsGrid->resizeColumnsToContents(); _statsGrid->resizeColumnsToContents();
} }

View File

@ -68,7 +68,12 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea
if (toSelect != -1) if (toSelect != -1)
{ {
_yearFrom->setCurrentIndex(toSelect); /* Index has not been changed if there is only one year */
if (toSelect == 0)
OnYearFromChange(toSelect);
else
_yearFrom->setCurrentIndex(toSelect);
toSelect=0; toSelect=0;
if (month != -1) if (month != -1)
{ {

View File

@ -335,15 +335,15 @@ void ImportPanel::OnLoadOperations()
if (nbAccounts) if (nbAccounts)
{ {
message += v.sprintf(_("%d accounts").toStdString().c_str(), nbAccounts); message += v.asprintf(_("%d accounts").toStdString().c_str(), nbAccounts);
if (nbCategories) message += _(" and "); if (nbCategories) message += _(" and ");
} }
if (nbCategories) if (nbCategories)
message += v.sprintf(_("%d categories").toStdString().c_str(), nbCategories); message += v.asprintf(_("%d categories").toStdString().c_str(), nbCategories);
if (nbTags) if (nbTags)
message += v.sprintf(_("%d tags").toStdString().c_str(), nbTags); message += v.asprintf(_("%d tags").toStdString().c_str(), nbTags);
message += _(" will be created, is it ok ?"); message += _(" will be created, is it ok ?");

View File

@ -22,6 +22,12 @@
#include "SearchPanel.hpp" #include "SearchPanel.hpp"
enum SEARCH_TYPE {
SEARCH_DEBIT = 0,
SEARCH_CREDIT,
SEARCH_DEBIT_AND_CREDIT
};
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) : SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
KissPanel(kiss, parent, lowResolution), _operations(0) KissPanel(kiss, parent, lowResolution), _operations(0)
{ {
@ -33,6 +39,7 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
QVBoxLayout *vbox = new QVBoxLayout; QVBoxLayout *vbox = new QVBoxLayout;
QVBoxLayout *vbox2 = new QVBoxLayout; QVBoxLayout *vbox2 = new QVBoxLayout;
QVBoxLayout *vbox3 = new QVBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout; QHBoxLayout *hbox = new QHBoxLayout;
_icons[KissPanel::LOW_RES_ICON] = SEARCH_LOW_ICON; _icons[KissPanel::LOW_RES_ICON] = SEARCH_LOW_ICON;
@ -72,8 +79,18 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
_categories[i] = _(categoryIt->name.toStdString().c_str()) ; _categories[i] = _(categoryIt->name.toStdString().c_str()) ;
} }
_searchType = new QComboBox();
_searchType->addItem(_("Debit"));
_searchType->addItem(_("Credit"));
_searchType->addItem(_("Debit+Credit"));
connect(_searchType, SIGNAL(currentIndexChanged(int)), this, SLOT(OnResultTypeChanged(int)));
_costRepartitionBanner = new CostRepartitionBanner(_kiss, this, _categories); _costRepartitionBanner = new CostRepartitionBanner(_kiss, this, _categories);
vbox3->addWidget(_searchType);
vbox3->addWidget(_costRepartitionBanner);
vbox2->addWidget(_changeAccountButton); vbox2->addWidget(_changeAccountButton);
vbox2->addWidget(_changeCategoryButton); vbox2->addWidget(_changeCategoryButton);
vbox2->addWidget(_changeTagButton); vbox2->addWidget(_changeTagButton);
@ -84,7 +101,7 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
hbox->addStretch(); hbox->addStretch();
hbox->addWidget(_grid); hbox->addWidget(_grid);
hbox->addStretch(); hbox->addStretch();
hbox->addWidget(_costRepartitionBanner, 2); hbox->addLayout(vbox3, 2);
vbox->addLayout(hbox, 2); vbox->addLayout(hbox, 2);
} }
@ -107,11 +124,12 @@ void SearchPanel::UpdateCostRepartition()
{ {
int i; int i;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
double total=0.0; int total=0;
std::vector<Operation>::iterator it; std::vector<Operation>::iterator it;
Account account; Account account;
Operation op; Operation op;
SEARCH_TYPE searchType = (SEARCH_TYPE) _searchType->currentIndex();
_costRepartitionBanner->Reset(); _costRepartitionBanner->Reset();
for (i=0; i<user->GetCategoriesNumber(); i++) for (i=0; i<user->GetCategoriesNumber(); i++)
@ -127,11 +145,14 @@ void SearchPanel::UpdateCostRepartition()
if (account.blocked && op.transfert && op.amount > 0) if (account.blocked && op.transfert && op.amount > 0)
op.amount = -op.amount; op.amount = -op.amount;
if (op.amount >= 0) continue;
_categoriesValues[_categoriesIndexes[op.category]] -= op.amount; if (searchType == SEARCH_DEBIT && op.amount > 0)
total -= op.amount; continue;
else if (searchType == SEARCH_CREDIT && op.amount < 0)
continue;
_categoriesValues[_categoriesIndexes[op.category]] += op.amount;
total += abs(op.amount);
} }
_costRepartitionBanner->UpdateCosts(_categoriesValues, total); _costRepartitionBanner->UpdateCosts(_categoriesValues, total);
@ -331,6 +352,11 @@ void SearchPanel::OnButtonRename()
NeedReload(); NeedReload();
} }
void SearchPanel::OnResultTypeChanged(int index)
{
OnButtonSearch();
}
void SearchPanel::OnShow() void SearchPanel::OnShow()
{ {
_wxUI->setWindowTitle(_kiss->GetUser()->_name + " - " + _("Search")); _wxUI->setWindowTitle(_kiss->GetUser()->_name + " - " + _("Search"));

View File

@ -21,6 +21,7 @@
#define SEARCHPANEL_H #define SEARCHPANEL_H
#include <QtGui> #include <QtGui>
#include <QComboBox>
#include "view.hpp" #include "view.hpp"
#include "grid/GridAccount.hpp" #include "grid/GridAccount.hpp"
@ -53,12 +54,15 @@ private slots:
void OnButtonChangeTag(); void OnButtonChangeTag();
void OnButtonRename(); void OnButtonRename();
void OnResultTypeChanged(int);
private: private:
void UpdateCostRepartition(); void UpdateCostRepartition();
std::vector<Operation> *_operations; std::vector<Operation> *_operations;
SearchBanner* _banner; SearchBanner* _banner;
GridAccount *_grid; GridAccount *_grid;
QComboBox *_searchType;
CostRepartitionBanner *_costRepartitionBanner; CostRepartitionBanner *_costRepartitionBanner;
QString* _categories; QString* _categories;
int *_categoriesValues; int *_categoriesValues;

View File

@ -93,7 +93,7 @@ void SnapshotsDialog::OnCreate()
int i; int i;
bak = Database::GetDatabaseFile() + ".bak."; bak = Database::GetDatabaseFile() + ".bak.";
bak += v.sprintf("%d.%02d.%02d", curDate.year(), curDate.month(), curDate.day()); bak += v.asprintf("%d.%02d.%02d", curDate.year(), curDate.month(), curDate.day());
if (dir.exists(bak)) if (dir.exists(bak))
{ {

View File

@ -165,7 +165,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
std::map<int, std::map<int, int> >::iterator accountYearIt; std::map<int, std::map<int, int> >::iterator accountYearIt;
std::map<int, int>::iterator accountMonthIt; std::map<int, int>::iterator accountMonthIt;
int total; int total;
int account, i, nbDays; int account, i, nbDays, nbTicks = 0;
QString value, v; QString value, v;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
QDate date, start, end; QDate date, start, end;
@ -195,6 +195,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
date = QDate(yearFrom, monthFrom+1, i+1); date = QDate(yearFrom, monthFrom+1, i+1);
xValue.setDate(date); xValue.setDate(date);
series->append(xValue.toMSecsSinceEpoch(), 0.0); series->append(xValue.toMSecsSinceEpoch(), 0.0);
nbTicks++;
} }
series->setName(_("0 line")); series->setName(_("0 line"));
@ -228,12 +229,13 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
// Line on 0 all over the years // Line on 0 all over the years
start = QDate(yearFrom, monthFrom+1, 1); start = QDate(yearFrom, monthFrom+1, 1);
end = QDate(yearTo, monthTo+1, 1); end = QDate(yearTo, monthTo+1, 1);
end = end.addMonths(1).addMonths(-1); end = end.addMonths(1);
date = start; date = start;
for (date = start; date <= end; date = date.addMonths(1)) for (date = start; date <= end; date = date.addMonths(1))
{ {
xValue.setDate(date); xValue.setDate(date);
series->append(xValue.toMSecsSinceEpoch(), 0.0); series->append(xValue.toMSecsSinceEpoch(), 0.0);
nbTicks++;
} }
axisX->setLabelsAngle(-60); axisX->setLabelsAngle(-60);
@ -282,9 +284,12 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
QLegend* legend = _plot->legend(); QLegend* legend = _plot->legend();
legend->setAlignment(Qt::AlignRight); legend->setAlignment(Qt::AlignRight);
_plot->addSeries(series0);
_plot->createDefaultAxes(); _plot->createDefaultAxes();
axisX->setTickCount(nbTicks);
_plot->setAxisX(axisX, series0); _plot->setAxisX(axisX, series0);
// _plot->addAxis(axisX, Qt::AlignRight);
if (!_chartView) if (!_chartView)
{ {
_chartView = new QChartView(_plot); _chartView = new QChartView(_plot);

View File

@ -25,16 +25,18 @@
#include <QPushButton> #include <QPushButton>
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QScreen>
#include "UsersDialog.hpp" #include "UsersDialog.hpp"
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog), _kiss(kiss), _wxUI(parent) UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) :
QDialog(parent, Qt::Dialog|Qt::WindowStaysOnTopHint), _kiss(kiss), _wxUI(parent)
{ {
QGridLayout* gridLayout; QGridLayout* gridLayout;
setWindowTitle(_("Users")); setWindowTitle(_("Users"));
setModal(true); setModal(true);
gridLayout = new QGridLayout(this); gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel(_("User "), this), 0, 0); gridLayout->addWidget(new QLabel(_("User "), this), 0, 0);
@ -64,15 +66,22 @@ UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog)
_users->addItem(*i); _users->addItem(*i);
} }
_users->setFocus();
if (users_list.size() == 0) if (users_list.size() == 0)
{ {
OnNewUser(); OnNewUser();
throw ExceptionNewUser(); throw ExceptionNewUser();
} }
else }
show();
void UsersDialog::showEvent(QShowEvent *event)
{
QDialog::showEvent(event);
// QRect scr = QApplication::primaryScreen()->geometry();
// move( scr.center() - rect().center() );
// activateWindow();
// raise();
// setFocus();
// std::cout << "SHOW EVENT" << std::endl;
} }
void UsersDialog::OnEnter() void UsersDialog::OnEnter()

View File

@ -35,6 +35,9 @@ public:
class ExceptionNewUser {}; class ExceptionNewUser {};
private:
void showEvent(QShowEvent *event);
private slots: private slots:
void OnEnter(); void OnEnter();
void OnOK(); void OnOK();

View File

@ -64,7 +64,7 @@ void CalendarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
else else
ac.end_date = _date; ac.end_date = _date;
} }
model->setData(index, qVariantFromValue(_date.toString(_dateFormat))); model->setData(index, QVariant::fromValue(_date.toString(_dateFormat)));
} }
void CalendarDelegate::setEditorData(QWidget *editor, void CalendarDelegate::setEditorData(QWidget *editor,

View File

@ -38,7 +38,7 @@ void ChoiceDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const const QModelIndex &index) const
{ {
QComboBox *combo = qobject_cast<QComboBox *>(editor); QComboBox *combo = qobject_cast<QComboBox *>(editor);
model->setData(index, qVariantFromValue(combo->currentText())); model->setData(index, QVariant::fromValue(combo->currentText()));
} }
void ChoiceDelegate::setEditorData(QWidget *editor, void ChoiceDelegate::setEditorData(QWidget *editor,

View File

@ -41,7 +41,7 @@ void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
s = QDate(_year, _month, combo->currentIndex()+1).toString(_dateFormat); s = QDate(_year, _month, combo->currentIndex()+1).toString(_dateFormat);
model->setData(index, qVariantFromValue(s)); model->setData(index, QVariant::fromValue(s));
} }
void DateDelegate::setEditorData(QWidget *editor, void DateDelegate::setEditorData(QWidget *editor,

View File

@ -35,7 +35,7 @@ void FloatDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
bool ok; bool ok;
double value = line->text().toDouble(&ok); double value = line->text().toDouble(&ok);
if (ok) if (ok)
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", value))); model->setData(index, QVariant::fromValue(s.asprintf("%.2lf", value)));
} }
void FloatDelegate::setEditorData(QWidget *editor, void FloatDelegate::setEditorData(QWidget *editor,

View File

@ -67,13 +67,13 @@ void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
_this->_operations->at(index.row()).formula = value; _this->_operations->at(index.row()).formula = value;
delete[] str2; delete[] str2;
res = ParseExp::EvaluateExpr(&opt, true); res = ParseExp::EvaluateExpr(&opt, true);
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res))); model->setData(index, QVariant::fromValue(s.asprintf("%.2lf", res)));
} }
else else
{ {
res = value.toDouble(&ok); res = value.toDouble(&ok);
if (ok) if (ok)
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res))); model->setData(index, QVariant::fromValue(s.asprintf("%.2lf", res)));
} }
} }

View File

@ -439,10 +439,10 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
setItem(line, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(op.day+1, month+1, year))); setItem(line, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(op.day+1, month+1, year)));
if (op.amount < 0) if (op.amount < 0)
{ {
setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)-op.amount/100))); setItem(line, DEBIT, new QTableWidgetItem(v.asprintf("%.2lf", (double)-op.amount/100)));
} }
else else
setItem(line, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)op.amount/100))); setItem(line, CREDIT, new QTableWidgetItem(v.asprintf("%.2lf", (double)op.amount/100)));
if (!op.meta) if (!op.meta)
setItem(line, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op.account))); setItem(line, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op.account)));
@ -464,8 +464,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
{ {
amount = _kiss->MetaPositiveAmount(op.id); amount = _kiss->MetaPositiveAmount(op.id);
setItem(line, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)amount/100))); setItem(line, DEBIT, new QTableWidgetItem(v.asprintf("%.2lf", (double)amount/100)));
setItem(line, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", (double)amount/100))); setItem(line, CREDIT, new QTableWidgetItem(v.asprintf("%.2lf", (double)amount/100)));
} }
if (line <= _fixCosts) if (line <= _fixCosts)
@ -1049,9 +1049,9 @@ void GridAccount::OnOperationModified(int row, int col)
/* Non null value --> set amount */ /* Non null value --> set amount */
if (op_tmp.amount > 0) if (op_tmp.amount > 0)
setItem(row, CREDIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)op_tmp.amount/100))); setItem(row, CREDIT, new QTableWidgetItem(value.asprintf("%.2lf", (double)op_tmp.amount/100)));
else if (op_tmp.amount < 0) else if (op_tmp.amount < 0)
setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)-op_tmp.amount/100))); setItem(row, DEBIT, new QTableWidgetItem(value.asprintf("%.2lf", (double)-op_tmp.amount/100)));
} }
} }
@ -1062,7 +1062,7 @@ void GridAccount::OnOperationModified(int row, int col)
if (new_op.amount < 0) if (new_op.amount < 0)
{ {
new_op.amount *= -1.0; new_op.amount *= -1.0;
setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)new_op.amount/100))); setItem(row, DEBIT, new QTableWidgetItem(value.asprintf("%.2lf", (double)new_op.amount/100)));
} }
if (new_op.amount != 0.0) new_op.amount *= -1.0; if (new_op.amount != 0.0) new_op.amount *= -1.0;
op_complete--; op_complete--;
@ -1077,7 +1077,7 @@ void GridAccount::OnOperationModified(int row, int col)
if (new_op.amount < 0) if (new_op.amount < 0)
{ {
new_op.amount *= -1.0; new_op.amount *= -1.0;
setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", (double)new_op.amount/100))); setItem(row, DEBIT, new QTableWidgetItem(value.asprintf("%.2lf", (double)new_op.amount/100)));
} }
op_complete--; op_complete--;
new_op.formula = _displayedOperations[row].formula; new_op.formula = _displayedOperations[row].formula;

View File

@ -35,9 +35,9 @@ void StarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QString value = line->text().trimmed(); QString value = line->text().trimmed();
if ((*_accounts)[index.row()].shared) if ((*_accounts)[index.row()].shared)
model->setData(index, qVariantFromValue(value+ "*")); model->setData(index, QVariant::fromValue(value+ "*"));
else else
model->setData(index, qVariantFromValue(value)); model->setData(index, QVariant::fromValue(value));
} }
void StarDelegate::setEditorData(QWidget *editor, void StarDelegate::setEditorData(QWidget *editor,

View File

@ -41,9 +41,9 @@ void TabDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
if (index.row() < (int) _operations->size() && (*_operations)[index.row()].id && if (index.row() < (int) _operations->size() && (*_operations)[index.row()].id &&
(*_operations)[index.row()].parent) (*_operations)[index.row()].parent)
model->setData(index, qVariantFromValue(" " + value)); model->setData(index, QVariant::fromValue(" " + value));
else else
model->setData(index, qVariantFromValue(value)); model->setData(index, QVariant::fromValue(value));
} }
void TabDelegate::setEditorData(QWidget *editor, void TabDelegate::setEditorData(QWidget *editor,

View File

@ -31,8 +31,6 @@
#include "UsersDialog.hpp" #include "UsersDialog.hpp"
#include <QDesktopWidget>
QString wxUI::months[12] ; QString wxUI::months[12] ;
QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86), QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
QColor(0xFF, 0x3E, 0x0E), QColor(0xFF, 0x3E, 0x0E),
@ -53,11 +51,10 @@ wxUI::wxUI(KissCount* kiss, const QString& title)
_needReload(0) _needReload(0)
{ {
QPushButton* button; QPushButton* button;
QDesktopWidget desk;
bool lowRes; bool lowRes;
int w; int w;
lowRes = (desk.availableGeometry().width() <= 1024); lowRes = (_kiss->primaryScreen()->size().width() <= 1024);
SetLanguage(""); SetLanguage("");
@ -194,10 +191,9 @@ void wxUI::InitPanels()
QPushButton* button; QPushButton* button;
_panels.clear(); _panels.clear();
int id=0; int id=0;
QDesktopWidget desk;
bool lowRes; bool lowRes;
lowRes = (desk.availableGeometry().width() <= 1024); lowRes = (_kiss->primaryScreen()->size().width() <= 1024);
ADD_PANEL(AccountPanel); ADD_PANEL(AccountPanel);
ADD_PANEL(StatsPanel); ADD_PANEL(StatsPanel);