54#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
57#include <QJsonDocument>
70static int idGenerator = 1;
80 persistentId_(_object.persistentId_),
81 objectType_(_object.objectType_),
82 flags_(_object.flags_),
83 visible_(_object.visible_),
87 name_(
"Copy of " + _object.name_),
88 commentsByKey_(_object.commentsByKey_)
98 QMap< QString, PerObjectData* >::const_iterator mapIter = _object.
dataMap_.begin();
99 while ( mapIter != _object.
dataMap_.end() ) {
104 dataMap_.insert(mapIter.key(),copiedData);
106 std::cerr <<
"Failed to copy per Object Data: " << mapIter.key().toStdString() << std::endl;
131 getObjectManager()->objectCreated(
id());
141 parentItem_(_parent),
166 getObjectManager()->objectCreated(
id());
170BaseObject::~BaseObject() {
179 getObjectManager()->objectDeleted(
id());
233 std::cerr <<
"BaseObect : overwriting data type" << std::endl;
245 output +=
"Info for Object with id " + QString::number(
id()) +
"\n";
246 output +=
"Object is : ";
253 output +=
" visible";
255 output +=
" invisible";
272 return flag(
"target");
277 if (
target() != _target ) {
290 return flag(
"source");
299 return flags_.contains(_flag);
304 bool emitted =
false;
306 if (
flags_.contains(_flag))
394 std::cerr <<
"Last not implemented yet! " << std::endl;
415 while ( parentPointer ) {
418 int nextIndex = ( thisPointer->
row() + 1);
419 if ( parentPointer->
childCount() > nextIndex ) {
424 thisPointer = parentPointer;
444 while ( current->
parent() != 0 ) {
446 current = current->
parent();
501 std::cerr <<
"Warning! Trying to append a child twice! Remove the append calls from your File plugin!" << std::endl;
517 if (
id_ == _objectId )
533 if (
name() == _name )
549 QList<BaseObject*>::iterator i;
558 std::cerr <<
"Illegal remove request" << std::endl;
567 QList< BaseObject* > items;
575 items.push_back(
this);
613 return (
parent()->
id() );
630 if ( current->
id() == _id )
634 current = current->
parent();
635 }
while ( current != 0 );
651 current = current->
parent();
653 }
while ( current != 0 );
659 std::vector< int > groups;
669 if ( current->
parent() != 0 )
670 groups.push_back( current->
id() );
673 current = current->
parent();
674 }
while ( current != 0 );
690 if ( current->
parent() != 0 )
691 groups.push_back( current->
name() );
694 current = current->
parent();
695 }
while ( current != 0 );
715 QFileInfo file_info(_filename);
717 QString
filename = file_info.fileName();
749 for (
int i = 0 ; i <
level() ; ++i )
752 std::cerr <<
"Node ";
753 std::cerr << std::string(
name().toLatin1());
755 std::cerr <<
" with id : ";
759 std::cerr <<
" and type " <<
typeName(
dataType()).toStdString() << std::endl;
768 std::cerr <<
"Copy not supported by this Object" << std::endl;
780 dataMap_.insert( _dataName, _data );
795 return dataMap_.contains(_dataName);
853 result.append(QString(
"BEGIN Comments for object \"%1\"").arg(
name()));
858 QJsonObject comment_obj;
860 it != it_end; ++it) {
862 QJsonParseError json_error;
863 QString test_json_str = QString::fromUtf8(
"{\"test\": %1}").arg(it.value());
864 QByteArray test_json_ba = test_json_str.toUtf8();
865 QJsonDocument test_json = QJsonDocument::fromJson(test_json_ba, &json_error);
866 if (json_error.error != QJsonParseError::NoError) {
867 comment_obj[it.key()] = it.value();
869 comment_obj[it.key()] = test_json.object().value(
"test");
872 result.append(QString::fromUtf8(QJsonDocument(comment_obj).toJson(QJsonDocument::Indented)));
874 result.append(QString(
"END Comments for object \"%1\"\n").arg(
name()));
876 return result.join(
"\n");
const DataType DATA_UNKNOWN(0)
None of the other Objects.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
const DataType DATA_GROUP(1)
Items used for Grouping.
void setObjectData(QString _dataName, PerObjectData *_data)
QString path_
path to the file from which the object is loaded ( defaults to "." )
QStringList getGroupNames()
void clearAllComments()
Get comment for the specified key.
void setPath(const QString &_path)
set the path to the object.
int row() const
get the row of this item from the parent
virtual QString getObjectinfo()
Get all Info for the Object as a string.
void removeChild(BaseObject *_item)
Remove a child from this object.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
BaseObject(const BaseObject &_object)
virtual void printObjectInfo()
Print all information about the object.
int childCount() const
get the number of children
QList< BaseObject * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects )
std::vector< int > getGroupIds()
QMap< QString, QString > commentsByKey_
Get comment for the specified key.
void setFileName(const QString &_filename)
set the filename for this object
QString filename() const
return the filename of the object
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setFlag(QString _flag, bool _set)
void setDataType(DataType _type)
int persistentId_
Persistent ID for this Object.
QString filename_
path to the file from which the object is loaded ( defaults to "." )
int id_
Unique ID for this Object.
void setParent(BaseObject *_parent)
Set the parent pointer.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
BaseObject * parentItem_
Parent item or 0 if rootnode.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
void visibilityChanged(int _objectId)
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
const QMap< QString, QString > & getAllComments() const
void appendChild(BaseObject *child)
add a child to this node
QString & getCommentByKey(const QString &key)
Get comment for the specified key.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
void dumpTree()
Debugging function, writing the subtree to output.
QMap< QString, PerObjectData * > & getPerObjectDataMap()
get reference to map of all perObject Datas
bool dataType(DataType _type) const
DataType dataType() const
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
virtual BaseObject * copy()
Returns a full copy of the object.
QString name_
Object/FileName ( defaults to NONAME )
QList< BaseObject * > childItems_
Children of this node.
bool isInGroup(int _id) const
bool hasCommentForKey(const QString &key) const
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
QString path() const
return the path to the object ( defaults to "." if unset )
void objectSelectionChanged(int _objectId)
BaseObject * child(int row)
return a child
void objectPropertiesChanged(int _objectId)
void clearObjectData(QString _dataName)
Clear the object data pointer ( this will not delete the object!! )
QMap< QString, PerObjectData * > dataMap_
get reference to map of all perObject Datas
void setFromFileName(const QString &_filename)
const QString getAllCommentsFlat() const
bool isGroup() const
Check if object is a group.
void clearComment(const QString &key)
Get comment for the specified key.
virtual bool visible()
return if object is visible
virtual PerObjectData * copyPerObjectData()
Copy Function.
void increaseObjectCount()
Decrease the number of current Object.
void addObjectToMap(int _objectId, BaseObject *_object)
Add object to internal object map.
BaseObject *& objectRoot()
Get the root of the object structure.
void decreaseTargetCount()
Increase the number of current Object.
void increaseTargetCount()
Decrease the number of current Object.
void decreaseObjectCount()
Increase the number of current Object.