20 #include "ui_AssignValuesWidget.h"
24 #include "DataStructure.h"
25 #include "DocumentManager.h"
28 #include "Modifiers/ValueModifier.h"
34 #include <KPushButton>
36 #include <QtGui/QDesktopWidget>
37 #include <QtGui/QGridLayout>
38 #include <QtGui/QLabel>
39 #include <QtGui/QLineEdit>
40 #include <QtGui/QPushButton>
41 #include <QtGui/QSpinBox>
42 #include <QtCore/QMap>
43 #include <QtCore/QPair>
45 #include <boost/random/mersenne_twister.hpp>
46 #include <boost/random/uniform_int.hpp>
47 #include <boost/random/uniform_real.hpp>
48 #include <boost/random/variate_generator.hpp>
57 ui =
new Ui::AssignValuesWidget;
59 setMainWidget(widget);
62 setButtons(KDialog::Apply | KDialog::Cancel | KDialog::Ok);
63 ui->buttonShowAdvanced->setIcon(KIcon(
"rocsadvancedsetup"));
64 KDialog::centerOnScreen(widget, -3);
67 Document* document = DocumentManager::self().activeDocument();
68 ui->dataType->addItem(i18n(
"All Data Types"), -1);
69 foreach (
int typeId, document->dataTypeList()) {
70 ui->dataType->addItem(document->dataType(typeId)->name(), typeId);
72 ui->connectionType->addItem(i18n(
"All Connection Types"), -1);
73 foreach (
int typeId, document->pointerTypeList()) {
74 ui->connectionType->addItem(document->pointerType(typeId)->name(), typeId);
78 ui->dataType->setEnabled(ui->applyToDataElements->isChecked());
79 ui->connectionType->setEnabled(ui->applyToConnections->isChecked());
84 KCompletion *complete = ui->propertyName->completionObject();
85 foreach (
int typeId, document->dataTypeList()) {
86 complete->insertItems(document->dataType(typeId)->properties());
88 foreach (
int typeId, document->pointerTypeList()) {
89 complete->insertItems(document->pointerType(typeId)->properties());
91 ui->propertyName->setContextMenuPolicy(Qt::DefaultContextMenu);
92 ui->propertyName->setPlaceholderText(i18n(
"Enter Property Name"));
103 uint badRandomSeed = qHash(currentTime) % 99999;
104 badRandomSeed = (badRandomSeed == 0) ? 1 : badRandomSeed;
105 ui->spinBoxIntegerGeneratorSeed->setValue(badRandomSeed);
106 ui->spinBoxFloatGeneratorSeed->setValue(badRandomSeed);
110 ui->checkBoxOverwriteValues->setVisible(
false);
111 ui->label->setVisible(
false);
112 ui->spinBoxIntegerGeneratorSeed->setVisible(
false);
113 ui->label_7->setVisible(
false);
114 ui->spinBoxFloatGeneratorSeed->setVisible(
false);
115 ui->label_9->setVisible(
false);
116 ui->LabelInitialString->setVisible(
false);
117 ui->LineEditInitialString->setVisible(
false);
129 ui->dataStructuresCombo->insertItems(0, dsNames);
135 if (Document::isValidIdentifier(ui->propertyName->text())) {
136 button(KDialog::Apply)->setEnabled(
true);
137 button(KDialog::Ok)->setEnabled(
true);
140 button(KDialog::Apply)->setEnabled(
false);
141 button(KDialog::Ok)->setEnabled(
false);
152 if (ui->dataStructuresCombo->count() == 0) {
156 ds = dsList[ui->dataStructuresCombo->currentIndex()];
157 QString property = ui->propertyName->text();
162 bool overrideValues = ui->checkBoxOverwriteValues->isChecked();
166 PointerList pointerList;
167 if (ui->applyToDataElements) {
168 int typeSelection = ui->dataType->itemData(ui->dataType->currentIndex()).toInt();
170 if (typeSelection == -1) {
171 foreach (
int typeId, ds->document()->dataTypeList()) {
172 if (!ds->document()->dataType(typeId)->properties().contains(
property)) {
173 ds->document()->dataType(typeId)->addProperty(
property);
175 dataList << ds->dataList(typeId);
178 if (typeSelection >= 0) {
179 if (!ds->document()->dataType(typeSelection)->properties().contains(
property)) {
180 ds->document()->dataType(typeSelection)->addProperty(
property);
182 dataList = ds->dataList(typeSelection);
185 if (ui->applyToConnections) {
186 int typeSelection = ui->connectionType->itemData(ui->connectionType->currentIndex()).toInt();
188 if (typeSelection == -1) {
189 foreach (
int typeId, ds->document()->pointerTypeList()) {
190 if (!ds->document()->pointerType(typeId)->properties().contains(
property)) {
191 ds->document()->pointerType(typeId)->addProperty(
property);
193 pointerList << ds->pointers(typeId);
196 if (typeSelection >= 0) {
197 if (!ds->document()->pointerType(typeSelection)->properties().contains(
property)) {
198 ds->document()->pointerType(typeSelection)->addProperty(
property);
200 pointerList = ds->pointers(typeSelection);
205 ValueModifier modifier;
206 switch ((AssignMethod) ui->comboBoxMethod->currentIndex()) {
208 int start = ui->spinBoxIDStartValue->value();
210 if (ui->applyToDataElements->isChecked()) {
211 modifier.enumerate(dataList,
property, start,
"", overrideValues);
213 if (ui->applyToConnections->isChecked()) {
214 modifier.enumerate(pointerList,
property, start,
"", overrideValues);
219 QString start = ui->LineEditInitialString->text();
221 if (ui->applyToDataElements->isChecked()) {
222 modifier.enumerateAlpha(dataList,
property, start, overrideValues);
224 if (ui->applyToConnections->isChecked()) {
225 modifier.enumerateAlpha(pointerList,
property, start, overrideValues);
230 int start = ui->SpinBoxAlphaNumericIDStart->value();
231 QString prefix = ui->LineEditAlphaNumericPrefix->text();
233 if (ui->applyToDataElements->isChecked()) {
234 modifier.enumerate(dataList,
property, start, prefix, overrideValues);
236 if (ui->applyToConnections->isChecked()) {
237 modifier.enumerate(pointerList,
property, start, prefix, overrideValues);
241 case UNIFORM_INTEGER: {
242 int seed = ui->spinBoxIntegerGeneratorSeed->value();
243 int lowerLimit = ui->spinBoxIntegerLowerLimit->value();
244 int upperLimit = ui->spinBoxIntegerUpperLimit->value();
246 if (ui->applyToDataElements->isChecked()) {
247 modifier.assignRandomIntegers(dataList,
property, lowerLimit, upperLimit, seed, overrideValues);
249 if (ui->applyToConnections->isChecked()) {
250 modifier.assignRandomIntegers(pointerList,
property, lowerLimit, upperLimit, seed, overrideValues);
254 case UNIFORM_FLOAT: {
255 int seed = ui->spinBoxFloatGeneratorSeed->value();
256 qreal lowerLimit = ui->spinBoxFloatLowerLimit->value();
257 qreal upperLimit = ui->spinBoxFloatUpperLimit->value();
259 if (ui->applyToDataElements->isChecked()) {
260 modifier.assignRandomReals(dataList,
property, lowerLimit, upperLimit, seed, overrideValues);
262 if (ui->applyToConnections->isChecked()) {
263 modifier.assignRandomReals(pointerList,
property, lowerLimit, upperLimit, seed, overrideValues);
268 QString constant = ui->lineEditConstantValue->text();
270 if (ui->applyToDataElements->isChecked()) {
271 modifier.assignConstantValue(dataList,
property, constant, overrideValues);
273 if (ui->applyToConnections->isChecked()) {
274 modifier.assignConstantValue(pointerList,
property, constant, overrideValues);
qint64 currentMSecsSinceEpoch()
QVariant property(const char *name) const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)