Changeset View
Changeset View
Standalone View
Standalone View
addons/project/kateprojectinfoviewcodeanalysis.cpp
Show All 30 Lines | |||||
31 | #include <kmessagewidget.h> | 31 | #include <kmessagewidget.h> | ||
32 | 32 | | |||
33 | KateProjectInfoViewCodeAnalysis::KateProjectInfoViewCodeAnalysis(KateProjectPluginView *pluginView, KateProject *project) | 33 | KateProjectInfoViewCodeAnalysis::KateProjectInfoViewCodeAnalysis(KateProjectPluginView *pluginView, KateProject *project) | ||
34 | : QWidget() | 34 | : QWidget() | ||
35 | , m_pluginView(pluginView) | 35 | , m_pluginView(pluginView) | ||
36 | , m_project(project) | 36 | , m_project(project) | ||
37 | , m_messageWidget(nullptr) | 37 | , m_messageWidget(nullptr) | ||
38 | , m_startStopAnalysis(new QPushButton(i18n("Start Analysis..."))) | 38 | , m_startStopAnalysis(new QPushButton(i18n("Start Analysis..."))) | ||
39 | , m_treeView(new QTreeView()) | 39 | , m_treeView(new QTreeView(this)) | ||
40 | , m_model(new QStandardItemModel(m_treeView)) | 40 | , m_model(new QStandardItemModel(m_treeView)) | ||
41 | , m_analyzer(nullptr) | 41 | , m_analyzer(nullptr) | ||
42 | , m_analysisTool(nullptr) | 42 | , m_analysisTool(nullptr) | ||
43 | , m_toolSelector(new QComboBox()) | 43 | , m_toolSelector(new QComboBox()) | ||
44 | { | 44 | { | ||
45 | /** | 45 | /** | ||
46 | * default style | 46 | * default style | ||
47 | */ | 47 | */ | ||
Show All 37 Lines | |||||
85 | * connect needed signals | 85 | * connect needed signals | ||
86 | */ | 86 | */ | ||
87 | connect(m_startStopAnalysis, &QPushButton::clicked, this, &KateProjectInfoViewCodeAnalysis::slotStartStopClicked); | 87 | connect(m_startStopAnalysis, &QPushButton::clicked, this, &KateProjectInfoViewCodeAnalysis::slotStartStopClicked); | ||
88 | connect(m_treeView, &QTreeView::clicked, this, &KateProjectInfoViewCodeAnalysis::slotClicked); | 88 | connect(m_treeView, &QTreeView::clicked, this, &KateProjectInfoViewCodeAnalysis::slotClicked); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | KateProjectInfoViewCodeAnalysis::~KateProjectInfoViewCodeAnalysis() | 91 | KateProjectInfoViewCodeAnalysis::~KateProjectInfoViewCodeAnalysis() | ||
92 | { | 92 | { | ||
93 | delete m_analyzer; | ||||
93 | } | 94 | } | ||
94 | 95 | | |||
95 | void KateProjectInfoViewCodeAnalysis::slotStartStopClicked() | 96 | void KateProjectInfoViewCodeAnalysis::slotStartStopClicked() | ||
96 | { | 97 | { | ||
97 | /** | 98 | /** | ||
98 | * get files for the external tool | 99 | * get files for the external tool | ||
99 | */ | 100 | */ | ||
100 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | 101 | m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool*>(); | ||
101 | m_analysisTool->setProject(m_project); | 102 | m_analysisTool->setProject(m_project); | ||
102 | 103 | | |||
103 | /** | 104 | /** | ||
104 | * clear existing entries | 105 | * clear existing entries | ||
105 | */ | 106 | */ | ||
106 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | 107 | m_model->removeRows(0, m_model->rowCount(), QModelIndex()); | ||
107 | 108 | | |||
108 | /** | 109 | /** | ||
109 | * launch cppcheck | 110 | * launch cppcheck | ||
110 | */ | 111 | */ | ||
111 | m_analyzer = new QProcess(this); | 112 | delete m_analyzer; | ||
113 | m_analyzer = new QProcess; | ||||
112 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | 114 | m_analyzer->setProcessChannelMode(QProcess::MergedChannels); | ||
113 | 115 | | |||
114 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | 116 | connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); | ||
115 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | 117 | connect(m_analyzer, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), | ||
116 | this, &KateProjectInfoViewCodeAnalysis::finished); | 118 | this, &KateProjectInfoViewCodeAnalysis::finished); | ||
117 | 119 | | |||
118 | m_analyzer->start(m_analysisTool->path(), m_analysisTool->arguments()); | 120 | m_analyzer->start(m_analysisTool->path(), m_analysisTool->arguments()); | ||
119 | 121 | | |||
120 | if (m_messageWidget) { | 122 | if (m_messageWidget) { | ||
121 | delete m_messageWidget; | 123 | delete m_messageWidget; | ||
122 | m_messageWidget = nullptr; | 124 | m_messageWidget = nullptr; | ||
123 | } | 125 | } | ||
124 | 126 | | |||
125 | if (!m_analyzer->waitForStarted()) { | 127 | if (!m_analyzer->waitForStarted()) { | ||
126 | m_messageWidget = new KMessageWidget(); | 128 | m_messageWidget = new KMessageWidget(this); | ||
127 | m_messageWidget->setCloseButtonVisible(true); | 129 | m_messageWidget->setCloseButtonVisible(true); | ||
128 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 130 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
129 | m_messageWidget->setWordWrap(false); | 131 | m_messageWidget->setWordWrap(false); | ||
130 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | 132 | m_messageWidget->setText(m_analysisTool->notInstalledMessage()); | ||
131 | static_cast<QVBoxLayout *>(layout())->insertWidget(0, m_messageWidget); | 133 | static_cast<QVBoxLayout *>(layout())->insertWidget(0, m_messageWidget); | ||
132 | m_messageWidget->animatedShow(); | 134 | m_messageWidget->animatedShow(); | ||
133 | return; | 135 | return; | ||
134 | } | 136 | } | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 187 | { | |||
205 | int line = m_model->item(index.row(), 1)->text().toInt(); | 207 | int line = m_model->item(index.row(), 1)->text().toInt(); | ||
206 | if (line >= 1) { | 208 | if (line >= 1) { | ||
207 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | 209 | view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); | ||
208 | } | 210 | } | ||
209 | } | 211 | } | ||
210 | 212 | | |||
211 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | 213 | void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) | ||
212 | { | 214 | { | ||
213 | m_messageWidget = new KMessageWidget(); | 215 | m_messageWidget = new KMessageWidget(this); | ||
214 | m_messageWidget->setCloseButtonVisible(true); | 216 | m_messageWidget->setCloseButtonVisible(true); | ||
215 | m_messageWidget->setWordWrap(false); | 217 | m_messageWidget->setWordWrap(false); | ||
216 | 218 | | |||
217 | if (exitCode == 0) { | 219 | if (exitCode == 0) { | ||
218 | m_messageWidget->setMessageType(KMessageWidget::Information); | 220 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||
219 | m_messageWidget->setText(i18n("Analysis finished.")); | 221 | m_messageWidget->setText(i18n("Analysis finished.")); | ||
220 | } else { | 222 | } else { | ||
221 | // unfortunately, output was eaten by slotReadyRead() | 223 | // unfortunately, output was eaten by slotReadyRead() | ||
222 | // TODO: get stderr output, show it here | 224 | // TODO: get stderr output, show it here | ||
223 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 225 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
224 | m_messageWidget->setText(i18n("Analysis failed!")); | 226 | m_messageWidget->setText(i18n("Analysis failed!")); | ||
225 | } | 227 | } | ||
226 | static_cast<QVBoxLayout*>(layout ())->insertWidget(0, m_messageWidget); | 228 | static_cast<QVBoxLayout*>(layout ())->insertWidget(0, m_messageWidget); | ||
227 | m_messageWidget->animatedShow (); | 229 | m_messageWidget->animatedShow (); | ||
228 | } | 230 | } |