Bonjour ,

j'ai une question concernant les methodes "virtelles",si j'ai bien compris,ces methodes là on peut les modifier dans les classe filles.
ma question est :
j'ai un fichier : ExaminerViewer.cpp ,

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
oQtExaminerViewer::SoQtExaminerViewer(QWidget * parent,
                                       const char * name,
                                       SbBool embed,
                                       SoQtFullViewer::BuildFlag flag,
                                       SoQtViewer::Type type)
  : inherited(parent, name, embed, flag, type, FALSE)
{
  PRIVATE(this) = new SoQtExaminerViewerP(this);
  PRIVATE(this)->constructor(TRUE);
}
 
// *************************************************************************
 
// Documented in common/viewers/SoGuiExaminerViewer.cpp.in.
SoQtExaminerViewer::SoQtExaminerViewer(QWidget * parent,
                                       const char * name,
                                       SbBool embed,
                                       SoQtFullViewer::BuildFlag flag,
                                       SoQtViewer::Type type,
                                       SbBool build)
  : inherited(parent, name, embed, flag, type, FALSE)
{
  PRIVATE(this) = new SoQtExaminerViewerP(this);
  PRIVATE(this)->constructor(build);
}
 
// *************************************************************************
 
SoQtExaminerViewer::~SoQtExaminerViewer()
{
  delete PRIVATE(this);
}
 
// *************************************************************************
 
// Documented in superclass.
void
SoQtExaminerViewer::setCamera(SoCamera * newCamera)
{
  // This method overridden from parent class to toggle the camera
  // type selection button pixmap and string of the zoom/dolly
  // thumbwheel.
 
  if (newCamera) {
    SoType camtype = newCamera->getTypeId();
    SbBool orthotype =
      camtype.isDerivedFrom(SoOrthographicCamera::getClassTypeId());
 
    this->setRightWheelString(orthotype ? "Zoom" : "Dolly");
    if (PRIVATE(this)->cameratogglebutton) {
      PRIVATE(this)->cameratogglebutton->setPixmap(orthotype ?
                                                   * (PRIVATE(this)->orthopixmap) :
                                                   * (PRIVATE(this)->perspectivepixmap));
    }
  }
 
  inherited::setCamera(newCamera);
}
 
// *************************************************************************
 
// Documented in superclass. Overridden so we can append the camera
// type switch button in the rightside button column.
void
SoQtExaminerViewer::createViewerButtons(QWidget * parent, SbPList * buttonlist)
{
  inherited::createViewerButtons(parent, buttonlist);
 
  PRIVATE(this)->cameratogglebutton = new QPushButton(parent);
 
#if (defined Q_WS_MAC && QT_VERSION >=0x030100) && defined(HAVE_QSTYLEFACTORY_H)
    // Since Qt/Mac 3.1.x, all pushbuttons (even those < 32x32) are drawn
    // using the Aqua style, i.e. with rounded edges and shading. This
    // looks really ugly in the viewer decoration. Drawing the buttons
    // in the Windows style gives us the flat, square buttons we want.
  QStyle * style = QStyleFactory::create("windows");
  if (style) { PRIVATE(this)->cameratogglebutton->setStyle(style); }
#endif
 
  PRIVATE(this)->cameratogglebutton->setFocusPolicy(QTWIDGET_NOFOCUS);
  assert(PRIVATE(this)->perspectivepixmap);
  assert(PRIVATE(this)->orthopixmap);
 
  QPixmap * p = NULL;
  SoType t = this->getCameraType();
  if (t.isDerivedFrom(SoOrthographicCamera::getClassTypeId()))
    p = PRIVATE(this)->orthopixmap;
  else if (t.isDerivedFrom(SoPerspectiveCamera::getClassTypeId()))
    p = PRIVATE(this)->perspectivepixmap;
  else assert(0 && "unsupported cameratype");
 
  PRIVATE(this)->cameratogglebutton->setPixmap(*p);
  PRIVATE(this)->cameratogglebutton->adjustSize();
 
  QObject::connect(PRIVATE(this)->cameratogglebutton, SIGNAL(clicked()),
                   PRIVATE(this), SLOT(cameratoggleClicked()));
 
  buttonlist->append(PRIVATE(this)->cameratogglebutton);
}
 
// *************************************************************************
 
// SoQtExaminerViewerP "private implementation" class.
 
#ifndef DOXYGEN_SKIP_THIS
 
SoQtExaminerViewerP::SoQtExaminerViewerP(SoQtExaminerViewer * publ)
  : SoGuiExaminerViewerP(publ)
{
}
 
SoQtExaminerViewerP::~SoQtExaminerViewerP()
{
  // Button pixmaps.
  delete this->orthopixmap;
  delete this->perspectivepixmap;
 
  this->genericDestructor();
}
 
