PARP Research Group | Universidad de Murcia |
src/qvblockprogramming/qvguiblocks/qvindexedstringlist.cppGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012. PARP Research Group. 00003 * <http://perception.inf.um.es> 00004 * University of Murcia, Spain. 00005 * 00006 * This file is part of the QVision library. 00007 * 00008 * QVision is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as 00010 * published by the Free Software Foundation, version 3 of the License. 00011 * 00012 * QVision is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with QVision. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00024 00025 #include <QVIndexedStringList> 00026 00027 QVIndexedStringList QVIndexedStringList::filter(const QString &str, Qt::CaseSensitivity cs) const 00028 { 00029 QVIndexedStringList isl = QStringList::filter(str, cs); 00030 if (isl.isEmpty()) isl.index = -1; 00031 else isl.index = 0; 00032 return isl; 00033 } 00034 00035 QVIndexedStringList QVIndexedStringList::filter(const QRegExp &rx) const 00036 { 00037 QVIndexedStringList isl = QStringList::filter(rx); 00038 if (isl.isEmpty()) isl.index = -1; 00039 else isl.index = 0; 00040 return isl; 00041 } 00042 00043 QVIndexedStringList QVIndexedStringList::operator+(const QVIndexedStringList &other) const 00044 { 00045 QVIndexedStringList n = *this; 00046 n += other; 00047 if (n.isEmpty()) n.index = -1; 00048 else n.index = 0; 00049 return n; 00050 } 00051 00052 void QVIndexedStringList::sort() 00053 { 00054 QString st = value(index); 00055 QStringList::sort(); 00056 index = indexOf(st); 00057 } 00058 00059 void QVIndexedStringList::append(const QString &str) 00060 { 00061 QStringList::append(str); 00062 if (index < 0) index = 0; 00063 } 00064 00065 00066 00067 QString QVIndexedStringList::getCurrent() const 00068 { 00069 if (index > -1) return QStringList::value(index); 00070 else return *(new QString()); 00071 } 00072 00073 bool QVIndexedStringList::setIndex(int i) 00074 { 00075 if ((i > -2) && (i < QVIndexedStringList::size())) 00076 { 00077 index = i; 00078 return true; 00079 } 00080 return false; 00081 } 00082 00083 bool QVIndexedStringList::incIndex() 00084 { 00085 return setIndex(getIndex() + 1); 00086 } 00087 bool QVIndexedStringList::decIndex() 00088 { 00089 return setIndex(getIndex() - 1); 00090 } |