50 #include "SingleObjectPropertyModel.hh"
52 SingleObjectPropertyModel::SingleObjectPropertyModel(QObject *parent)
55 currentlySelectedIndices(),
56 currentlyVisualizedIndices()
59 QVBoxLayout* layout =
new QVBoxLayout();
60 widgets =
new QWidget();
61 widgets->setLayout(layout);
64 SingleObjectPropertyModel::~SingleObjectPropertyModel()
66 for (
unsigned int i = 0; i < propertyVisualizers.size(); i++)
67 delete propertyVisualizers[i];
76 for (
int i = 0; i < selectedIndices.size(); ++i)
78 const int row = selectedIndices[i].row();
82 propertyVisualizers[row]->visualize(
true, 0);
86 propertyVisualizers[row]->visualize(
true, widgets[i]);
90 std::vector<unsigned int>& vec = currentlyVisualizedIndices;
91 vec.erase(std::remove(vec.begin(), vec.end(), row), vec.end());
98 std::vector<unsigned int> deleteIndices;
100 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
102 propertyVisualizers[it->row()]->removeProperty();
103 QWidget* w = propertyVisualizers[it->row()]->getWidget();
104 widgets->layout()->removeWidget(w);
105 delete propertyVisualizers[it->row()];
106 propertyVisualizers[it->row()] = 0;
107 deleteIndices.push_back(it->row());
110 std::sort(deleteIndices.begin(), deleteIndices.end());
112 for (
int i = deleteIndices.size()-1; i >= 0; i--)
114 for (
int j = currentlyVisualizedIndices.size()-1; j >= 0; j--)
116 if (currentlyVisualizedIndices[j] == deleteIndices[i])
118 currentlyVisualizedIndices.erase(currentlyVisualizedIndices.begin() + j);
119 else if (currentlyVisualizedIndices[j] > deleteIndices[i])
122 currentlyVisualizedIndices[j]--;
126 for (
int i = deleteIndices.size()-1; i >= 0; i--){
127 propertyVisualizers.erase(propertyVisualizers.begin() + deleteIndices[i]);
133 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
134 propertyVisualizers[it->row()]->duplicateProperty();
138 for (QModelIndexList::Iterator it = selectedIndices.begin(); it != selectedIndices.end(); ++it)
140 propertyVisualizers[it->row()]->clear();
141 std::vector<unsigned int>& vec = currentlyVisualizedIndices;
142 vec.erase(std::remove(vec.begin(), vec.end(), it->row()), vec.end());
148 QLayout* layout = widgets->layout();
150 currentlySelectedIndices = selectedIndices;
152 for (
unsigned int i = 0; i < propertyVisualizers.size(); i++)
154 propertyVisualizers[i]->getWidget()->hide();
157 for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = selectedIndices.end();
158 it != it_end; ++it) {
159 QWidget* widget = propertyVisualizers[it->row()]->getWidget();
160 layout->addWidget(widget);
163 widgets->setLayout(layout);
168 connect(propViz, SIGNAL(log(QString)),
this, SLOT(slotLog(QString)));
169 connect(propViz, SIGNAL(log(
Logtype, QString)),
this, SLOT(slotLog(
Logtype, QString)));
172 int SingleObjectPropertyModel::rowCount(
const QModelIndex & parent)
const {
173 return propertyVisualizers.size();
176 QVariant SingleObjectPropertyModel::data(
const QModelIndex & index,
int role)
const {
178 case Qt::DisplayRole:
179 return propertyVisualizers[index.row()]->getName();
181 return QVariant::Invalid;
185 QVariant SingleObjectPropertyModel::headerData(
int section, Qt::Orientation orientation,
int role)
const {
187 case Qt::DisplayRole:
188 return tr(
"Some header. %1 %2").arg(section).arg(orientation);
191 return QAbstractListModel::headerData(section, orientation, role);
197 for (
unsigned int i = 0; i < currentlyVisualizedIndices.size(); i++)
199 propertyVisualizers[currentlyVisualizedIndices[i]]->visualize(
false, 0);
206 QString selected_filter = tr(
"All Files (*)");
208 QString fileName = QFileDialog::getOpenFileName(0, tr(
"Load Property"), QString(), filter, &selected_filter);
223 QString fileName = QFileDialog::getSaveFileName(0, tr(
"Save Property"), defaultName, filter);
230 QString filter= tr(
"All Files (*)");
242 name += tr(
".vprop");
244 name += tr(
".hprop");
246 name += tr(
".eprop");
248 name += tr(
".fprop");
250 name += tr(
".hfprop");
252 name += tr(
".cprop");
260 file_.setFileName(_filename);
261 if(file_.open(QIODevice::ReadWrite | QIODevice::Text))
262 file_stream_ =
new QTextStream(&file_);
283 s = file_stream_->readLine();
286 else return QString(
"");
293 (*file_stream_) << _s <<
'\n';
295 else std::cerr <<
"Warning: filestream not available...\n";
303 if (filename ==
"")
return;
306 QTextStream* file_stream_ = 0;
308 openFile(filename, file_, file_stream_);
315 for (
int i = 0; i < n; ++i)
328 if (filename ==
"")
return;
331 QTextStream* file_stream_ = 0;
333 openFile(filename, file_, file_stream_);
335 QString header =
readLine(file_stream_);
347 emit log(
"Property could not be loaded.");
355 for (
unsigned int i = 0; i < n; ++i)
357 QString propertyText =
readLine(file_stream_);
364 for (
unsigned int i = 0; i < propertyVisualizers.size(); ++i)
366 const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
367 if ((propInfo.entityType() == filter) && (QString::compare(tr(propInfo.propName().c_str()), propName)==0) && (propInfo.typeinfo() == typeInfo))
368 return propertyVisualizers[i];
380 return propertyVisualizers[index.row()]->getPropertyInfo();
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
virtual void clear(QModelIndexList selectedIndices)
Clears the selected property visualization.
QString readLine(QTextStream *file_stream_)
Read line from a file.
This class vizualizes a property.
Logtype
Log types for Message Window.
QString getSaveFilename(unsigned int propId)
Asks the user for a file to load.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
void loadProperty()
Loads property.
QString getLoadFilename()
Asks the user for a file to load.
virtual QString getDefaultSaveFilename(unsigned int propId)
Returns the default file name.
Wraps the information of a type.
virtual void visualize(QModelIndexList selectedIndices, QWidgetList widgets=QWidgetList())
Visualizes the selected properties.
void saveProperty(unsigned int propId)
Saves property.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
virtual void setPropertyFromFile(QTextStream *&file_stream_, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
virtual void objectUpdated()
Revisualizes visualized properties.
virtual QString getPropertyText(unsigned int i)=0
Returns the value of a property in text form.
virtual void duplicateProperty(QModelIndexList selectedIndices)
Duplicates the selected properties.
virtual int getEntityCount()=0
Returns the number of entities.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const
Returns the property info for the property with the given index.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
void closeFile(QFile &file_, QTextStream *&file_stream_)
Closes a file.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
virtual void removeProperty(QModelIndexList selectedIndices)
Removes the selected properties.
void openFile(QString _filename, QFile &file_, QTextStream *&file_stream_)
Opens a file.
virtual QString getHeader()=0
Returns the header for saving.
Cellection of information about a property.
void writeLine(QString _s, QTextStream *&file_stream_)
Writes a line to a file.