Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BaseObject.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50
51
52
53 //=============================================================================
54 //
55 // Types
56 //
57 //=============================================================================
58
65 #ifndef BASEOBJECT_HH
66 #define BASEOBJECT_HH
67
68 //== INCLUDES =================================================================
69
70 #include <OpenFlipper/common/GlobalDefines.hh>
71 #include <OpenFlipper/common/DataTypes.hh>
72 #include <OpenFlipper/common/UpdateType.hh>
73 #include <QObject>
74 #include <QString>
75 #include <QList>
76 #include <QStringList>
77 #include <vector>
78 #include <QMap>
79 #include "perObjectData.hh"
80 #if QT_VERSION >= 0x050000
81 #include <QJsonDocument>
82 #include <QJsonObject>
83 #endif
84
85 //== TYPEDEFS =================================================================
86
87
88 //== CLASS DEFINITION =========================================================
89
94 class DLLEXPORTONLY BaseObject : public QObject {
95
96 Q_OBJECT
97
98 friend class BaseObjectData;
99 friend class Core;
100
101 public :
102
106 BaseObject(const BaseObject& _object);
107
112 BaseObject( BaseObject *_parent = 0);
113
114 virtual ~BaseObject();
115
118 static int NOOBJECT;
119
120 //===========================================================================
123 //===========================================================================
124 public:
128 int id() const;
129
134 int persistentId() const;
135
138 void persistentId( int _id );
139
140 private:
146 int id_;
147
153 int persistentId_;
154
155 //===========================================================================
158 //===========================================================================
159
160 public:
164 bool dataType(DataType _type) const;
165
168 DataType dataType() const;
169
173 void setDataType(DataType _type);
174
175 private:
179 DataType objectType_;
180
183 //===========================================================================
186 //===========================================================================
187
188 public:
192 virtual void cleanup();
193
196 //===========================================================================
199 //===========================================================================
200 public:
202 virtual QString getObjectinfo();
203
205 virtual void printObjectInfo();
206
209 //===========================================================================
212 //===========================================================================
213
214 signals:
215 void objectSelectionChanged(int _objectId);
216
217 public:
223 bool target();
224
227 void target(bool _target);
228
232 bool source();
233
236 void source(bool _source);
237
240 bool flag(QString _flag);
241
244 void setFlag(QString _flag, bool _set);
245
248 QStringList flags();
249
250 private:
251
255 QStringList flags_;
256
257
260 //===========================================================================
263 //===========================================================================
264
265 signals:
271 void visibilityChanged(int _objectId);
272
273
274 public :
276 virtual bool visible();
277
279 virtual void visible(bool _visible);
280
281 protected :
286 bool visible_;
287
290 //===========================================================================
293 //===========================================================================
294
295 public:
296
297
299 void dumpTree();
300
302 virtual BaseObject* copy();
303
304 //===========================================================================
307 //===========================================================================
308
309 protected:
318 virtual void update(UpdateType _type = UPDATE_ALL);
319
323 //===========================================================================
326 //===========================================================================
327
328 public:
329
332 BaseObject* last();
333
336 BaseObject* next();
337
340 int level();
341
342 private:
344 BaseObject *parentItem_;
345
347 QList<BaseObject*> childItems_;
348
349 public:
350 //===========================================================================
353 //===========================================================================
354
355 public:
356
358 int row() const;
359
361 BaseObject *parent();
362 const BaseObject *parent() const;
363
365 void setParent(BaseObject* _parent);
366
369 //===========================================================================
372 //===========================================================================
373
374 public:
375
377 BaseObject* childExists(int _objectId);
378
380 BaseObject* childExists(QString _name);
381
383 void appendChild(BaseObject *child);
384
386 BaseObject *child(int row);
387
389 int childCount() const;
390
392 void removeChild( BaseObject* _item );
393
395 QList< BaseObject* > getLeafs();
396
398 void deleteSubtree();
399
402 //===========================================================================
405 //===========================================================================
406
407 public:
408
414 int group() const;
415
417 bool isGroup() const;
418
423 bool isInGroup( int _id ) const;
424
429 bool isInGroup( QString _name ) const;
430
433 std::vector< int > getGroupIds();
434
437 QStringList getGroupNames();
438
439
442 //===========================================================================
445 //===========================================================================
446
451 void setFromFileName(const QString &_filename);
452
453
455 QString path() const;
456
458 void setPath(const QString &_path);
459
461 QString name( ) const;
462
463
464 /* set the name of the object. ( If you overwrite it, call BaseObject::setName(_name ) it in your funtion first)
465 * this is may not the filename of the given object, because one file can have multiple objects
466 */
467 virtual void setName(QString _name );
468
470 QString filename() const;
471
473 void setFileName(const QString &_filename);
474
475 private:
476
478 QString path_;
479 QString filename_;
480
481 signals:
485 void objectPropertiesChanged(int _objectId);
486
487 private:
488
490 QString name_;
491
492
495 //===========================================================================
499 //===========================================================================
500
501 public:
502
510 void setObjectData( QString _dataName , PerObjectData* _data );
511
513 void clearObjectData( QString _dataName );
514
516 bool hasObjectData( QString _dataName );
517
519 PerObjectData* objectData( QString _dataName );
520
522 void deleteData();
523
526 //===========================================================================
529 //===========================================================================
530
536 QMap<QString, PerObjectData*>& getPerObjectDataMap();
537
538
539 private:
540
541 QMap<QString, PerObjectData* > dataMap_;
542
545 //===========================================================================
548 //===========================================================================
549
550 public:
556 QString &getCommentByKey(const QString &key) {
557 return commentsByKey_[key];
558 }
559
565 const QString getCommentByKey(const QString &key) const {
566 return commentsByKey_.value(key);
567 }
568
570 bool hasCommentForKey(const QString &key) const {
571 return commentsByKey_.contains(key);
572 }
573
575 bool hasComments() const {
576 return !commentsByKey_.empty();
577 }
578
579 void clearComment(const QString &key) {
580 commentsByKey_.remove(key);
581 }
582
583 void clearAllComments() {
584 commentsByKey_.clear();
585 }
586
588 const QMap<QString, QString> &getAllComments() const {
589 return commentsByKey_;
590 }
591
593 const QString getAllCommentsFlat() const {
594 QStringList result;
595
596 result.append(QString("BEGIN Comments for object \"%1\"").arg(name()));
597
598 /*
599 * Compose JSON parsable object.
600 */
601 #if QT_VERSION >= 0x050000
602 QJsonObject comment_obj;
603 for (QMap<QString, QString>::const_iterator it = commentsByKey_.begin(), it_end = commentsByKey_.end();
604 it != it_end; ++it) {
605
606 QJsonParseError json_error;
607 QString test_json_str = QString::fromUtf8("{\"test\": %1}").arg(it.value());
608 QByteArray test_json_ba = test_json_str.toUtf8();
609 QJsonDocument test_json = QJsonDocument::fromJson(test_json_ba, &json_error);
610 if (json_error.error != QJsonParseError::NoError) {
611 comment_obj[it.key()] = it.value();
612 } else {
613 comment_obj[it.key()] = test_json.object().value("test");
614 }
615 }
616 result.append(QString::fromUtf8(QJsonDocument(comment_obj).toJson(QJsonDocument::Indented)));
617 #else
618 for (QMap<QString, QString>::const_iterator it = commentsByKey_.begin(), it_end = commentsByKey_.end();
619 it != it_end; ++it) {
620 result.append(QString("%1: %2").arg(it.key(), it.value()));
621 }
622 #endif
623
624 result.append(QString("END Comments for object \"%1\"\n").arg(name()));
625
626 return result.join("\n");
627 }
628
629 private:
630 QMap<QString, QString> commentsByKey_;
631
634 };
635
636
637 //=============================================================================
638 #endif // BASEOBJECT_HH defined
639 //=============================================================================
BaseObject::path_
QString path_
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.hh:478
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::getAllCommentsFlat
const QString getAllCommentsFlat() const
Definition: BaseObject.hh:593
BaseObject::dataMap_
QMap< QString, PerObjectData * > dataMap_
get reference to map of all perObject Datas
Definition: BaseObject.hh:541
BaseObject::visible_
bool visible_
Definition: BaseObject.hh:286
UpdateType
Update type class.
Definition: UpdateType.hh:70
BaseObject::clearComment
void clearComment(const QString &key)
Get comment for the specified key.
Definition: BaseObject.hh:579
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
GlobalDefines.hh
BaseObject::getAllComments
const QMap< QString, QString > & getAllComments() const
Definition: BaseObject.hh:588
Core
Definition: Core.hh:139
DataTypes.hh
BaseObject::childItems_
QList< BaseObject * > childItems_
Children of this node.
Definition: BaseObject.hh:347
Core::visibilityChanged
void visibilityChanged(int _id)
Tell plugins that the visibility of an object has changed.
BaseObject::objectType_
DataType objectType_
Definition: BaseObject.hh:179
Core::objectSelectionChanged
void objectSelectionChanged(int)
This signal is emitted if the object has been changed (source/target)
BaseObject::filename_
QString filename_
path to the file from which the object is loaded ( defaults to "." )
Definition: BaseObject.hh:479
BaseObject
Definition: BaseObject.hh:94
BaseObject::NOOBJECT
static int NOOBJECT
Definition: BaseObject.hh:118
BaseObject::flags_
QStringList flags_
Definition: BaseObject.hh:255
BaseObject::getCommentByKey
const QString getCommentByKey(const QString &key) const
Get comment for the specified key.
Definition: BaseObject.hh:565
BaseObject::name_
QString name_
Object/FileName ( defaults to NONAME )
Definition: BaseObject.hh:490
Core::objectPropertiesChanged
void objectPropertiesChanged(int _id)
Tell plugins that object properties such as object names have been changed.
perObjectData.hh
BaseObject::getCommentByKey
QString & getCommentByKey(const QString &key)
Get comment for the specified key.
Definition: BaseObject.hh:556
BaseObject::commentsByKey_
QMap< QString, QString > commentsByKey_
Get comment for the specified key.
Definition: BaseObject.hh:630
BaseObject::persistentId_
int persistentId_
Persistent ID for this Object.
Definition: BaseObject.hh:153
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
BaseObject::id_
int id_
Unique ID for this Object.
Definition: BaseObject.hh:146
PerObjectData
Object Payload.
Definition: perObjectData.hh:86
BaseObject::hasComments
bool hasComments() const
Definition: BaseObject.hh:575
BaseObject::clearAllComments
void clearAllComments()
Get comment for the specified key.
Definition: BaseObject.hh:583
BaseObject::hasCommentForKey
bool hasCommentForKey(const QString &key) const
Definition: BaseObject.hh:570
BaseObject::parentItem_
BaseObject * parentItem_
Parent item or 0 if rootnode.
Definition: BaseObject.hh:344