Qt Virtual Chart Table (QVCT)
COverlayObject.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QDataStream>
21 #include <QTreeWidgetItem>
22 
23 // QVCT
25 
26 
27 //------------------------------------------------------------------------------
28 // CONSTRUCTORS / DESTRUCTOR
29 //------------------------------------------------------------------------------
30 
31 COverlayObject::COverlayObject( COverlayObject::EType _eType, const QString& _rqsName )
32  : QTreeWidgetItem( _eType )
33  , qsName( _rqsName )
34 {}
35 
36 
37 //------------------------------------------------------------------------------
38 // METHODS
39 //------------------------------------------------------------------------------
40 
41 //
42 // OTHER
43 //
44 
45 void COverlayObject::serialize( QDataStream& _rqDataStream ) const
46 {
47  _rqDataStream << qsName;
48 }
49 
50 void COverlayObject::unserialize( QDataStream& _rqDataStream )
51 {
52  _rqDataStream >> qsName;
53 }
54 
55 QString COverlayObject::newChildName( const QString& _rqsName, int _iZeroPrefix, bool _bForceSuffix ) const
56 {
57  QString __qsName;
58  int __iSuffix = 0;
59  bool __bValid;
60  do
61  {
62  __qsName = _rqsName;
63  if( _bForceSuffix || __iSuffix ) __qsName += "("+QString::number( __iSuffix+1 ).prepend( QString( _iZeroPrefix, '0' ) ).right( _iZeroPrefix+1 )+")";
64  __bValid = true;
65  for( int __i = QTreeWidgetItem::childCount()-1; __i >= 0; __i-- )
66  {
67  if( __qsName == ((COverlayObject*)QTreeWidgetItem::child( __i ))->getName() )
68  {
69  __bValid = false;
70  __iSuffix++;
71  break;
72  }
73  }
74  }
75  while( !__bValid );
76  return __qsName;
77 }
78 
79 QString COverlayObject::newChildName( const QString& _rqsName, int _iZeroPrefix, int _iSuffix ) const
80 {
81  return _rqsName + "("+QString::number( _iSuffix ).prepend( QString( _iZeroPrefix, '0' ) ).right( _iZeroPrefix+1 )+")";
82 }
Generic overlay object.
virtual void serialize(QDataStream &_rqDataStream) const
Serializes (store) this object's data to binary format.
EType
Overlay object type.
QString getName() const
Returns this object's name.
virtual void unserialize(QDataStream &_rqDataStream)
Unserializes (restore) this object's data from binary format.
QString newChildName(const QString &_rqsName, int _iZeroPrefix=0, bool _bForceSuffix=false) const
Returns a valid (non-duplicate) name for a new sibling of this object.
QString qsName
Object name.
COverlayObject(EType _eType, const QString &_rqsName)