Quantum GIS API Documentation  1.8
src/core/qgssearchstring.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                            qgssearchstring.cpp
00003           interface for parsing and evaluation of search strings
00004                           --------------------
00005     begin                : 2005-07-26
00006     copyright            : (C) 2005 by Martin Dobias
00007     email                : won.der at centrum.sk
00008 ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "qgssearchstring.h"
00020 #include "qgssearchtreenode.h"
00021 
00022 
00024 extern QgsSearchTreeNode* parseSearchString( const QString& str, QString& parserErrorMsg );
00025 
00026 QgsSearchString::QgsSearchString()
00027 {
00028   mTree = NULL;
00029 }
00030 
00031 QgsSearchString::QgsSearchString( const QString & str )
00032 {
00033   mTree = NULL;
00034   setString( str );
00035 }
00036 
00037 QgsSearchString::QgsSearchString( const QgsSearchString& str )
00038 {
00039   if ( str.mTree )
00040     mTree = new QgsSearchTreeNode( *str.mTree );
00041   else
00042     mTree = NULL;
00043   mString = str.mString;
00044 }
00045 
00046 QgsSearchString& QgsSearchString::operator=( const QgsSearchString & str )
00047 {
00048   clear();
00049 
00050   if ( str.mTree )
00051     mTree = new QgsSearchTreeNode( *str.mTree );
00052   else
00053     mTree = NULL;
00054   mString = str.mString;
00055 
00056   return *this;
00057 }
00058 
00059 
00060 QgsSearchString::~QgsSearchString()
00061 {
00062   delete mTree; // deletes complete tree
00063 }
00064 
00065 
00066 bool QgsSearchString::setString( QString str )
00067 {
00068   mParserErrorMsg.clear();
00069 
00070   // empty string
00071   if ( str.isEmpty() )
00072   {
00073     clear();
00074     return true;
00075   }
00076 
00077   // calls external C function that does all parsing
00078   QgsSearchTreeNode* tree = parseSearchString( str, mParserErrorMsg );
00079   if ( tree )
00080   {
00081     delete mTree;
00082     mTree = tree;
00083     mString = str;
00084     return true;
00085   }
00086 
00087   return false;
00088 }
00089 
00090 
00091 bool QgsSearchString::setTree( QgsSearchTreeNode* tree )
00092 {
00093   if ( tree == NULL )
00094   {
00095     clear();
00096   }
00097   else
00098   {
00099     delete mTree;
00100     mTree = new QgsSearchTreeNode( *tree );
00101     mString = mTree->makeSearchString();
00102   }
00103   return true;
00104 }
00105 
00106 bool QgsSearchString::isEmpty()
00107 {
00108   return ( mTree == NULL );
00109 }
00110 
00111 void QgsSearchString::clear()
00112 {
00113   delete mTree;
00114   mTree = NULL;
00115   mString.clear();
00116 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines