Changeset View
Changeset View
Standalone View
Standalone View
analyzers/cppcheck/problemmodel.cpp
Show All 15 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
16 | along with this program; see the file COPYING. If not, write to | 16 | along with this program; see the file COPYING. If not, write to | ||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "problemmodel.h" | 21 | #include "problemmodel.h" | ||
22 | 22 | | |||
23 | #include "plugin.h" | 23 | #include "plugin.h" | ||
24 | #include "problem.h" | ||||
24 | #include "utils.h" | 25 | #include "utils.h" | ||
25 | 26 | | |||
26 | #include <interfaces/icore.h> | 27 | #include <interfaces/icore.h> | ||
27 | #include <interfaces/ilanguagecontroller.h> | 28 | #include <interfaces/ilanguagecontroller.h> | ||
28 | #include <interfaces/iproject.h> | 29 | #include <interfaces/iproject.h> | ||
29 | #include <shell/problemmodelset.h> | 30 | #include <shell/problemmodelset.h> | ||
30 | 31 | | |||
31 | #include <klocalizedstring.h> | 32 | #include <klocalizedstring.h> | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
80 | } | 81 | } | ||
81 | 82 | | |||
82 | void ProblemModel::addProblems(const QVector<KDevelop::IProblem::Ptr>& problems) | 83 | void ProblemModel::addProblems(const QVector<KDevelop::IProblem::Ptr>& problems) | ||
83 | { | 84 | { | ||
84 | static int maxLength = 0; | 85 | static int maxLength = 0; | ||
85 | 86 | | |||
86 | if (m_problems.isEmpty()) { | 87 | if (m_problems.isEmpty()) { | ||
87 | maxLength = 0; | 88 | maxLength = 0; | ||
89 | clearProblems(); // Remove starting notification | ||||
88 | } | 90 | } | ||
89 | 91 | | |||
90 | for (auto problem : problems) { | 92 | for (auto problem : problems) { | ||
91 | fixProblemFinalLocation(problem); | 93 | fixProblemFinalLocation(problem); | ||
92 | 94 | | |||
93 | m_problems.append(problem); | 95 | m_problems.append(problem); | ||
94 | addProblem(problem); | 96 | addProblem(problem); | ||
95 | 97 | | |||
96 | // This performs adjusting of columns width in the ProblemsView | 98 | // This performs adjusting of columns width in the ProblemsView | ||
97 | if (maxLength < problem->description().length()) { | 99 | if (maxLength < problem->description().length()) { | ||
98 | maxLength = problem->description().length(); | 100 | maxLength = problem->description().length(); | ||
99 | setProblems(m_problems); | 101 | setProblems(m_problems); | ||
100 | } | 102 | } | ||
101 | } | 103 | } | ||
102 | } | 104 | } | ||
103 | 105 | | |||
106 | void ProblemModel::setNotification(const QString& message) | ||||
107 | { | ||||
108 | KDevelop::IProblem::Ptr notificationProblem(new CppcheckProblem); | ||||
kfunk: Pretty hacky IMO | |||||
109 | notificationProblem->setSeverity(KDevelop::IProblem::Hint); | ||||
110 | notificationProblem->setDescription(message); | ||||
111 | | ||||
112 | fixProblemFinalLocation(notificationProblem); | ||||
113 | setProblems({ notificationProblem }); | ||||
114 | } | ||||
115 | | ||||
104 | void ProblemModel::setProblems() | 116 | void ProblemModel::setProblems() | ||
105 | { | 117 | { | ||
118 | if (m_problems.isEmpty()) { | ||||
119 | setNotification(i18n("Analysis of (%1) completed, no problems detected.", prettyPathName(m_path))); | ||||
120 | } else { | ||||
106 | setProblems(m_problems); | 121 | setProblems(m_problems); | ||
107 | } | 122 | } | ||
123 | } | ||||
108 | 124 | | |||
109 | void ProblemModel::reset() | 125 | void ProblemModel::reset() | ||
110 | { | 126 | { | ||
111 | reset(nullptr, QString()); | 127 | reset(nullptr, QString()); | ||
112 | } | 128 | } | ||
113 | 129 | | |||
114 | void ProblemModel::reset(KDevelop::IProject* project, const QString& path) | 130 | void ProblemModel::reset(KDevelop::IProject* project, const QString& path) | ||
115 | { | 131 | { | ||
116 | m_project = project; | 132 | m_project = project; | ||
117 | m_path = path; | 133 | m_path = path; | ||
118 | 134 | | |||
119 | clearProblems(); | 135 | clearProblems(); | ||
120 | m_problems.clear(); | 136 | m_problems.clear(); | ||
121 | 137 | | |||
122 | QString tooltip = i18nc("@info:tooltip", "Re-run last Cppcheck analyze"); | 138 | QString tooltip = i18nc("@info:tooltip", "Re-Run Last Cppcheck Analysis"); | ||
123 | if (m_project) { | 139 | if (m_project) { | ||
124 | tooltip += QString(" (%1)").arg(prettyPathName(m_path)); | 140 | QString target = prettyPathName(m_path); | ||
141 | tooltip += QString(" (%1)").arg(target); | ||||
as said in the other review: the placeholder should be set once, and then get displayed whenever the model is empty. also reword the message to make it less funny, and remove the parens: Analysis of %1 started... mwolff: as said in the other review: the placeholder should be set once, and then get displayed… | |||||
142 | setNotification(i18n("Analysis of (%1) started, expect problems to come...", target)); | ||||
both times passing QString(), as I said in the other report - this argument should be removed mwolff: both times passing `QString()`, as I said in the other report - this argument should be removed | |||||
125 | } | 143 | } | ||
mwolff: I also don't get why we want to pass the location | |||||
126 | setFullUpdateTooltip(tooltip); | 144 | setFullUpdateTooltip(tooltip); | ||
127 | } | 145 | } | ||
128 | 146 | | |||
129 | void ProblemModel::show() | 147 | void ProblemModel::show() | ||
130 | { | 148 | { | ||
131 | problemModelSet()->showModel(problemModelId); | 149 | problemModelSet()->showModel(problemModelId); | ||
132 | } | 150 | } | ||
133 | 151 | | |||
134 | void ProblemModel::forceFullUpdate() | 152 | void ProblemModel::forceFullUpdate() | ||
135 | { | 153 | { | ||
136 | if (m_project && !m_plugin->isRunning()) { | 154 | if (m_project && !m_plugin->isRunning()) { | ||
137 | m_plugin->runCppcheck(m_project, m_path); | 155 | m_plugin->runCppcheck(m_project, m_path); | ||
138 | } | 156 | } | ||
139 | } | 157 | } | ||
140 | 158 | | |||
141 | } | 159 | } |
Pretty hacky IMO