performance improvement in EntryView class

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@47 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 52089355a8
commit d68659e395
  1. 29
      src/lib/EntryView.cpp
  2. 6
      src/lib/EntryView.h
  3. 20
      src/mainwindow.cpp

@ -25,9 +25,12 @@
#include <QDropEvent> #include <QDropEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QHeaderView> #include <QHeaderView>
#include <QTime>
#include "main.h" #include "main.h"
#include "EntryView.h" #include "EntryView.h"
KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){ KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
CurrentGroup=0; CurrentGroup=0;
updateColumns(); updateColumns();
@ -65,13 +68,15 @@ ContextMenu->popup(e->globalPos());
void KeepassEntryView::updateItems(){ void KeepassEntryView::updateItems(unsigned int GroupID){
clear(); clear();
Items.clear(); Items.clear();
if(!db)return; if(!db)return;
if(!GroupID)return;
EntryViewItem *tmp=NULL; EntryViewItem *tmp=NULL;
for(int i=0;i<db->Entries.size();i++){ for(int i=0;i<db->Entries.size();i++){
CEntry* entry=&db->Entries[i]; CEntry* entry=&db->Entries[i];
if(entry->GroupID==GroupID){
Items.push_back(tmp=new EntryViewItem(this)); Items.push_back(tmp=new EntryViewItem(this));
Items.back()->pEntry=entry; Items.back()->pEntry=entry;
int j=0; int j=0;
@ -103,19 +108,11 @@ for(int i=0;i<db->Entries.size();i++){
if(config.Columns[9]){ if(config.Columns[9]){
tmp->setText(j++,entry->BinaryDesc);} tmp->setText(j++,entry->BinaryDesc);}
Items.back()->setIcon(0,EntryIcons[entry->ImageID]); Items.back()->setIcon(0,EntryIcons[entry->ImageID]);
} }}
setCurrentGroup(CurrentGroup);
}
void KeepassEntryView::setCurrentGroup(uint id){
CurrentGroup=id;
for(int i=0; i<Items.size();i++){
setItemHidden(Items[i],(Items[i]->pEntry->GroupID != id));
}
} }
void KeepassEntryView::showSearchResults(QList<Q_UINT32>& results){ void KeepassEntryView::showSearchResults(QList<Q_UINT32>& results){
setCurrentGroup(0); updateItems(0);
for(int j=0; j<results.size(); j++){ for(int j=0; j<results.size(); j++){
for(int i=0; i<Items.size();i++){ for(int i=0; i<Items.size();i++){
if(Items[i]->pEntry->sID == results[j]) if(Items[i]->pEntry->sID == results[j])
@ -124,12 +121,12 @@ for(int j=0; j<results.size(); j++){
} }
} }
void KeepassEntryView::refreshVisibleItems(){ void KeepassEntryView::refreshItems(){
EntryViewItem *tmp=NULL; EntryViewItem *tmp=NULL;
for(int i=0;i<Items.size();i++){ for(int i=0;i<Items.size();i++){
tmp=Items[i]; tmp=Items[i];
CEntry* entry=tmp->pEntry; CEntry* entry=tmp->pEntry;
if(entry->GroupID==CurrentGroup){
int j=0; int j=0;
if(config.Columns[0]){ if(config.Columns[0]){
tmp->setText(j++,entry->Title);} tmp->setText(j++,entry->Title);}
@ -162,8 +159,6 @@ if(entry->GroupID==CurrentGroup){
} }
} }
}
void KeepassEntryView::updateColumns(){ void KeepassEntryView::updateColumns(){
setColumnCount(0); setColumnCount(0);
@ -191,7 +186,9 @@ if(config.Columns[9]){
setHeaderLabels(cols); setHeaderLabels(cols);
} }
void KeepassEntryView::paintEvent(QPaintEvent * event){
QTreeWidget::paintEvent(event);
}
EntryViewItem::EntryViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){ EntryViewItem::EntryViewItem(QTreeWidget *parent):QTreeWidgetItem(parent){

@ -30,9 +30,8 @@ class EntryViewItem;
class KeepassEntryView:public QTreeWidget{ class KeepassEntryView:public QTreeWidget{
public: public:
KeepassEntryView(QWidget* parent=0); KeepassEntryView(QWidget* parent=0);
void updateItems(); void updateItems(unsigned int group);
void refreshVisibleItems(); void refreshItems();
void setCurrentGroup(uint GroupID);
void updateColumns(); void updateColumns();
void showSearchResults(QList<Q_UINT32>& results); void showSearchResults(QList<Q_UINT32>& results);
PwDatabase* db; PwDatabase* db;
@ -42,6 +41,7 @@ private:
int CurrentGroup; int CurrentGroup;
protected: protected:
virtual void contextMenuEvent(QContextMenuEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void paintEvent ( QPaintEvent * event );
}; };

@ -242,8 +242,7 @@ if(db->loadDatabase(filename,err)==true){
//SUCCESS //SUCCESS
setCaption(tr("Keepass - %1").arg(filename)); setCaption(tr("Keepass - %1").arg(filename));
GroupView->updateItems(); GroupView->updateItems();
EntryView->updateItems(); EntryView->updateItems(0);
EntryView->setCurrentGroup(0);
setStateFileOpen(true); setStateFileOpen(true);
setStateFileModified(false); setStateFileModified(false);
} }
@ -292,8 +291,7 @@ setCaption(tr("Keepass - %1").arg(tr("[neu]")));
GroupView->db=db; GroupView->db=db;
EntryView->db=db; EntryView->db=db;
GroupView->updateItems(); GroupView->updateItems();
EntryView->updateItems(); EntryView->updateItems(0);
EntryView->setCurrentGroup(0);
setStateFileOpen(true); setStateFileOpen(true);
setStateFileModified(true); setStateFileModified(true);
FileOpen=true; FileOpen=true;
@ -349,7 +347,7 @@ else{
void KeepassMainWindow::editEntry(CEntry* pEntry){ void KeepassMainWindow::editEntry(CEntry* pEntry){
CEditEntryDlg dlg(db,pEntry,this,"EditEntryDialog",true); CEditEntryDlg dlg(db,pEntry,this,"EditEntryDialog",true);
dlg.exec(); dlg.exec();
EntryView->refreshVisibleItems(); EntryView->refreshItems();
if(dlg.ModFlag)setStateFileModified(true); if(dlg.ModFlag)setStateFileModified(true);
} }
@ -541,7 +539,7 @@ if(cur){
if(GroupView->isSearchResultGroup((GroupViewItem*)cur)){ if(GroupView->isSearchResultGroup((GroupViewItem*)cur)){
EntryView->showSearchResults(SearchResults); EntryView->showSearchResults(SearchResults);
} }
else EntryView->setCurrentGroup(((GroupViewItem*)cur)->pGroup->ID); else EntryView->updateItems(((GroupViewItem*)cur)->pGroup->ID);
} }
} }
@ -623,7 +621,7 @@ NewEntry.GroupID=currentGroup()->ID;
CEditEntryDlg dlg(db,&NewEntry,this,"EditEntryDialog",true); CEditEntryDlg dlg(db,&NewEntry,this,"EditEntryDialog",true);
if(dlg.exec()){ if(dlg.exec()){
db->addEntry(&NewEntry); db->addEntry(&NewEntry);
EntryView->updateItems(); EntryView->updateItems(currentGroup()->ID);
setStateFileModified(true); setStateFileModified(true);
} }
} }
@ -640,7 +638,7 @@ for(int i=0; i<entries.size();i++){
db->cloneEntry(((EntryViewItem*)entries[i])->pEntry); db->cloneEntry(((EntryViewItem*)entries[i])->pEntry);
} }
setStateFileModified(true); setStateFileModified(true);
EntryView->updateItems(); EntryView->updateItems(currentGroup()->ID);
} }
void KeepassMainWindow::OnEditDeleteEntry(){ void KeepassMainWindow::OnEditDeleteEntry(){
@ -651,7 +649,7 @@ for(int i=0; i<entries.size();i++){
db->deleteEntry(((EntryViewItem*)entries[i])->pEntry); db->deleteEntry(((EntryViewItem*)entries[i])->pEntry);
} }
setStateFileModified(true); setStateFileModified(true);
EntryView->updateItems(); EntryView->updateItems(currentGroup()->ID);
} }
void KeepassMainWindow::removeFromSearchResults(int id){ void KeepassMainWindow::removeFromSearchResults(int id){
@ -747,13 +745,13 @@ config.Columns[7]=ViewColumnsLastChangeAction->isChecked();
config.Columns[8]=ViewColumnsLastAccessAction->isChecked(); config.Columns[8]=ViewColumnsLastAccessAction->isChecked();
config.Columns[9]=ViewColumnsAttachmentAction->isChecked(); config.Columns[9]=ViewColumnsAttachmentAction->isChecked();
EntryView->updateColumns(); EntryView->updateColumns();
if(FileOpen) EntryView->updateItems(); if(FileOpen) EntryView->refreshItems();
} }
void KeepassMainWindow::OnUsernPasswVisibilityChanged(bool value){ void KeepassMainWindow::OnUsernPasswVisibilityChanged(bool value){
config.ListView_HidePasswords=ViewHidePasswordsAction->isChecked(); config.ListView_HidePasswords=ViewHidePasswordsAction->isChecked();
config.ListView_HideUsernames=ViewHideUsernamesAction->isChecked(); config.ListView_HideUsernames=ViewHideUsernamesAction->isChecked();
EntryView->updateItems(); EntryView->refreshItems();
} }
void KeepassMainWindow::OnFileModified(){ void KeepassMainWindow::OnFileModified(){