• 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
  • Interface
DataPropertiesWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2009-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "DataPropertiesWidget.h"
21 #include "Data.h"
22 #include <KDebug>
23 #include "Scene/DataItem.h"
24 #include "DataStructure.h"
25 #include "Actions/PropertiesDialogAction.h"
26 #include "model_GraphProperties.h"
27 #include <QPainter>
28 #include <DataStructureBackendManager.h>
29 #include <DataStructureBackendInterface.h>
30 
31 DataPropertiesWidget::DataPropertiesWidget(DataPtr data, QWidget* parent)
32  : KDialog(parent)
33 {
34  ui = new Ui::DataPropertiesWidget;
35  ui->setupUi(mainWidget());
36 
37  // edit data types by separate dialog
38  QPointer<PropertiesDialogAction> dataTypePropertiesAction = new PropertiesDialogAction(
39  i18n("Edit Data Types"), data->dataStructure()->document()->dataType(data->dataType()), this);
40  ui->_editType->setDefaultAction(dataTypePropertiesAction);
41  ui->_editType->setIcon(KIcon("document-properties"));
42  connect(data->dataStructure()->document(), SIGNAL(dataTypeCreated(int)), this, SLOT(updateDataTypes()));
43  connect(data->dataStructure()->document(), SIGNAL(dataTypeRemoved(int)), this, SLOT(updateDataTypes()));
44 
45  setCaption(i18nc("@title:window", "Data Element Properties"));
46  setButtons(Close);
47  setAttribute(Qt::WA_DeleteOnClose);
48  setData(data);
49 }
50 
51 void DataPropertiesWidget::setData(DataPtr data)
52 {
53  DataTypePtr dataType;
54  if (_data == data) {
55  return;
56  }
57  if (_data) {
58  dataType = _data->dataStructure()->document()->dataType(_data->dataType());
59  dataType->disconnect(this);
60  _data->disconnect(this);
61  ui->_dataType->clear();
62  }
63  _data = data;
64 
65  updateDataTypes();
66 
67  delete ui->extraItems->layout();
68  ui->extraItems->setLayout(DataStructureBackendManager::self().dataExtraProperties(_data, this));
69  reflectAttributes();
70 
71  // listen to ui
72  connect(ui->_dataType, SIGNAL(currentIndexChanged(int)),
73  this, SLOT(setDataType(int)));
74  connect(ui->_color, SIGNAL(activated(QColor)),
75  this, SLOT(colorChanged(QColor)));
76 
77  dataType = _data->dataStructure()->document()->dataType(_data->dataType());
78  connect(dataType.get(), SIGNAL(propertyAdded(QString,QVariant)), this, SLOT(updateProperties()));
79  connect(dataType.get(), SIGNAL(propertyRemoved(QString)), this, SLOT(updateProperties()));
80  connect(dataType.get(), SIGNAL(propertyRenamed(QString,QString)), this, SLOT(updateProperties()));
81 
82  GraphPropertiesModel *model = new GraphPropertiesModel();
83  model->setDataSource(_data.get());
84 
85  ui->_propertiesTable->setModel(model);
86  ui->_propertiesTable->horizontalHeader()->setProperty("stretchLastSection", true);
87 }
88 
89 void DataPropertiesWidget::setPosition(QPointF screenPosition)
90 {
91  move(screenPosition.x() + 10, screenPosition.y() + 10);
92 }
93 
94 void DataPropertiesWidget::reflectAttributes()
95 {
96  if (!ui->extraItems->layout()) {
97  _oldDataStructurePlugin = DataStructureBackendManager::self().activeBackend()->internalName();
98  }
99 
100  if (_oldDataStructurePlugin != DataStructureBackendManager::self().activeBackend()->internalName()) {
101  ui->extraItems->layout()->deleteLater();
102  }
103 
104  if (!ui->extraItems->layout()) {
105  ui->extraItems->setLayout(DataStructureBackendManager::self().dataExtraProperties(_data, this));
106  }
107 
108  ui->_color->setColor(_data->color().value<QColor>());
109 
110  DataTypePtr dataType = _data->dataStructure()->document()->dataType(_data->dataType());
111  ui->_dataType->setCurrentIndex(ui->_dataType->findData(QVariant(_data->dataType())));
112 }
113 
114 void DataPropertiesWidget::colorChanged(const QColor& c)
115 {
116  _data->setColor(QColor(c));
117 }
118 
119 void DataPropertiesWidget::setDataType(int dataTypeIndex)
120 {
121  _data->setDataType(ui->_dataType->itemData(dataTypeIndex).toInt());
122 }
123 
124 void DataPropertiesWidget::updateDataTypes()
125 {
126  ui->_dataType->clear();
127  // setup data types combobox
128  foreach (int dataType, _data->dataStructure()->document()->dataTypeList()) {
129  QString dataTypeString = _data->dataStructure()->document()->dataType(dataType)->name();
130  ui->_dataType->addItem(dataTypeString, QVariant(dataType));
131  }
132  if (_data) {
133  ui->_dataType->setCurrentIndex(ui->_dataType->findData(QVariant(_data->dataType())));
134  }
135 }
136 
137 void DataPropertiesWidget::updateProperties()
138 {
139  // TODO the following can be solved much nicer by updating the model
140  GraphPropertiesModel *model = new GraphPropertiesModel();
141  model->setDataSource(_data.get());
142  ui->_propertiesTable->model()->deleteLater();
143  ui->_propertiesTable->setModel(model);
144 }
QWidget
PropertiesDialogAction
Definition: PropertiesDialogAction.h:31
QPointer
KDialog
QPointF
PropertiesDialogAction.h
QPointF::x
qreal x() const
QPointF::y
qreal y() const
GraphPropertiesModel
Definition: model_GraphProperties.h:29
DataPropertiesWidget::setPosition
void setPosition(QPointF screenPosition)
Definition: DataPropertiesWidget.cpp:89
DataPropertiesWidget::setData
void setData(DataPtr data)
Definition: DataPropertiesWidget.cpp:51
QString
QColor
model_GraphProperties.h
DataPropertiesWidget::DataPropertiesWidget
DataPropertiesWidget(DataPtr data, QWidget *parent=0)
Definition: DataPropertiesWidget.cpp:31
GraphPropertiesModel::setDataSource
void setDataSource(QObject *dataSource)
Definition: model_GraphProperties.cpp:95
DataItem.h
DataPropertiesWidget.h
QVariant
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