r18871 - gnucash/trunk/src - Cutecash: Add gnc::Numeric wrapper for gnc_numeric.
Christian Stimming
cstim at code.gnucash.org
Sun Mar 7 16:27:38 EST 2010
Author: cstim
Date: 2010-03-07 16:27:38 -0500 (Sun, 07 Mar 2010)
New Revision: 18871
Trac: http://svn.gnucash.org/trac/changeset/18871
Added:
gnucash/trunk/src/gnc/Numeric.cpp
gnucash/trunk/src/gnc/Numeric.hpp
gnucash/trunk/src/gnc/Split.cpp
Modified:
gnucash/trunk/src/engine/CMakeLists.txt
gnucash/trunk/src/gnc/Account.hpp
gnucash/trunk/src/gnc/AccountItemModel.hpp
gnucash/trunk/src/gnc/CMakeLists.txt
gnucash/trunk/src/gnc/Split.hpp
gnucash/trunk/src/gnc/SplitListModel.cpp
gnucash/trunk/src/gnc/main.cpp
gnucash/trunk/src/gnc/mainwindow.cpp
Log:
Cutecash: Add gnc::Numeric wrapper for gnc_numeric.
Modified: gnucash/trunk/src/engine/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/engine/CMakeLists.txt 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/engine/CMakeLists.txt 2010-03-07 21:27:38 UTC (rev 18871)
@@ -3,6 +3,7 @@
ADD_DEFINITIONS (-DG_LOG_DOMAIN=\"gnc.engine\")
INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES (${GCONF2_INCLUDE_DIRS})
INCLUDE_DIRECTORIES (${LIBINTL_INCLUDE_PATH})
INCLUDE_DIRECTORIES (${REGEX_INCLUDE_PATH})
INCLUDE_DIRECTORIES (${GUILE_INCLUDE_DIRS})
@@ -41,11 +42,13 @@
gnc-budget.h
gnc-commodity.h
gnc-engine.h
+ gnc-euro.h
gnc-event.h
gnc-hooks.h
gnc-pricedb.h
+ gnc-session-scm.h
gnc-session.h
- gnc-session-scm.h
+ gnc-ui-util.h
gncObject.h
kvp-scm.h
policy.h
@@ -98,11 +101,13 @@
gnc-budget.c
gnc-commodity.c
gnc-engine.c
+ gnc-euro.c
gnc-hooks.c
gnc-lot.c
gnc-pricedb.c
+ gnc-session-scm.c
gnc-session.c
- gnc-session-scm.c
+ gnc-ui-util.c
gncmod-engine.c
kvp-scm.c
engine-helpers.c
Modified: gnucash/trunk/src/gnc/Account.hpp
===================================================================
--- gnucash/trunk/src/gnc/Account.hpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/Account.hpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -39,6 +39,9 @@
namespace gnc
{
+typedef QList< ::Account*> AccountQList;
+
+
class Account : public WeakPointer< ::Account >
{
public:
@@ -81,7 +84,6 @@
//@}
- typedef QList< ::Account*> AccountQList;
static AccountQList fromGList(GList* glist)
{
AccountQList result;
Modified: gnucash/trunk/src/gnc/AccountItemModel.hpp
===================================================================
--- gnucash/trunk/src/gnc/AccountItemModel.hpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/AccountItemModel.hpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -85,7 +85,7 @@
QModelIndex parent(const QModelIndex &index) const { return QModelIndex(); }
private:
- Account::AccountQList m_list;
+ AccountQList m_list;
};
Modified: gnucash/trunk/src/gnc/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/gnc/CMakeLists.txt 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/CMakeLists.txt 2010-03-07 21:27:38 UTC (rev 18871)
@@ -12,7 +12,9 @@
SET (gnc_SOURCES
AccountItemModel.cpp
Book.cpp
+ Numeric.cpp
Session.cpp
+ Split.cpp
SplitListModel.cpp
main.cpp
mainwindow.cpp
Added: gnucash/trunk/src/gnc/Numeric.cpp
===================================================================
--- gnucash/trunk/src/gnc/Numeric.cpp (rev 0)
+++ gnucash/trunk/src/gnc/Numeric.cpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -0,0 +1,49 @@
+/*
+ * Numeric.cpp
+ * Copyright (C) 2010 Christian Stimming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "Numeric.hpp"
+#include "gnc/Account.hpp"
+#include "gnc/Split.hpp"
+
+namespace gnc
+{
+
+// These are in the cpp file to avoid circular dependency between the
+// headers
+
+PrintAmountInfo::PrintAmountInfo(const Account& account, bool use_symbol)
+ : base_class(gnc_account_print_info(account.get(), use_symbol))
+{}
+PrintAmountInfo::PrintAmountInfo(const Split& split, bool use_symbol)
+ : base_class(gnc_split_amount_print_info(split.get(), use_symbol))
+{}
+
+QString Numeric::printAmount(const PrintAmountInfo& info)
+{
+ char buf[256];
+ if (!xaccSPrintAmount (buf, *this, info))
+ buf[0] = '\0';
+ return QString::fromUtf8(buf);
+}
+
+
+} // END namespace gnc
Added: gnucash/trunk/src/gnc/Numeric.hpp
===================================================================
--- gnucash/trunk/src/gnc/Numeric.hpp (rev 0)
+++ gnucash/trunk/src/gnc/Numeric.hpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -0,0 +1,134 @@
+/*
+ * Numeric.hpp
+ * Copyright (C) 2010 Christian Stimming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef GNC_NUMERIC_HPP
+#define GNC_NUMERIC_HPP
+
+// gnucash includes
+#include "config.h"
+extern "C"
+{
+#include "qof.h"
+#include "engine/gnc-ui-util.h"
+}
+
+#include <QString>
+
+namespace gnc
+{
+
+class Account;
+class Split;
+
+inline QString gchar_to_QString(gchar* tmp_string)
+{
+ QString result = QString::fromUtf8(tmp_string);
+ g_free(tmp_string);
+ return result;
+}
+
+
+class PrintAmountInfo : public ::GNCPrintAmountInfo
+{
+public:
+ typedef ::GNCPrintAmountInfo base_class;
+
+ PrintAmountInfo(const base_class& other)
+ : base_class(other)
+ {}
+ PrintAmountInfo(bool use_symbol)
+ : base_class(gnc_default_print_info(use_symbol))
+ {}
+
+ PrintAmountInfo(const Account& account, bool use_symbol);
+ PrintAmountInfo(const Split& split, bool use_symbol);
+
+ static PrintAmountInfo share_places(int decplaces) { return gnc_share_print_info_places(decplaces); }
+ static PrintAmountInfo default_share() { return gnc_default_share_print_info(); }
+ static PrintAmountInfo default_price() { return gnc_default_price_print_info(); }
+ static PrintAmountInfo integral() { return gnc_integral_print_info(); }
+};
+
+class Numeric : public ::gnc_numeric
+{
+public:
+ typedef ::gnc_numeric base_class;
+ Numeric(gint64 num, gint64 denom)
+ {
+ base_class::num = num;
+ base_class::denom = denom;
+ }
+ Numeric(const base_class& other) : base_class(other) {}
+ static Numeric zero() { return Numeric(0, 1); }
+ Numeric(double in, gint64 denom, gint how)
+ {
+ *this = double_to_gnc_numeric(in, denom, how);
+ }
+ static bool string_to_numeric(const QString& str, Numeric& n)
+ {
+ return string_to_gnc_numeric(str.toUtf8(), &n);
+ }
+ Numeric(GNCNumericErrorCode error_code)
+ {
+ *this = gnc_numeric_error(error_code);
+ }
+
+ gint64 num() const { return base_class::num; }
+ gint64 denom() const { return base_class::denom; }
+ gdouble to_double() const { return gnc_numeric_to_double(*this); }
+ QString to_string() const
+ {
+ return gchar_to_QString(gnc_numeric_to_string(*this));
+ }
+
+ GNCNumericErrorCode check() const { return gnc_numeric_check(*this); }
+ gint compare(const Numeric& b) const { return gnc_numeric_compare(*this, b); }
+ bool zero_p() const { return gnc_numeric_zero_p(*this); }
+ bool negative_p() const { return gnc_numeric_negative_p(*this); }
+ bool positive_p() const { return gnc_numeric_positive_p(*this); }
+ bool eq(const Numeric& b) const { return gnc_numeric_eq(*this, b); }
+ bool equal(const Numeric& b) const { return gnc_numeric_equal(*this, b); }
+ bool same(const Numeric& b, gint64 denom, gint how) const { return gnc_numeric_same(*this, b, denom, how); }
+
+ Numeric add(const Numeric& b, gint64 denom, gint how) const { return gnc_numeric_add(*this, b, denom, how); }
+ Numeric sub(const Numeric& b, gint64 denom, gint how) const { return gnc_numeric_sub(*this, b, denom, how); }
+ Numeric mul(const Numeric& b, gint64 denom, gint how) const { return gnc_numeric_mul(*this, b, denom, how); }
+ Numeric div(const Numeric& b, gint64 denom, gint how) const { return gnc_numeric_div(*this, b, denom, how); }
+ Numeric neg() const { return gnc_numeric_neg(*this); }
+ Numeric abs() const { return gnc_numeric_abs(*this); }
+
+ Numeric add_fixed(const Numeric& b) const { return gnc_numeric_add_fixed(*this, b); }
+ Numeric sub_fixed(const Numeric& b) const { return gnc_numeric_sub_fixed(*this, b); }
+
+ Numeric reduce() const { return gnc_numeric_reduce(*this); }
+
+ QString printAmount(const PrintAmountInfo& info);
+};
+
+inline bool operator==(const Numeric& a, const Numeric& b)
+{
+ return a.equal(b);
+}
+
+} // END namespace gnc
+
+#endif
Added: gnucash/trunk/src/gnc/Split.cpp
===================================================================
--- gnucash/trunk/src/gnc/Split.cpp (rev 0)
+++ gnucash/trunk/src/gnc/Split.cpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -0,0 +1,43 @@
+/*
+ * Split.cpp
+ * Copyright (C) 2010 Christian Stimming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "Split.hpp"
+
+#include "gnc/Account.hpp"
+#include "gnc/Book.hpp"
+#include "gnc/Transaction.hpp"
+
+namespace gnc
+{
+
+Book Split::getBook() const { return xaccSplitGetBook(get()); }
+
+Account Split::getAccount() const { return xaccSplitGetAccount(get()); }
+void Split::setAccount(Account& acc) { xaccSplitSetAccount(get(), acc.get()); }
+
+
+Transaction Split::getParent() const { return xaccSplitGetParent(get()); }
+void Split::setParent(Transaction& trans) { xaccSplitSetParent(get(), trans.get()); }
+
+
+
+} // END namespace gnc
Modified: gnucash/trunk/src/gnc/Split.hpp
===================================================================
--- gnucash/trunk/src/gnc/Split.hpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/Split.hpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -34,20 +34,18 @@
#include <QString>
#include <QList>
-namespace gnc
-{
-class Split;
-typedef QList< ::Split*> SplitQList;
-}
-
#include "gnc/WeakPointer.hpp"
-#include "gnc/Account.hpp"
-#include "gnc/Book.hpp"
-#include "gnc/Transaction.hpp"
+#include "gnc/Numeric.hpp"
namespace gnc
{
+class Book;
+class Account;
+class Transaction;
+typedef QList< ::Split*> SplitQList;
+
+
class Split : public WeakPointer< ::Split >
{
public:
@@ -56,12 +54,12 @@
: base_class(ptr)
{ }
- Book getBook() const { return xaccSplitGetBook(get()); }
- Account getAccount() const { return xaccSplitGetAccount(get()); }
- void setAccount(Account& acc) { xaccSplitSetAccount(get(), acc.get()); }
+ Book getBook() const;
+ Account getAccount() const;
+ void setAccount(Account& acc);
- Transaction getParent() const { return xaccSplitGetParent(get()); }
- void setParent(Transaction& trans) { xaccSplitSetParent(get(), trans.get()); }
+ Transaction getParent() const;
+ void setParent(Transaction& trans);
QString getMemo() const { return QString::fromUtf8(xaccSplitGetMemo(get())); }
void setMemo(const QString& v) { xaccSplitSetMemo(get(), v.toUtf8()); }
@@ -76,10 +74,7 @@
QString getCorrAccountFullName() const
{
- char * r = xaccSplitGetCorrAccountFullName(get());
- QString result = QString::fromUtf8(r);
- g_free (r);
- return result;
+ return gchar_to_QString(xaccSplitGetCorrAccountFullName(get()));
}
QString getCorrAccountName() const { return QString::fromUtf8(xaccSplitGetCorrAccountName(get())); }
QString getCorrAccountCode() const { return QString::fromUtf8(xaccSplitGetCorrAccountCode(get())); }
Modified: gnucash/trunk/src/gnc/SplitListModel.cpp
===================================================================
--- gnucash/trunk/src/gnc/SplitListModel.cpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/SplitListModel.cpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -1,5 +1,5 @@
/*
- * SplitListModel.hpp
+ * SplitListModel.cpp
* Copyright (C) 2010 Christian Stimming
*
* This program is free software; you can redistribute it and/or
@@ -21,6 +21,7 @@
*/
#include "SplitListModel.hpp"
+#include "gnc/Transaction.hpp"
#include <QDebug>
namespace gnc
Modified: gnucash/trunk/src/gnc/main.cpp
===================================================================
--- gnucash/trunk/src/gnc/main.cpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/main.cpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -43,6 +43,7 @@
#include "engine/gnc-session.h"
#include "engine/engine-helpers.h"
#include "engine/gnc-engine.h"
+#include "engine/gnc-ui-util.h" // for gnc_ui_util_init()
#include "swig-runtime.h"
#include "backend/xml/gnc-backend-xml.h"
@@ -183,6 +184,7 @@
//gnc_module_init_backend_dbi();
gnc_module_init_business_core_init();
gnc_module_init_business_core_xml_init();
+ gnc_ui_util_init();
// From here on the new C++ code
QApplication app(argc, argv);
Modified: gnucash/trunk/src/gnc/mainwindow.cpp
===================================================================
--- gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-07 21:02:50 UTC (rev 18870)
+++ gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-07 21:27:38 UTC (rev 18871)
@@ -46,6 +46,7 @@
#include "gnc/Account.hpp"
#include "gnc/AccountItemModel.hpp"
#include "gnc/Book.hpp"
+#include "gnc/Numeric.hpp"
#include "gnc/Split.hpp"
#include "gnc/SplitListModel.hpp"
More information about the gnucash-changes
mailing list