Finish column order storage

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@326 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent 21fe83bb82
commit 9c3ef9a709
  1. 24
      src/KpxConfig.h
  2. 133
      src/lib/EntryView.cpp

@ -49,8 +49,16 @@ public:
QColor bannerColor2(){return stringToColor(settings.value("Options/BannerColor2","0,117,175").toString());}
QColor bannerTextColor(){return stringToColor(settings.value("Options/BannerTextColor","222,222,222").toString());}
int clipboardTimeOut(){return settings.value("Options/ClipboardTimeOut",20).toInt();}
QByteArray entryView(){return settings.value("UI/EntryView").toByteArray();}
QByteArray entryViewSearch(){return settings.value("UI/EntryViewSearch").toByteArray();}
QBitArray columns(){return stringToBitArray(settings.value("UI/Columns","11111000000").toString(),11);}
QList<int> columnOrder(){return stringToIntArray(settings.value("UI/ColumnOrder","100,100,100,100,100,100,100,100,100,100,100").toString(),11);}
QList<int> columnSizes(){return stringToIntArray(settings.value("UI/ColumnSizes","15,10,10,10,10,10,10,10,10,10,10").toString(),11);}
int columnSort(){return settings.value("UI/ColumnSort",0).toInt();}
Qt::SortOrder columnSortOrder(){return static_cast<Qt::SortOrder>(settings.value("UI/ColumnSortOrder",Qt::AscendingOrder).toInt());}
QBitArray searchColumns(){return stringToBitArray(settings.value("UI/SearchColumns","11111000000").toString(),11);}
QList<int> searchColumnOrder(){return stringToIntArray(settings.value("UI/SearchColumnOrder","100,100,100,100,100,100,100,100,100,100,100").toString(),11);}
QList<int> searchColumnSizes(){return stringToIntArray(settings.value("UI/SearchColumnSizes","15,10,10,10,10,10,10,10,10,10,10").toString(),11);}
int searchColumnSort(){return settings.value("UI/SearchColumnSort",0).toInt();}
Qt::SortOrder searchColumnSortOrder(){return static_cast<Qt::SortOrder>(settings.value("UI/SearchColumnSortOrder",Qt::AscendingOrder).toInt());}
QStringList fileDlgHistory(unsigned index){return settings.value(QString("FileDlgHistory/ENTRY%1").arg(index)).toStringList();}
GrpTreeState groupTreeState(){return stringToGrpTreeState(settings.value("Options/GroupTreeState").toString());}
bool hidePasswords(){return settings.value("UI/HidePasswords",true).toBool();}
@ -112,8 +120,16 @@ public:
void setBannerColor2(const QColor& value){settings.setValue("Options/BannerColor2",colorToString(value));}
void setBannerTextColor(const QColor& value){settings.setValue("Options/BannerTextColor",colorToString(value));}
void setClipboardTimeOut(int value){settings.setValue("Options/ClipboardTimeOut",value);}
void setEntryView(const QByteArray& value){settings.setValue("UI/EntryView",value);}
void setEntryViewSearch(const QByteArray& value){settings.setValue("UI/EntryViewSearch",value);}
void setColumns(const QBitArray& value){settings.setValue("UI/Columns",bitArrayToString(value));}
void setColumnOrder(const QList<int>& value){settings.setValue("UI/ColumnOrder",intArrayToString(value));}
void setColumnSizes(const QList<int>& value){settings.setValue("UI/ColumnSizes",intArrayToString(value));}
void setColumnSort(int value){settings.setValue("UI/ColumnSort",value);}
void setColumnSortOrder(int value){settings.setValue("UI/ColumnSortOrder",value);}
void setSearchColumns(const QBitArray& value){settings.setValue("UI/SearchColumns",bitArrayToString(value));}
void setSearchColumnOrder(const QList<int>& value){settings.setValue("UI/SearchColumnOrder",intArrayToString(value));}
void setSearchColumnSizes(const QList<int>& value){settings.setValue("UI/SearchColumnSizes",intArrayToString(value));}
void setSearchColumnSort(int value){settings.setValue("UI/SearchColumnSort",value);}
void setSearchColumnSortOrder(int value){settings.setValue("UI/SearchColumnSortOrder",value);}
void setFileDlgHistory(unsigned index,const QStringList& value){settings.setValue(QString("FileDlgHistory/ENTRY%1").arg(index), value);}
void setGroupTreeState(GrpTreeState value){settings.setValue("Options/GroupTreeState",grpTreeStateToString(value));}
void setHidePasswords(bool value){settings.setValue("UI/HidePasswords",value);}

