From 0cfee943b887afbb4841daf233274b04de7e57e0 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Mon, 11 Dec 2000 05:53:36 +0000 Subject: [PATCH] Added the files needed for searching.. --- searchresult.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++ searchresult.h | 28 ++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 searchresult.cpp create mode 100644 searchresult.h 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++; + } +} diff --git a/searchresult.h b/searchresult.h new file mode 100644 index 0000000..128d4dc --- /dev/null +++ b/searchresult.h @@ -0,0 +1,28 @@ +#ifndef SEARCHRESULT_H +#define SEARCHRESULT_H +#include "ui/searchresultbase.h" + +//QT includes +#include + +class SearchResult : public SearchResultBase +{ + Q_OBJECT + +public: + SearchResult(QString searchword, int cat, QWidget* parent = 0, const char* name = 0, bool modal = true, WFlags fl = 0 ); + ~SearchResult(); + +public slots: + void slotDel(); + void slotModify(); + +protected: //Attributes + QString m_searchword; + int m_cat; + +protected: //FUnktions + void Find(); +}; + +#endif // SEARCHRESULT_H -- 2.39.2