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

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

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