mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[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:
parent
e08bea1336
commit
905e478531
@ -42,8 +42,6 @@ extern "C"
|
||||
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 @@ public:
|
||||
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
|
||||
|
@ -180,7 +180,7 @@ AccountListModel::AccountListModel(Account rootaccount, QObject *parent)
|
||||
|
||||
void AccountListModel::recreateCache()
|
||||
{
|
||||
m_list = Account::fromGList(m_root.get_descendants());
|
||||
m_list = accountFromGList(m_root.get_descendants());
|
||||
reset();
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,11 @@ protected:
|
||||
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()
|
||||
|
@ -80,6 +80,20 @@ inline ::Timespec toTimespec(const QDateTime& qdt)
|
||||
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++
|
||||
|
@ -37,6 +37,7 @@ extern "C"
|
||||
|
||||
#include "gnc/GncInstance.hpp"
|
||||
#include "gnc/Numeric.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace gnc
|
||||
{
|
||||
@ -45,7 +46,7 @@ class Account;
|
||||
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 @@ public:
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ ViewletModel::leftVGenerate(::Account *selectedAccount)
|
||||
::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 @@ ViewletModel::rightVGenerate(::Account *selectedAccount)
|
||||
::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 @@ ViewletModel::buildSplitListDateSort(AccountQList accountsList)
|
||||
|
||||
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 @@ ViewletModel::lessThanByDate(::Split* a, ::Split* b)
|
||||
void
|
||||
ViewletModel::buildMiniJournalStruct(SplitQList splitList)
|
||||
{
|
||||
int numOfSplits = splitList.count();
|
||||
int numOfSplits = splitList.size();
|
||||
Split split;
|
||||
int i;
|
||||
QDate tempDate;
|
||||
|
@ -16,6 +16,7 @@ extern "C"
|
||||
|
||||
#include "gnc/Split.hpp"
|
||||
#include "gnc/SplitListModel.hpp"
|
||||
#include "gnc/AccountItemModel.hpp"
|
||||
|
||||
namespace gnc
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -80,6 +80,20 @@ inline ::Timespec toTimespec(const Glib::DateTime& gdt)
|
||||
}
|
||||
#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.
|
||||
|
@ -189,16 +189,17 @@ void TmpSplit::clear(::Account* account)
|
||||
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
|
||||
|
@ -189,19 +189,10 @@ public:
|
||||
}
|
||||
|
||||
|
||||
#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 @@ public:
|
||||
/** 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
|
||||
{
|
||||
|
@ -126,17 +126,21 @@ Glib::RefPtr<Split> Transaction::getSplit(int i) const
|
||||
{
|
||||
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 @@ TmpTransaction::TmpTransaction(const Transaction& t)
|
||||
, 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 @@ void TmpTransaction::resetContent()
|
||||
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 @@ void TmpTransaction::copyTo(Glib::RefPtr<Transaction> t) const
|
||||
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 @@ Glib::RefPtr<Transaction> TmpTransaction::createAsReal() const
|
||||
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);
|
||||
|
@ -155,7 +155,7 @@ public:
|
||||
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 @@ public:
|
||||
{
|
||||
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 @@ public:
|
||||
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 @@ private:
|
||||
TmpSplitList m_splits;
|
||||
Glib::RefPtr<Commodity> m_commodity;
|
||||
Glib::Date m_datePosted;
|
||||
time_t m_dateTimeEntered;
|
||||
//Glib::DateTime m_dateTimeEntered;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user