1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/***************************************************************************
* Copyright 2010 Julien Desgats <julien.desgats@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "greputil.h"
#include <algorithm>
#include <QChar>
#include <QComboBox>
static int const MAX_LAST_SEARCH_ITEMS_COUNT = 15;
QString substitudePattern(const QString& pattern, const QString& searchString)
{
QString subst = searchString;
QString result;
bool expectEscape = false;
for (const QChar ch : pattern) {
if(expectEscape)
{
expectEscape = false;
if (ch == QLatin1Char('%'))
result.append(QLatin1Char('%'));
else if (ch == QLatin1Char('s'))
result.append(subst);
else
result.append(QLatin1Char('%') + ch);
}
else if (ch == QLatin1Char('%'))
expectEscape = true;
else
result.append(ch);
}
return result;
}
QStringList qCombo2StringList( QComboBox* combo, bool allowEmpty )
{
QStringList list;
if (!combo) {
return list;
}
QString currentText = combo->currentText();
int skippedItem = combo->currentIndex();
if (!currentText.isEmpty() || allowEmpty) {
list << currentText;
}
if (skippedItem != -1 && currentText != combo->itemText(skippedItem)) {
skippedItem = -1;
}
for (int i = 0; i < std::min(MAX_LAST_SEARCH_ITEMS_COUNT, combo->count()); ++i) {
if (i != skippedItem && !combo->itemText(i).isEmpty()) {
list << combo->itemText(i);
}
}
return list;
}
|