Test change - can I push OK?
[kdeedu-porting.git] / kalzium / src / search.cpp
blob344a279ce2bde6392adb90e88e64f2a0bedd7436
1 /***************************************************************************
2 * Copyright (C) 2006 by Pino Toscano, toscano.pino@tiscali.it *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #include "search.h"
22 #include "element.h"
23 #include "kalziumdataobject.h"
25 Search::Search()
26 : m_isActive( false ), m_searchKind( Search::SearchAll )
30 QString Search::searchText() const
32 return m_searchText;
35 Search::SearchKind Search::searchKind() const
37 return m_searchKind;
40 bool Search::isActive() const
42 return m_isActive;
45 const QList<Element*>& Search::foundElements() const
47 return m_foundElements;
50 bool Search::matches( Element* e ) const
52 return m_foundElements.contains( e );
55 void Search::doSearch( const QString& text, SearchKind kind )
57 m_isActive = true;
58 m_searchText = text;
59 m_searchKind = kind;
60 QList<Element*> newresults;
61 foreach( Element* e, KalziumDataObject::instance()->ElementList )
63 bool found = false;
64 if ( !found && e->dataAsString( ChemicalDataObject::name ).contains( text, Qt::CaseInsensitive ) ) found = true;
65 if ( !found && e->dataAsString( ChemicalDataObject::symbol ).contains( text, Qt::CaseInsensitive ) ) found = true;
66 if ( found )
67 newresults << e;
69 if ( newresults != m_foundElements )
71 m_foundElements = newresults;
72 emit searchChanged();
76 void Search::resetSearch()
78 if ( !m_isActive ) return;
80 m_foundElements.clear();
81 m_isActive = false;
82 emit searchReset();
85 #include "search.moc"