GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/listeners/renamelistener.cpp Lines: 9 27 33.3 %
Date: 2017-11-29 Branches: 1 18 5.6 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "listeners/renamelistener.h"
22
23
#include "gui/viewport.h"
24
25
#include "gui/windows/socialwindow.h"
26
#include "gui/windows/textdialog.h"
27
28
#include "resources/map/map.h"
29
#include "resources/map/mapitem.h"
30
#include "resources/map/speciallayer.h"
31
32
#include "debug.h"
33
34
4
RenameListener::RenameListener() :
35
    ActionListener(),
36
    mMapItemX(0),
37
    mMapItemY(0),
38
8
    mDialog(nullptr)
39
{
40
4
}
41
42
4
void RenameListener::setMapItem(const MapItem *const mapItem)
43
{
44
4
    if (mapItem != nullptr)
45
    {
46
        mMapItemX = mapItem->getX();
47
        mMapItemY = mapItem->getY();
48
    }
49
    else
50
    {
51
4
        mMapItemX = 0;
52
4
        mMapItemY = 0;
53
    }
54
4
}
55
56
void RenameListener::action(const ActionEvent &event)
57
{
58
    if (event.getId() == "ok" && (viewport != nullptr) && (mDialog != nullptr))
59
    {
60
        const Map *const map = viewport->getMap();
61
        if (map == nullptr)
62
            return;
63
64
        const SpecialLayer *const sl = map->getSpecialLayer();
65
        MapItem *item = nullptr;
66
        if (sl != nullptr)
67
        {
68
            item = sl->getTile(mMapItemX, mMapItemY);
69
            if (item != nullptr)
70
                item->setComment(mDialog->getText());
71
        }
72
        item = map->findPortalXY(mMapItemX, mMapItemY);
73
        if (item != nullptr)
74
            item->setComment(mDialog->getText());
75
76
        if (socialWindow != nullptr)
77
            socialWindow->updatePortalNames();
78
    }
79
    mDialog = nullptr;
80
4
}