r18804 - gnucash/trunk/src/gnc - C++ experiment: Add first simple model/view widget for the loaded account list.
Christian Stimming
cstim at code.gnucash.org
Wed Mar 3 16:50:49 EST 2010
Author: cstim
Date: 2010-03-03 16:50:49 -0500 (Wed, 03 Mar 2010)
New Revision: 18804
Trac: http://svn.gnucash.org/trac/changeset/18804
Added:
gnucash/trunk/src/gnc/AccountItemModel.hpp
Modified:
gnucash/trunk/src/gnc/Account.hpp
gnucash/trunk/src/gnc/CMakeLists.txt
gnucash/trunk/src/gnc/WeakPointer.hpp
gnucash/trunk/src/gnc/mainwindow.cpp
gnucash/trunk/src/gnc/mainwindow.hpp
gnucash/trunk/src/gnc/mainwindow.ui
Log:
C++ experiment: Add first simple model/view widget for the loaded account list.
Modified: gnucash/trunk/src/gnc/Account.hpp
===================================================================
--- gnucash/trunk/src/gnc/Account.hpp 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/Account.hpp 2010-03-03 21:50:49 UTC (rev 18804)
@@ -2,6 +2,7 @@
#define GNC_ACCOUNT_HPP
// gnucash includes
+#include "config.h"
extern "C"
{
#include "qof.h"
@@ -10,6 +11,8 @@
#include "gnc/WeakPointer.hpp"
+#include <QAbstractItemModel>
+
namespace gnc
{
@@ -20,6 +23,15 @@
Account(element_type* ptr = 0)
: base_class(ptr)
{ }
+ std::string getName() const { return xaccAccountGetName(get()); }
+ Account get_parent() const { return gnc_account_get_parent(get()); }
+ Account get_root() { return gnc_account_get_root(get()); }
+ bool is_root() const { return gnc_account_is_root(get()); }
+ gint n_children() const { return gnc_account_n_children(get()); }
+ GList *get_children() const { return gnc_account_get_children(get()); }
+ GList * get_descendants () const { return gnc_account_get_descendants (get()); }
+ Account nth_child (gint num) const { return gnc_account_nth_child(get(), num); }
+
};
} // END namespace gnc
Added: gnucash/trunk/src/gnc/AccountItemModel.hpp
===================================================================
--- gnucash/trunk/src/gnc/AccountItemModel.hpp (rev 0)
+++ gnucash/trunk/src/gnc/AccountItemModel.hpp 2010-03-03 21:50:49 UTC (rev 18804)
@@ -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
Modified: gnucash/trunk/src/gnc/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/gnc/CMakeLists.txt 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/CMakeLists.txt 2010-03-03 21:50:49 UTC (rev 18804)
@@ -17,6 +17,7 @@
)
SET (gnc_QOBJECT_HEADERS
+ AccountItemModel.hpp
mainwindow.hpp
)
SET (gnc_HEADERS ${gnc_QOBJECT_HEADERS}
Modified: gnucash/trunk/src/gnc/WeakPointer.hpp
===================================================================
--- gnucash/trunk/src/gnc/WeakPointer.hpp 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/WeakPointer.hpp 2010-03-03 21:50:49 UTC (rev 18804)
@@ -1,6 +1,8 @@
#ifndef GNC_WEAKPOINTER_HPP
#define GNC_WEAKPOINTER_HPP
+#include <string>
+
namespace gnc
{
Modified: gnucash/trunk/src/gnc/mainwindow.cpp
===================================================================
--- gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-03 21:50:49 UTC (rev 18804)
@@ -1,7 +1,8 @@
+#include <QtCore/QSettings>
+#include <QtGui/QCloseEvent>
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
#include <QtGui/QToolBar>
-#include <QtGui/QMessageBox>
-#include <QtGui/QFileDialog>
-#include <QtCore/QSettings>
#include "config.h"
#include "mainwindow.hpp"
@@ -19,6 +20,7 @@
}
#include "gnc/Account.hpp"
+#include "gnc/AccountItemModel.hpp"
#include "gnc/Book.hpp"
namespace gnc
@@ -38,6 +40,7 @@
MainWindow::MainWindow()
: ui(new Ui::MainWindow)
+ , m_accountItemModel(NULL)
{
ui->setupUi(this);
@@ -47,8 +50,8 @@
readSettings();
- connect(ui->textEdit->document(), SIGNAL(contentsChanged()),
- this, SLOT(documentWasModified()));
+// connect(ui->labelMain, SIGNAL(linkActivated(const QString&)),
+// this, SLOT(documentWasModified()));
setWindowIcon(QIcon(":/pixmaps/gnucash-icon-32x32.png"));
@@ -101,7 +104,7 @@
void MainWindow::documentWasModified()
{
- setWindowModified(ui->textEdit->document()->isModified());
+// setWindowModified(ui->textEdit->document()->isModified());
}
void MainWindow::createActions()
@@ -118,19 +121,19 @@
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
- connect(ui->actionCut, SIGNAL(triggered()), ui->textEdit, SLOT(cut()));
- connect(ui->actionCopy, SIGNAL(triggered()), ui->textEdit, SLOT(copy()));
- connect(ui->actionPaste, SIGNAL(triggered()), ui->textEdit, SLOT(paste()));
+// connect(ui->actionCut, SIGNAL(triggered()), ui->textEdit, SLOT(cut()));
+// connect(ui->actionCopy, SIGNAL(triggered()), ui->textEdit, SLOT(copy()));
+// connect(ui->actionPaste, SIGNAL(triggered()), ui->textEdit, SLOT(paste()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
ui->actionCut->setEnabled(false);
ui->actionCopy->setEnabled(false);
- connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
- ui->actionCut, SLOT(setEnabled(bool)));
- connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
- ui->actionCopy, SLOT(setEnabled(bool))); // why doesn't this work?!?
+// connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
+// ui->actionCut, SLOT(setEnabled(bool)));
+// connect(ui->textEdit, SIGNAL(copyAvailable(bool)),
+// ui->actionCopy, SLOT(setEnabled(bool)));
}
void MainWindow::createToolBars()
@@ -169,7 +172,7 @@
bool MainWindow::maybeSave()
{
- if (ui->textEdit->document()->isModified())
+ if (false)//ui->textEdit->document()->isModified())
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Application"),
@@ -187,7 +190,7 @@
void MainWindow::setCurrentFile(const QString &fileName)
{
curFile = fileName;
- ui->textEdit->document()->setModified(false);
+// ui->textEdit->document()->setModified(false);
setWindowModified(false);
QString shownName;
@@ -393,15 +396,28 @@
/* close up the old file session (if any) */
m_session.reset(new_session);
- ::Account * new_root = m_session.get_book().get_root_account().get();
- if (we_are_in_error)
- new_root = NULL;
-
qof_event_resume ();
/* Call this after re-enabling events. */
gnc_book_opened (m_session);
+ // ////////////////////////////////////////////////////////////
+ // Some display about this file
+
+ Account root (m_session.get_book().get_root_account());
+ if (root)
+ {
+ m_accountItemModel = new AccountItemModel(root, this);
+ ui->tableView->setModel(m_accountItemModel);
+ ui->tabWidget->setCurrentIndex(1); //setCurrentWidget(ui->tableView);
+ }
+ else
+ {
+ //ui->labelMain->setText(tr("No root account"));
+ }
+
+ // ////////////////////////////////////////////////////////////
+
QApplication::restoreOverrideCursor();
setCurrentFile(fileName);
Modified: gnucash/trunk/src/gnc/mainwindow.hpp
===================================================================
--- gnucash/trunk/src/gnc/mainwindow.hpp 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/mainwindow.hpp 2010-03-03 21:50:49 UTC (rev 18804)
@@ -4,6 +4,7 @@
#include <QMainWindow>
#include <QSharedPointer>
#include "gnc/Session.hpp"
+#include "gnc/AccountItemModel.hpp"
class QAction;
class QMenu;
@@ -58,6 +59,7 @@
QToolBar *editToolBar;
Session m_session;
+ AccountItemModel *m_accountItemModel;
};
} // END namespace gnc
Modified: gnucash/trunk/src/gnc/mainwindow.ui
===================================================================
--- gnucash/trunk/src/gnc/mainwindow.ui 2010-03-03 21:34:01 UTC (rev 18803)
+++ gnucash/trunk/src/gnc/mainwindow.ui 2010-03-03 21:50:49 UTC (rev 18804)
@@ -63,14 +63,14 @@
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
- <string>Example Text Editor</string>
+ <string>Account Name List View</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>0</number>
</property>
<item>
- <widget class="QPlainTextEdit" name="textEdit"/>
+ <widget class="QTableView" name="tableView"/>
</item>
</layout>
</widget>
More information about the gnucash-changes
mailing list