diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
commit | 2595a15ebeb6fc46b7cb241d01ec0c2460ec2111 (patch) | |
tree | 18a8f0f4ac5a86dacfa74c3537551ec39bc85e75 /src/field.cpp | |
parent | 1d90725a4001fab9d3922b2cbcceeee5e2d1686f (diff) | |
download | tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.tar.gz tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.zip |
TQt4 port tellico
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1239054 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/field.cpp')
-rw-r--r-- | src/field.cpp | 240 |
1 files changed, 120 insertions, 120 deletions
diff --git a/src/field.cpp b/src/field.cpp index 206062a..a5ab6a6 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -21,22 +21,22 @@ #include <klocale.h> #include <kglobal.h> -#include <qstringlist.h> -#include <qregexp.h> -#include <qdatetime.h> +#include <tqstringlist.h> +#include <tqregexp.h> +#include <tqdatetime.h> namespace { - static const QRegExp comma_split = QRegExp(QString::fromLatin1("\\s*,\\s*")); + static const TQRegExp comma_split = TQRegExp(TQString::tqfromLatin1("\\s*,\\s*")); } using Tellico::Data::Field; //these get overwritten, but are here since they're static -QStringList Field::s_articlesApos; -QRegExp Field::s_delimiter = QRegExp(QString::fromLatin1("\\s*;\\s*")); +TQStringList Field::s_articlesApos; +TQRegExp Field::s_delimiter = TQRegExp(TQString::tqfromLatin1("\\s*;\\s*")); // this constructor is for anything but Choice type -Field::Field(const QString& name_, const QString& title_, Type type_/*=Line*/) +Field::Field(const TQString& name_, const TQString& title_, Type type_/*=Line*/) : KShared(), m_name(name_), m_title(title_), m_category(i18n("General")), m_desc(title_), m_type(type_), m_flags(0), m_formatFlag(FormatNone) { @@ -54,21 +54,21 @@ Field::Field(const QString& name_, const QString& title_, Type type_/*=Line*/) m_flags = AllowMultiple; if(m_type == Table2) { m_type = Table; - setProperty(QString::fromLatin1("columns"), QChar('2')); + setProperty(TQString::tqfromLatin1("columns"), TQChar('2')); } else { - setProperty(QString::fromLatin1("columns"), QChar('1')); + setProperty(TQString::tqfromLatin1("columns"), TQChar('1')); } } else if(m_type == Date) { // hidden from user m_formatFlag = FormatDate; } else if(m_type == Rating) { - setProperty(QString::fromLatin1("minimum"), QChar('1')); - setProperty(QString::fromLatin1("maximum"), QChar('5')); + setProperty(TQString::tqfromLatin1("minimum"), TQChar('1')); + setProperty(TQString::tqfromLatin1("maximum"), TQChar('5')); } m_id = getID(); } // if this constructor is called, the type is necessarily Choice -Field::Field(const QString& name_, const QString& title_, const QStringList& allowed_) +Field::Field(const TQString& name_, const TQString& title_, const TQStringList& allowed_) : KShared(), m_name(name_), m_title(title_), m_category(i18n("General")), m_desc(title_), m_type(Field::Choice), m_allowed(allowed_), m_flags(0), m_formatFlag(FormatNone) { m_id = getID(); @@ -83,7 +83,7 @@ Field::Field(const Field& field_) m_allowed = field_.allowed(); } else if(m_type == Table2) { m_type = Table; - setProperty(QString::fromLatin1("columns"), QChar('2')); + setProperty(TQString::tqfromLatin1("columns"), TQChar('2')); } m_id = getID(); } @@ -101,7 +101,7 @@ Field& Field::operator=(const Field& field_) { m_allowed = field_.allowed(); } else if(m_type == Table2) { m_type = Table; - setProperty(QString::fromLatin1("columns"), QChar('2')); + setProperty(TQString::tqfromLatin1("columns"), TQChar('2')); } m_flags = field_.flags(); m_formatFlag = field_.formatFlag(); @@ -113,7 +113,7 @@ Field& Field::operator=(const Field& field_) { Field::~Field() { } -void Field::setTitle(const QString& title_) { +void Field::setTitle(const TQString& title_) { m_title = title_; if(isSingleCategory()) { m_category = title_; @@ -123,16 +123,16 @@ void Field::setTitle(const QString& title_) { void Field::setType(Field::Type type_) { m_type = type_; if(m_type != Field::Choice) { - m_allowed = QStringList(); + m_allowed = TQStringList(); } if(m_type == Table || m_type == Table2) { m_flags |= AllowMultiple; if(m_type == Table2) { m_type = Table; - setProperty(QString::fromLatin1("columns"), QChar('2')); + setProperty(TQString::tqfromLatin1("columns"), TQChar('2')); } - if(property(QString::fromLatin1("columns")).isEmpty()) { - setProperty(QString::fromLatin1("columns"), QChar('1')); + if(property(TQString::tqfromLatin1("columns")).isEmpty()) { + setProperty(TQString::tqfromLatin1("columns"), TQChar('1')); } } if(isSingleCategory()) { @@ -144,7 +144,7 @@ void Field::setType(Field::Type type_) { } } -void Field::setCategory(const QString& category_) { +void Field::setCategory(const TQString& category_) { if(!isSingleCategory()) { m_category = category_; } @@ -166,13 +166,13 @@ void Field::setFormatFlag(FormatFlag flag_) { } } -const QString& Field::defaultValue() const { - return property(QString::fromLatin1("default")); +const TQString& Field::defaultValue() const { + return property(TQString::tqfromLatin1("default")); } -void Field::setDefaultValue(const QString& value_) { - if(m_type != Choice || m_allowed.findIndex(value_) > -1) { - setProperty(QString::fromLatin1("default"), value_); +void Field::setDefaultValue(const TQString& value_) { + if(m_type != Choice || m_allowed.tqfindIndex(value_) > -1) { + setProperty(TQString::tqfromLatin1("default"), value_); } } @@ -187,9 +187,9 @@ Tellico::Data::FieldVec Field::dependsOn(CollPtr coll_) const { return vec; } - const QStringList fieldNames = dependsOn(); + const TQStringList fieldNames = dependsOn(); // do NOT call recursively! - for(QStringList::ConstIterator it = fieldNames.begin(); it != fieldNames.end(); ++it) { + for(TQStringList::ConstIterator it = fieldNames.begin(); it != fieldNames.end(); ++it) { FieldPtr field = coll_->fieldByName(*it); if(!field) { // allow the user to also use field titles @@ -202,27 +202,27 @@ Tellico::Data::FieldVec Field::dependsOn(CollPtr coll_) const { return vec; } -QStringList Field::dependsOn() const { - QStringList list; +TQStringList Field::dependsOn() const { + TQStringList list; if(m_type != Dependent) { return list; } - QRegExp rx(QString::fromLatin1("%\\{(.+)\\}")); + TQRegExp rx(TQString::tqfromLatin1("%\\{(.+)\\}")); rx.setMinimal(true); // do NOT call recursively! - for(int pos = m_desc.find(rx); pos > -1; pos = m_desc.find(rx, pos+3)) { + for(int pos = m_desc.tqfind(rx); pos > -1; pos = m_desc.tqfind(rx, pos+3)) { list << rx.cap(1); } return list; } -QString Field::format(const QString& value_, FormatFlag flag_) { +TQString Field::format(const TQString& value_, FormatFlag flag_) { if(value_.isEmpty()) { return value_; } - QString text; + TQString text; switch(flag_) { case FormatTitle: text = formatTitle(value_); @@ -243,12 +243,12 @@ QString Field::format(const QString& value_, FormatFlag flag_) { return text; } -QString Field::formatTitle(const QString& title_) { - QString newTitle = title_; +TQString Field::formatTitle(const TQString& title_) { + TQString newTitle = title_; // special case for multi-column tables, assume user never has '::' in a value - const QString colonColon = QString::fromLatin1("::"); - QString tail; - if(newTitle.find(colonColon) > -1) { + const TQString colonColon = TQString::tqfromLatin1("::"); + TQString tail; + if(newTitle.tqfind(colonColon) > -1) { tail = colonColon + newTitle.section(colonColon, 1); newTitle = newTitle.section(colonColon, 0, 0); } @@ -258,18 +258,18 @@ QString Field::formatTitle(const QString& title_) { } if(Config::autoFormat()) { - const QString lower = newTitle.lower(); + const TQString lower = newTitle.lower(); // TODO if the title has ",the" at the end, put it at the front - const QStringList& articles = Config::articleList(); - for(QStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { + const TQStringList& articles = Config::articleList(); + for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { // assume white space is already stripped // the articles are already in lower-case - if(lower.startsWith(*it + QChar(' '))) { - QRegExp regexp(QChar('^') + QRegExp::escape(*it) + QString::fromLatin1("\\s*"), false); + if(lower.startsWith(*it + TQChar(' '))) { + TQRegExp regexp(TQChar('^') + TQRegExp::escape(*it) + TQString::tqfromLatin1("\\s*"), false); // can't just use *it since it's in lower-case - QString article = newTitle.left((*it).length()); - newTitle = newTitle.replace(regexp, QString::null) - .append(QString::fromLatin1(", ")) + TQString article = newTitle.left((*it).length()); + newTitle = newTitle.tqreplace(regexp, TQString()) + .append(TQString::tqfromLatin1(", ")) .append(article); break; } @@ -277,50 +277,50 @@ QString Field::formatTitle(const QString& title_) { } // also, arbitrarily impose rule that a space must follow every comma - newTitle.replace(comma_split, QString::fromLatin1(", ")); + newTitle.tqreplace(comma_split, TQString::tqfromLatin1(", ")); return newTitle + tail; } -QString Field::formatName(const QString& name_, bool multiple_/*=true*/) { - static const QRegExp spaceComma(QString::fromLatin1("[\\s,]")); - static const QString colonColon = QString::fromLatin1("::"); +TQString Field::formatName(const TQString& name_, bool multiple_/*=true*/) { + static const TQRegExp spaceComma(TQString::tqfromLatin1("[\\s,]")); + static const TQString colonColon = TQString::tqfromLatin1("::"); // the ending look-ahead is so that a space is not added at the end - static const QRegExp periodSpace(QString::fromLatin1("\\.\\s*(?=.)")); + static const TQRegExp periodSpace(TQString::tqfromLatin1("\\.\\s*(?=.)")); - QStringList entries; + TQStringList entries; if(multiple_) { // split by semi-colon, optionally preceded or followed by white spacee - entries = QStringList::split(s_delimiter, name_, false); + entries = TQStringList::split(s_delimiter, name_, false); } else { entries << name_; } - QRegExp lastWord; + TQRegExp lastWord; lastWord.setCaseSensitive(false); - QStringList names; - for(QStringList::ConstIterator it = entries.begin(); it != entries.end(); ++it) { - QString name = *it; + TQStringList names; + for(TQStringList::ConstIterator it = entries.begin(); it != entries.end(); ++it) { + TQString name = *it; // special case for 2-column tables, assume user never has '::' in a value - QString tail; - if(name.find(colonColon) > -1) { + TQString tail; + if(name.tqfind(colonColon) > -1) { tail = colonColon + name.section(colonColon, 1); name = name.section(colonColon, 0, 0); } - name.replace(periodSpace, QString::fromLatin1(". ")); + name.tqreplace(periodSpace, TQString::tqfromLatin1(". ")); if(Config::autoCapitalization()) { name = capitalize(name); } // split the name by white space and commas - QStringList words = QStringList::split(spaceComma, name, false); - lastWord.setPattern(QChar('^') + QRegExp::escape(words.last()) + QChar('$')); + TQStringList words = TQStringList::split(spaceComma, name, false); + lastWord.setPattern(TQChar('^') + TQRegExp::escape(words.last()) + TQChar('$')); // if it contains a comma already and the last word is not a suffix, don't format it - if(!Config::autoFormat() || (name.find(',') > -1 && Config::nameSuffixList().grep(lastWord).isEmpty())) { + if(!Config::autoFormat() || (name.tqfind(',') > -1 && Config::nameSuffixList().grep(lastWord).isEmpty())) { // arbitrarily impose rule that no spaces before a comma and // a single space after every comma - name.replace(comma_split, QString::fromLatin1(", ")); + name.tqreplace(comma_split, TQString::tqfromLatin1(", ")); names << name + tail; continue; } @@ -329,48 +329,48 @@ QString Field::formatName(const QString& name_, bool multiple_/*=true*/) { if(words.count() > 1) { // if the last word is a suffix, it has to be kept with last name if(Config::nameSuffixList().grep(lastWord).count() > 0) { - words.prepend(words.last().append(QChar(','))); + words.prepend(words.last().append(TQChar(','))); words.remove(words.fromLast()); } // now move the word // adding comma here when there had been a suffix is because it was originally split with space or comma - words.prepend(words.last().append(QChar(','))); + words.prepend(words.last().append(TQChar(','))); words.remove(words.fromLast()); // update last word regexp - lastWord.setPattern(QChar('^') + QRegExp::escape(words.last()) + QChar('$')); + lastWord.setPattern(TQChar('^') + TQRegExp::escape(words.last()) + TQChar('$')); // this is probably just something for me, limited to english while(Config::surnamePrefixList().grep(lastWord).count() > 0) { words.prepend(words.last()); words.remove(words.fromLast()); - lastWord.setPattern(QChar('^') + QRegExp::escape(words.last()) + QChar('$')); + lastWord.setPattern(TQChar('^') + TQRegExp::escape(words.last()) + TQChar('$')); } - names << words.join(QChar(' ')) + tail; + names << words.join(TQChar(' ')) + tail; } else { names << name + tail; } } - return names.join(QString::fromLatin1("; ")); + return names.join(TQString::tqfromLatin1("; ")); } -QString Field::formatDate(const QString& date_) { +TQString Field::formatDate(const TQString& date_) { // internally, this is "year-month-day" // any of the three may be empty // if they're not digits, return the original string bool empty = true; // for empty year, use current // for empty month or date, use 1 - QStringList s = QStringList::split('-', date_, true); + TQStringList s = TQStringList::split('-', date_, true); bool ok = true; - int y = s.count() > 0 ? s[0].toInt(&ok) : QDate::currentDate().year(); + int y = s.count() > 0 ? s[0].toInt(&ok) : TQDate::tqcurrentDate().year(); if(ok) { empty = false; } else { - y = QDate::currentDate().year(); + y = TQDate::tqcurrentDate().year(); } int m = s.count() > 1 ? s[1].toInt(&ok) : 1; if(ok) { @@ -385,86 +385,86 @@ QString Field::formatDate(const QString& date_) { d = 1; } // rather use ISO date formatting than locale formatting for now. Primarily, it makes sorting just work. - return empty ? date_ : QDate(y, m, d).toString(Qt::ISODate); + return empty ? date_ : TQString(TQDate(y, m, d).toString(Qt::ISODate)); // use short form // return KGlobal::locale()->formatDate(date, true); } -QString Field::capitalize(QString str_) { +TQString Field::capitalize(TQString str_) { // regexp to split words - static const QRegExp rx(QString::fromLatin1("[-\\s,.;]")); + static const TQRegExp rx(TQString::tqfromLatin1("[-\\s,.;]")); if(str_.isEmpty()) { return str_; } // first letter is always capitalized - str_.replace(0, 1, str_.at(0).upper()); + str_.tqreplace(0, 1, str_.tqat(0).upper()); // special case for french words like l'espace - int pos = str_.find(rx, 1); + int pos = str_.tqfind(rx, 1); int nextPos; - QRegExp wordRx; + TQRegExp wordRx; wordRx.setCaseSensitive(false); - QStringList notCap = Config::noCapitalizationList(); + TQStringList notCap = Config::noCapitalizationList(); // don't capitalize the surname prefixes // does this hold true everywhere other than english? notCap += Config::surnamePrefixList(); - QString word = str_.mid(0, pos); + TQString word = str_.mid(0, pos); // now check to see if words starts with apostrophe list - for(QStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { + for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { if(word.lower().startsWith(*it)) { uint l = (*it).length(); - str_.replace(l, 1, str_.at(l).upper()); + str_.tqreplace(l, 1, str_.tqat(l).upper()); break; } } while(pos > -1) { // also need to compare against list of non-capitalized words - nextPos = str_.find(rx, pos+1); + nextPos = str_.tqfind(rx, pos+1); if(nextPos == -1) { nextPos = str_.length(); } word = str_.mid(pos+1, nextPos-pos-1); bool aposMatch = false; // now check to see if words starts with apostrophe list - for(QStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { + for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { if(word.lower().startsWith(*it)) { uint l = (*it).length(); - str_.replace(pos+l+1, 1, str_.at(pos+l+1).upper()); + str_.tqreplace(pos+l+1, 1, str_.tqat(pos+l+1).upper()); aposMatch = true; break; } } if(!aposMatch) { - wordRx.setPattern(QChar('^') + QRegExp::escape(word) + QChar('$')); + wordRx.setPattern(TQChar('^') + TQRegExp::escape(word) + TQChar('$')); if(notCap.grep(wordRx).isEmpty() && nextPos-pos > 1) { - str_.replace(pos+1, 1, str_.at(pos+1).upper()); + str_.tqreplace(pos+1, 1, str_.tqat(pos+1).upper()); } } - pos = str_.find(rx, pos+1); + pos = str_.tqfind(rx, pos+1); } return str_; } -QString Field::sortKeyTitle(const QString& title_) { - const QString lower = title_.lower(); - const QStringList& articles = Config::articleList(); - for(QStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { +TQString Field::sortKeyTitle(const TQString& title_) { + const TQString lower = title_.lower(); + const TQStringList& articles = Config::articleList(); + for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { // assume white space is already stripped // the articles are already in lower-case - if(lower.startsWith(*it + QChar(' '))) { + if(lower.startsWith(*it + TQChar(' '))) { return title_.mid((*it).length() + 1); } } // check apostrophes, too - for(QStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { + for(TQStringList::ConstIterator it = s_articlesApos.begin(); it != s_articlesApos.end(); ++it) { if(lower.startsWith(*it)) { return title_.mid((*it).length()); } @@ -474,10 +474,10 @@ QString Field::sortKeyTitle(const QString& title_) { // articles should all be in lower-case void Field::articlesUpdated() { - const QStringList articles = Config::articleList(); + const TQStringList articles = Config::articleList(); s_articlesApos.clear(); - for(QStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { - if((*it).endsWith(QChar('\''))) { + for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { + if((*it).endsWith(TQChar('\''))) { s_articlesApos += (*it); } } @@ -503,9 +503,9 @@ Field::FieldMap Field::typeMap() { } // just for formatting's sake -QStringList Field::typeTitles() { +TQStringList Field::typeTitles() { const FieldMap& map = typeMap(); - QStringList list; + TQStringList list; list.append(map[Field::Line]); list.append(map[Field::Para]); list.append(map[Field::Choice]); @@ -520,20 +520,20 @@ QStringList Field::typeTitles() { return list; } -QStringList Field::split(const QString& string_, bool allowEmpty_) { - return string_.isEmpty() ? QStringList() : QStringList::split(s_delimiter, string_, allowEmpty_); +TQStringList Field::split(const TQString& string_, bool allowEmpty_) { + return string_.isEmpty() ? TQStringList() : TQStringList::split(s_delimiter, string_, allowEmpty_); } -void Field::addAllowed(const QString& value_) { +void Field::addAllowed(const TQString& value_) { if(m_type != Choice) { return; } - if(m_allowed.findIndex(value_) == -1) { + if(m_allowed.tqfindIndex(value_) == -1) { m_allowed += value_; } } -void Field::setProperty(const QString& key_, const QString& value_) { +void Field::setProperty(const TQString& key_, const TQString& value_) { m_properties.insert(key_, value_); } @@ -547,30 +547,30 @@ void Field::convertOldRating(Data::FieldPtr field_) { } if(field_->name() != Latin1Literal("rating") - && field_->property(QString::fromLatin1("rating")) != Latin1Literal("true")) { + && field_->property(TQString::tqfromLatin1("rating")) != Latin1Literal("true")) { return; // nothing to do } int min = 10; int max = 1; bool ok; - const QStringList& allow = field_->allowed(); - for(QStringList::ConstIterator it = allow.begin(); it != allow.end(); ++it) { + const TQStringList& allow = field_->allowed(); + for(TQStringList::ConstIterator it = allow.begin(); it != allow.end(); ++it) { int n = Tellico::toUInt(*it, &ok); if(!ok) { return; // no need to convert } - min = QMIN(min, n); - max = QMAX(max, n); + min = TQMIN(min, n); + max = TQMAX(max, n); } - max = QMIN(max, 10); + max = TQMIN(max, 10); if(min >= max) { min = 1; max = 5; } - field_->setProperty(QString::fromLatin1("minimum"), QString::number(min)); - field_->setProperty(QString::fromLatin1("maximum"), QString::number(max)); - field_->setProperty(QString::fromLatin1("rating"), QString::null); + field_->setProperty(TQString::tqfromLatin1("minimum"), TQString::number(min)); + field_->setProperty(TQString::tqfromLatin1("maximum"), TQString::number(max)); + field_->setProperty(TQString::tqfromLatin1("rating"), TQString()); field_->setType(Rating); } @@ -580,15 +580,15 @@ long Field::getID() { return ++id; } -void Field::stripArticles(QString& value) { - const QStringList articles = Config::articleList(); +void Field::stripArticles(TQString& value) { + const TQStringList articles = Config::articleList(); if(articles.isEmpty()) { return; } - for(QStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { - QRegExp rx(QString::fromLatin1("\\b") + *it + QString::fromLatin1("\\b")); + for(TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it) { + TQRegExp rx(TQString::tqfromLatin1("\\b") + *it + TQString::tqfromLatin1("\\b")); value.remove(rx); } value = value.stripWhiteSpace(); - value.remove(QRegExp(QString::fromLatin1(",$"))); + value.remove(TQRegExp(TQString::tqfromLatin1(",$"))); } |