@ -21,10 +21,13 @@
#include <QHeaderView>
#include <QClipboard>
#include <QProcess>
#include <algorithm>
#include "lib/AutoType.h"
#include "lib/EntryView.h"
#include "dialogs/EditEntryDlg.h"
#define NUM_COLUMNS 11
// just for the lessThan funtion
/*QList<EntryViewItem*>* pItems;
KeepassEntryView* pEntryView;*/
@ -34,7 +37,8 @@ KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
header()->setResizeMode(QHeaderView::Interactive);
header()->setStretchLastSection(false);
header()->setClickable(true);
//header()->setCascadingSectionResizes(true);
header()->setCascadingSectionResizes(true);
header()->setStretchLastSection(true);
retranslateColumns();
restoreHeaderView();
@ -68,84 +72,69 @@ void KeepassEntryView::setColumnVisible(int col, bool visible) {
}
void KeepassEntryView::saveHeaderView() {
if (ViewMode == Normal)
config->setEntryView( header()->saveState() );
else
config->setEntryViewSearch( header()->saveState() );
QBitArray columns(NUM_COLUMNS);
QList<int> columnOrder;
QList<int> columnsSizes;
int columnSort = header()->sortIndicatorSection();
Qt::SortOrder columnSortOrder = header()->sortIndicatorOrder();
for (int i=0; i<NUM_COLUMNS; ++i) {
columns.setBit(i, columnVisible(i));
columnOrder << header()->visualIndex(i);
columnsSizes << header()->sectionSize(i);
}
if (ViewMode == Normal) {
config->setColumns(columns);
config->setColumnOrder(columnOrder);
config->setColumnSizes(columnsSizes);
config->setColumnSort(columnSort);
config->setColumnSortOrder(columnSortOrder);
}
else {
config->setSearchColumns(columns);
config->setSearchColumnOrder(columnOrder);
config->setSearchColumnSizes(columnsSizes);
config->setSearchColumnSort(columnSort);
config->setSearchColumnSortOrder(columnSortOrder);
}
}
void KeepassEntryView::restoreHeaderView() {
QBitArray columns;
QList<int> columnOrder;
QList<int> columnSizes;
int columnSort;
Qt::SortOrder columnSortOrder;
if (ViewMode == Normal) {
QByteArray state = config->entryView();
if (state.isEmpty()) {
for (int i=10; i>=0; --i) {
if (i <= 3) {
setColumnVisible(i, true);
header()->moveSection(header()->visualIndex(i), 0);
}
else {
setColumnVisible(i, false);
}
}
header()->setSortIndicator(0, Qt::AscendingOrder);
header()->setSortIndicatorShown(true);
header()->resizeSection(0, (int) (header()->sectionSize(0) * 1.5));
}
else {
header()->restoreState(state);
setColumnVisible(10, false); // just to be sure
QApplication::processEvents();
//QHash<int, int> sectionSize;
QList<int> visibleSections;
for (int i=0; i<=10; ++i) {
if (columnVisible(i)) {
qDebug("%d",i);
visibleSections.append(i);
header()->hideSection(i);
}
}
QApplication::processEvents();
for (int i=0; i<visibleSections.size(); ++i) {
qDebug("%d",visibleSections[i]);
header()->showSection(visibleSections[i]);
}
/*for (int i=0; i<=10; ++i) {
if (columnVisible(i)) {
int size = header()->sectionSize(i);
header()->resizeSection(i, 1);
header()->resizeSection(i, size);
}
}*/
}
columns = config->columns();
columnOrder = config->columnOrder();
columnSizes = config->columnSizes();
columnSort = config->columnSort();
columnSortOrder = config->columnSortOrder();
columns[10] = 0; // just to be sure
}
else {
QByteArray state = config->entryViewSearch();
if (state.isEmpty()) {
for (int i=10; i>=0; --i) {
if (i <= 3 || i == 10) {
setColumnVisible(i, true);
header()->moveSection(header()->visualIndex(i), 0);
}
else {
setColumnVisible(i, false);
}
}
header()->moveSection(header()->visualIndex(10), 0);
header()->setSortIndicator(10, Qt::AscendingOrder);
header()->setSortIndicatorShown(true);
}
else {
header()->restoreState(state);
}
columns = config->searchColumns();
columnOrder = config->searchColumnOrder();
columnSizes = config->searchColumnSizes();
columnSort = config->searchColumnSort();
columnSortOrder = config->searchColumnSortOrder();
}
QMap<int,int> order; // key=visual index; value=logical index
for (int i=0; i<NUM_COLUMNS; ++i) {
order.insert(columnOrder[i], i);
}
for (QMap<int,int>::const_iterator i = order.constBegin(); i != order.constEnd(); ++i) {
setColumnVisible(i.value(), columns.testBit(i.value()));
header()->moveSection(header()->visualIndex(i.value()), NUM_COLUMNS-1);
header()->resizeSection(i.value(), std::max(columnSizes[i.value()], header()->minimumSectionSize()));
}
header()->setSortIndicator(columnSort, columnSortOrder);
}
void KeepassEntryView::OnGroupChanged(IGroupHandle* group){