r21486 - gnucash/trunk/src - [Gtkmm] [Cutecash] Unify the glibmm and Qt C++ wrappers of the engine even more.
Christian Stimming
cstim at code.gnucash.org
Mon Oct 24 16:41:16 EDT 2011
Author: cstim
Date: 2011-10-24 16:41:15 -0400 (Mon, 24 Oct 2011)
New Revision: 21486
Trac: http://svn.gnucash.org/trac/changeset/21486
Modified:
gnucash/trunk/src/gnc/Account.hpp
gnucash/trunk/src/gnc/AccountItemModel.cpp
gnucash/trunk/src/gnc/AccountItemModel.hpp
gnucash/trunk/src/gnc/Numeric.hpp
gnucash/trunk/src/gnc/Split.hpp
gnucash/trunk/src/gnc/fpo/ViewletModel.cpp
gnucash/trunk/src/gnc/fpo/ViewletModel.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Numeric.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp
gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp
Log:
[Gtkmm] [Cutecash] Unify the glibmm and Qt C++ wrappers of the engine even more.
Modified: gnucash/trunk/src/gnc/Account.hpp
===================================================================
--- gnucash/trunk/src/gnc/Account.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/Account.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -42,9 +42,7 @@
namespace gnc
{
-typedef QList< ::Account*> AccountQList;
-
/** Wrapper around a gnucash ::Account pointer with C++ methods for
* easier setter and getter access.
*
@@ -96,18 +94,6 @@
gint get_tree_depth () const { return gnc_account_get_tree_depth(gobj()); }
//@}
-
- static AccountQList fromGList(GList* glist)
- {
- AccountQList result;
- GList* list = glist;
- while (list)
- {
- result.append(reinterpret_cast< ::Account*>(list->data));
- list = g_list_next(list);
- }
- return result;
- }
};
} // END namespace gnc
Modified: gnucash/trunk/src/gnc/AccountItemModel.cpp
===================================================================
--- gnucash/trunk/src/gnc/AccountItemModel.cpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/AccountItemModel.cpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -180,7 +180,7 @@
void AccountListModel::recreateCache()
{
- m_list = Account::fromGList(m_root.get_descendants());
+ m_list = accountFromGList(m_root.get_descendants());
reset();
}
Modified: gnucash/trunk/src/gnc/AccountItemModel.hpp
===================================================================
--- gnucash/trunk/src/gnc/AccountItemModel.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/AccountItemModel.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -63,8 +63,12 @@
Account m_root;
};
+typedef QList< ::Account*> AccountQList;
+inline AccountQList accountFromGList(GList *glist)
+{
+ return fromGList<AccountQList>(glist);
+}
-
/** Specialization of the account tree model for when all accounts
* should be viewed as a flat list instead of a tree. Only the index()
* and parent() functions had to be overridden - quite easy. */
Modified: gnucash/trunk/src/gnc/Numeric.hpp
===================================================================
--- gnucash/trunk/src/gnc/Numeric.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/Numeric.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -80,6 +80,20 @@
return result;
}
+/** Copies the pointer values from the given GList into the specified output
+ * list type, such as std::vector<FooBar*>. */
+template<class ResultListType>
+ResultListType fromGList(GList* glist)
+{
+ ResultListType result;
+ GList* list = glist;
+ while (list)
+ {
+ result.push_back(reinterpret_cast< typename ResultListType::value_type >(list->data));
+ list = g_list_next(list);
+ }
+ return result;
+}
/** Wrapper around a gnucash ::GNCPrintAmountInfo structure with C++
Modified: gnucash/trunk/src/gnc/Split.hpp
===================================================================
--- gnucash/trunk/src/gnc/Split.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/Split.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -37,6 +37,7 @@
#include "gnc/GncInstance.hpp"
#include "gnc/Numeric.hpp"
+#include <vector>
namespace gnc
{
@@ -45,7 +46,7 @@
class Transaction;
class TmpTransaction;
-typedef QList< ::Split*> SplitQList;
+typedef std::vector< ::Split*> SplitQList;
/** Wrapper around a gnucash ::Split pointer with C++ methods for
@@ -98,17 +99,9 @@
Numeric getReconciledBalance() const { return xaccSplitGetReconciledBalance(gobj()); }
-
static SplitQList fromGList(GList* glist)
{
- SplitQList result;
- GList* list = glist;
- while (list)
- {
- result.append(reinterpret_cast< ::Split*>(list->data));
- list = g_list_next(list);
- }
- return result;
+ return gnc::fromGList<SplitQList>(glist);
}
};
Modified: gnucash/trunk/src/gnc/fpo/ViewletModel.cpp
===================================================================
--- gnucash/trunk/src/gnc/fpo/ViewletModel.cpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/fpo/ViewletModel.cpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -25,7 +25,7 @@
::Account *rootAccount = gnc_book_get_root_account(book);
GList *accountsGList = gnc_account_get_descendants(rootAccount);
- AccountQList accountsList = Account::fromGList(accountsGList);
+ AccountQList accountsList = accountFromGList(accountsGList);
int numOfAccounts = accountsList.count();
qDebug()<<"Total num of accounts: "<<numOfAccounts;
@@ -50,7 +50,7 @@
::Account *rootAccount = gnc_book_get_root_account(book);
GList *accountsGList = gnc_account_get_descendants(rootAccount);
- AccountQList accountsList = Account::fromGList(accountsGList);
+ AccountQList accountsList = accountFromGList(accountsGList);
int numOfAccounts = accountsList.count();
qDebug()<<"Total num of accounts: "<<numOfAccounts;
@@ -136,10 +136,10 @@
SplitQList tempList = Split::fromGList(::xaccAccountGetSplitList(C_acct));
- int numOfSplits = tempList.count();
+ int numOfSplits = tempList.size();
for(int i=0; i<numOfSplits; i++)
{
- allSplitsList.append(tempList.at(i));
+ allSplitsList.push_back(tempList.at(i));
}
}
@@ -158,7 +158,7 @@
void
ViewletModel::buildMiniJournalStruct(SplitQList splitList)
{
- int numOfSplits = splitList.count();
+ int numOfSplits = splitList.size();
Split split;
int i;
QDate tempDate;
Modified: gnucash/trunk/src/gnc/fpo/ViewletModel.hpp
===================================================================
--- gnucash/trunk/src/gnc/fpo/ViewletModel.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/gnc/fpo/ViewletModel.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -16,6 +16,7 @@
#include "gnc/Split.hpp"
#include "gnc/SplitListModel.hpp"
+#include "gnc/AccountItemModel.hpp"
namespace gnc
{
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Account.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -173,21 +173,6 @@
}
//@}
-
-#if 0
- static AccountQList fromGList(GList* glist)
- {
- AccountQList result;
- GList* list = glist;
- while (list)
- {
- result.append(reinterpret_cast< ::Account*>(list->data));
- list = g_list_next(list);
- }
- return result;
- }
-#endif
-
};
} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Numeric.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Numeric.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Numeric.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -80,6 +80,20 @@
}
#endif
+/** Copies the pointer values from the given GList into the specified output
+ * list type, such as std::vector<FooBar*>. */
+template<class ResultListType>
+ResultListType fromGList(GList* glist)
+{
+ ResultListType result;
+ GList* list = glist;
+ while (list)
+ {
+ result.push_back(reinterpret_cast< typename ResultListType::value_type >(list->data));
+ list = g_list_next(list);
+ }
+ return result;
+}
/** Wrapper around a gnucash ::GNCPrintAmountInfo structure with C++
* methods for easier setter and getter access.
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Split.cpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -189,16 +189,17 @@
m_value = Numeric::zero();
}
-void TmpSplit::copyInto(Transaction& t) const
+void TmpSplit::copyInto(Glib::RefPtr<Transaction> t) const
{
-// Glib::RefPtr<Split> s(Glib::wrap(xaccMallocSplit(t.getBook()->gobj())));
-// s->setAccount(m_account);
-// s->setParent(t);
-// s->setMemo(m_memo);
-// s->setAction(m_action);
-// s->setReconcile(m_reconcile);
-// s->setAmount(m_amount);
-// s->setValue(m_value);
+ g_assert(t);
+ Glib::RefPtr<Split> s(Glib::wrap(xaccMallocSplit(t->getBook()->gobj())));
+ s->setAccount(m_account);
+ s->setParent(t);
+ s->setMemo(m_memo);
+ s->setAction(m_action);
+ s->setReconcile(m_reconcile);
+ s->setAmount(m_amount);
+ s->setValue(m_value);
}
} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Split.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -189,19 +189,10 @@
}
-#if 0
static SplitQList fromGList(GList* glist)
{
- SplitQList result;
- GList* list = glist;
- while (list)
- {
- result.append(reinterpret_cast< ::Split*>(list->data));
- list = g_list_next(list);
- }
- return result;
+ return gnc::fromGList<SplitQList>(glist);
}
-#endif
};
@@ -232,7 +223,7 @@
/** Copies the content of this tmp split into the given real
* transaction by allocating a new real gnc::Split and adding it
* to the given real gnc::Transaction. */
- void copyInto(Transaction& t) const;
+ void copyInto(Glib::RefPtr<Transaction> t) const;
::Account* getAccount() const
{
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.cpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -126,17 +126,21 @@
{
return Glib::wrap(xaccTransGetSplit(gobj(), i));
}
-void Transaction::appendSplit(Split& split)
+void Transaction::appendSplit(Glib::RefPtr<Split> split)
{
- xaccSplitSetParent(split.gobj(), gobj());
+ g_assert(split);
+ xaccSplitSetParent(split->gobj(), gobj());
}
int Transaction::getSplitIndex(const Split& split) const
{
return xaccTransGetSplitIndex(gobj(), split.gobj());
}
-::Transaction* Transaction::newInstance(const ::QofBook* b)
+::Transaction* Transaction::newInstance(const Glib::RefPtr<Book> b)
{
- return xaccMallocTransaction (const_cast< ::QofBook*>(b));
+ if (b)
+ return xaccMallocTransaction (const_cast< ::QofBook*>(b->gobj()));
+ else
+ return NULL;
}
// ////////////////////////////////////////////////////////////
@@ -151,14 +155,9 @@
, m_notes(t.getNotes())
, m_commodity(t.getCurrency())
, m_datePosted(t.getDatePosted())
- //, m_dateTimeEntered(t.getDateEntered())
+ , m_dateTimeEntered(t.getDateEnteredTT())
{
- SplitQList slist
-#if HAVE_GLIBMM_VECTORUTILS_H
- = Glib::ListHandlier<Glib::RefPtr<Split> >::list_to_vector(t.getSplitList());
-#else
- ;
-#endif
+ SplitQList slist = Split::fromGList(t.getSplitList());
for (SplitQList::const_iterator iter = slist.begin(); iter != slist.end(); ++iter)
{
m_splits.push_back(TmpSplit(Glib::wrap(*iter), this));
@@ -178,7 +177,7 @@
m_notes.clear();
m_commodity.reset();
m_datePosted = Glib::Date();
- //m_dateTimeEntered = QDateTime();
+ m_dateTimeEntered = 0;
for (int i = 0; i < m_splits.size(); ++i)
{
TmpSplit& split = m_splits[i];
@@ -196,13 +195,13 @@
t->setNotes(m_notes);
t->setCurrency(m_commodity);
t->setDatePosted(m_datePosted);
- //t->setDateEntered(m_dateTimeEntered);
+ t->setDateEntered(m_dateTimeEntered);
for (int i = 0; i < m_splits.size(); ++i)
{
- //m_splits[i].copyInto(t);
+ m_splits[i].copyInto(t);
}
}
-#if 0
+
Glib::RefPtr<Transaction> TmpTransaction::createAsReal() const
{
assert (!m_splits.empty());
@@ -210,13 +209,13 @@
assert (acc);
Glib::RefPtr<Book> book(acc->getBook());
assert (book);
- Glib::RefPtr<Transaction> trans(Glib::wrap(Transaction::newInstance(book->gobj())));
+ Glib::RefPtr<Transaction> trans(Glib::wrap(Transaction::newInstance(book)));
trans->beginEdit();
copyTo(trans);
trans->commitEdit();
return trans;
}
-#endif
+
void TmpTransaction::push_back(const TmpSplit& s)
{
m_splits.push_back(s);
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp 2011-10-24 07:59:30 UTC (rev 21485)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Transaction.hpp 2011-10-24 20:41:15 UTC (rev 21486)
@@ -155,7 +155,7 @@
return xaccTransCountSplits(gobj());
}
Glib::RefPtr<Split> findSplitByAccount(const Account& acc) const;
- void appendSplit(Split& split);
+ void appendSplit(Glib::RefPtr<Split> split);
Glib::RefPtr<Split> getSplit(int i) const;
int getSplitIndex(const Split& split) const;
::SplitList* getSplitList() const
@@ -189,14 +189,22 @@
{
xaccTransSetDatePostedGDate(gobj(), *d.gobj());
}
-// void setDateEntered(const Glib::DateTime& t) { xaccTransSetDateEnteredSecs(gobj(), t.toTime_t()); }
Glib::Date getDatePosted() const
{
return Glib::Date(xaccTransGetDatePostedGDate(gobj()));
}
+ void setDateEntered(time_t t)
+ {
+ xaccTransSetDateEnteredSecs(gobj(), t);
+ }
+// void setDateEntered(const Glib::DateTime& t) { xaccTransSetDateEnteredSecs(gobj(), t.toTime_t()); }
+ time_t getDateEnteredTT() const
+ {
+ return timespecToTime_t(xaccTransRetDateEnteredTS(gobj()));
+ }
//Glib::DateTime getDateEntered() const { return toGDateTime(xaccTransRetDateEnteredTS(gobj())); }
- static ::Transaction* newInstance(const ::QofBook* b);
+ static ::Transaction* newInstance(const Glib::RefPtr<Book> b);
};
@@ -287,6 +295,14 @@
m_datePosted = v;
}
+ time_t getDateEnteredTT() const
+ {
+ return m_dateTimeEntered;
+ }
+ void setDateEntered(time_t v)
+ {
+ m_dateTimeEntered = v;
+ }
//Glib::DateTime getDateEntered() const { return m_dateTimeEntered; }
//void setDateEntered(const Glib::DateTime& v) { m_dateTimeEntered = v; }
@@ -297,6 +313,7 @@
TmpSplitList m_splits;
Glib::RefPtr<Commodity> m_commodity;
Glib::Date m_datePosted;
+ time_t m_dateTimeEntered;
//Glib::DateTime m_dateTimeEntered;
};
More information about the gnucash-changes
mailing list