43 #include "SingleObjectPropertyModel.hh" 44 #include "ScriptObjects/ScriptSettings.hh" 46 #include <QTextStream> 48 SingleObjectPropertyModel::SingleObjectPropertyModel(QObject *parent)
51 currentlySelectedIndices(),
52 currentlyVisualizedIndices()
55 QVBoxLayout* layout =
new QVBoxLayout();
56 widgets =
new QWidget();
57 widgets->setLayout(layout);
60 SingleObjectPropertyModel::~SingleObjectPropertyModel()
62 for (
unsigned int i = 0; i < propertyVisualizers.size(); i++)
63 delete propertyVisualizers[i];
72 for (
int i = 0; i < selectedIndices.size(); ++i)
74 const int row = selectedIndices[i].row();
78 propertyVisualizers[row]->visualize(
true, 0);
82 propertyVisualizers[row]->visualize(
true, widgets[i]);
86 std::vector<unsigned int>& vec = currentlyVisualizedIndices;
87 vec.erase(std::remove(vec.begin(), vec.end(), row), vec.end());
94 std::vector<unsigned int> deleteIndices;
96 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
98 propertyVisualizers[it->row()]->removeProperty();
99 QWidget* w = propertyVisualizers[it->row()]->getWidget();
100 widgets->layout()->removeWidget(w);
101 delete propertyVisualizers[it->row()];
102 propertyVisualizers[it->row()] = 0;
103 deleteIndices.push_back(it->row());
106 std::sort(deleteIndices.begin(), deleteIndices.end());
108 for (
int i = deleteIndices.size()-1; i >= 0; i--)
110 for (
int j = currentlyVisualizedIndices.size()-1; j >= 0; j--)
112 if (currentlyVisualizedIndices[j] == deleteIndices[i])
114 currentlyVisualizedIndices.erase(currentlyVisualizedIndices.begin() + j);
115 else if (currentlyVisualizedIndices[j] > deleteIndices[i])
118 currentlyVisualizedIndices[j]--;
122 for (
int i = deleteIndices.size()-1; i >= 0; i--){
123 propertyVisualizers.erase(propertyVisualizers.begin() + deleteIndices[i]);
129 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
130 propertyVisualizers[it->row()]->duplicateProperty();
134 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
136 propertyVisualizers[it->row()]->clear();
137 std::vector<unsigned int>& vec = currentlyVisualizedIndices;
138 vec.erase(std::remove(vec.begin(), vec.end(), it->row()), vec.end());
144 QLayout* layout = widgets->layout();
146 currentlySelectedIndices = selectedIndices;
148 for (
unsigned int i = 0; i < propertyVisualizers.size(); i++)
150 propertyVisualizers[i]->getWidget()->hide();
153 for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = selectedIndices.end();
154 it != it_end; ++it) {
155 QWidget* widget = propertyVisualizers[it->row()]->getWidget();
156 layout->addWidget(widget);
159 widgets->setLayout(layout);
164 connect(propViz, SIGNAL(log(QString)),
this, SLOT(slotLog(QString)));
165 connect(propViz, SIGNAL(log(
Logtype, QString)),
this, SLOT(slotLog(
Logtype, QString)));
168 int SingleObjectPropertyModel::rowCount(
const QModelIndex & parent)
const {
169 return propertyVisualizers.size();
172 QVariant SingleObjectPropertyModel::data(
const QModelIndex & index,
int role)
const {
174 case Qt::DisplayRole:
175 return propertyVisualizers[index.row()]->getName();
177 return QVariant::Invalid;
181 QVariant SingleObjectPropertyModel::headerData(
int section, Qt::Orientation orientation,
int role)
const {
183 case Qt::DisplayRole:
184 return tr(
"Some header. %1 %2").arg(section).arg(orientation);
187 return QAbstractListModel::headerData(section, orientation, role);
193 for (
unsigned int i = 0; i < currentlyVisualizedIndices.size(); i++)
195 propertyVisualizers[currentlyVisualizedIndices[i]]->visualize(
false, 0);
201 QString filter = getLoadFilenameFilter();
202 QString selected_filter = tr(
"All Files (*)");
204 QString fileName = QFileDialog::getOpenFileName(0, tr(
"Load Property"), QString(), filter, &selected_filter);
216 QString filter(getSaveFilenameFilter(propId));
217 QString defaultName = getDefaultSaveFilename(propId);
219 QString fileName = QFileDialog::getSaveFileName(0, tr(
"Save Property"), defaultName, filter);
226 QString filter= tr(
"All Files (*)");
238 name += tr(
".vprop");
240 name += tr(
".hprop");
242 name += tr(
".eprop");
244 name += tr(
".fprop");
246 name += tr(
".hfprop");
248 name += tr(
".cprop");
257 QString filename = getSaveFilename(propId);
258 if (filename ==
"")
return;
260 QFile file(filename);
261 if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
262 std::cerr <<
"PropertyVis saveProperty(): cannot open file for writing" << std::endl;
265 QTextStream file_stream(&file);
267 file_stream << propVis->
getHeader() <<
'\n';
270 for (
int i = 0; i < n; ++i)
273 file_stream << propertyText <<
'\n';
280 QString filename = getLoadFilename();
281 if (filename ==
"")
return;
283 QFile file(filename);
284 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
285 std::cerr <<
"PropertyVis loadProperty(): cannot open file for reading" << std::endl;
289 QTextStream file_stream(&file);
291 QString header = file_stream.readLine();
295 if (parseHeader(header, propVis, n))
297 setPropertyFromFile(file_stream, n, propVis);
301 emit log(
"Property could not be loaded.");
308 for (
unsigned int i = 0; i < n; ++i)
310 QString propertyText = file_stream.readLine();
317 for (
unsigned int i = 0; i < propertyVisualizers.size(); ++i)
319 const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
320 if ((propInfo.entityType() == filter) && (QString::compare(tr(propInfo.propName().c_str()), propName)==0) && (propInfo.typeinfo() == typeInfo))
321 return propertyVisualizers[i];
328 return getPropertyVisualizer(propName, filter, typeInfo) == 0;
333 return propertyVisualizers[index.row()]->getPropertyInfo();
339 return createSettingsScriptObject(ctx, vis->
getWidget());
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.
virtual void duplicateProperty(QModelIndexList selectedIndices)
Duplicates the selected properties.
virtual QString getHeader()=0
Returns the header for saving.
QString getLoadFilename()
Asks the user for a file to load.
Logtype
Log types for Message Window.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
virtual void objectUpdated()
Revisualizes visualized properties.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
void loadProperty()
Loads property.
Wraps the information of a type.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())
Visualizes the selected properties.
virtual int getEntityCount()=0
Returns the number of entities.
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
This class vizualizes a property.
virtual void removeProperty(QModelIndexList selectedIndices)
Removes the selected properties.
virtual QWidget * getWidget()
Returns the visualizer's widget.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
void saveProperty(unsigned int propId)
Saves property.
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx)
Returns a qscript object that can be used to access visualisation parameters.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const
Returns the property info for the property with the given index.
virtual QString getPropertyText(unsigned int i)=0
Returns the value of a property in text form.
Cellection of information about a property.
virtual void clear(QModelIndexList selectedIndices)
Clears the selected property visualization.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.