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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/***************************************************************************
* Copyright 1999-2001 Bernd Gehrmann and the KDevelop Team *
* bernd@kdevelop.org *
* Copyright 2007 Dukju Ahn <dukjuahn@gmail.com> *
* Copyright 2010 Silvère Lestang <silvere.lestang@gmail.com> *
* 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. *
* *
***************************************************************************/
#ifndef KDEVPLATFORM_PLUGIN_GREPOUTPUTMODEL_H
#define KDEVPLATFORM_PLUGIN_GREPOUTPUTMODEL_H
#include <QStandardItemModel>
#include <QList>
#include <language/codegen/documentchangeset.h>
class QModelIndex;
class QRegExp;
namespace KDevelop {
class IStatus;
}
class GrepOutputItem : public QStandardItem
{
public:
using List = QList<GrepOutputItem>;
GrepOutputItem(const KDevelop::DocumentChangePointer& change, const QString& text, bool checkable);
GrepOutputItem(const QString &filename, const QString &text, bool checkable);
~GrepOutputItem() override;
QString filename() const ;
int lineNumber() const ;
KDevelop::DocumentChangePointer change() const ;
bool isText() const ;
/// Recursively apply check state to children
void propagateState() ;
/// Check children to determine current state
void refreshState() ;
QVariant data ( int role = Qt::UserRole + 1 ) const override;
private:
KDevelop::DocumentChangePointer m_change;
};
Q_DECLARE_METATYPE(GrepOutputItem::List)
class GrepOutputModel : public QStandardItemModel
{
Q_OBJECT
public:
explicit GrepOutputModel( QObject *parent = nullptr );
~GrepOutputModel() override;
void setRegExp(const QRegExp& re);
void setReplacementTemplate(const QString &tmpl);
/// applies replacement on given text
QString replacementFor(const QString &text);
void clear(); // resets file & match counts
bool hasResults();
QModelIndex previousItemIndex(const QModelIndex ¤tIdx) const;
QModelIndex nextItemIndex(const QModelIndex ¤tIdx) const;
const GrepOutputItem *getRootItem() const;
void makeItemsCheckable(bool checkable);
bool itemsCheckable() const;
public Q_SLOTS:
void appendOutputs( const QString &filename, const GrepOutputItem::List &lines );
void activate( const QModelIndex &idx );
void doReplacements();
void setReplacement(const QString &repl);
//receive status message from GrepJob, and store it
void showMessageSlot( KDevelop::IStatus*, const QString& message );
//emit stored message as signal 'showMessage' to GrepOutputView.
//called when user selects a search with the combobox
void showMessageEmit();
Q_SIGNALS:
void showMessage( KDevelop::IStatus*, const QString& message );
void showErrorMessage(const QString & message, int timeout = 0);
private:
void makeItemsCheckable(bool checkable, GrepOutputItem* item);
QRegExp m_regExp;
QString m_replacement;
QString m_replacementTemplate;
QString m_finalReplacement;
bool m_finalUpToDate = false; /// says if m_finalReplacement is up to date or must be regenerated
GrepOutputItem *m_rootItem = nullptr;
int m_fileCount = 0;
int m_matchCount = 0;
QString m_savedMessage;
KDevelop::IStatus *m_savedIStatus;
bool m_itemsCheckable = false;
private Q_SLOTS:
void updateCheckState(QStandardItem*);
};
#endif
|