[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bknipptasch=5D_/=3A_move_AccountSortFilterProxyModel?=
From: Stefan_Böhmann <kde () hilefoks ! org>
Date: 2011-02-02 17:52:43
Message-ID: 20110202175243.4C515A60D1 () git ! kde ! org
[Download RAW message or body]
Git commit 2d596ac5a35acaba011fb66744676e458d498f75 by Stefan Böhmann.
Committed on 01/02/11 at 12:45.
Pushed by sboehmann into branch 'master'.
move AccountSortFilterProxyModel from gui/ to core/
M +2 -0 core/CMakeLists.txt
A +298 -0 core/accountsortfilterproxymodel.cpp [License: GPL (v2+)]
A +76 -0 core/accountsortfilterproxymodel.h [License: GPL (v2+)]
A +1 -0 core/include/Knipptasch/AccountSortFilterProxyModel [License: \
UNKNOWN] M +0 -2 gui/CMakeLists.txt
D +0 -283 gui/accountsortfilterproxymodel.cpp
D +0 -64 gui/accountsortfilterproxymodel.h
M +2 -0 gui/accountwidget.cpp
http://commits.kde.org/knipptasch/2d596ac5a35acaba011fb66744676e458d498f75
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index e06a3a2..26b22fb 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -22,6 +22,7 @@ set( knipptasch_core_SOURCES
accountmodel.cpp
categorymodel.cpp
+ accountsortfilterproxymodel.cpp
widgets/dateedit.cpp
widgets/datevalidator.cpp
@@ -50,6 +51,7 @@ set( knipptasch_core_HEADERS
accountmodel.h
categorymodel.h
+ accountsortfilterproxymodel.h
widgets/dateedit.h
widgets/datevalidator.h
diff --git a/core/accountsortfilterproxymodel.cpp \
b/core/accountsortfilterproxymodel.cpp new file mode 100644
index 0000000..87e82e3
--- /dev/null
+++ b/core/accountsortfilterproxymodel.cpp
@@ -0,0 +1,298 @@
+/*
+ * Copyright 2008-2010 Stefan Böhmann <kde@hilefoks.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "accountsortfilterproxymodel.h"
+
+#include "backend/money.h"
+#include "backend/account.h"
+#include "backend/posting.h"
+
+#include <QDate>
+#include <QTimer>
+#include <QColor>
+
+
+#define TEST_LESS_THAN_RESULT_TRUE 1
+#define TEST_LESS_THAN_RESULT_FALSE 0
+#define TEST_LESS_THAN_RESULT_UNKNOWN -1
+
+
+
+AccountSortFilterProxyModel::AccountSortFilterProxyModel(QObject *parent)
+ : QSortFilterProxyModel( parent )
+{
+ connect( this, SIGNAL( modelReset() ), this, SLOT( updateCache() ) );
+
+ connect( this, SIGNAL( rowsInserted(const QModelIndex &, int, int) ),
+ this, SLOT( updateCache() ) );
+ connect( this, SIGNAL( rowsRemoved(const QModelIndex &, int, int) ),
+ this, SLOT( updateCache() ) );
+
+ QTimer::singleShot( 0, this, SLOT( updateCache() ) );
+}
+
+
+Account* AccountSortFilterProxyModel::account()
+{
+ AccountModel *model = qobject_cast<AccountModel*>( sourceModel() );
+ Q_ASSERT( model );
+
+ return model->account();
+}
+
+
+const Account* AccountSortFilterProxyModel::account() const
+{
+ const AccountModel *model = qobject_cast<const AccountModel*>( sourceModel() );
+ Q_ASSERT( model );
+
+ return model->account();
+}
+
+
+QVariant AccountSortFilterProxyModel::data(const QModelIndex &idx, int role) const
+{
+ if( !idx.isValid() ) {
+ return QSortFilterProxyModel::data( idx, role );
+ }
+
+ if( mapToSource( idx ).column() == AccountModel::BALANCE ) {
+ if( role == Qt::TextAlignmentRole ) {
+ return static_cast<int>( Qt::AlignRight | Qt::AlignVCenter );
+ }
+ else if( role == Qt::ForegroundRole ) {
+ if( !m_cache.contains( idx.row() ) ) { // Value not cached
+ return QVariant();
+ }
+
+ const AccountModel *model = qobject_cast<const AccountModel*>( \
sourceModel() ); + Q_ASSERT( model );
+
+ Money m = data( idx, Qt::EditRole ).value<Money>();
+ if( m >= 0.0 && model->positiveAmountForegroundColor().isValid() ) {
+ return model->positiveAmountForegroundColor();
+ }
+ else if( m < 0.0 && model->negativeAmountForegroundColor().isValid() ) {
+ return model->negativeAmountForegroundColor();
+ }
+ }
+ else if( role == Qt::EditRole ) {
+ // Although this column is not editable, this value is still needed (!
+ return QVariant::fromValue( m_cache.value( idx.row() ) );
+ }
+ else if( role == Qt::DisplayRole ) {
+ return m_cache.contains( idx.row() )
+ ? m_cache.value( idx.row() ).toString()
+ : "-";
+ }
+ }
+
+ return QSortFilterProxyModel::data( idx, role );
+}
+
+
+bool AccountSortFilterProxyModel::setData(const QModelIndex &idx, const QVariant \
&value, int role) +{
+ if( !QSortFilterProxyModel::setData( idx, value, role ) ) {
+ return false;
+ }
+
+ if( mapToSource( idx ).column() == AccountModel::AMOUNT ) {
+ updateCache( idx.row() );
+ }
+
+ return true;
+}
+
+
+AccountSortFilterProxyModel::PostingSortOrder \
AccountSortFilterProxyModel::postingSortOrder() const +{
+ return m_postingSortOrder;
+}
+
+
+void AccountSortFilterProxyModel::setPostingSortOrder(AccountSortFilterProxyModel::PostingSortOrder \
order) +{
+ m_postingSortOrder = order;
+}
+
+
+void AccountSortFilterProxyModel::updateCache(int firstRow)
+{
+ const int amountColumnView = mapFromSource( sourceModel()->index( 0, \
AccountModel::AMOUNT ) ).column(); + const int balanceColumnView = mapFromSource( \
sourceModel()->index( 0, AccountModel::BALANCE ) ).column(); +
+ if( firstRow <= 0 ) {
+ m_cache.clear();
+ }
+
+ for(int viewIndex = qMax( firstRow, 0 ); viewIndex < rowCount(); ++viewIndex) {
+ Money money = data( index( viewIndex, amountColumnView ), Qt::EditRole \
).value<Money>(); +
+ if( viewIndex <= 0 ) {
+ money += account()->openingBalance();
+ }
+ else {
+ money += data( index( viewIndex - 1, balanceColumnView ), Qt::EditRole \
).value<Money>(); + }
+
+ m_cache.insert( viewIndex, money );
+ }
+}
+
+
+bool AccountSortFilterProxyModel::lessThan(const QModelIndex &left, const \
QModelIndex &right) const +{
+ int result = lessThanByType( left, right );
+
+ if( result > TEST_LESS_THAN_RESULT_UNKNOWN ) {
+ return result == TEST_LESS_THAN_RESULT_TRUE ? true : false;
+ }
+
+ result = lessThanDateBased( left, right );
+ if( result > TEST_LESS_THAN_RESULT_UNKNOWN ) {
+ return result == TEST_LESS_THAN_RESULT_TRUE ? true : false;
+ }
+
+ QString lstr = sourceModel()->data(
+ createIndex( left.row(), AccountModel::POSTINGTEXT ),
+ Qt::EditRole
+ ).toString().trimmed();
+
+ QString rstr = sourceModel()->data(
+ createIndex( right.row(), AccountModel::POSTINGTEXT ),
+ Qt::EditRole
+ ).toString().trimmed();
+
+ Money lamount = sourceModel()->data(
+ createIndex( left.row(), AccountModel::AMOUNT ),
+ Qt::EditRole
+ ).value<Money>();
+
+ Money ramount = sourceModel()->data(
+ createIndex( right.row(), AccountModel::AMOUNT ),
+ Qt::EditRole
+ ).value<Money>();
+
+ if( !( lstr.isEmpty() && rstr.isEmpty() ) ) {
+ return lstr < rstr;
+ }
+ else if( lamount != ramount ) {
+ return lamount < ramount;
+ }
+
+ return left.row() < right.row();
+}
+
+
+int AccountSortFilterProxyModel::lessThanByType(const QModelIndex &left, const \
QModelIndex &right) const +{
+ const AccountModel *model = qobject_cast<const AccountModel*>( sourceModel() );
+ Q_ASSERT( model );
+
+ int l_type = model->postingType( left.row() );
+ int r_type = model->postingType( right.row() );
+
+ if( l_type < r_type ) {
+ return TEST_LESS_THAN_RESULT_TRUE;
+ }
+ else if( l_type > r_type ) {
+ return TEST_LESS_THAN_RESULT_FALSE;
+ }
+
+ return TEST_LESS_THAN_RESULT_UNKNOWN;
+}
+
+
+int AccountSortFilterProxyModel::lessThanDateBased(const QModelIndex &left, const \
QModelIndex &right) const +{
+ const QDate l_maturity = sourceModel()->data(
+ createIndex( left.row(), AccountModel::MATURITY ),
+ Qt::EditRole ).value<QDate>();
+
+ const QDate r_maturity = sourceModel()->data(
+ createIndex( right.row(), AccountModel::MATURITY ),
+ Qt::EditRole ).value<QDate>();
+
+ const QDate l_valuedate = sourceModel()->data(
+ createIndex( left.row(), AccountModel::VALUEDATE ),
+ Qt::EditRole ).value<QDate>();
+
+ const QDate r_valuedate = sourceModel()->data(
+ createIndex( right.row(), AccountModel::VALUEDATE ),
+ Qt::EditRole ).value<QDate>();
+
+ QDate l_primary, r_primary, l_secondary, r_secondary;
+
+ switch( postingSortOrder() ) {
+ case AccountSortFilterProxyModel::Maturity:
+ l_primary = l_maturity;
+ r_primary = r_maturity;
+ l_secondary = l_valuedate;
+ r_secondary = r_valuedate;
+ break;
+
+ case AccountSortFilterProxyModel::ValueDate:
+ l_primary = l_valuedate;
+ r_primary = r_valuedate;
+ l_secondary = l_maturity;
+ r_secondary = r_maturity;
+
+ default:
+ Q_ASSERT_X( false, Q_FUNC_INFO, "Unhandled \
'AbstractPreferences::PostingSortOrder' configuration value" ); + }
+
+ if( l_primary.isValid() && !r_primary.isValid() ) {
+ return TEST_LESS_THAN_RESULT_TRUE;
+ }
+ else if( !l_primary.isValid() && r_primary.isValid() ) {
+ return TEST_LESS_THAN_RESULT_FALSE;
+ }
+ else if( l_primary.isValid() && r_primary.isValid() ) {
+ if( l_primary != r_primary ) {
+ return l_primary < r_primary
+ ? TEST_LESS_THAN_RESULT_TRUE
+ : TEST_LESS_THAN_RESULT_FALSE;
+ }
+ }
+
+ Q_ASSERT( ( l_primary.isValid() && l_primary == r_primary )
+ || ( !l_primary.isValid() && !r_primary.isValid() ) );
+
+
+ if( l_secondary.isValid() && !r_secondary.isValid() ) {
+ return TEST_LESS_THAN_RESULT_TRUE;
+ }
+ else if( !l_secondary.isValid() && r_secondary.isValid() ) {
+ return TEST_LESS_THAN_RESULT_FALSE;
+ }
+ else if( l_secondary.isValid() && r_secondary.isValid() ) {
+ if( l_secondary != r_secondary ) {
+ return l_secondary < r_secondary
+ ? TEST_LESS_THAN_RESULT_TRUE
+ : TEST_LESS_THAN_RESULT_FALSE;
+ }
+ }
+ Q_ASSERT( ( l_secondary.isValid() && l_secondary == r_secondary )
+ || ( !l_secondary.isValid() && !r_secondary.isValid() ) );
+
+ return TEST_LESS_THAN_RESULT_UNKNOWN;
+}
+
+
+
+// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on; +// vim:set spell et sw=4 ts=4 nowrap \
cino=l1,cs,U1:
diff --git a/core/accountsortfilterproxymodel.h b/core/accountsortfilterproxymodel.h
new file mode 100644
index 0000000..0d2fbde
--- /dev/null
+++ b/core/accountsortfilterproxymodel.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2008-2010 Stefan Böhmann <kde@hilefoks.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef ACCOUNTSORTFILTERPROXYMODEL_H
+#define ACCOUNTSORTFILTERPROXYMODEL_H
+
+#include "knipptasch_core_export.h"
+
+#include "accountmodel.h"
+#include "backend/money.h"
+
+#include <QSortFilterProxyModel>
+#include <QMap>
+
+
+/**
+ * @class AccountSortFilterProxyModel
+ * @brief
+ *
+ * @author Stefan Böhmann <kde@hilefoks.org>
+ */
+class KNIPPTASCH_CORE_EXPORT AccountSortFilterProxyModel : public \
QSortFilterProxyModel +{
+ Q_OBJECT
+
+ public:
+ enum PostingSortOrder
+ {
+ Maturity = 0,
+ ValueDate
+ };
+
+ explicit AccountSortFilterProxyModel(QObject *parent = 0);
+
+ Account* account();
+ const Account* account() const;
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = \
Qt::EditRole); +
+ AccountSortFilterProxyModel::PostingSortOrder postingSortOrder() const;
+ void setPostingSortOrder(AccountSortFilterProxyModel::PostingSortOrder \
order); +
+ public slots:
+ void updateCache(int firstRow = 0);
+
+ protected:
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+
+ private:
+ int lessThanByType(const QModelIndex &left, const QModelIndex &right) const;
+ int lessThanDateBased(const QModelIndex &left, const QModelIndex &right) \
const; +
+ private:
+ mutable QMap<int, Money> m_cache;
+ AccountSortFilterProxyModel::PostingSortOrder m_postingSortOrder;
+};
+
+
+#endif
+
+// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on; +// vim:set spell et sw=4 ts=4 nowrap \
cino=l1,cs,U1:
diff --git a/core/include/Knipptasch/AccountSortFilterProxyModel \
b/core/include/Knipptasch/AccountSortFilterProxyModel new file mode 100644
index 0000000..f133755
--- /dev/null
+++ b/core/include/Knipptasch/AccountSortFilterProxyModel
@@ -0,0 +1 @@
+#include <accountsortfilerproxymodel.h>
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index 82a9374..acb4270 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -1,7 +1,6 @@
project( knipptasch )
set(knipptasch_SOURCES
- accountsortfilterproxymodel.cpp
accountwidget.cpp
welcomewidget.cpp
mainwindow.cpp
@@ -36,7 +35,6 @@ set(knipptasch_SOURCES
set( knipptasch_HEADERS
mainwindow.h
accountwidget.h
- accountsortfilterproxymodel.h
welcomewidget.h
aboutdialog.h
savemodifieddialog.h
diff --git a/gui/accountsortfilterproxymodel.cpp \
b/gui/accountsortfilterproxymodel.cpp deleted file mode 100644
index 9ad74f8..0000000
--- a/gui/accountsortfilterproxymodel.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright 2008-2010 Stefan Böhmann <kde@hilefoks.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#include "accountsortfilterproxymodel.h"
-
-#include "preferences.h"
-#include "backend/money.h"
-#include "backend/account.h"
-#include "backend/posting.h"
-
-#include <QDate>
-#include <QDebug>
-#include <QTimer>
-
-#define TEST_LESS_THAN_RESULT_TRUE 1
-#define TEST_LESS_THAN_RESULT_FALSE 0
-#define TEST_LESS_THAN_RESULT_UNKNOWN -1
-
-
-
-AccountSortFilterProxyModel::AccountSortFilterProxyModel(QObject *parent)
- : QSortFilterProxyModel( parent )
-{
- connect( this, SIGNAL( modelReset() ), this, SLOT( updateCache() ) );
-
- connect( this, SIGNAL( rowsInserted(const QModelIndex &, int, int) ),
- this, SLOT( updateCache() ) );
- connect( this, SIGNAL( rowsRemoved(const QModelIndex &, int, int) ),
- this, SLOT( updateCache() ) );
-
- QTimer::singleShot( 0, this, SLOT( updateCache() ) );
-}
-
-
-Account* AccountSortFilterProxyModel::account()
-{
- AccountModel *model = qobject_cast<AccountModel*>( sourceModel() );
- Q_ASSERT( model );
-
- return model->account();
-}
-
-
-const Account* AccountSortFilterProxyModel::account() const
-{
- const AccountModel *model = qobject_cast<const AccountModel*>( sourceModel() );
- Q_ASSERT( model );
-
- return model->account();
-}
-
-
-QVariant AccountSortFilterProxyModel::data(const QModelIndex &idx, int role) const
-{
- if( !idx.isValid() ) {
- return QSortFilterProxyModel::data( idx, role );
- }
-
- if( mapToSource( idx ).column() == AccountModel::BALANCE ) {
- if( role == Qt::TextAlignmentRole ) {
- return static_cast<int>( Qt::AlignRight | Qt::AlignVCenter );
- }
- else if( role == Qt::ForegroundRole ) {
- if( !m_cache.contains( idx.row() ) ) { // Value not cached
- return QVariant();
- }
-
- Money m = data( idx, Qt::EditRole ).value<Money>();
- if( m >= 0.0 && Preferences::self()->positiveAmountForegroundEnabled() ) \
{
- return Preferences::self()->positiveAmountForegroundColor();
- }
- else if( m < 0.0 && \
Preferences::self()->negativeAmountForegroundEnabled() ) {
- return Preferences::self()->negativeAmountForegroundColor();
- }
- }
- else if( role == Qt::EditRole ) {
- // Although this column is not editable, this value is still needed (!
- return QVariant::fromValue( m_cache.value( idx.row() ) );
- }
- else if( role == Qt::DisplayRole ) {
- return m_cache.contains( idx.row() )
- ? m_cache.value( idx.row() ).toString()
- : "-";
- }
- }
-
- return QSortFilterProxyModel::data( idx, role );
-}
-
-
-bool AccountSortFilterProxyModel::setData(const QModelIndex &idx, const QVariant \
&value, int role)
-{
- if( !QSortFilterProxyModel::setData( idx, value, role ) ) {
- return false;
- }
-
- if( mapToSource( idx ).column() == AccountModel::AMOUNT ) {
- updateCache( idx.row() );
- }
-
- return true;
-}
-
-
-void AccountSortFilterProxyModel::updateCache(int firstRow)
-{
- const int amountColumnView = mapFromSource( sourceModel()->index( 0, \
AccountModel::AMOUNT ) ).column();
- const int balanceColumnView = mapFromSource( sourceModel()->index( 0, \
AccountModel::BALANCE ) ).column();
-
- if( firstRow <= 0 ) {
- m_cache.clear();
- }
-
- for(int viewIndex = qMax( firstRow, 0 ); viewIndex < rowCount(); ++viewIndex) {
- Money money = data( index( viewIndex, amountColumnView ), Qt::EditRole \
).value<Money>();
-
- if( viewIndex <= 0 ) {
- money += account()->openingBalance();
- }
- else {
- money += data( index( viewIndex - 1, balanceColumnView ), Qt::EditRole \
).value<Money>();
- }
-
- m_cache.insert( viewIndex, money );
- }
-}
-
-
-bool AccountSortFilterProxyModel::lessThan(const QModelIndex &left, const \
QModelIndex &right) const
-{
- int result = lessThanByType( left, right );
-
- if( result > TEST_LESS_THAN_RESULT_UNKNOWN ) {
- return result == TEST_LESS_THAN_RESULT_TRUE ? true : false;
- }
-
- result = lessThanDateBased( left, right );
- if( result > TEST_LESS_THAN_RESULT_UNKNOWN ) {
- return result == TEST_LESS_THAN_RESULT_TRUE ? true : false;
- }
-
- QString lstr = sourceModel()->data(
- createIndex( left.row(), AccountModel::POSTINGTEXT ),
- Qt::EditRole
- ).toString().trimmed();
-
- QString rstr = sourceModel()->data(
- createIndex( right.row(), AccountModel::POSTINGTEXT ),
- Qt::EditRole
- ).toString().trimmed();
-
- Money lamount = sourceModel()->data(
- createIndex( left.row(), AccountModel::AMOUNT ),
- Qt::EditRole
- ).value<Money>();
-
- Money ramount = sourceModel()->data(
- createIndex( right.row(), AccountModel::AMOUNT ),
- Qt::EditRole
- ).value<Money>();
-
- if( !( lstr.isEmpty() && rstr.isEmpty() ) ) {
- return lstr < rstr;
- }
- else if( lamount != ramount ) {
- return lamount < ramount;
- }
-
- return left.row() < right.row();
-}
-
-
-int AccountSortFilterProxyModel::lessThanByType(const QModelIndex &left, const \
QModelIndex &right) const
-{
- const AccountModel *model = qobject_cast<const AccountModel*>( sourceModel() );
- Q_ASSERT( model );
-
- int l_type = model->postingType( left.row() );
- int r_type = model->postingType( right.row() );
-
- if( l_type < r_type ) {
- return TEST_LESS_THAN_RESULT_TRUE;
- }
- else if( l_type > r_type ) {
- return TEST_LESS_THAN_RESULT_FALSE;
- }
-
- return TEST_LESS_THAN_RESULT_UNKNOWN;
-}
-
-
-int AccountSortFilterProxyModel::lessThanDateBased(const QModelIndex &left, const \
QModelIndex &right) const
-{
- const QDate l_maturity = sourceModel()->data(
- createIndex( left.row(), AccountModel::MATURITY ),
- Qt::EditRole ).value<QDate>();
-
- const QDate r_maturity = sourceModel()->data(
- createIndex( right.row(), AccountModel::MATURITY ),
- Qt::EditRole ).value<QDate>();
-
- const QDate l_valuedate = sourceModel()->data(
- createIndex( left.row(), AccountModel::VALUEDATE ),
- Qt::EditRole ).value<QDate>();
-
- const QDate r_valuedate = sourceModel()->data(
- createIndex( right.row(), AccountModel::VALUEDATE ),
- Qt::EditRole ).value<QDate>();
-
- QDate l_primary, r_primary, l_secondary, r_secondary;
-
- switch( Preferences::self()->sortPostingsBy() ) {
- case Preferences::Maturity:
- l_primary = l_maturity;
- r_primary = r_maturity;
- l_secondary = l_valuedate;
- r_secondary = r_valuedate;
- break;
-
- case Preferences::ValueDate:
- l_primary = l_valuedate;
- r_primary = r_valuedate;
- l_secondary = l_maturity;
- r_secondary = r_maturity;
-
- default:
- Q_ASSERT_X( false, Q_FUNC_INFO, "Unhandled 'SortPostingBy' configuration \
value" );
- }
-
- if( l_primary.isValid() && !r_primary.isValid() ) {
- return TEST_LESS_THAN_RESULT_TRUE;
- }
- else if( !l_primary.isValid() && r_primary.isValid() ) {
- return TEST_LESS_THAN_RESULT_FALSE;
- }
- else if( l_primary.isValid() && r_primary.isValid() ) {
- if( l_primary != r_primary ) {
- return l_primary < r_primary
- ? TEST_LESS_THAN_RESULT_TRUE
- : TEST_LESS_THAN_RESULT_FALSE;
- }
- }
-
- Q_ASSERT( ( l_primary.isValid() && l_primary == r_primary )
- || ( !l_primary.isValid() && !r_primary.isValid() ) );
-
-
- if( l_secondary.isValid() && !r_secondary.isValid() ) {
- return TEST_LESS_THAN_RESULT_TRUE;
- }
- else if( !l_secondary.isValid() && r_secondary.isValid() ) {
- return TEST_LESS_THAN_RESULT_FALSE;
- }
- else if( l_secondary.isValid() && r_secondary.isValid() ) {
- if( l_secondary != r_secondary ) {
- return l_secondary < r_secondary
- ? TEST_LESS_THAN_RESULT_TRUE
- : TEST_LESS_THAN_RESULT_FALSE;
- }
- }
- Q_ASSERT( ( l_secondary.isValid() && l_secondary == r_secondary )
- || ( !l_secondary.isValid() && !r_secondary.isValid() ) );
-
- return TEST_LESS_THAN_RESULT_UNKNOWN;
-}
-
-
-
-// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on;
-// vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1:
diff --git a/gui/accountsortfilterproxymodel.h b/gui/accountsortfilterproxymodel.h
deleted file mode 100644
index f0d22aa..0000000
--- a/gui/accountsortfilterproxymodel.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2008-2010 Stefan Böhmann <kde@hilefoks.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef ACCOUNTSORTFILTERPROXYMODEL_H
-#define ACCOUNTSORTFILTERPROXYMODEL_H
-
-#include "accountmodel.h"
-#include "backend/money.h"
-
-#include <QSortFilterProxyModel>
-#include <QMap>
-
-
-/**
- * @class AccountSortFilterProxyModel
- * @brief
- *
- * @author Stefan Böhmann <kde@hilefoks.org>
- */
-class AccountSortFilterProxyModel : public QSortFilterProxyModel
-{
- Q_OBJECT
-
- public:
- explicit AccountSortFilterProxyModel(QObject *parent = 0);
-
- Account* account();
- const Account* account() const;
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role = \
Qt::EditRole);
-
- public slots:
- void updateCache(int firstRow = 0);
-
- protected:
- bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
-
- private:
- int lessThanByType(const QModelIndex &left, const QModelIndex &right) const;
- int lessThanDateBased(const QModelIndex &left, const QModelIndex &right) \
const;
-
- private:
- mutable QMap<int, Money> m_cache;
-};
-
-
-#endif
-
-// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on;
-// vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1:
diff --git a/gui/accountwidget.cpp b/gui/accountwidget.cpp
index c21911c..a4179c6 100644
--- a/gui/accountwidget.cpp
+++ b/gui/accountwidget.cpp
@@ -303,6 +303,8 @@ void AccountWidget::loadConfig()
ui->view->horizontalHeader()->restoreState( arr );
}
+ m_proxy->setPostingSortOrder( \
static_cast<AccountSortFilterProxyModel::PostingSortOrder>( p->sortPostingsBy() ) ); \
+
m_model->setPositiveAmountForegroundColor(
p->positiveAmountForegroundEnabled()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic