Remove one hack of the QTipLabel hack.

This code used two hacks: it created a class with
metaObject()->className() == "QTipLabel" to fool the code in Qt into
applying the style properly to this class.

But it did that by creating a class called QTipLabel. This works as
long as the class in Qt is hidden by symbol visibility. When symbol
visibility is disabled (for whatever reason), then Creator simply
crashes due to size mismatches and memory corruptions (virtual tables,
etc.)

This patch makes the class be called TextEditor::Internal::QTipLabel,
but fools moc into thinking it isn't.

A proper solution would be to simply override the meta object.

Signed-off-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
Thiago Macieira
2010-08-31 17:41:34 +02:00
committed by Leandro Melo
parent 67d0ab3fac
commit 7e48b8e5be
5 changed files with 18 additions and 19 deletions

View File

@@ -40,7 +40,7 @@ TipFactory::TipFactory()
TipFactory::~TipFactory() TipFactory::~TipFactory()
{} {}
QTipLabel *TipFactory::createTip(const TipContent &content, QWidget *w) Internal::QTipLabel *TipFactory::createTip(const TipContent &content, QWidget *w)
{ {
QTipLabel *tip = 0; QTipLabel *tip = 0;
if (content.typeId() == TextContent::TEXT_CONTENT_ID) if (content.typeId() == TextContent::TEXT_CONTENT_ID)

View File

@@ -32,15 +32,12 @@
#include <QtGui/QWidget> #include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QTipLabel;
QT_END_NAMESPACE
namespace TextEditor { namespace TextEditor {
class TipContent; class TipContent;
namespace Internal { namespace Internal {
class QTipLabel;
class TipFactory class TipFactory
{ {

View File

@@ -41,8 +41,8 @@
#include <QtGui/QStylePainter> #include <QtGui/QStylePainter>
#include <QtGui/QStyleOptionFrame> #include <QtGui/QStyleOptionFrame>
using namespace TextEditor; namespace TextEditor {
using namespace Internal; namespace Internal {
namespace { namespace {
// @todo: Reuse... // @todo: Reuse...
@@ -59,8 +59,6 @@ namespace {
} }
} }
QT_BEGIN_NAMESPACE
QTipLabel::QTipLabel(QWidget *parent) : QTipLabel::QTipLabel(QWidget *parent) :
QLabel(parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), QLabel(parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget),
m_tipContent(0) m_tipContent(0)
@@ -83,8 +81,6 @@ void QTipLabel::setContent(const TipContent &content)
const TipContent &QTipLabel::content() const const TipContent &QTipLabel::content() const
{ return *m_tipContent; } { return *m_tipContent; }
QT_END_NAMESPACE
ColorTip::ColorTip(QWidget *parent) : QTipLabel(parent) ColorTip::ColorTip(QWidget *parent) : QTipLabel(parent)
{ {
resize(QSize(40, 40)); resize(QSize(40, 40));
@@ -183,3 +179,9 @@ void TextTip::resizeEvent(QResizeEvent *event)
QLabel::resizeEvent(event); QLabel::resizeEvent(event);
} }
// need to include it here to force it to be inside the namespaces
#include "moc_tips.cpp"
} // namespace Internal
} // namespace TextEditor

View File

@@ -38,7 +38,10 @@ namespace TextEditor {
class TipContent; class TipContent;
} }
QT_BEGIN_NAMESPACE #ifndef Q_MOC_RUN
namespace TextEditor {
namespace Internal {
#endif
// Please do not change the name of this class. Detailed comments in tooltip.h. // Please do not change the name of this class. Detailed comments in tooltip.h.
class QTipLabel : public QLabel class QTipLabel : public QLabel
@@ -60,11 +63,6 @@ private:
TextEditor::TipContent *m_tipContent; TextEditor::TipContent *m_tipContent;
}; };
QT_END_NAMESPACE
namespace TextEditor {
namespace Internal {
class ColorTip : public QTipLabel class ColorTip : public QTipLabel
{ {
Q_OBJECT Q_OBJECT
@@ -96,7 +94,9 @@ private:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
}; };
#ifndef Q_MOC_RUN
} // namespace Internal } // namespace Internal
} // namespace TextEditor } // namespace TextEditor
#endif
#endif // TIPS_H #endif // TIPS_H

View File

@@ -49,13 +49,13 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPoint; class QPoint;
class QWidget; class QWidget;
class QTipLabel;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace TextEditor { namespace TextEditor {
namespace Internal { namespace Internal {
class TipFactory; class TipFactory;
class QTipLabel;
} }
class TipContent; class TipContent;
@@ -93,7 +93,7 @@ private:
void hideTipWithDelay(); void hideTipWithDelay();
Internal::TipFactory *m_tipFactory; Internal::TipFactory *m_tipFactory;
QTipLabel *m_tip; Internal::QTipLabel *m_tip;
QWidget *m_widget; QWidget *m_widget;
QRect m_rect; QRect m_rect;
QTimer m_showTimer; QTimer m_showTimer;