Skip to content

Commit

Permalink
Merge branch 'Issue#14'
Browse files Browse the repository at this point in the history
* Issue#14:
  Some design changes (issue #14)
  • Loading branch information
Alberto Losi committed Jan 23, 2013
2 parents a2c99ea + 3e6b288 commit 3ce954c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 101 deletions.
34 changes: 15 additions & 19 deletions Libs/Qt/Widgets/msvQVTKButtons.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class msvQVTKButtonsPrivate
protected:

msvQVTKButtons* const q_ptr;
msvVTKButtons* m_VTKButtons;
vtkCommand* m_HighlightCallback;
msvVTKButtons* VtkButton;
vtkCommand* HighlightCallback;

public:
msvQVTKButtonsPrivate(msvQVTKButtons& object);
Expand All @@ -109,28 +109,25 @@ class msvQVTKButtonsPrivate

//------------------------------------------------------------------------------
msvQVTKButtonsPrivate::msvQVTKButtonsPrivate(msvQVTKButtons& object)
: m_VTKButtons(NULL), q_ptr(&object)
: VtkButton(NULL), q_ptr(&object)
{
Q_Q(msvQVTKButtons);
//static_cast<msvVTKButtons*>(this->vtkButtons());
//m_VTKButton = msvVTKButtons::New();
this->m_HighlightCallback = vtkButtonHighLightCallback::New();
reinterpret_cast<vtkButtonHighLightCallback*>(
this->m_HighlightCallback)->ToolButton = q;
Q_Q(msvQVTKButtons);
this->HighlightCallback = vtkButtonHighLightCallback::New();
reinterpret_cast<vtkButtonHighLightCallback*>(
this->HighlightCallback)->ToolButton = q;

static_cast<msvVTKButtons*>(this->vtkButtons())->GetButton()->GetRepresentation()->AddObserver(vtkCommand::HighlightEvent,this->m_HighlightCallback);
q->setVTKButtonsInterface(this->vtkButtons());
static_cast<msvVTKButtons*>(this->vtkButtons())->GetButton()->GetRepresentation()->AddObserver(vtkCommand::HighlightEvent,this->HighlightCallback);
}

//------------------------------------------------------------------------------
/*virtual*/ msvVTKButtonsInterface* msvQVTKButtonsPrivate::vtkButtons()
{
Q_Q(msvQVTKButtons);
if(!this->m_VTKButtons)
{
this->m_VTKButtons = msvVTKButtons::New();
q->setVTKButtonsInterface(this->m_VTKButtons);
}
return this->m_VTKButtons;
if(!this->VtkButton)
{
this->VtkButton = msvVTKButtons::New();
}
return this->VtkButton;
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -200,7 +197,6 @@ QImage msvQVTKButtons::getPreview(int width, int height)
vtkUnsignedCharArray::SafeDownCast(
vtkImage->GetPointData()->GetScalars());

vtkImage->Delete();
if(!width || !height || !scalars)
return QImage();
QImage qImage(width, height, QImage::Format_ARGB32);
Expand All @@ -217,7 +213,7 @@ QImage msvQVTKButtons::getPreview(int width, int height)
*(qImageBits+(qImageBitIndex++))=color;
}
}

vtkImage->Delete();
return qImage;
}
return QImage();
Expand Down
42 changes: 19 additions & 23 deletions Libs/Qt/Widgets/msvQVTKButtonsGroup.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class msvQVTKButtonsGroupPrivate
protected:

msvQVTKButtonsGroup* const q_ptr;
QVector<msvQVTKButtonsInterface*> m_Elements;
msvVTKButtonsGroup* m_VTKButtons;
QVector<msvQVTKButtonsInterface*> Elements;
msvVTKButtonsGroup* VtkButtonsGroup;

public:
msvQVTKButtonsGroupPrivate(msvQVTKButtonsGroup& object);
Expand All @@ -60,7 +60,7 @@ class msvQVTKButtonsGroupPrivate
void update(){static_cast<msvVTKButtonsGroup*>(this->vtkButtons())->Update();};

msvQVTKButtonsInterface* getElement(int index);
inline int numberOfElements(){return m_Elements.size();};
inline int numberOfElements(){return Elements.size();};
void addElement(msvQVTKButtonsInterface* buttons);
void removeElement(msvQVTKButtonsInterface* buttons);
virtual msvVTKButtonsInterface* vtkButtons();
Expand All @@ -69,22 +69,20 @@ class msvQVTKButtonsGroupPrivate

//------------------------------------------------------------------------------
msvQVTKButtonsGroupPrivate::msvQVTKButtonsGroupPrivate(msvQVTKButtonsGroup& object)
: m_VTKButtons(NULL), q_ptr(&object)
: VtkButtonsGroup(NULL), q_ptr(&object)
{
static_cast<msvVTKButtonsGroup*>(this->vtkButtons());
//m_VTKButtonsGroup = msvVTKButtonsGroup::New();
Q_Q(msvQVTKButtonsGroup);
q->setVTKButtonsInterface(this->vtkButtons());
}

//------------------------------------------------------------------------------
/*virtual*/ msvVTKButtonsInterface* msvQVTKButtonsGroupPrivate::vtkButtons()
{
Q_Q(msvQVTKButtonsGroup);
if(!this->m_VTKButtons)
if(!this->VtkButtonsGroup)
{
this->m_VTKButtons = msvVTKButtonsGroup::New();
q->setVTKButtonsInterface(this->m_VTKButtons);
this->VtkButtonsGroup = msvVTKButtonsGroup::New();
}
return this->m_VTKButtons;
return this->VtkButtonsGroup;
}

//------------------------------------------------------------------------------
Expand All @@ -104,8 +102,8 @@ void msvQVTKButtonsGroupPrivate::addElement(msvQVTKButtonsInterface* buttons)
buttons->bounds(b);
double dimension = (b[1]-b[0])*(b[3]-b[2])*(b[5]-b[4]);
q->connect(buttons, SIGNAL(show(bool)), q, SLOT(show(bool)));
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = m_Elements.begin();
buttonsIt != m_Elements.end(); buttonsIt++)
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = Elements.begin();
buttonsIt != Elements.end(); buttonsIt++)
{
if(*buttonsIt == buttons)
{
Expand All @@ -115,25 +113,25 @@ void msvQVTKButtonsGroupPrivate::addElement(msvQVTKButtonsInterface* buttons)
double cur_dimension = (b[1]-b[0])*(b[3]-b[2])*(b[5]-b[4]);
if(dimension > cur_dimension)
{
m_Elements.insert(i,buttons);
Elements.insert(i,buttons);
return;
}
i++;
}
m_Elements.push_back(buttons);
Elements.push_back(buttons);
}

//------------------------------------------------------------------------------
void msvQVTKButtonsGroupPrivate::removeElement(msvQVTKButtonsInterface* buttons)
{
// remove elements on both vectors
int index = 0;
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = m_Elements.begin();
buttonsIt != m_Elements.end(); buttonsIt++)
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = Elements.begin();
buttonsIt != Elements.end(); buttonsIt++)
{
if(*buttonsIt == buttons)
{
m_Elements.remove(index);
Elements.remove(index);
return;
}
index++;
Expand All @@ -144,11 +142,11 @@ void msvQVTKButtonsGroupPrivate::removeElement(msvQVTKButtonsInterface* buttons)
//------------------------------------------------------------------------------
msvQVTKButtonsInterface* msvQVTKButtonsGroupPrivate::getElement(int index)
{
if(index > m_Elements.size() - 1)
if(index > Elements.size() - 1)
{
return NULL;
}
return m_Elements.at(index);
return Elements.at(index);
}

//------------------------------------------------------------------------------
Expand All @@ -165,11 +163,9 @@ void msvQVTKButtonsGroupPrivate::setIconFileName(QString iconfilename)

//------------------------------------------------------------------------------
msvQVTKButtonsGroup::msvQVTKButtonsGroup(QObject *parent)
: msvQVTKButtonsInterface(), m_SliderCallback(NULL),
d_ptr(new msvQVTKButtonsGroupPrivate(*this))
: msvQVTKButtonsInterface(), d_ptr(new msvQVTKButtonsGroupPrivate(*this))
{
Q_UNUSED(parent);

}

//------------------------------------------------------------------------------
Expand Down
7 changes: 0 additions & 7 deletions Libs/Qt/Widgets/msvQVTKButtonsGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
class vtkRenderer;
class msvQVTKButtons;
class vtkSliderWidget;
class vtkSliderCallback;
class vtkSliderCallback2;
class vtkCommand;

// Pimpl
Expand Down Expand Up @@ -102,11 +100,6 @@ public slots:
/// Calculate element position
void calculatePosition();

// QVector<msvQVTKButtonsInterface*> m_Elements; //< Vector of buttons
// vtkSliderWidget* m_Slider; //< Slider widget
vtkSliderCallback* m_SliderCallback; //< Slider callback function
vtkSliderCallback2* m_SliderCallback2; //< Slider callback function

private:
Q_DECLARE_PRIVATE(msvQVTKButtonsGroup);
Q_DISABLE_COPY(msvQVTKButtonsGroup);
Expand Down
26 changes: 13 additions & 13 deletions Libs/Qt/Widgets/msvQVTKButtonsInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ class msvQVTKButtonsInterfacePrivate

protected:
msvQVTKButtonsInterface* const q_ptr; ///< PIMPL pointer
msvVTKButtonsInterface* m_VTKButtons;
QString m_IconFileName;
msvQVTKButtonsAction* m_Action;
msvVTKButtonsInterface* VtkButtonsInterface;
QString IconFileName;
msvQVTKButtonsAction* Action;

public:
inline void setLabel(QString label){this->vtkButtonsInterface()->SetLabel(label.toAscii());};
inline QString label(){return QString(this->vtkButtonsInterface()->GetLabel());};
inline void setLabel(QString label){this->vtkButtonsInterface()->SetLabelText(label.toAscii());};
inline QString label(){return QString(this->vtkButtonsInterface()->GetLabelText());};
inline void setTooltip(QString tooltip){this->vtkButtonsInterface()->SetTooltip(tooltip.toStdString().c_str());};
inline QString tooltip(){return QString(this->vtkButtonsInterface()->GetTooltip());};
inline QString iconFileName(){return m_IconFileName;};
inline QString iconFileName(){return IconFileName;};
inline void setShowButton(bool show){this->vtkButtonsInterface()->SetShowButton(show);};
inline bool showButton(){return this->vtkButtonsInterface()->GetShowButton();};
inline void setShowLabel(bool show){this->vtkButtonsInterface()->SetShowLabel(show);};
inline bool showLabel(){return this->vtkButtonsInterface()->GetShowLabel();};
inline void setAction(msvQVTKButtonsAction* action){m_Action = action;};
inline msvQVTKButtonsAction* action(){return m_Action;};
inline void setAction(msvQVTKButtonsAction* action){Action = action;};
inline msvQVTKButtonsAction* action(){return Action;};
inline vtkButtonWidget* button(){return this->vtkButtonsInterface()->GetButton();};
inline void setBounds(double bds[6]){this->vtkButtonsInterface()->SetBounds(bds);};
inline void bounds(double bds[6]){this->vtkButtonsInterface()->GetBounds(bds);};
inline void update(){this->vtkButtonsInterface()->Update();};
inline void setCurrentRenderer(vtkRenderer* renderer){this->vtkButtonsInterface()->SetCurrentRenderer(renderer);};
inline void setVTKButtonsInterface(msvVTKButtonsInterface *buttons){this->m_VTKButtons = buttons;};
inline void setVTKButtonsInterface(msvVTKButtonsInterface *buttons){this->VtkButtonsInterface = buttons;};
void setIconFileName(QString iconfilename);
msvQVTKButtonsInterfacePrivate(msvQVTKButtonsInterface& object);
virtual msvVTKButtonsInterface* vtkButtonsInterface();
Expand All @@ -65,15 +65,15 @@ class msvQVTKButtonsInterfacePrivate

//------------------------------------------------------------------------------
msvQVTKButtonsInterfacePrivate::msvQVTKButtonsInterfacePrivate(msvQVTKButtonsInterface& object)
: m_VTKButtons(NULL), q_ptr(&object)
: VtkButtonsInterface(NULL), q_ptr(&object)
{

}

//------------------------------------------------------------------------------
/*virtual*/ msvVTKButtonsInterface* msvQVTKButtonsInterfacePrivate::vtkButtonsInterface()
{
return m_VTKButtons;
return VtkButtonsInterface;
}

//------------------------------------------------------------------------------
Expand All @@ -85,8 +85,8 @@ msvQVTKButtonsInterfacePrivate::~msvQVTKButtonsInterfacePrivate()
//------------------------------------------------------------------------------
void msvQVTKButtonsInterfacePrivate::setIconFileName(QString iconfilename)
{
m_IconFileName = iconfilename; QImage image;
image.load(m_IconFileName);
IconFileName = iconfilename; QImage image;
image.load(IconFileName);
vtkQImageToImageSource *imageToVTK = vtkQImageToImageSource::New();
imageToVTK->SetQImage(&image);
imageToVTK->Update();
Expand Down
7 changes: 0 additions & 7 deletions Libs/Qt/Widgets/msvQVTKButtonsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MSV_QT_WIDGETS_EXPORT msvQVTKButtonsInterface : public QObject {
Q_PROPERTY(bool showLabel READ showLabel WRITE setShowLabel);

public:

/// Object constructor
msvQVTKButtonsInterface(QObject *parent = 0);

Expand Down Expand Up @@ -123,15 +122,9 @@ class MSV_QT_WIDGETS_EXPORT msvQVTKButtonsInterface : public QObject {
void show(bool show);

protected:

QScopedPointer<msvQVTKButtonsInterfacePrivate> d_ptr;
vtkCommand *m_ButtonCallback; ///< Callback called by picking on vtkButton
vtkCommand *m_HighlightCallback; ///< Callback called by hovering over the button.

//virtual void calculatePosition() = 0;

private:

Q_DECLARE_PRIVATE(msvQVTKButtonsInterface);
Q_DISABLE_COPY(msvQVTKButtonsInterface);
};
Expand Down
18 changes: 9 additions & 9 deletions Libs/Qt/Widgets/msvQVTKButtonsManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class msvQVTKButtonsManagerPrivate
protected:

msvQVTKButtonsManager* const q_ptr;
QVector<msvQVTKButtonsInterface*> m_Elements; //< Vector of buttons
QVector<msvQVTKButtonsInterface*> Elements; //< Vector of buttons

public:

Expand All @@ -57,8 +57,8 @@ msvQVTKButtonsManagerPrivate::~msvQVTKButtonsManagerPrivate()
//------------------------------------------------------------------------------
void msvQVTKButtonsManagerPrivate::setElementProperty(QString name, QVariant value)
{
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = m_Elements.begin();
buttonsIt != m_Elements.end(); buttonsIt++)
for(QVector<msvQVTKButtonsInterface*>::iterator buttonsIt = Elements.begin();
buttonsIt != Elements.end(); buttonsIt++)
{
(*buttonsIt)->setProperty(name.toStdString().c_str(),value);
}
Expand All @@ -67,17 +67,17 @@ void msvQVTKButtonsManagerPrivate::setElementProperty(QString name, QVariant val
//------------------------------------------------------------------------------
msvQVTKButtonsGroup *msvQVTKButtonsManagerPrivate::createGroup()
{
m_Elements.push_back(new msvQVTKButtonsGroup());
msvVTKButtonsManager::GetInstance()->AddElement(m_Elements.at(m_Elements.size()-1)->vtkButtonsInterface());
return static_cast<msvQVTKButtonsGroup*>(m_Elements.at(m_Elements.size()-1));
Elements.push_back(new msvQVTKButtonsGroup());
msvVTKButtonsManager::GetInstance()->AddElement(Elements.at(Elements.size()-1)->vtkButtonsInterface());
return static_cast<msvQVTKButtonsGroup*>(Elements.at(Elements.size()-1));
}

//------------------------------------------------------------------------------
msvQVTKButtons *msvQVTKButtonsManagerPrivate::createButtons()
{
m_Elements.push_back(new msvQVTKButtons());
msvVTKButtonsManager::GetInstance()->AddElement(m_Elements.at(m_Elements.size()-1)->vtkButtonsInterface());
return static_cast<msvQVTKButtons*>(m_Elements.at(m_Elements.size()-1));
Elements.push_back(new msvQVTKButtons());
msvVTKButtonsManager::GetInstance()->AddElement(Elements.at(Elements.size()-1)->vtkButtonsInterface());
return static_cast<msvQVTKButtons*>(Elements.at(Elements.size()-1));
}

//------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions Libs/VTK/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ endif()
# Sources
# --------------------------------------------------------------------------
set(msvVTKWidgets_SRCS
msvVTKProp3DButtonRepresentation.cxx
msvVTKSliderFixedRepresentation2D.cxx
msvVTKButtonsInterface.cxx
msvVTKButtons.cxx
msvVTKButtonsGroup.cxx
msvVTKAnimate.cxx
msvVTKButtons.cxx
msvVTKButtonsAction.cxx
msvVTKButtonsGroup.cxx
msvVTKButtonsInterface.cxx
msvVTKButtonsManager.cxx
msvVTKProp3DButtonRepresentation.cxx
msvVTKSliderFixedRepresentation2D.cxx
)

# Abstract/pure virtual classes
Expand Down
13 changes: 1 addition & 12 deletions Libs/VTK/Widgets/msvVTKButtonsInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ void msvVTKButtonsInterface::SetCurrentRenderer(vtkRenderer* renderer)
}
}

void msvVTKButtonsInterface::SetLabel(const char* label)
{
if(NULL!=this->LabelText)
{
delete[] this->LabelText;
this->LabelText = NULL;
}
this->LabelText = new char[strlen(label)+1];
strcpy(this->LabelText,label);
}

//----------------------------------------------------------------------
void msvVTKButtonsInterface::Update()
{
Expand All @@ -139,7 +128,7 @@ void msvVTKButtonsInterface::Update()
if (this->GetShowLabel())
{
//Add a label to the button and change its text property
rep->GetBalloon()->SetBalloonText(this->GetLabel());
rep->GetBalloon()->SetBalloonText(this->GetLabelText());
vtkTextProperty *textProp = rep->GetBalloon()->GetTextProperty();
rep->GetBalloon()->SetPadding(2);
textProp->SetFontSize(13);
Expand Down
Loading

0 comments on commit 3ce954c

Please sign in to comment.