[Gtkmm] [Cutecash] Unify the glibmm and Qt C++ wrappers of the engine even more.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21486 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-10-24 20:41:15 +00:00
parent e08bea1336
commit 905e478531
13 changed files with 91 additions and 86 deletions

View File

@ -42,8 +42,6 @@ extern "C"
namespace gnc namespace gnc
{ {
typedef QList< ::Account*> AccountQList;
/** Wrapper around a gnucash ::Account pointer with C++ methods for /** Wrapper around a gnucash ::Account pointer with C++ methods for
* easier setter and getter access. * easier setter and getter access.
@ -96,18 +94,6 @@ public:
gint get_tree_depth () const { return gnc_account_get_tree_depth(gobj()); } 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 } // END namespace gnc

View File

@ -180,7 +180,7 @@ AccountListModel::AccountListModel(Account rootaccount, QObject *parent)
void AccountListModel::recreateCache() void AccountListModel::recreateCache()
{ {
m_list = Account::fromGList(m_root.get_descendants()); m_list = accountFromGList(m_root.get_descendants());
reset(); reset();
} }

View File

@ -63,7 +63,11 @@ protected:
Account m_root; 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 /** Specialization of the account tree model for when all accounts
* should be viewed as a flat list instead of a tree. Only the index() * should be viewed as a flat list instead of a tree. Only the index()

View File

@ -80,6 +80,20 @@ inline ::Timespec toTimespec(const QDateTime& qdt)
return result; 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++ /** Wrapper around a gnucash ::GNCPrintAmountInfo structure with C++

View File

@ -37,6 +37,7 @@ extern "C"
#include "gnc/GncInstance.hpp" #include "gnc/GncInstance.hpp"
#include "gnc/Numeric.hpp" #include "gnc/Numeric.hpp"
#include <vector>
namespace gnc namespace gnc
{ {
@ -45,7 +46,7 @@ class Account;
class Transaction; class Transaction;
class TmpTransaction; class TmpTransaction;
typedef QList< ::Split*> SplitQList; typedef std::vector< ::Split*> SplitQList;
/** Wrapper around a gnucash ::Split pointer with C++ methods for /** Wrapper around a gnucash ::Split pointer with C++ methods for
@ -98,17 +99,9 @@ public:
Numeric getReconciledBalance() const { return xaccSplitGetReconciledBalance(gobj()); } Numeric getReconciledBalance() const { return xaccSplitGetReconciledBalance(gobj()); }
static SplitQList fromGList(GList* glist) static SplitQList fromGList(GList* glist)
{ {
SplitQList result; return gnc::fromGList<SplitQList>(glist);
GList* list = glist;
while (list)
{
result.append(reinterpret_cast< ::Split*>(list->data));
list = g_list_next(list);
}
return result;
} }
}; };

View File

@ -25,7 +25,7 @@ ViewletModel::leftVGenerate(::Account *selectedAccount)
::Account *rootAccount = gnc_book_get_root_account(book); ::Account *rootAccount = gnc_book_get_root_account(book);
GList *accountsGList = gnc_account_get_descendants(rootAccount); GList *accountsGList = gnc_account_get_descendants(rootAccount);
AccountQList accountsList = Account::fromGList(accountsGList); AccountQList accountsList = accountFromGList(accountsGList);
int numOfAccounts = accountsList.count(); int numOfAccounts = accountsList.count();
qDebug()<<"Total num of accounts: "<<numOfAccounts; qDebug()<<"Total num of accounts: "<<numOfAccounts;
@ -50,7 +50,7 @@ ViewletModel::rightVGenerate(::Account *selectedAccount)
::Account *rootAccount = gnc_book_get_root_account(book); ::Account *rootAccount = gnc_book_get_root_account(book);
GList *accountsGList = gnc_account_get_descendants(rootAccount); GList *accountsGList = gnc_account_get_descendants(rootAccount);
AccountQList accountsList = Account::fromGList(accountsGList); AccountQList accountsList = accountFromGList(accountsGList);
int numOfAccounts = accountsList.count(); int numOfAccounts = accountsList.count();
qDebug()<<"Total num of accounts: "<<numOfAccounts; qDebug()<<"Total num of accounts: "<<numOfAccounts;
@ -136,10 +136,10 @@ ViewletModel::buildSplitListDateSort(AccountQList accountsList)
SplitQList tempList = Split::fromGList(::xaccAccountGetSplitList(C_acct)); SplitQList tempList = Split::fromGList(::xaccAccountGetSplitList(C_acct));
int numOfSplits = tempList.count(); int numOfSplits = tempList.size();
for(int i=0; i<numOfSplits; i++) for(int i=0; i<numOfSplits; i++)
{ {
allSplitsList.append(tempList.at(i)); allSplitsList.push_back(tempList.at(i));
} }
} }
@ -158,7 +158,7 @@ ViewletModel::lessThanByDate(::Split* a, ::Split* b)
void void
ViewletModel::buildMiniJournalStruct(SplitQList splitList) ViewletModel::buildMiniJournalStruct(SplitQList splitList)
{ {
int numOfSplits = splitList.count(); int numOfSplits = splitList.size();
Split split; Split split;
int i; int i;
QDate tempDate; QDate tempDate;

View File

@ -16,6 +16,7 @@ extern "C"
#include "gnc/Split.hpp" #include "gnc/Split.hpp"
#include "gnc/SplitListModel.hpp" #include "gnc/SplitListModel.hpp"
#include "gnc/AccountItemModel.hpp"
namespace gnc namespace gnc
{ {

View File

@ -173,21 +173,6 @@ public:
} }
//@} //@}
#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 } // END namespace gnc

View File

@ -80,6 +80,20 @@ inline ::Timespec toTimespec(const Glib::DateTime& gdt)
} }
#endif #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++ /** Wrapper around a gnucash ::GNCPrintAmountInfo structure with C++
* methods for easier setter and getter access. * methods for easier setter and getter access.

View File

@ -189,16 +189,17 @@ void TmpSplit::clear(::Account* account)
m_value = Numeric::zero(); 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()))); g_assert(t);
// s->setAccount(m_account); Glib::RefPtr<Split> s(Glib::wrap(xaccMallocSplit(t->getBook()->gobj())));
// s->setParent(t); s->setAccount(m_account);
// s->setMemo(m_memo); s->setParent(t);
// s->setAction(m_action); s->setMemo(m_memo);
// s->setReconcile(m_reconcile); s->setAction(m_action);
// s->setAmount(m_amount); s->setReconcile(m_reconcile);
// s->setValue(m_value); s->setAmount(m_amount);
s->setValue(m_value);
} }
} // END namespace gnc } // END namespace gnc

View File

@ -189,19 +189,10 @@ public:
} }
#if 0
static SplitQList fromGList(GList* glist) static SplitQList fromGList(GList* glist)
{ {
SplitQList result; return gnc::fromGList<SplitQList>(glist);
GList* list = glist;
while (list)
{
result.append(reinterpret_cast< ::Split*>(list->data));
list = g_list_next(list);
}
return result;
} }
#endif
}; };
@ -232,7 +223,7 @@ public:
/** Copies the content of this tmp split into the given real /** Copies the content of this tmp split into the given real
* transaction by allocating a new real gnc::Split and adding it * transaction by allocating a new real gnc::Split and adding it
* to the given real gnc::Transaction. */ * to the given real gnc::Transaction. */
void copyInto(Transaction& t) const; void copyInto(Glib::RefPtr<Transaction> t) const;
::Account* getAccount() const ::Account* getAccount() const
{ {

View File

@ -126,17 +126,21 @@ Glib::RefPtr<Split> Transaction::getSplit(int i) const
{ {
return Glib::wrap(xaccTransGetSplit(gobj(), i)); 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 int Transaction::getSplitIndex(const Split& split) const
{ {
return xaccTransGetSplitIndex(gobj(), split.gobj()); 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 @@ TmpTransaction::TmpTransaction(const Transaction& t)
, m_notes(t.getNotes()) , m_notes(t.getNotes())
, m_commodity(t.getCurrency()) , m_commodity(t.getCurrency())
, m_datePosted(t.getDatePosted()) , m_datePosted(t.getDatePosted())
//, m_dateTimeEntered(t.getDateEntered()) , m_dateTimeEntered(t.getDateEnteredTT())
{ {
SplitQList slist SplitQList slist = Split::fromGList(t.getSplitList());
#if HAVE_GLIBMM_VECTORUTILS_H
= Glib::ListHandlier<Glib::RefPtr<Split> >::list_to_vector(t.getSplitList());
#else
;
#endif
for (SplitQList::const_iterator iter = slist.begin(); iter != slist.end(); ++iter) for (SplitQList::const_iterator iter = slist.begin(); iter != slist.end(); ++iter)
{ {
m_splits.push_back(TmpSplit(Glib::wrap(*iter), this)); m_splits.push_back(TmpSplit(Glib::wrap(*iter), this));
@ -178,7 +177,7 @@ void TmpTransaction::resetContent()
m_notes.clear(); m_notes.clear();
m_commodity.reset(); m_commodity.reset();
m_datePosted = Glib::Date(); m_datePosted = Glib::Date();
//m_dateTimeEntered = QDateTime(); m_dateTimeEntered = 0;
for (int i = 0; i < m_splits.size(); ++i) for (int i = 0; i < m_splits.size(); ++i)
{ {
TmpSplit& split = m_splits[i]; TmpSplit& split = m_splits[i];
@ -196,13 +195,13 @@ void TmpTransaction::copyTo(Glib::RefPtr<Transaction> t) const
t->setNotes(m_notes); t->setNotes(m_notes);
t->setCurrency(m_commodity); t->setCurrency(m_commodity);
t->setDatePosted(m_datePosted); t->setDatePosted(m_datePosted);
//t->setDateEntered(m_dateTimeEntered); t->setDateEntered(m_dateTimeEntered);
for (int i = 0; i < m_splits.size(); ++i) 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 Glib::RefPtr<Transaction> TmpTransaction::createAsReal() const
{ {
assert (!m_splits.empty()); assert (!m_splits.empty());
@ -210,13 +209,13 @@ Glib::RefPtr<Transaction> TmpTransaction::createAsReal() const
assert (acc); assert (acc);
Glib::RefPtr<Book> book(acc->getBook()); Glib::RefPtr<Book> book(acc->getBook());
assert (book); assert (book);
Glib::RefPtr<Transaction> trans(Glib::wrap(Transaction::newInstance(book->gobj()))); Glib::RefPtr<Transaction> trans(Glib::wrap(Transaction::newInstance(book)));
trans->beginEdit(); trans->beginEdit();
copyTo(trans); copyTo(trans);
trans->commitEdit(); trans->commitEdit();
return trans; return trans;
} }
#endif
void TmpTransaction::push_back(const TmpSplit& s) void TmpTransaction::push_back(const TmpSplit& s)
{ {
m_splits.push_back(s); m_splits.push_back(s);

View File

@ -155,7 +155,7 @@ public:
return xaccTransCountSplits(gobj()); return xaccTransCountSplits(gobj());
} }
Glib::RefPtr<Split> findSplitByAccount(const Account& acc) const; 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; Glib::RefPtr<Split> getSplit(int i) const;
int getSplitIndex(const Split& split) const; int getSplitIndex(const Split& split) const;
::SplitList* getSplitList() const ::SplitList* getSplitList() const
@ -189,14 +189,22 @@ public:
{ {
xaccTransSetDatePostedGDate(gobj(), *d.gobj()); xaccTransSetDatePostedGDate(gobj(), *d.gobj());
} }
// void setDateEntered(const Glib::DateTime& t) { xaccTransSetDateEnteredSecs(gobj(), t.toTime_t()); }
Glib::Date getDatePosted() const Glib::Date getDatePosted() const
{ {
return Glib::Date(xaccTransGetDatePostedGDate(gobj())); 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())); } //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 @@ public:
m_datePosted = v; 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; } //Glib::DateTime getDateEntered() const { return m_dateTimeEntered; }
//void setDateEntered(const Glib::DateTime& v) { m_dateTimeEntered = v; } //void setDateEntered(const Glib::DateTime& v) { m_dateTimeEntered = v; }
@ -297,6 +313,7 @@ private:
TmpSplitList m_splits; TmpSplitList m_splits;
Glib::RefPtr<Commodity> m_commodity; Glib::RefPtr<Commodity> m_commodity;
Glib::Date m_datePosted; Glib::Date m_datePosted;
time_t m_dateTimeEntered;
//Glib::DateTime m_dateTimeEntered; //Glib::DateTime m_dateTimeEntered;
}; };