1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "EntityLinkSourceIssueGenerator.h"
21 
22 #include "Model/Entity.h"
23 #include "Model/EntityAttributes.h"
24 #include "Model/Issue.h"
25 #include "Model/IssueQuickFix.h"
26 #include "Model/MapFacade.h"
27 
28 #include <cassert>
29 
30 namespace TrenchBroom {
31     namespace Model {
32         class EntityLinkSourceIssueGenerator::EntityLinkSourceIssue : public EntityIssue {
33         public:
34             static const IssueType Type;
35         public:
EntityLinkSourceIssue(Entity * entity)36             EntityLinkSourceIssue(Entity* entity) :
37             EntityIssue(entity) {}
38 
doGetType() const39             IssueType doGetType() const {
40                 return Type;
41             }
42 
doGetDescription() const43             const String doGetDescription() const {
44                 return entity()->classname() + " has unused targetname key";
45             }
46         };
47 
48         const IssueType EntityLinkSourceIssueGenerator::EntityLinkSourceIssue::Type = Issue::freeType();
49 
50         class EntityLinkSourceIssueGenerator::EntityLinkSourceIssueQuickFix : public IssueQuickFix {
51         public:
EntityLinkSourceIssueQuickFix()52             EntityLinkSourceIssueQuickFix() :
53             IssueQuickFix("Delete property") {}
54         private:
doApply(MapFacade * facade,const IssueList & issues) const55             void doApply(MapFacade* facade, const IssueList& issues) const {
56                 facade->removeAttribute(AttributeNames::Targetname);
57             }
58         };
59 
EntityLinkSourceIssueGenerator()60         EntityLinkSourceIssueGenerator::EntityLinkSourceIssueGenerator() :
61         IssueGenerator(EntityLinkSourceIssue::Type, "Missing entity link source") {
62             addQuickFix(new EntityLinkSourceIssueQuickFix());
63         }
64 
doGenerate(Entity * entity,IssueList & issues) const65         void EntityLinkSourceIssueGenerator::doGenerate(Entity* entity, IssueList& issues) const {
66             if (entity->hasMissingSources())
67                 issues.push_back(new EntityLinkSourceIssue(entity));
68         }
69     }
70 }
71