Blob Blame History Raw
From d116fc872c0a6e3b0b4322fd26e884394cb4cc19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cristian=20One=C8=9B?= <onet.cristian@gmail.com>
Date: Wed, 21 Nov 2012 21:04:32 +0200
Subject: [PATCH 07/22] Save the header state in the investment view's lists.

Since pretty much all the bigger item views in KMyMoney have a persistent header state make the investment view's lists behave in the same way.
Fix the default sorting order in the 'Prices' and 'Update prices' dialogs since those are stand alone they don't have a persistent header state yet
because they don't even have a persistent size.

BUG: 310260
(cherry picked from commit 7c972b7b2bc05f00fe8f3e03b3d7ef0570d20a66)
---
 kmymoney/dialogs/kequitypriceupdatedlg.cpp |  1 +
 kmymoney/dialogs/kmymoneypricedlg.cpp      |  1 +
 kmymoney/views/kinvestmentview.cpp         | 40 ++++++++++++++++--------------
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/kmymoney/dialogs/kequitypriceupdatedlg.cpp b/kmymoney/dialogs/kequitypriceupdatedlg.cpp
index ff96bab..177bc78 100644
--- a/kmymoney/dialogs/kequitypriceupdatedlg.cpp
+++ b/kmymoney/dialogs/kequitypriceupdatedlg.cpp
@@ -69,6 +69,7 @@ KEquityPriceUpdateDlg::KEquityPriceUpdateDlg(QWidget *parent, const QString& sec
   headerList << i18n("Symbol") << i18nc("Equity name", "Name")
   << i18n("Price") << i18n("Date");
 
+  lvEquityList->header()->setSortIndicator(0, Qt::AscendingOrder);
   lvEquityList->setColumnWidth(NAME_COL, 125);
 
   // This is a "get it up and running" hack.  Will replace this in the future.
diff --git a/kmymoney/dialogs/kmymoneypricedlg.cpp b/kmymoney/dialogs/kmymoneypricedlg.cpp
index 0aa5af3..61d197b 100644
--- a/kmymoney/dialogs/kmymoneypricedlg.cpp
+++ b/kmymoney/dialogs/kmymoneypricedlg.cpp
@@ -60,6 +60,7 @@ KMyMoneyPriceDlg::KMyMoneyPriceDlg(QWidget* parent) :
   m_searchWidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
   m_listLayout->insertWidget(0, m_searchWidget);
 
+  m_priceList->header()->setSortIndicator(0, Qt::AscendingOrder);
   m_priceList->header()->setStretchLastSection(true);
   m_priceList->setContextMenuPolicy(Qt::CustomContextMenu);
 
diff --git a/kmymoney/views/kinvestmentview.cpp b/kmymoney/views/kinvestmentview.cpp
index b3c13e8..8e407f8 100644
--- a/kmymoney/views/kinvestmentview.cpp
+++ b/kmymoney/views/kinvestmentview.cpp
@@ -71,6 +71,18 @@ KInvestmentView::KInvestmentView(QWidget *parent) :
 {
   setupUi(this);
 
+  // load the header state of the equities list
+  KConfigGroup grp = KGlobal::config()->group("KInvestmentView_Equities");
+  QByteArray columns;
+  columns = grp.readEntry("HeaderState", columns);
+  m_investmentsList->header()->restoreState(columns);
+
+  // load the header state of the securities list
+  grp = KGlobal::config()->group("KInvestmentView_Securities");
+  columns.clear();
+  columns = grp.readEntry("HeaderState", columns);
+  m_securitiesList->header()->restoreState(columns);
+
   //first set up everything for the equities tab
   d->m_filterProxyModel = new AccountNamesFilterProxyModel(this);
   d->m_filterProxyModel->addAccountType(MyMoneyAccount::Investment);
@@ -81,8 +93,6 @@ KInvestmentView::KInvestmentView(QWidget *parent) :
 
   m_investmentsList->setContextMenuPolicy(Qt::CustomContextMenu);
   m_investmentsList->setSortingEnabled(true);
-  //KConfigGroup grp = KGlobal::config()->group("Investment Settings");
-  //m_table->restoreLayout(grp);
 
   for (int i = 0; i < MaxViewTabs; ++i)
     d->m_needReload[i] = false;
@@ -123,8 +133,16 @@ KInvestmentView::KInvestmentView(QWidget *parent) :
 
 KInvestmentView::~KInvestmentView()
 {
-  KConfigGroup grp = KGlobal::config()->group("Investment Settings");
-  //m_table->saveLayout(grp);
+  // save the header state of the equities list
+  KConfigGroup grp = KGlobal::config()->group("KInvestmentView_Equities");
+  QByteArray columns = m_investmentsList->header()->saveState();
+  grp.writeEntry("HeaderState", columns);
+
+  // save the header state of the securities list
+  grp = KGlobal::config()->group("KInvestmentView_Securities");
+  columns = m_securitiesList->header()->saveState();
+  grp.writeEntry("HeaderState", columns);
+
   delete d;
 }
 
@@ -357,12 +375,6 @@ void KInvestmentView::loadInvestmentTab(void)
     delete e;
   }
 
-  //resize the column width
-  m_investmentsList->resizeColumnToContents(0);
-  m_investmentsList->resizeColumnToContents(1);
-  m_investmentsList->resizeColumnToContents(2);
-  m_investmentsList->resizeColumnToContents(3);
-
   // and tell everyone what's selected
   emit accountSelected(d->m_account);
 }
@@ -449,14 +461,6 @@ void KInvestmentView::loadSecuritiesList(void)
   }
   m_securitiesList->setSortingEnabled(true);
 
-  //resize column width
-  m_securitiesList->resizeColumnToContents(1);
-  m_securitiesList->resizeColumnToContents(2);
-  m_securitiesList->resizeColumnToContents(3);
-  m_securitiesList->resizeColumnToContents(4);
-  m_securitiesList->resizeColumnToContents(5);
-  m_securitiesList->resizeColumnToContents(6);
-
   slotUpdateSecuritiesButtons();
 }
 
-- 
1.8.1.4