// This contains the real constructor code (the two SoQtExaminerViewer
// constructors are only entry points for this method).
void
SoQtExaminerViewerP::constructor(SbBool build)
{
  this->genericConstructor();
 
  this->cameratogglebutton = NULL;
 
  this->orthopixmap = new QPixmap((const char **)ortho_xpm);
  this->perspectivepixmap = new QPixmap((const char **)perspective_xpm);
  assert(this->orthopixmap->size() == this->perspectivepixmap->size());
 
  PUBLIC(this)->setClassName("SoQtExaminerViewer");
 
  PUBLIC(this)->setPopupMenuString("Examiner Viewer");
  PUBLIC(this)->setLeftWheelString("Rotx");
  PUBLIC(this)->setBottomWheelString("Roty");
 
  if (build) {
    QWidget * widget = PUBLIC(this)->buildWidget(PUBLIC(this)->getParentWidget());
    PUBLIC(this)->setBaseWidget(widget);
  }
}
 
void
SoQtExaminerViewerP::cameratoggleClicked()
{
  if (PUBLIC(this)->getCamera()) PUBLIC(this)->toggleCameraType();
}
 
// *************************************************************************
 
#endif // DOXYGEN_SKIP_THIS
 
#undef PRIVATE
#undef PUBLIC
un ExaminerViewerP.h qui est finalement le header du ExaminerViewer.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class SoQtExaminerViewer;
class QPixmap;
 
// ************************************************************************
 
// This class contains private data and methods used within the
// SoQtExaminerViewer class.
 
class SoQtExaminerViewerP : public QObject, public SoGuiExaminerViewerP
{
  Q_OBJECT
 
public:
  SoQtExaminerViewerP(SoQtExaminerViewer * publ);
  ~SoQtExaminerViewerP();
 
  void constructor(SbBool buildNow);
 
  QPixmap * orthopixmap, * perspectivepixmap;
  class QPushButton * cameratogglebutton;
 
public slots:
  // viewer buttons row:
  void cameratoggleClicked(void);
};
 
// ************************************************************************
 
#endif // ! SOQTEXAMINERVIEWERP_H
et un SoQtExaminerviewer.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
#ifndef SOQT_EXAMINERVIEWER_H
#define SOQT_EXAMINERVIEWER_H
 
#include <Inventor/SbLinear.h>
#include <Inventor/Qt/viewers/SoQtFullViewer.h>
 
class SoSeparator;
class SoSwitch;
class SoTranslation;
class SoScale;
 
class SoQtThumbWheel;
 
// *************************************************************************
 
class SOQT_DLL_API SoQtExaminerViewer : public SoQtFullViewer {
  SOQT_OBJECT_HEADER(SoQtExaminerViewer, SoQtFullViewer);
 
public:
  SoQtExaminerViewer(QWidget * parent = NULL,
                        const char * name = NULL,
                        SbBool embed = TRUE,
                        SoQtFullViewer::BuildFlag flag = BUILD_ALL,
                        SoQtViewer::Type type = BROWSER);
  ~SoQtExaminerViewer();
 
  void setAnimationEnabled(const SbBool enable);
  SbBool isAnimationEnabled(void) const;
 
  void stopAnimating(void);
  SbBool isAnimating(void) const;
 
  void setFeedbackVisibility(const SbBool enable);
  SbBool isFeedbackVisible(void) const;
 
  void setFeedbackSize(const int size);
  int getFeedbackSize(void) const;
 
  virtual void setViewing(SbBool enable);
  virtual void setCamera(SoCamera * camera);
  virtual void setCursorEnabled(SbBool enable);
 
protected:
  SoQtExaminerViewer(QWidget * parent,
                        const char * name,
                        SbBool embed,
                        SoQtFullViewer::BuildFlag flag,
                        SoQtViewer::Type type,
                        SbBool build);
 
  virtual void leftWheelMotion(float val);
  virtual void bottomWheelMotion(float val);
  virtual void rightWheelMotion(float val);
 
  virtual void createViewerButtons(QWidget * parent, SbPList * buttonlist);
 
  virtual const char * getDefaultWidgetName(void) const;
  virtual const char * getDefaultTitle(void) const;
  virtual const char * getDefaultIconTitle(void) const;
 
  virtual SbBool processSoEvent(const SoEvent * const event);
  virtual void setSeekMode(SbBool enable);
  virtual void actualRedraw(void);
 
  virtual void afterRealizeHook(void);
 
private:
  class SoQtExaminerViewerP * pimpl;
 
  friend class SoGuiExaminerViewerP;
  friend class SoQtExaminerViewerP;
};
 
#endif // ! SOQT_EXAMINERVIEWER_H
dans le SoQtExaminerViewer.h on declare SoQtExaminerViewerP comme classe amie.
et au final,dans mon code,je fais un include de <SoQtExaminerViewer.h>

je dois ajouter un bouton à mon viewer et donc je remarque que je peux utiliser createViewerButtons qui est une methode virtuelle,je veux la reimplementer pour ajouter un bouton à mon viewer,et donc je crée une classe Myclasse,qui va heriter de ma classe ExaminerViewer et j'ajoute mon bouton.

mon problem reside dans l'organisation des fichier,entre MyClass.h,Myclass.h et MyClassP.h (puisque je dois suivre la meme organisation)

oubien,est ce que je peux utiliser les headers de la meme classe Examinerviewer et pas la peine d'en faire de nouveau pour Myclass(puisque moi au final je reinplemente qu'une methode de cette classe).
et donc mon Myclass.cpp aura la forme de "class Myclass::public ExaminerVieiwer(){}" etc ..(pas de headers donc)

j'avoue que je suis un peu confuse,si qu'elqu'un peut m'aider ladessus.
Merci