54 #include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh> 57 #include <QJsonDocument> 58 #include <QJsonObject> 70 static int idGenerator = 1;
80 persistentId_(_object.persistentId_),
81 objectType_(_object.objectType_),
82 flags_(_object.flags_),
83 visible_(_object.visible_),
87 commentsByKey_(_object.commentsByKey_)
100 QMap< QString, PerObjectData* >::const_iterator mapIter = _object.
dataMap_.begin();
101 while ( mapIter != _object.
dataMap_.end() ) {
106 dataMap_.insert(mapIter.key(),copiedData);
108 std::cerr <<
"Failed to copy per Object Data: " << mapIter.key().toStdString() << std::endl;
133 getObjectManager()->objectCreated(
id());
168 getObjectManager()->objectCreated(
id());
172 BaseObject::~BaseObject() {
181 getObjectManager()->objectDeleted(
id());
235 std::cerr <<
"BaseObect : overwriting data type" << std::endl;
247 output +=
"Info for Object with id " + QString::number(
id()) +
"\n";
248 output +=
"Object is : ";
255 output +=
" visible";
257 output +=
" invisible";
274 return flag(
"target");
279 if (
target() != _target ) {
292 return flag(
"source");
301 return flags_.contains(_flag);
306 bool emitted =
false;
308 if (
flags_.contains(_flag))
396 std::cerr <<
"Last not implemented yet! " << std::endl;
417 while ( parentPointer ) {
420 int nextIndex = ( thisPointer->
row() + 1);
421 if ( parentPointer->
childCount() > nextIndex ) {
426 thisPointer = parentPointer;
446 while ( current->
parent() != 0 ) {
448 current = current->
parent();
503 std::cerr <<
"Warning! Trying to append a child twice! Remove the append calls from your File plugin!" << std::endl;
519 if (
id_ == _objectId )
535 if (
name() == _name )
551 QList<BaseObject*>::iterator i;
560 std::cerr <<
"Illegal remove request" << std::endl;
569 QList< BaseObject* > items;
577 items.push_back(
this);
615 return (
parent()->
id() );
632 if ( current->
id() == _id )
636 current = current->
parent();
637 }
while ( current != 0 );
653 current = current->
parent();
655 }
while ( current != 0 );
661 std::vector< int > groups;
671 if ( current->
parent() != 0 )
672 groups.push_back( current->
id() );
675 current = current->
parent();
676 }
while ( current != 0 );
692 if ( current->
parent() != 0 )
693 groups.push_back( current->
name() );
696 current = current->
parent();
697 }
while ( current != 0 );
717 QFileInfo file_info(_filename);
719 QString
filename = file_info.fileName();
751 for (
int i = 0 ; i <
level() ; ++i )
754 std::cerr <<
"Node ";
755 std::cerr << std::string(
name().toLatin1());
757 std::cerr <<
" with id : ";
761 std::cerr <<
" and type " <<
typeName(
dataType()).toStdString() << std::endl;
770 std::cerr <<
"Copy not supported by this Object" << std::endl;
782 dataMap_.insert( _dataName, _data );
797 return dataMap_.contains(_dataName);
814 QMapIterator<QString, PerObjectData* > i(
dataMap_);
815 while (i.hasNext()) {
859 result.append(QString(
"BEGIN Comments for object \"%1\"").arg(
name()));
864 QJsonObject comment_obj;
866 it != it_end; ++it) {
868 QJsonParseError json_error;
869 QString test_json_str = QString::fromUtf8(
"{\"test\": %1}").arg(it.value());
870 QByteArray test_json_ba = test_json_str.toUtf8();
871 QJsonDocument test_json = QJsonDocument::fromJson(test_json_ba, &json_error);
872 if (json_error.error != QJsonParseError::NoError) {
873 comment_obj[it.key()] = it.value();
875 comment_obj[it.key()] = test_json.object().value(
"test");
878 result.append(QString::fromUtf8(QJsonDocument(comment_obj).toJson(QJsonDocument::Indented)));
880 result.append(QString(
"END Comments for object \"%1\"\n").arg(
name()));
882 return result.join(
"\n");
virtual QString getObjectinfo()
Get all Info for the Object as a string.
void visibilityChanged(int _objectId)
void decreaseObjectCount()
Increase the number of current Object.
void clearObjectData(QString _dataName)
Clear the object data pointer ( this will not delete the object!! )
void setFlag(QString _flag, bool _set)
virtual PerObjectData * copyPerObjectData()
Copy Function.
void setPath(const QString &_path)
set the path to the object.
QList< BaseObject *> getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
BaseObject * child(int row)
return a child
void deleteData()
Delete all data attached to this object ( calls delete on each object )
QString path() const
return the path to the object ( defaults to "." if unset )
int childCount() const
get the number of children
void decreaseTargetCount()
Increase the number of current Object.
void setObjectData(QString _dataName, PerObjectData *_data)
void removeChild(BaseObject *_item)
Remove a child from this object.
void clearAllComments()
Get comment for the specified key.
const QString getAllCommentsFlat() const
QString & getCommentByKey(const QString &key)
Get comment for the specified key.
BaseObject(const BaseObject &_object)
BaseObject *& objectRoot()
Get the root of the object structure.
QStringList getGroupNames()
BaseObject * parentItem_
Parent item or 0 if rootnode.
const DataType DATA_GROUP(1)
Items used for Grouping.
QList< BaseObject * > childItems_
Children of this node.
QMap< QString, PerObjectData * > & getPerObjectDataMap()
get reference to map of all perObject Datas
QString filename() const
return the filename of the object
QString name_
Object/FileName ( defaults to NONAME )
bool hasCommentForKey(const QString &key) const
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
bool dataType(DataType _type) const
void dumpTree()
Debugging function, writing the subtree to output.
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
void appendChild(BaseObject *child)
add a child to this node
QMap< QString, PerObjectData *> dataMap_
get reference to map of all perObject Datas
bool isInGroup(int _id) const
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setParent(BaseObject *_parent)
Set the parent pointer.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
int row() const
get the row of this item from the parent
QString filename_
path to the file from which the object is loaded ( defaults to "." )
QString name() const
return the name of the object. The name defaults to NONAME if unset.
virtual void printObjectInfo()
Print all information about the object.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
void increaseTargetCount()
Decrease the number of current Object.
bool isGroup() const
Check if object is a group.
std::vector< int > getGroupIds()
QString path_
path to the file from which the object is loaded ( defaults to "." )
int persistentId_
Persistent ID for this Object.
int id_
Unique ID for this Object.
void objectPropertiesChanged(int _objectId)
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
virtual bool visible()
return if object is visible
void setFileName(const QString &_filename)
set the filename for this object
const QMap< QString, QString > & getAllComments() const
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
void objectSelectionChanged(int _objectId)
void setDataType(DataType _type)
void increaseObjectCount()
Decrease the number of current Object.
QMap< QString, QString > commentsByKey_
Get comment for the specified key.
void addObjectToMap(int _objectId, BaseObject *_object)
Add object to internal object map.
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
virtual BaseObject * copy()
Returns a full copy of the object.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
DataType dataType() const
void setFromFileName(const QString &_filename)
void clearComment(const QString &key)
Get comment for the specified key.