File indexing completed on 2024-04-14 04:31:23

0001 /* This file is part of KDevelop
0002 
0003    Copyright 2017 Anton Anikin <anton.anikin@htower.ru>
0004 
0005    This program is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This program is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013    General Public License for more details.
0014 
0015    You should have received a copy of the GNU General Public License
0016    along with this program; see the file COPYING.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "problemmodel.h"
0022 
0023 #include "plugin.h"
0024 #include "utils.h"
0025 
0026 #include <interfaces/icore.h>
0027 #include <interfaces/ilanguagecontroller.h>
0028 #include <shell/problemmodelset.h>
0029 
0030 #include <klocalizedstring.h>
0031 
0032 namespace verapp
0033 {
0034 
0035 inline KDevelop::ProblemModelSet* problemModelSet()
0036 {
0037     return KDevelop::ICore::self()->languageController()->problemModelSet();
0038 }
0039 
0040 static const QString problemModelId = QStringLiteral("Vera++");
0041 
0042 ProblemModel::ProblemModel(Plugin* plugin)
0043     : KDevelop::ProblemModel(plugin)
0044     , m_plugin(plugin)
0045     , m_project(nullptr)
0046 {
0047     setFeatures(CanDoFullUpdate |
0048                 ScopeFilter |
0049                 SeverityFilter |
0050                 Grouping |
0051                 CanByPassScopeFilter);
0052 
0053     reset();
0054 
0055     problemModelSet()->addModel(problemModelId, i18n("Vera++"), this);
0056 }
0057 
0058 ProblemModel::~ProblemModel()
0059 {
0060     problemModelSet()->removeModel(problemModelId);
0061 }
0062 
0063 KDevelop::IProject* ProblemModel::project() const
0064 {
0065     return m_project;
0066 }
0067 
0068 void ProblemModel::addProblems(const QVector<KDevelop::IProblem::Ptr>& problems)
0069 {
0070     static int maxLength = 0;
0071 
0072     if (m_problems.isEmpty()) {
0073         maxLength = 0;
0074     }
0075 
0076     m_problems.append(problems);
0077     for (auto p : problems) {
0078         addProblem(p);
0079 
0080         // This performs adjusting of columns width in the ProblemsView
0081         if (maxLength < p->description().length()) {
0082             maxLength = p->description().length();
0083             setProblems(m_problems);
0084             break;
0085         }
0086     }
0087 }
0088 
0089 void ProblemModel::setProblems()
0090 {
0091     setProblems(m_problems);
0092 }
0093 
0094 void ProblemModel::reset()
0095 {
0096     reset(nullptr, QString());
0097 }
0098 
0099 void ProblemModel::reset(KDevelop::IProject* project, const QString& path)
0100 {
0101     m_project = project;
0102     m_path = path;
0103 
0104     clearProblems();
0105     m_problems.clear();
0106 
0107     QString tooltip = i18nc("@info:tooltip", "Re-Run Last Vera++ Analysis");
0108     if (m_project) {
0109         tooltip += QString(" (%1)").arg(prettyPathName(m_path));
0110     }
0111     setFullUpdateTooltip(tooltip);
0112 }
0113 
0114 void ProblemModel::show()
0115 {
0116     problemModelSet()->showModel(problemModelId);
0117 }
0118 
0119 void ProblemModel::forceFullUpdate()
0120 {
0121     if (m_project && !m_plugin->isRunning()) {
0122         m_plugin->runVerapp(m_project, m_path);
0123     }
0124 }
0125 
0126 }