Quantum GIS API Documentation
1.7.4
|
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 /* $Id$ */ 00019 00020 #include "qgssearchstring.h" 00021 #include "qgssearchtreenode.h" 00022 00023 00025 extern QgsSearchTreeNode* parseSearchString( const QString& str, QString& parserErrorMsg ); 00026 00027 00028 QgsSearchString::QgsSearchString() 00029 { 00030 mTree = NULL; 00031 } 00032 00033 QgsSearchString::QgsSearchString( const QString & str ) 00034 { 00035 mTree = NULL; 00036 setString( str ); 00037 } 00038 00039 QgsSearchString::QgsSearchString( const QgsSearchString& str ) 00040 { 00041 if ( str.mTree ) 00042 mTree = new QgsSearchTreeNode( *str.mTree ); 00043 else 00044 mTree = NULL; 00045 mString = str.mString; 00046 } 00047 00048 QgsSearchString& QgsSearchString::operator=( const QgsSearchString & str ) 00049 { 00050 clear(); 00051 00052 if ( str.mTree ) 00053 mTree = new QgsSearchTreeNode( *str.mTree ); 00054 else 00055 mTree = NULL; 00056 mString = str.mString; 00057 00058 return *this; 00059 } 00060 00061 00062 QgsSearchString::~QgsSearchString() 00063 { 00064 delete mTree; // deletes complete tree 00065 } 00066 00067 00068 bool QgsSearchString::setString( QString str ) 00069 { 00070 mParserErrorMsg.clear(); 00071 00072 // empty string 00073 if ( str.isEmpty() ) 00074 { 00075 clear(); 00076 return true; 00077 } 00078 00079 // calls external C function that does all parsing 00080 QgsSearchTreeNode* tree = parseSearchString( str, mParserErrorMsg ); 00081 if ( tree ) 00082 { 00083 delete mTree; 00084 mTree = tree; 00085 mString = str; 00086 return true; 00087 } 00088 00089 return false; 00090 } 00091 00092 00093 bool QgsSearchString::setTree( QgsSearchTreeNode* tree ) 00094 { 00095 if ( tree == NULL ) 00096 { 00097 clear(); 00098 } 00099 else 00100 { 00101 delete mTree; 00102 mTree = new QgsSearchTreeNode( *tree ); 00103 mString = mTree->makeSearchString(); 00104 } 00105 return true; 00106 } 00107 00108 bool QgsSearchString::isEmpty() 00109 { 00110 return ( mTree == NULL ); 00111 } 00112 00113 void QgsSearchString::clear() 00114 { 00115 delete mTree; 00116 mTree = NULL; 00117 mString.clear(); 00118 }