• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/VisualEditor

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • VisualEditor
  • Actions
AssignValueAction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright (C) 2011 Andreas Cord-Landwehr <phoenixx@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 
21 #include "AssignValueAction.h"
22 
23 #include "GraphVisualEditor.h"
24 #include "Scene/GraphScene.h"
25 #include "Scene/DataItem.h"
26 #include "DataStructure.h"
27 #include "Pointer.h"
28 #include "Modifiers/ValueModifier.h"
29 
30 #include <KIcon>
31 
32 AssignValueAction::AssignValueAction(const QString& name, GraphScene *scene, AssignMethod method, QWidget *parent)
33  : KAction(KIcon(), name, parent)
34 {
35  _graphScene = scene;
36  switch (method) {
37  case Enumerate:
38  connect(this, SIGNAL(triggered()), this, SLOT(enumerateSelected()));
39  break;
40  case RandomInteger:
41  connect(this, SIGNAL(triggered()), this, SLOT(assignRandomIntegersSelected()));
42  break;
43  case RandomReal:
44  connect(this, SIGNAL(triggered()), this, SLOT(assignRandomRealsSelected()));
45  break;
46  default:
47  break;
48  }
49 }
50 
51 
52 AssignValueAction::AssignValueAction(const QString& name, GraphScene *scene, AssignMethod method, DataStructurePtr ds, QWidget *parent)
53  : KAction(KIcon(), name, parent)
54 {
55  _graphScene = scene;
56  _dataStructure = ds;
57  switch (method) {
58  case Enumerate:
59  connect(this, SIGNAL(triggered()), this, SLOT(enumerateDataStructure()));
60  break;
61  case RandomInteger:
62  connect(this, SIGNAL(triggered()), this, SLOT(assignRandomIntegersDataStructure()));
63  break;
64  case RandomReal:
65  connect(this, SIGNAL(triggered()), this, SLOT(assignRandomRealsDataStructure()));
66  break;
67  default:
68  break;
69  }
70 }
71 
72 
73 void AssignValueAction::enumerateDataStructure()
74 {
75  if (_dataStructure) {
76  ValueModifier modifier;
77  //FIXME only default data type considered
78  modifier.enumerate<DataPtr>(_dataStructure->dataList(0), QString("value"), 1, "", true);
79  }
80 }
81 
82 
83 void AssignValueAction::enumerateSelected()
84 {
85  DataList dataList;
86  QList<QGraphicsItem*> itemList = _graphScene->selectedItems();
87  foreach(QGraphicsItem * i, itemList) {
88  if (DataItem *dataItem = qgraphicsitem_cast<DataItem*>(i)) {
89  dataList.append(dataItem->data());
90  }
91  }
92  ValueModifier modifier;
93  modifier.enumerate<DataPtr>(dataList, QString("value"), 1, "", true);
94 }
95 
96 void AssignValueAction::assignRandomIntegersDataStructure()
97 {
98  if (_dataStructure) {
99  ValueModifier modifier;
100  //FIXME use really random seed
101  //FIXME only default data type considered
102  modifier.assignRandomIntegers(_dataStructure->dataList(0), QString("value"), 1, 100, 1, true);
103  }
104 }
105 
106 
107 void AssignValueAction::assignRandomIntegersSelected()
108 {
109  DataList dataList;
110  QList<QGraphicsItem*> itemList = _graphScene->selectedItems();
111  foreach(QGraphicsItem * i, itemList) {
112  if (DataItem *dataItem = qgraphicsitem_cast<DataItem*>(i)) {
113  dataList.append(dataItem->data());
114  }
115  }
116  ValueModifier modifier;
117  modifier.assignRandomIntegers(dataList, QString("value"), 1, 100, 1, true);
118 }
119 
120 
121 void AssignValueAction::assignRandomRealsDataStructure()
122 {
123  if (_dataStructure) {
124  ValueModifier modifier;
125  //FIXME use really random seed
126  //FIXME only default data type considered
127  modifier.assignRandomReals(_dataStructure->dataList(0), QString("value"), 1, 10, 1, true);
128  }
129 }
130 
131 
132 void AssignValueAction::assignRandomRealsSelected()
133 {
134  DataList dataList;
135  QList<QGraphicsItem*> itemList = _graphScene->selectedItems();
136  foreach(QGraphicsItem * i, itemList) {
137  if (DataItem *dataItem = qgraphicsitem_cast<DataItem*>(i)) {
138  dataList.append(dataItem->data());
139  }
140  }
141  ValueModifier modifier;
142  modifier.assignRandomReals(dataList, QString("value"), 1, 10, 1, true);
143 }
QWidget
AssignValueAction::RandomReal
Definition: AssignValueAction.h:34
QGraphicsScene::selectedItems
QList< QGraphicsItem * > selectedItems() const
AssignValueAction.h
QGraphicsItem
GraphScene.h
AssignValueAction::enumerateDataStructure
void enumerateDataStructure()
Definition: AssignValueAction.cpp:73
AssignValueAction::assignRandomRealsSelected
void assignRandomRealsSelected()
Definition: AssignValueAction.cpp:132
AssignValueAction::Enumerate
Definition: AssignValueAction.h:34
GraphVisualEditor.h
GraphScene
Definition: GraphScene.h:38
AssignValueAction::enumerateSelected
void enumerateSelected()
Definition: AssignValueAction.cpp:83
QString
QList
AssignValueAction::assignRandomRealsDataStructure
void assignRandomRealsDataStructure()
Definition: AssignValueAction.cpp:121
AssignValueAction::assignRandomIntegersDataStructure
void assignRandomIntegersDataStructure()
Definition: AssignValueAction.cpp:96
AssignValueAction::AssignMethod
AssignMethod
Definition: AssignValueAction.h:34
DataItem
Definition: DataItem.h:38
KAction
DataItem.h
AssignValueAction::RandomInteger
Definition: AssignValueAction.h:34
AssignValueAction::AssignValueAction
AssignValueAction(const QString &name, GraphScene *scene, AssignMethod method, QWidget *parent)
Creates a new assign value action that assigns values to selected data items.
Definition: AssignValueAction.cpp:32
AssignValueAction::assignRandomIntegersSelected
void assignRandomIntegersSelected()
Definition: AssignValueAction.cpp:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/VisualEditor

Skip menu "rocs/VisualEditor"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal