m_excludeExpr(NULL),
m_blockStartExpr(NULL),
m_blockEndExpr(NULL),
- m_singleBlock(false),
+ m_blocksPerFile(false),
m_caseSensitive(false),
m_fromHit(0),
m_toHit(0),
int linesAbove, int linesBelow,
bool caseSensitive, PrefixMode prefixMode,
const QString& blockStart, const QString& blockEnd,
- bool singleBlock)
+ int blocksPerFile)
{
int ixFile = -1;
int hitNo = 0;
m_linesAbove = linesAbove;
m_linesBelow = linesBelow;
m_prefixMode = prefixMode;
- m_singleBlock = singleBlock;
+ m_blocksPerFile = blocksPerFile;
delete m_includeExpr;
delete m_excludeExpr;
m_blockEndExpr = blockEnd.isEmpty() ? NULL : new QRegularExpression(blockEnd, option);
QString full;
QString node;
- int hitFileNo = -1;
+ int hitFileNo = 0;
while (ixFile < fileCount - 1 && hitNo < m_toHit){
++ixFile;
full = m_table.item(ixFile, colPath)->text();
default:
break;
}
+ int currentBlock = 0;
QString prefixOther = prefixHit;
if (m_linesAbove + m_linesBelow > 0){
prefixHit = ">" + prefixHit;
lineNo = m_lastHitPosition.m_line;
}
int firstHitFile = true;
- int firstFileIndex = 0;
+ int firstFileIndex = -1;
bool inBlock = m_blockStartExpr == NULL;
while(lastHit < m_toHit && lineNo < lastIx){
QString line = lines[++lineNo];
}
if (m_blockEndExpr != 0 && m_blockEndExpr->match(line).hasMatch()){
inBlock = false;
- if (m_singleBlock)
+ if (++currentBlock >= m_blocksPerFile)
break;
}
}
int fromHit, int toHit, int linesAbove, int linesBelow,
bool caseSensitive, PrefixMode prefixMode,
const QString& blockStart, const QString& blockEnd,
- bool singleBlock);
+ int blocksPerFile);
private:
int filterOneFile(const QString &filename, const QString& node, int lastHit,
QRegularExpression* m_excludeExpr;
QRegularExpression* m_blockStartExpr;
QRegularExpression* m_blockEndExpr;
- bool m_singleBlock;
+ int m_blocksPerFile;
bool m_caseSensitive;
int m_fromHit;
int m_toHit;
const QString& baseDirectory,
const QString& filePatterns,
QWidget *parent) :
- ReGuiApplication(application, "rsearch", homeDir, 2, 10100100, "de", parent),
+ ReGuiApplication(application, "research", homeDir, 2, 10100100, "de", parent),
ReGuiValidator(),
ui(new Ui::MainWindow),
m_fileFinder(NULL),
m_timer(new QTimer(this)),
m_filenames()
{
+ ReIntComboBox::m_defaultAnnouncer = this;
ReComboBox::setDefaultHistorySize(20);
m_timer->setSingleShot(true);
initializeGui();
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimerTask()));
+ ui->comboBoxFromHit->setMinValue(1);
delete m_fileFinder;
m_fileFinder = new FileFinder(*ui->tableWidget, *m_fileCache);
(PrefixMode) ui->comboBoxPrefixMode->currentIndex(),
ui->comboBoxStartPattern->currentText(),
ui->comboBoxEndPattern->currentText(),
- ui->checkBoxSingleBlock->isChecked());
+ ui->comboBoxBlocksPerFile->currentValue());
switchFilter(false);
int found = pageSize;
if (m_lastHitPosition->m_hitCount >= 0
</size>
</property>
<property name="text">
- <string>99</string>
+ <string notr="true">99</string>
</property>
</widget>
</item>
</size>
</property>
<property name="text">
- <string>0</string>
+ <string notr="true">0</string>
</property>
</widget>
</item>
<attribute name="title">
<string>Options</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_8">
- <item>
- <layout class="QGridLayout" name="gridLayout" columnstretch="0,1,0,1,0,2">
- <property name="sizeConstraint">
- <enum>QLayout::SetMaximumSize</enum>
- </property>
- <item row="0" column="0">
- <widget class="QLabel" name="label_8">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Lines above:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="ReComboBox" name="comboBoxLinesAbove">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>175</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="editable">
- <bool>true</bool>
- </property>
- <property name="currentText">
- <string>0</string>
- </property>
- </widget>
- </item>
- <item row="0" column="2">
- <widget class="QLabel" name="label_9">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Lines below:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="3">
- <widget class="ReComboBox" name="comboBoxLinesBelow">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>175</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="editable">
- <bool>true</bool>
- </property>
- <property name="currentText">
- <string notr="true">0</string>
- </property>
- </widget>
- </item>
- <item row="0" column="4">
- <widget class="QLabel" name="label_18">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>Prefix:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="5">
- <widget class="QComboBox" name="comboBoxPrefixMode">
- <property name="minimumSize">
- <size>
- <width>0</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>175</width>
- <height>16777215</height>
- </size>
- </property>
- <item>
+ <widget class="QWidget" name="layoutWidget">
+ <property name="geometry">
+ <rect>
+ <x>11</x>
+ <y>11</y>
+ <width>608</width>
+ <height>90</height>
+ </rect>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_12">
+ <item>
+ <layout class="QFormLayout" name="formLayout_4">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
<property name="text">
- <string>Placeholder</string>
+ <string>Lines above:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReIntComboBox" name="comboBoxLinesAbove">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="ReIntComboBox" name="comboBoxLinesBelow">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string notr="true">0</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
</property>
- </item>
- <item>
<property name="text">
- <string>Filename with path</string>
+ <string>Lines below:</string>
</property>
- </item>
- <item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QFormLayout" name="formLayout_10">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="checkBox">
<property name="text">
- <string>Filename without path</string>
+ <string>Case sensitive</string>
</property>
- </item>
- <item>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_24">
<property name="text">
- <string>No filename</string>
+ <string/>
</property>
- </item>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QFormLayout" name="formLayout_6">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_18">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Prefix:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="comboBoxPrefixMode">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <item>
+ <property name="text">
+ <string>Placeholder</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Filename with path</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Filename without path</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>No filename</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_23">
+ <property name="text">
+ <string>Hits per file:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="ReIntComboBox" name="comboBoxHitsPerFile">
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
</widget>
<widget class="QWidget" name="tabBlock">
<attribute name="title">
<string>Block</string>
</attribute>
- <layout class="QFormLayout" name="formLayout_5">
- <item row="0" column="0">
- <widget class="QLabel" name="label_16">
- <property name="text">
- <string>Start pattern:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="ReComboBox" name="comboBoxStartPattern">
- <property name="editable">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_17">
- <property name="text">
- <string>End pattern:</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="ReComboBox" name="comboBoxEndPattern">
- <property name="editable">
- <bool>true</bool>
- </property>
- </widget>
+ <layout class="QVBoxLayout" name="verticalLayout_8">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_14" stretch="1,0">
+ <item>
+ <layout class="QFormLayout" name="formLayout_5">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_16">
+ <property name="text">
+ <string>Start pattern:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReComboBox" name="comboBoxStartPattern">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_17">
+ <property name="text">
+ <string>End pattern:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="ReComboBox" name="comboBoxEndPattern">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QFormLayout" name="formLayout_9">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_22">
+ <property name="text">
+ <string>Blocks per file:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReIntComboBox" name="comboBoxBlocksPerFile">
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QCheckBox" name="checkBoxBlockCaseSensitive">
+ <property name="text">
+ <string>Case sensitive</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
</item>
</layout>
</widget>
- <widget class="QWidget" name="tabBlockOptions">
+ <widget class="QWidget" name="tabNearBy">
<attribute name="title">
- <string>Block Options</string>
+ <string>"Near by" Search</string>
</attribute>
- <widget class="QCheckBox" name="checkBoxSingleBlock">
- <property name="geometry">
- <rect>
- <x>20</x>
- <y>20</y>
- <width>171</width>
- <height>25</height>
- </rect>
- </property>
- <property name="text">
- <string>A single block only</string>
- </property>
- </widget>
+ <layout class="QVBoxLayout" name="verticalLayout_9">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_13" stretch="1,0">
+ <item>
+ <layout class="QFormLayout" name="formLayout_7">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_19">
+ <property name="text">
+ <string>Search pattern:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReComboBox" name="comboBoxNearByPattern">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QCheckBox" name="checkBox_2">
+ <property name="text">
+ <string>Case sensitive</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QFormLayout" name="formLayout_8">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_20">
+ <property name="text">
+ <string>Max. lines above the hit:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReComboBox" name="comboBoxNearByAbove">
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string notr="true">0</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_21">
+ <property name="text">
+ <string>Max. lines below the hit:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="ReComboBox" name="comboBoxNearByBelow">
+ <property name="maximumSize">
+ <size>
+ <width>75</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string notr="true">0</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
</widget>
</widget>
</item>
</widget>
</item>
<item>
- <widget class="ReComboBox" name="comboBoxFromHit">
+ <widget class="ReIntComboBox" name="comboBoxFromHit">
<property name="maximumSize">
<size>
<width>100</width>
</widget>
</item>
<item>
- <widget class="ReComboBox" name="comboBoxPageSize">
+ <widget class="ReIntComboBox" name="comboBoxPageSize">
<property name="maximumSize">
<size>
<width>100</width>
<bool>true</bool>
</property>
<property name="currentText">
- <string notr="true">10</string>
+ <string notr="true">50</string>
</property>
</widget>
</item>
<extends>QComboBox</extends>
<header>gui/ReComboBox.hpp</header>
</customwidget>
+ <customwidget>
+ <class>ReIntComboBox</class>
+ <extends>QComboBox</extends>
+ <header>ReIntComboBox.hpp</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
</message>
<message>
<source>Found: %1 hit(s) in %2</source>
- <translation>Gefunden: %1 Treffer in %d</translation>
+ <translation>Gefunden: %1 Treffer in %2</translation>
</message>
<message>
<source>missing a base directory</source>
<source>I am working...</source>
<translation>Ich arbeite...</translation>
</message>
+ <message>
+ <source>Hits per file:</source>
+ <translation>Treffer je Datei:</translation>
+ </message>
+ <message>
+ <source>Blocks per file:</source>
+ <translation>Blöcke je Datei:</translation>
+ </message>
+ <message>
+ <source>Search pattern:</source>
+ <translation>Suchmuster:</translation>
+ </message>
+ <message>
+ <source>Max. lines above the hit:</source>
+ <translation>Max. Zeilen über dem Treffer:</translation>
+ </message>
+ <message>
+ <source>Max. lines below the hit:</source>
+ <translation>Max. Zeilen unter dem Treffer:</translation>
+ </message>
+ <message>
+ <source>"Near by" Search</source>
+ <translation>"Nahe bei"-Suche</translation>
+ </message>
</context>
<context>
<name>QObject</name>
<translation>Willkommen!</translation>
</message>
</context>
+<context>
+ <name>ReIntComboBox</name>
+ <message>
+ <source>integer expected, not an empty string</source>
+ <translation>Ganzzahl erwartet, kein leerer String</translation>
+ </message>
+ <message>
+ <source>not a number:</source>
+ <translation>Keine Zahl:</translation>
+ </message>
+ <message>
+ <source>value to small: %1 < %2</source>
+ <translation>Wert zu klein: %1 < %2 </translation>
+ </message>
+ <message>
+ <source>value to large: %1 > %2</source>
+ <translation>Wert zu groß: %1 > %2</translation>
+ </message>
+</context>
</TS>
../../base/ReFileSearch.cpp \
filefinder.cpp \
filecache.cpp \
- filefilter.cpp
+ filefilter.cpp \
+ ../../gui/ReIntComboBox.cpp
HEADERS += mainwindow.hpp \
../../base/rebase.hpp \
../../base/ReFileSearch.hpp \
filefinder.hpp \
filecache.hpp \
- filefilter.hpp
+ filefilter.hpp \
+ ../../gui/ReIntComboBox.hpp
FORMS += mainwindow.ui \
aboutdialog.ui
}
}
}
- return rc;
+ return rc;
+}
+
+/**
+ * Tests whether a string is a number.
+ *
+ * @param text text to inspect
+ * @param value OUT: the value of text interpreted as integer
+ * @return <i>true</i>: <i>text</i>is a number
+ */
+bool ReQStringUtils::isAnInteger(const QString &text, int *value)
+{
+ bool isNegative = false;
+ bool rc = ! text.isEmpty();
+ if (rc){
+ int start = 0;
+ if (text[0] == QChar('-')){
+ isNegative = true;
+ start = 1;
+ }
+ rc = lengthOfUInt(text, start, 10, (unsigned *) value) == text.length() - start;
+ if (value != NULL && isNegative)
+ *value = - *value;
+ }
+ return rc;
}
/**
QString ReQStringUtils::numberToName(int number, const char* charSet, int charSetSize){
QString rc;
if (charSet == NULL){
- charSet = "-$ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- charSetSize = 37+1; // strlen(charSet)
+ charSet = "-$ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ charSetSize = 26+1+1; // strlen(charSet)
}
if (number < 0){
number = -number;
static QString& ensureLastChar(QString& value, QChar lastChar);
static bool hasPrefixAndNumber(const QString prefix, const QString& line,
int& no, QString& value);
+ static bool isAnInteger(const QString& text, int* value = NULL);
static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
NULL);
static int lengthOfDateTime(const ReString& text, int start = 0,
*/
void ReTest::assertLogContainsLocation(int location, const char* file, int lineNo)
{
- QByteArray pattern("^.20[\\d:. ]+\\(");
- pattern += location;
- pattern += "\\)";
+ char pattern[128];
+ snprintf(pattern, sizeof pattern, "^.20[\\d:. ]+\\(%d\\)", location);
if (! logContains(pattern, true)){
error("%s-%d: not found: location %d\n", file, lineNo, location,
m_memoryAppender.getLines().join().constData());
checkEqu(0, stat(dir.constData(), &info));
checkF(S_ISDIR(info.st_mode));
checkF(ReFileUtils::makeDirWithParents(dir.constData(), &m_memoryLogger));
- checkLogContainsLocation(51003);
+ checkLogContainsLocation(12508);
checkLogContains(dir.constData(), false);
}
void testIsDirectoy(){
checkEqu("1.001 TB", ReQStringUtils::readableSize(1001000000000l));
}
void testReadableDuration(){
-#define clf(sec) clock_t(clock_t((sec) * CLOCKS_PER_SEC))
+#define clf(sec) qint64((sec) * 1000)
checkEqu("0.000 sec", ReQStringUtils::readableDuration(clf(0.0)));
QString value = ReQStringUtils::readableDuration(clf(1.234));
checkEqu("1.234 sec", value);
checkEqu("/a/b/c", s);
}
+ void testIsAnInteger(){
+ checkT(ReQStringUtils::isAnInteger("1"));
+ int value;
+ checkT(ReQStringUtils::isAnInteger("1", &value));
+ checkEqu(1, value);
+ checkT(ReQStringUtils::isAnInteger("-76453", &value));
+ checkEqu(-76453, value);
+ checkF(ReQStringUtils::isAnInteger(""));
+ checkF(ReQStringUtils::isAnInteger("", &value));
+ checkF(ReQStringUtils::isAnInteger("12a"));
+ checkF(ReQStringUtils::isAnInteger("12a", &value));
+ checkF(ReQStringUtils::isAnInteger(".12"));
+ checkF(ReQStringUtils::isAnInteger(".12", &value));
+ checkF(ReQStringUtils::isAnInteger("-12,"));
+ checkF(ReQStringUtils::isAnInteger("-12,", &value));
+ }
+
virtual void runTests(void) {
+ testIsAnInteger();
testChomp();
testReadableSize();
testReadableDuration();
--- /dev/null
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+ReAnnouncer* ReIntComboBox::m_defaultAnnouncer = NULL;
+
+/**
+ * Constructor.
+ * @param parent
+ */
+ReIntComboBox::ReIntComboBox(QWidget *parent) :
+ ReComboBox(parent),
+ m_minValue(0),
+ m_maxValue(0x7ffffff),
+ m_defaultValue(0),
+ m_announcer(m_defaultAnnouncer),
+ m_emptyAllowed(false)
+{
+ connect(this, SIGNAL(textEdited(const QString&, const QString&)),
+ this, SLOT(textEdited(const QString&, const QString&)));
+}
+
+/**
+ * Returns the current value.
+ *
+ * @return the current value
+ */
+int ReIntComboBox::currentValue() const
+{
+ QString value = currentText();
+ int rc = m_defaultValue;
+ if (! value.isEmpty())
+ rc = value.toInt();
+ return rc;
+}
+
+/**
+ * Returns the current announcer (logger for error messages).
+ * @return the current announcer
+ */
+ReAnnouncer* ReIntComboBox::announcer() const
+{
+ return m_announcer;
+}
+
+/**
+ * Returns the flag "empty allowed".
+ *
+ * @return the flag "empty allowed"
+ */
+bool ReIntComboBox::emptyAllowed() const
+{
+ return m_emptyAllowed;
+}
+
+/**
+ * Prints an error message with the stored announcer.
+ *
+ * @param message the error message
+ */
+void ReIntComboBox::error(const QString& message, const QString* defaultValue)
+{
+ if (m_announcer != NULL)
+ m_announcer->say(LOG_ERROR, message);
+ if (defaultValue == NULL){
+ setCurrentText(QString::number(m_defaultValue));
+ } else {
+ if (ReQStringUtils::isAnInteger(*defaultValue))
+ setCurrentText(*defaultValue);
+ else
+ setCurrentText(QString::number(m_defaultValue));
+ }
+}
+/**
+ * Returns the current default value (uses for errors).
+ *
+ * @return the current default value
+ */
+int ReIntComboBox::defaultValue() const
+{
+ return m_defaultValue;
+}
+
+/**
+ * Gets the maximal allowed value.
+ *
+ * @return the maximal allowed value
+ */
+int ReIntComboBox::maxValue() const
+{
+ return m_maxValue;
+}
+
+/**
+ * Gets the maximal allowed value.
+ *
+ * @return the maximal allowed value
+ */
+int ReIntComboBox::minValue() const
+{
+ return m_minValue;
+}
+
+/**
+ * Handles the event "changed text".
+ *
+ * @param oldValue value before editing
+ * @param newValue value after editing
+ */
+void ReIntComboBox::textEdited(const QString& oldValue, const QString& newValue)
+{
+ int value;
+ if (newValue.isEmpty()){
+ if (! m_emptyAllowed)
+ error(tr("integer expected, not an empty string"), &oldValue);
+ } else if (! ReQStringUtils::isAnInteger(newValue, &value)){
+ error(tr("not a number:") + " " + newValue, &oldValue);
+ } else if (value < m_minValue) {
+ error(tr("value to small: %1 < %2").arg(value).arg(m_minValue), &oldValue);
+ } else if (value > m_maxValue) {
+ error(tr("value to large: %1 > %2").arg(value).arg(m_maxValue), &oldValue);
+ }
+}
+
+/**
+ * Sets the flag "empty allowed".
+ *
+ * @param emptyAllowed <i>true</i>: the field may be empty.<br>
+ * <i>false</i>: the field must not be empty
+ */
+void ReIntComboBox::setEmptyAllowed(bool emptyAllowed)
+{
+ m_emptyAllowed = emptyAllowed;
+}
+
+/**
+ * Sets the maximal value.
+ *
+ * @param maxValue the maximal allowed value
+ */
+void ReIntComboBox::setMaxValue(int maxValue)
+{
+ m_maxValue = maxValue;
+}
+
+/**
+ * Sets the minimal value.
+ *
+ * @param minValue the minimal allowed value
+ */
+void ReIntComboBox::setMinValue(int minValue)
+{
+ m_minValue = minValue;
+}
+
+/**
+ * Sets the maximal value.
+ *
+ * @param maxValue the maximal allowed value
+ */
+void ReIntComboBox::setDefaultValue(int defaultValue)
+{
+ m_defaultValue = defaultValue;
+}
+
+/**
+ * Sets the announcer (to log errors).
+ *
+ * @param announcer the new announcer (or NULL)
+ */
+void ReIntComboBox::setAnnouncer(ReAnnouncer* announcer)
+{
+ m_announcer = announcer;
+}
+
--- /dev/null
+#ifndef REINTCOMBOBOX_H
+#define REINTCOMBOBOX_H
+
+#ifndef RECOMBOBOX_HPP
+#include "gui/ReComboBox.hpp"
+#endif
+
+class ReAnnouncer;
+/**
+ * Implements a combo box containing a integer as value.
+ */
+class ReIntComboBox : public ReComboBox
+{
+ Q_OBJECT
+public:
+ ReIntComboBox(QWidget *parent);
+public:
+ ReAnnouncer* announcer() const;
+ int currentValue() const;
+ int defaultValue() const;
+ bool emptyAllowed() const;
+ void error(const QString& message, const QString* defaultValue = NULL);
+ int maxValue() const;
+ int minValue() const;
+ void textEdited(const QString& oldValue, const QString& newValue);
+ void setAnnouncer(ReAnnouncer* announcer);
+ void setDefaultValue(int defaultValue);
+ void setEmptyAllowed(bool emptyAllowed);
+ void setMaxValue(int maxValue);
+ void setMinValue(int minValue);
+private:
+ int m_minValue;
+ int m_maxValue;
+ int m_defaultValue;
+ ReAnnouncer* m_announcer;
+ bool m_emptyAllowed;
+public:
+ static ReAnnouncer* m_defaultAnnouncer;
+};
+
+#endif // REINTCOMBOBOX_H
LOC_CHANGE_VALUE_2, // 11712
};
-QString ReSettings::TRUE = "t";
-QString ReSettings::FALSE = "";
+QString ReSettings::sTRUE = "t";
+QString ReSettings::sFALSE = "";
/**
* Constructor.
* Tests whether a given value is allowed respecting the <code>m_limits</code>
* @param value the value to test
* @param error OUT: NULL or the error message
- * @return <code>true</code>: the value is allowed<br>
+ * @return <code>sTRUE</code>: the value is allowed<br>
*/
bool ReProperty::isValid(const QString& value, QString* error) {
- bool rc = true;
+ bool rc = true;
if (error != NULL)
*error = "";
if (m_limits != NULL) {
int minimum, maximum;
if (sscanf(m_limits, "[%d,%d]", &minimum, &maximum) == 2) {
if (nValue < minimum) {
- rc = false;
+ rc = false;
if (error != NULL)
*error = value + " < " + minimum;
} else if (nValue > maximum) {
- rc = false;
+ rc = false;
if (error != NULL)
*error = value + " < " + maximum;
}
* @return the value of the property
*/
bool ReSettings::boolValue(const char* name) {
- bool rc = false;
+ bool rc = false;
ReProperty* property = m_settings.value(name, NULL);
if (property == NULL)
m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_1, "missing bool property %s",
case PT_BOOL:
property->m_value =
value.isEmpty() ?
- ReSettings::FALSE : ReSettings::TRUE;
+ ReSettings::sFALSE : ReSettings::sTRUE;
break;
case PT_INT:
if (property->isValid(value))
m_delay(delay),
m_file(file),
m_logger(logger){
- m_timer.setSingleShot(true);
+ m_timer.setSingleShot(true);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
}
#include <QAction>
#include <QApplication>
#include "gui/ReComboBox.hpp"
+#include "gui/ReIntComboBox.hpp"
#include "gui/ReGuiUtils.hpp"
#include "gui/ReGuiQueue.hpp"
#include "gui/ReStateStorage.hpp"