43#include "SingleObjectPropertyModel.hh"
44#include "ScriptObjects/ScriptSettings.hh"
48SingleObjectPropertyModel::SingleObjectPropertyModel(QObject *parent)
51 currentlySelectedIndices(),
52 currentlyVisualizedIndices()
55 QVBoxLayout* layout =
new QVBoxLayout();
56 widgets =
new QWidget();
57 widgets->setLayout(layout);
60SingleObjectPropertyModel::~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)));
168int SingleObjectPropertyModel::rowCount(
const QModelIndex & parent)
const {
169 return propertyVisualizers.size();
172QVariant SingleObjectPropertyModel::data(
const QModelIndex & index,
int role)
const {
174 case Qt::DisplayRole:
175 return propertyVisualizers[index.row()]->getName();
182QVariant SingleObjectPropertyModel::headerData(
int section, Qt::Orientation orientation,
int role)
const {
184 case Qt::DisplayRole:
185 return tr(
"Some header. %1 %2").arg(section).arg(orientation);
188 return QAbstractListModel::headerData(section, orientation, role);
192QModelIndex SingleObjectPropertyModel::index(
int row,
int column,
const QModelIndex &parent)
const
195 return createIndex(row, column, propertyVisualizers[row]);
200 for (
unsigned int i = 0; i < currentlyVisualizedIndices.size(); i++)
202 propertyVisualizers[currentlyVisualizedIndices[i]]->visualize(
false, 0);
209 QString selected_filter = tr(
"All Files (*)");
211 QString fileName = QFileDialog::getOpenFileName(0, tr(
"Load Property"), QString(), filter, &selected_filter);
226 QString fileName = QFileDialog::getSaveFileName(0, tr(
"Save Property"), defaultName, filter);
233 QString filter= tr(
"All Files (*)");
245 name += tr(
".vprop");
247 name += tr(
".hprop");
249 name += tr(
".eprop");
251 name += tr(
".fprop");
253 name += tr(
".hfprop");
255 name += tr(
".cprop");
265 if (filename ==
"")
return;
267 QFile file(filename);
268 if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
269 std::cerr <<
"PropertyVis saveProperty(): cannot open file for writing" << std::endl;
272 QTextStream file_stream(&file);
274 file_stream << propVis->
getHeader() <<
'\n';
277 for (
int i = 0; i < n; ++i)
280 file_stream << propertyText <<
'\n';
288 if (filename ==
"")
return;
290 QFile file(filename);
291 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
292 std::cerr <<
"PropertyVis loadProperty(): cannot open file for reading" << std::endl;
296 QTextStream file_stream(&file);
298 QString header = file_stream.readLine();
308 emit log(
"Property could not be loaded.");
315 for (
unsigned int i = 0; i < n; ++i)
317 QString propertyText = file_stream.readLine();
324 for (
unsigned int i = 0; i < propertyVisualizers.size(); ++i)
326 const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
327 if ((propInfo.entityType() == filter) && (QString::compare(tr(propInfo.propName().c_str()), propName)==0) && (propInfo.typeinfo() == typeInfo))
328 return propertyVisualizers[i];
340 return propertyVisualizers[index.row()]->getPropertyInfo();
343#if QT_VERSION_MAJOR < 6
347 return createSettingsScriptObject(ctx, vis->
getWidget());
Logtype
Log types for Message Window.
Cellection of information about a property.
This class vizualizes a property.
virtual int getEntityCount()=0
Returns the number of entities.
virtual QString getHeader()=0
Returns the header for saving.
virtual QString getPropertyText(unsigned int i)=0
Returns the value of a property in text form.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
virtual QWidget * getWidget()
Returns the visualizer's widget.
void connectLogs(PropertyVisualizer *propViz) override
Connects the PropertyVisualizer log signals with the log slot.
virtual void updateWidget(const QModelIndexList &selectedIndices) override
Updates the widget.
virtual void objectUpdated() override
Revisualizes visualized properties.
virtual void removeProperty(QModelIndexList selectedIndices) override
Removes the selected properties.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx)
Returns a qscript object that can be used to access visualisation parameters.
virtual void duplicateProperty(QModelIndexList selectedIndices) override
Duplicates the selected properties.
void saveProperty(unsigned int propId)
Saves property.
void loadProperty()
Loads property.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList()) override
Visualizes the selected properties.
virtual void clear(QModelIndexList selectedIndices) override
Clears the selected property visualization.
QString getLoadFilename()
Asks the user for a file to load.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const override
Returns the property info for the property with the given index.
Wraps the information of a type.