FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
FdCommandsResults.cpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------
2 // Copyright © 2011-2013 Mathieu Schopfer
3 //
4 // This file is part of FreeDebks.
5 //
6 // FreeDebks 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 // FreeDebks 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 FreeDebks. If not, see <http://www.gnu.org/licenses/>.
18 // --------------------------------------------------------------------
19 
20 #include "FdCommandsResults.hpp"
21 #include "FdModelResults.hpp"
22 
24 {
25  setText(QObject::tr("add a new row", "Undo/Redo add a new row to the results page."));
26  mAction = new FdResultsRemove(results, QList<locationResults>() << location);
27 }
28 
29 void FdResultsAdd::redo()
30 {
31  mAction->undo();
32 }
33 
34 void FdResultsAdd::undo()
35 {
36  mAction->redo();
37 }
38 
39 FdResultsDragDrop::FdResultsDragDrop(FdModelResults *model, QList<int> rows, int row) : QUndoCommand()
40 {
41  setText(QObject::tr("move %n row(s)", "Move row(s) in a drag and drop action.", rows.size()));
42  mRemove = new FdResultsRemove(model, rows);
43 
44  // Calculate the drop row, in function of dragged rows
45  for(int i = 0; i < rows.size(); ++i)
46  {
47  if(row > rows[i])
48  --row;
49  }
50  row = row+1;
51 
52  for(int i = 0; i < rows.size(); ++i)
53  {
54  locationResults result;
55  result.item = model->item(rows[i]);
56  result.row = row+i;
57  mAddActions << new FdResultsAdd(model, result);
58  }
59 }
60 
62 {
63  mRemove->redo();
64 
65  for(int i = 0; i < mAddActions.size(); ++i)
66  mAddActions[i]->redo();
67 }
68 
70 {
71  for(int i = 0; i < mAddActions.size(); ++i)
72  mAddActions[i]->undo();
73 
74  mRemove->undo();
75 }
76 
77 FdResultsSetData::FdResultsSetData(FdModelResults *results, FdItemResults_p calculation, ResultsColumn column, QVariant newValue) : QUndoCommand(), mResults(results), mCalculation(calculation), mColumn(column), mNewValue(newValue)
78 {
79  mOldValue = mResults->data(mCalculation, mColumn);
80  switch(mColumn)
81  {
82  case ResultsId:
83  setText(QObject::tr("change id", "Will appear like this : Undo/Redo change id."));
84  break;
85  case ResultsLabel:
86  setText(QObject::tr("change label", "Will appear like this : Undo/Redo change label."));
87  break;
88  case ResultsCalculation:
89  setText(QObject::tr("change calculation", "Will appear like this : Undo/Redo change calculation."));
90  break;
91  }
92 }
93 
95 {
97 }
98 
100 {
102 }
103 
104 FdResultsRemove::FdResultsRemove(FdModelResults *model, QList<int> rows) : mModel(model)
105 {
106  for(int i = 0; i < rows.size(); ++i)
107  {
108  struct locationResults location;
109  location.item = model->item(rows[i]);
110  location.row = rows[i];
111  mMap << location;
112  }
113 
114  init();
115 }
116 
117 FdResultsRemove::FdResultsRemove(FdModelResults *model, QList<locationResults> location) :
118  mModel(model), mMap(location)
119 {
120  init();
121 }
122 
124 {
125  setText(QObject::tr("remove %n row(s)", "Undo/redo remove rows from the results page.", mMap.size()));
126 }
127 
129 {
130  for(int i = 0; i < mMap.size(); ++i)
131  mModel->removeCalculation(mMap[i].item);
132 }
133 
135 {
136  for(int i = 0; i < mMap.size(); i++)
137  mModel->insertCalculation(mMap[i].item, mMap[i].row);
138 }