Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ experiment: Add first simple model/view widget for the loaded acc…
…ount list. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18804 57a11ea4-9604-0410-9ed3-97b8803252fd
- Loading branch information
Showing
7 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef GNC_ACCOUNTITEMMODEL_HPP | ||
#define GNC_ACCOUNTITEMMODEL_HPP | ||
|
||
#include "gnc/Account.hpp" | ||
|
||
#include <QAbstractItemModel> | ||
#include <QAbstractListModel> | ||
|
||
namespace gnc | ||
{ | ||
|
||
class AccountItemModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
AccountItemModel(Account rootaccount, QObject *parent = 0) | ||
: QAbstractListModel(parent) | ||
, m_root(rootaccount) | ||
{ | ||
GList* list = m_root.get_descendants(); | ||
while (list) | ||
{ | ||
m_acclist.append(reinterpret_cast< ::Account*>(list->data)); | ||
list = g_list_next(list); | ||
} | ||
} | ||
|
||
int rowCount(const QModelIndex& parent = QModelIndex()) const { return m_acclist.size(); } | ||
QVariant data(const QModelIndex& index, int role) const | ||
{ | ||
if (!index.isValid()) | ||
return QVariant(); | ||
if (index.row() > rowCount(index)) | ||
return QVariant(); | ||
if (role == Qt::DisplayRole) | ||
return QString::fromStdString(Account(m_acclist.at(index.row())).getName()); | ||
else | ||
return QVariant(); | ||
} | ||
QVariant headerData(int section, Qt::Orientation orientation, int role) const | ||
{ | ||
if (role != Qt::DisplayRole) | ||
return QVariant(); | ||
if (orientation == Qt::Horizontal) | ||
return QString("Account Name"); | ||
else | ||
return QString("#%1").arg(1 + section); | ||
} | ||
private: | ||
Account m_root; | ||
QList< ::Account*> m_acclist; | ||
}; | ||
|
||
} // END namespace gnc | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ifndef GNC_WEAKPOINTER_HPP | ||
#define GNC_WEAKPOINTER_HPP | ||
|
||
#include <string> | ||
|
||
namespace gnc | ||
{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters