1 /* This file is part of the KDE project
2    Copyright 2005,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, USA.
18 */
19 
20 // Local
21 #include "ValidityCommand.h"
22 
23 
24 #include <KLocalizedString>
25 
26 #include "CellStorage.h"
27 #include "Sheet.h"
28 #include "ValidityStorage.h"
29 
30 using namespace Calligra::Sheets;
31 
ValidityCommand()32 ValidityCommand::ValidityCommand()
33         : AbstractRegionCommand()
34 {
35 }
36 
process(Element * element)37 bool ValidityCommand::process(Element* element)
38 {
39     if (!m_reverse) {
40         // create undo
41         if (m_firstrun)
42             m_undoData += m_sheet->validityStorage()->undoData(Region(element->rect()));
43         m_sheet->cellStorage()->setValidity(Region(element->rect()), m_validity);
44     }
45     return true;
46 }
47 
mainProcessing()48 bool ValidityCommand::mainProcessing()
49 {
50     if (m_reverse) {
51         m_sheet->cellStorage()->setValidity(*this, Validity());
52         for (int i = 0; i < m_undoData.count(); ++i)
53             m_sheet->cellStorage()->setValidity(Region(m_undoData[i].first.toRect()), m_undoData[i].second);
54     }
55     return AbstractRegionCommand::mainProcessing();
56 }
57 
setValidity(Validity validity)58 void ValidityCommand::setValidity(Validity validity)
59 {
60     m_validity = validity;
61     if (m_validity.isEmpty())
62         setText(kundo2_i18n("Remove Validity Check"));
63     else
64         setText(kundo2_i18n("Add Validity Check"));
65 }
66