* @param list list widget to store the filtered lines
*/
FileFilter::FileFilter(QTableWidget &table, QListWidget &list, FileCache& cache,
- HitPosition& lastHitPosition) :
+ HitPosition& lastHitPosition, QStringList& filenames) :
m_table(table),
m_list(list),
m_cache(cache),
m_linesAbove(0),
m_linesBelow(0),
m_lastHitPosition(lastHitPosition),
- m_prefixMode(pmNone)
+ m_prefixMode(pmNone),
+ m_filenames(filenames)
{
}
delete m_excludeExpr;
delete m_blockStartExpr;
delete m_blockEndExpr;
-
+ m_filenames.clear();
QRegularExpression::PatternOption option = caseSensitive
? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption;
m_includeExpr = includePattern.isEmpty() ? NULL : new QRegularExpression(includePattern, option);
m_excludeExpr = excludePattern.isEmpty() ? NULL : new QRegularExpression(excludePattern, option);
- m_blockStartExpr = includePattern.isEmpty() ? NULL : new QRegularExpression(blockStart, option);
- m_blockEndExpr = excludePattern.isEmpty() ? NULL : new QRegularExpression(blockEnd, option);
+ m_blockStartExpr = blockStart.isEmpty() ? NULL : new QRegularExpression(blockStart, option);
+ m_blockEndExpr = blockEnd.isEmpty() ? NULL : new QRegularExpression(blockEnd, option);
QString full;
QString node;
int hitFileNo = -1;
lineNo = m_lastHitPosition.m_line;
}
int firstHitFile = true;
+ int firstFileIndex = -1;
+ bool inBlock = m_blockStartExpr == NULL;
while(lastHit < m_toHit && lineNo < lastIx){
QString line = lines[++lineNo];
+ if (! inBlock){
+ if (m_blockStartExpr->match(line).hasMatch())
+ inBlock = true;
+ else
+ continue;
+ }
if (m_includeExpr != NULL && ! m_includeExpr->match(line).hasMatch())
continue;
if (m_excludeExpr != NULL && m_excludeExpr->match(line).hasMatch())
for (int ix = max(lastLine + 1, max(0, lineNo - m_linesAbove));
ix <= min(lineNo + m_linesBelow, lastIx);
ix++){
+ if (m_prefixMode != pmFull){
+ if (firstFileIndex < 0){
+ firstFileIndex = m_filenames.size();
+ m_filenames.append(filename);
+ } else {
+ if ((firstFileIndex - m_filenames.size()) % 16 == 0)
+ m_filenames.append("\t" + QString::number(firstFileIndex));
+ else
+ m_filenames.append("");
+ }
+ }
m_list.addItem((ix == lineNo ? prefixHit : prefixOther)
+ QString::number(ix + 1) + ": " + lines[ix]);
}
}
+ if (m_blockEndExpr != 0 && m_blockEndExpr->match(line).hasMatch()){
+ inBlock = false;
+ if (m_singleBlock)
+ break;
+ }
}
return lastHit;
}
{
public:
FileFilter(QTableWidget& table, QListWidget& list, FileCache& cache,
- HitPosition& lastHitPosition);
+ HitPosition& lastHitPosition, QStringList& filenames);
virtual ~FileFilter();
public:
void filter(const QString& includePattern, const QString& excludePattern,
int m_linesBelow;
HitPosition& m_lastHitPosition;
PrefixMode m_prefixMode;
+ // m_filenames[ix] contains the filename with path of listWidgetHits[ix]
+ // or m_filenames[ix].isEmpty(): then the next (reverse) non empty entry
+ // contains the filename
+ // or m_filenames[ix] = "\t<no>" where m_filenames[no] contains the filename
+ QStringList& m_filenames;
};
#endif // FILEFILTER_H
int last = m_table.rowCount();
m_files.insert(full);
m_table.setRowCount(last + 1);
- m_table.setItem(last, colNode, new QTableWidgetItem(node));
- m_table.setItem(last, colSize, new QTableWidgetItem(QString::number(info.size())));
+ QTableWidgetItem* current;
+ m_table.setItem(last, colNode, current = new QTableWidgetItem(node));
+ current->setFlags(current->flags() ^ Qt::ItemIsEditable);
+ m_table.setItem(last, colSize, current = new QTableWidgetItem(QString::number(info.size())));
+ current->setFlags(current->flags() ^ Qt::ItemIsEditable);
QString date = info.lastModified().toString("yyyy.MM.dd hh:mm.ss");
- m_table.setItem(last, colDate, new QTableWidgetItem(date));
- m_table.setItem(last, colPath, new QTableWidgetItem(path));
+ m_table.setItem(last, colDate, current = new QTableWidgetItem(date));
+ current->setFlags(current->flags() ^ Qt::ItemIsEditable);
+ m_table.setItem(last, colPath, current = new QTableWidgetItem(path));
+ current->setFlags(current->flags() ^ Qt::ItemIsEditable);
}
}
m_test(true),
m_lastHitPosition(new HitPosition()),
m_currentTask(ttUndef),
- m_timer(new QTimer(this))
+ m_timer(new QTimer(this)),
+ m_filenames()
{
ReComboBox::setDefaultHistorySize(20);
m_timer->setSingleShot(true);
this, SLOT(clearLastHitPosition(const QString&, const QString&)));
connect(ui->comboBoxFromHit, SIGNAL(textEdited(QString,QString)),
this, SLOT(onFromHitChanged(const QString&, const QString&)));
+ connect(ui->tableWidget, SIGNAL(cellEntered(int,int)),
+ this, SLOT(onCellEntered(int, int)));
+ connect(ui->listWidgetHits, SIGNAL(itemClicked(QListWidgetItem*)),
+ this, SLOT(onHitLineClicked(QListWidgetItem*)));
+
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimerTask()));
if (m_test){
}
}
+void MainWindow::onCellEntered(int row, int column)
+{
+ row++;
+}
+
+/**
+ * Shows the current hit line as file and content in 2 fields.
+ *
+ * @param item the current hit line
+ */
+void MainWindow::onHitLineClicked(QListWidgetItem* item){
+ if (ui->lineEditCurrentFile->isVisible()){
+ int row = item->listWidget()->row(item);
+ QString line = item->text();
+ int ix = line.indexOf(':');
+ ui->lineEditCurrentLine->setText(item->text().mid(ix + 1));
+ PrefixMode mode = (PrefixMode) ui->comboBoxPrefixMode->currentIndex();
+ if (mode == pmFull){
+ // format: <filename>-<lineNo>: <content>
+ line = line.mid(0, ix);
+ ui->lineEditCurrentFile->setText(line.mid(0, line.lastIndexOf('-')));
+ } else {
+ QString name;
+ while(row >= 0){
+ name = m_filenames[row--];
+ if (name.isEmpty()){
+ continue;
+ } else if (name[0] == QChar('\t')){
+ name = m_filenames[atoi(name.toLatin1().data() + 1)];
+ break;
+ }
+ }
+ ui->lineEditCurrentFile->setText(name);
+ }
+ }
+}
/**
* Writes the known number of hits into the label.
{
qint64 start = QDateTime::currentMSecsSinceEpoch();
FileFilter filter(*ui->tableWidget, *ui->listWidgetHits, *m_fileCache,
- *m_lastHitPosition);
+ *m_lastHitPosition, m_filenames);
int from = comboInt(ui->comboBoxFromHit, 0);
int pageSize = comboInt(ui->comboBoxPageSize, s_defaultPageSize);
int above = comboInt(ui->comboBoxLinesAbove, 0);
void clearLastHitPosition(const QString &, const QString &);
void onAbout();
void onAdd();
+ void onCellEntered(int row, int column);
void onClear();
void onDetach();
void onFilter();
void onFromHitChanged(const QString &oldValue, const QString &newValue);
+ void onHitLineClicked(QListWidgetItem *item);
void onNext();
void onPrevious();
void onSelectBaseDirectory();
HitPosition* m_lastHitPosition;
TimerTask m_currentTask;
QTimer* m_timer;
+ // m_filenames[ix] contains the filename with path of listWidgetHits[ix]
+ // or m_filenames[ix].isEmpty(): then the next (reverse) non empty entry
+ // contains the filename
+ // or m_filenames[ix] = "\t<no>" where m_filenames[no] contains the filename
+ QStringList m_filenames;
};
#endif // MAINWINDOW_H
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
+ <property name="editTriggers">
+ <set>QAbstractItemView::AllEditTriggers</set>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::MultiSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
+ <attribute name="verticalHeaderShowSortIndicator" stdset="0">
+ <bool>false</bool>
+ </attribute>
<column>
<property name="text">
<string>Name</string>
</property>
<item>
<property name="text">
- <string>Filename with path</string>
+ <string>Placeholder</string>
</property>
</item>
<item>
<property name="text">
- <string>Filename without path</string>
+ <string>Filename with path</string>
</property>
</item>
<item>
<property name="text">
- <string>Placeholder</string>
+ <string>Filename without path</string>
</property>
</item>
<item>
</item>
</layout>
</item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <widget class="QLineEdit" name="lineEditCurrentFile"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="labelCurrentSeparator">
+ <property name="text">
+ <string>:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditCurrentLine"/>
+ </item>
+ </layout>
+ </item>
</layout>
</widget>
</widget>
};
enum PrefixMode {
+ pmPlaceholder,
pmFull,
pmNode,
- pmPlaceholder,
pmNone,
};