File indexing completed on 2024-04-28 04:38:54
0001 /* 0002 SPDX-FileCopyrightText: 1999-2001 Bernd Gehrmann <bernd@kdevelop.org> 0003 SPDX-FileCopyrightText: 1999-2001 the KDevelop Team 0004 SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com> 0005 SPDX-FileCopyrightText: 2010 Silvère Lestang <silvere.lestang@gmail.com> 0006 SPDX-FileCopyrightText: 2010 Julien Desgats <julien.desgats@gmail.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #ifndef KDEVPLATFORM_PLUGIN_GREPOUTPUTMODEL_H 0012 #define KDEVPLATFORM_PLUGIN_GREPOUTPUTMODEL_H 0013 0014 #include <QStandardItemModel> 0015 #include <QList> 0016 0017 #include <language/codegen/documentchangeset.h> 0018 0019 class QModelIndex; 0020 class QRegExp; 0021 0022 namespace KDevelop { 0023 class IStatus; 0024 } 0025 0026 class GrepOutputItem : public QStandardItem 0027 { 0028 public: 0029 using List = QList<GrepOutputItem>; 0030 0031 GrepOutputItem(const KDevelop::DocumentChangePointer& change, const QString& text, bool checkable); 0032 GrepOutputItem(const QString &filename, const QString &text, bool checkable); 0033 ~GrepOutputItem() override; 0034 0035 QString filename() const ; 0036 int lineNumber() const ; 0037 KDevelop::DocumentChangePointer change() const ; 0038 bool isText() const ; 0039 /// Recursively apply check state to children 0040 void propagateState() ; 0041 /// Check children to determine current state 0042 void refreshState() ; 0043 0044 QVariant data ( int role = Qt::UserRole + 1 ) const override; 0045 0046 private: 0047 KDevelop::DocumentChangePointer m_change; 0048 }; 0049 0050 Q_DECLARE_METATYPE(GrepOutputItem::List) 0051 0052 class GrepOutputModel : public QStandardItemModel 0053 { 0054 Q_OBJECT 0055 0056 public: 0057 explicit GrepOutputModel( QObject *parent = nullptr ); 0058 ~GrepOutputModel() override; 0059 0060 void setRegExp(const QRegExp& re); 0061 void setReplacementTemplate(const QString &tmpl); 0062 /// applies replacement on given text 0063 QString replacementFor(const QString &text); 0064 void clear(); // resets file & match counts 0065 bool hasResults(); 0066 0067 QModelIndex previousItemIndex(const QModelIndex ¤tIdx) const; 0068 QModelIndex nextItemIndex(const QModelIndex ¤tIdx) const; 0069 const GrepOutputItem *getRootItem() const; 0070 0071 void makeItemsCheckable(bool checkable); 0072 bool itemsCheckable() const; 0073 0074 public Q_SLOTS: 0075 void appendOutputs( const QString &filename, const GrepOutputItem::List &lines ); 0076 void activate( const QModelIndex &idx ); 0077 void doReplacements(); 0078 void setReplacement(const QString &repl); 0079 //receive status message from GrepJob, and store it 0080 void showMessageSlot( KDevelop::IStatus*, const QString& message ); 0081 //emit stored message as signal 'showMessage' to GrepOutputView. 0082 //called when user selects a search with the combobox 0083 void showMessageEmit(); 0084 0085 Q_SIGNALS: 0086 void showMessage( KDevelop::IStatus*, const QString& message ); 0087 void showErrorMessage(const QString& message); 0088 0089 private: 0090 void makeItemsCheckable(bool checkable, GrepOutputItem* item); 0091 0092 QRegExp m_regExp; 0093 QString m_replacement; 0094 QString m_replacementTemplate; 0095 QString m_finalReplacement; 0096 bool m_finalUpToDate = false; /// says if m_finalReplacement is up to date or must be regenerated 0097 GrepOutputItem *m_rootItem = nullptr; 0098 int m_fileCount = 0; 0099 int m_matchCount = 0; 0100 QString m_savedMessage; 0101 KDevelop::IStatus *m_savedIStatus; 0102 bool m_itemsCheckable = false; 0103 0104 private Q_SLOTS: 0105 void updateCheckState(QStandardItem*); 0106 }; 0107 0108 #endif