X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=searchresult.cpp;fp=searchresult.cpp;h=03bbb42d51c70067ae46ce7c1c32205c522868bc;hp=0000000000000000000000000000000000000000;hb=0cfee943b887afbb4841daf233274b04de7e57e0;hpb=d5ab42bc1239fdd6ae46c17a4c698935e19eb745 diff --git a/searchresult.cpp b/searchresult.cpp new file mode 100644 index 0000000..03bbb42 --- /dev/null +++ b/searchresult.cpp @@ -0,0 +1,113 @@ +#include "searchresult.h" +#include + +#include + +//local includes +#include "contact.h" +#include "contactmodifyer.h" + +/* + * Constructs a SearchResult which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +SearchResult::SearchResult(QString searchword, int cat, QWidget* parent, const char* name, bool modal, WFlags fl ) + : SearchResultBase( parent, name, modal, fl ) +{ + m_searchword = searchword; + m_cat = cat; + Find(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SearchResult::~SearchResult() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * public slot + */ +void SearchResult::slotDel() +{ + QListViewItem* lvi = ContactView->selectedItem(); + + if (lvi == '\0') + { + return; + } + + int num = lvi->text(0).toInt(); + + if (num < 1 || num > CContact::getNum()) + return; + + CContact* contact = CContact::getFirst(); + + for (int i = 1; i < num; i++, contact = contact->getNext()) + { + if (contact->getNext() == '\0') + { + return; + } + } + + delete contact; + Find(); +} +/* + * public slot + */ +void SearchResult::slotModify() +{ + QListViewItem* lvi = ContactView->selectedItem(); + + if (lvi == '\0') + { + return; + } + + int num = lvi->text(0).toInt(); + + if (num < 1 || num > CContact::getNum()) + return; + + CContact* contact = CContact::getFirst(); + + for (int i = 1; i < num; i++, contact = contact->getNext()) + { + if (contact->getNext() == '\0') + { + return; + } + } + ContactModifier modify(contact); + if(modify.exec() == QDialog::Accepted) + Find(); +} + +//Protected functions +void SearchResult::Find() +{ + ContactView->clear(); + CContact* contact = CContact::getFirst(); + + int i = 1; + char s[100]; + + while (contact != '\0') + { + if (contact->search(m_cat, m_searchword)) + { + sprintf(s,"%i",i);//.arg(i); + (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber()); + } + contact = contact->getNext(); + i++; + } +}