00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "Filter.h"
00012
00013
00014 Filter::Filter(const QString & name, MtpContext * ctxt) {
00015 this->name = name;
00016 this->m_context = ctxt;
00017 }
00018
00019
00020 Filter::~Filter() {}
00021
00022 void Filter::setPolicy(Policy p) {
00023 this->pol = p;
00024 }
00025
00026 Filter::Policy Filter::policy() const {
00027 return this->pol;
00028 }
00029
00030 bool Filter::isEnabled() const {
00031 return this->active;
00032 }
00033
00034 void Filter::setEnabled(bool b) {
00035 this->active = b;
00036 }
00037
00038 void Filter::enable() {
00039 this->active = true;
00040 }
00041
00042 void Filter::disable() {
00043 this->active = false;
00044 }
00045
00046 QString Filter::getName() const {
00047 return name;
00048 }
00049
00050 QString Filter::getResult() const {
00051 return result;
00052 }
00053
00054 void Filter::setResult(const QString& r) {
00055 result = r;
00056 }
00057
00058 QString Filter::applyProcessedRegexpToPattern(MtpRegExp & re, const QString & pat) {
00059 QString res(pat);
00060
00061 if(m_context) {
00062 QRegExp rx( "\\\\(\\w+)\\\\" );
00063 QStringList list;
00064
00065 int pos = 0;
00066 while ( pos >= 0 ) {
00067 pos = rx.search( pat, pos );
00068 if ( pos > -1 ) {
00069 list += rx.cap( 1 );
00070 pos += rx.matchedLength();
00071 }
00072 }
00073 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00074 QString value;
00075 if ((value = m_context->getValue(*it)) != QString::null)
00076 res = res.replace(QRegExp("\\\\" + *it + "\\\\"),value);
00077 }
00078 }
00079
00080 QRegExp rx( "\\\\(\\d+)\\\\" );
00081 QStringList list;
00082
00083 int pos = 0;
00084 while ( pos >= 0 ) {
00085 pos = rx.search( pat, pos );
00086 if ( pos > -1 ) {
00087 list += rx.cap( 1 );
00088 pos += rx.matchedLength();
00089 }
00090 }
00091 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00092 QString repl(re.cap((*it).toInt()));
00093 res = res.replace(QRegExp("\\\\" + *it + "\\\\"),repl);
00094 }
00095 return res;
00096 }