++++++ main.cpp ++++++
#include <QApplication>
#include "window.h"
int main(int argc, char *argv[])
{
Window window;
window.show();
return app.exec();
}
++++++ window.h ++++++
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class CoinWidget;
{
Q_OBJECT
public:
Window();
private:
CoinWidget *coinWidget;
};
#endif
++++++ window.cpp ++++++
#include <QtGui>
#include "coinwidget.h"
#include "window.h"
Window::Window()
{
coinWidget = new CoinWidget;
xSlider = createSlider();
connect(xSlider, SIGNAL(valueChanged(int)), coinWidget, SLOT(setXRotation(int)));
connect(coinWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
// NOTE: above is how I did it when I thought I could place the model in
// the CoinWidget class. Now that I've a separate class, Model,
// which contains the model, I don't know how I can pass SIGNALs to
// a Model object without declaring the object here first... but which
// doesn't make sense to do. I declare the "model" object in the
// Coinwidget::Coinwidget() constructor. ...although, as I asked above:
// perhaps I should leave this as it is, then forward the signal on to the
// model class?
mainLayout->addWidget(coinWidget);
mainLayout->addWidget(xSlider);
setLayout(mainLayout);
xSlider->setValue(12);
setWindowTitle(tr("Hello COIN"));
}
{
slider->setRange(0, 360);
slider->setSingleStep(36);
slider->setPageStep(12);
slider->setTickInterval(12);
slider
->setTickPosition
(QSlider::TicksRight);
return slider;
}
++++++ coinwidget.h ++++++
#ifndef COINWIDGET_H
#define COINWIDGET_H
#include <QMainWindow>
#include <Inventor/Qt/SoQt.h>
{
Q_OBJECT
public:
~CoinWidget();
QSize minimumSizeHint
() const;
float deg2rad(int angle) { return (angle * 3.1416/180.00); }
public slots:
// refer to other comments
void setXRotation(int angle);
signals:
// refer to other comments
void xRotationChanged(int angle);
protected:
private:
void normalizeAngle(int *angle);
};
#endif
++++++ coinwidget.cpp ++++++
#include <QtGui>
#include <QtCore>
#include <Inventor/Qt/SoQt.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include "coinwidget.h"
#include "model.h"
{
SoQt::init(this);
Model *model = new Model(this);
setCentralWidget(model->getWidget());
model->setDefaultScene();
}
CoinWidget::~CoinWidget() {
// delete model; // : error C2065: 'model' : undeclared identifier
// So I added "delete this;" in Model::~Model();
// Is this the proper way to delete pointer/allocated memory
// to the "model" object?
}
QSize CoinWidget
::minimumSizeHint() const {
}
QSize CoinWidget
::sizeHint() const {
}
void CoinWidget::setXRotation(int angle)
{
// I was thinking that I should delete this member function, since this Class is set up
// only to initialize the Coin3d window... but--again, as I asked above--maybe I should
// keep it, and pass the signal again to the Model class. I realize, btw, that the
// function doesn't do anything currently. I'll sort that out after I figure out how to
// route the signals/slots.
float a = deg2rad(angle);
qDebug("angle = %.4f", a);
}
++++++ model.h ++++++
#ifndef MODEL_H
#define MODEL_H
#include <Inventor/Qt/SoQt.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/fields/SoSFFloat.h>
class Model : public SoQtExaminerViewer
{
public:
Model
( QWidget *parent
= NULL,
const char *name
=NULL,
const SbBool embed
=TRUE);
~Model(void);
void setDefaultScene();
protected:
private:
SoSeparator *root;
SoRotationXYZ *myRot;
SoSFFloat xRot;
};
#endif
++++++ model.cpp ++++++
#include <Inventor/Qt/SoQt.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
//#include <Inventor/fields/SoSFFloat.h>
#include <model.h>
Model
::Model( QWidget *parent,
const char * name,
const SbBool embed
) : SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_ALL, SoQtViewer::BROWSER, TRUE) {
QWidget *widget
= this
->buildWidget
(this
->getParentWidget
());
this->setBaseWidget(widget);
this->setDecoration(false);
}
Model::~Model() {
delete this;
/* FYI Pete:
"You can not call delete on nodes [including SoSeparators, SoRotationXYZ, etc.]
because the destructor is protected. Nodes are deleted when you call unref() on
them and the reference count goes to zero. You must of course first ref() a node
before you can unref() it." from a Coin3d developer
*/
root->unref();
myRot->unref(); //actually, I guess I shouldn't do this since I didn't "ref()" it.
}
void Model::setDefaultScene(void) {
root = new SoSeparator;
root->ref();
root->addChild(new SoCone);
this->setSceneGraph(root);
this->show();
}
++++++ main.cpp ++++++
#include <QApplication>
#include "window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
++++++ window.h ++++++
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class CoinWidget;
class QSlider;
class Window : public QWidget
{
Q_OBJECT
public:
Window();
private:
QSlider *createSlider();
CoinWidget *coinWidget;
QSlider *xSlider;
};
#endif
++++++ window.cpp ++++++
#include <QtGui>
#include "coinwidget.h"
#include "window.h"
Window::Window()
{
coinWidget = new CoinWidget;
xSlider = createSlider();
connect(xSlider, SIGNAL(valueChanged(int)), coinWidget, SLOT(setXRotation(int)));
connect(coinWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
// NOTE: above is how I did it when I thought I could place the model in
// the CoinWidget class. Now that I've a separate class, Model,
// which contains the model, I don't know how I can pass SIGNALs to
// a Model object without declaring the object here first... but which
// doesn't make sense to do. I declare the "model" object in the
// Coinwidget::Coinwidget() constructor. ...although, as I asked above:
// perhaps I should leave this as it is, then forward the signal on to the
// model class?
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(coinWidget);
mainLayout->addWidget(xSlider);
setLayout(mainLayout);
xSlider->setValue(12);
setWindowTitle(tr("Hello COIN"));
}
QSlider *Window::createSlider()
{
QSlider *slider = new QSlider(Qt::Vertical);
slider->setRange(0, 360);
slider->setSingleStep(36);
slider->setPageStep(12);
slider->setTickInterval(12);
slider->setTickPosition(QSlider::TicksRight);
return slider;
}
++++++ coinwidget.h ++++++
#ifndef COINWIDGET_H
#define COINWIDGET_H
#include <QMainWindow>
#include <Inventor/Qt/SoQt.h>
class CoinWidget : public QMainWindow
{
Q_OBJECT
public:
CoinWidget(QWidget *parent = 0);
~CoinWidget();
QSize minimumSizeHint() const;
QSize sizeHint() const;
float deg2rad(int angle) { return (angle * 3.1416/180.00); }
public slots:
// refer to other comments
void setXRotation(int angle);
signals:
// refer to other comments
void xRotationChanged(int angle);
protected:
private:
void normalizeAngle(int *angle);
};
#endif
++++++ coinwidget.cpp ++++++
#include <QtGui>
#include <QtCore>
#include <Inventor/Qt/SoQt.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include "coinwidget.h"
#include "model.h"
CoinWidget::CoinWidget(QWidget *parent) : QMainWindow(parent)
{
SoQt::init(this);
Model *model = new Model(this);
setCentralWidget(model->getWidget());
model->setDefaultScene();
}
CoinWidget::~CoinWidget() {
// delete model; // : error C2065: 'model' : undeclared identifier
// So I added "delete this;" in Model::~Model();
// Is this the proper way to delete pointer/allocated memory
// to the "model" object?
}
QSize CoinWidget::minimumSizeHint() const {
return QSize(200, 200);
}
QSize CoinWidget::sizeHint() const {
return QSize(400, 400);
}
void CoinWidget::setXRotation(int angle)
{
// I was thinking that I should delete this member function, since this Class is set up
// only to initialize the Coin3d window... but--again, as I asked above--maybe I should
// keep it, and pass the signal again to the Model class. I realize, btw, that the
// function doesn't do anything currently. I'll sort that out after I figure out how to
// route the signals/slots.
float a = deg2rad(angle);
qDebug("angle = %.4f", a);
}
++++++ model.h ++++++
#ifndef MODEL_H
#define MODEL_H
#include <Inventor/Qt/SoQt.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/fields/SoSFFloat.h>
class Model : public SoQtExaminerViewer
{
public:
Model( QWidget *parent = NULL, const char *name=NULL, const SbBool embed=TRUE);
~Model(void);
void setDefaultScene();
protected:
private:
SoSeparator *root;
SoRotationXYZ *myRot;
SoSFFloat xRot;
};
#endif
++++++ model.cpp ++++++
#include <Inventor/Qt/SoQt.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
//#include <Inventor/fields/SoSFFloat.h>
#include <model.h>
Model::Model( QWidget *parent, const char * name, const SbBool embed)
: SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_ALL, SoQtViewer::BROWSER, TRUE) {
QWidget *widget = this->buildWidget(this->getParentWidget());
this->setBaseWidget(widget);
this->setDecoration(false);
}
Model::~Model() {
delete this;
/* FYI Pete:
"You can not call delete on nodes [including SoSeparators, SoRotationXYZ, etc.]
because the destructor is protected. Nodes are deleted when you call unref() on
them and the reference count goes to zero. You must of course first ref() a node
before you can unref() it." from a Coin3d developer
*/
root->unref();
myRot->unref(); //actually, I guess I shouldn't do this since I didn't "ref()" it.
}
void Model::setDefaultScene(void) {
root = new SoSeparator;
root->ref();
root->addChild(new SoCone);
this->setSceneGraph(root);
this->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks