Made CrumblePath API a bit more consistent/generic

Was a bit confusing to pass QVariant data in and get an int back.

Change-Id: I613d2eb88ade45baee85a4f84d7db6d3ce7fb923
Reviewed-on: http://codereview.qt.nokia.com/205
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
This commit is contained in:
Thorbjørn Lindeijer
2011-05-30 11:20:06 +02:00
committed by Christiaan Janssen
parent 61fc11b9c0
commit 38c798a642
5 changed files with 27 additions and 21 deletions

View File

@@ -50,6 +50,8 @@ static const int ArrowBorderSize = 12;
class CrumblePathButton : public QPushButton
{
Q_OBJECT
public:
enum SegmentType {
LastSegment = 1,
@@ -203,10 +205,9 @@ void CrumblePathButton::mouseReleaseEvent(QMouseEvent *e)
void CrumblePathButton::changeEvent(QEvent *e)
{
if (e && e->type() == QEvent::EnabledChange) {
if (e && e->type() == QEvent::EnabledChange)
update();
}
}
void CrumblePathButton::select(bool s)
{
@@ -279,7 +280,7 @@ void CrumblePath::pushElement(const QString &title, const QVariant &data)
{
CrumblePathButton *newButton = new CrumblePathButton(title, this);
newButton->hide();
connect(newButton, SIGNAL(clicked()), SLOT(mapClickToIndex()));
connect(newButton, SIGNAL(clicked()), SLOT(emitElementClicked()));
int segType = CrumblePathButton::MiddleSegment;
if (!d->m_buttons.isEmpty()) {
@@ -298,7 +299,7 @@ void CrumblePath::pushElement(const QString &title, const QVariant &data)
void CrumblePath::addChild(const QString &title, const QVariant &data)
{
QTC_ASSERT(d->m_buttons.count() > 0,return);
QTC_ASSERT(!d->m_buttons.isEmpty(), return);
QPushButton *lastButton = d->m_buttons.last();
@@ -308,7 +309,7 @@ void CrumblePath::addChild(const QString &title, const QVariant &data)
QAction *childAction = new QAction(title, lastButton);
childAction->setData(data);
connect(childAction, SIGNAL(triggered()), this, SLOT(mapClickToIndex()));
connect(childAction, SIGNAL(triggered()), this, SLOT(emitElementClicked()));
childList->addAction(childAction);
lastButton->setMenu(childList);
}
@@ -344,7 +345,7 @@ void CrumblePath::resizeButtons()
{
int totalWidthLeft = width();
if (d->m_buttons.length() >= 1) {
if (!d->m_buttons.isEmpty()) {
QPoint nextElementPosition(0, 0);
d->m_buttons.first()->raise();
@@ -389,13 +390,15 @@ void CrumblePath::resizeButtons()
}
}
void CrumblePath::mapClickToIndex()
void CrumblePath::emitElementClicked()
{
QObject *element = sender();
if (QString("QAction") == element->metaObject()->className())
emit elementClicked(static_cast<QAction *>(element)->data().toInt());
else if (QString("QPushButton") == element->metaObject()->className())
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
if (QAction *action = qobject_cast<QAction*>(element))
emit elementClicked(action->data());
else if (CrumblePathButton *button = qobject_cast<CrumblePathButton*>(element))
emit elementClicked(button->data());
}
} // namespace Utils
#include "crumblepath.moc"

View File

@@ -50,6 +50,7 @@ class QTCREATOR_UTILS_EXPORT CrumblePath : public QWidget
public:
explicit CrumblePath(QWidget *parent = 0);
~CrumblePath();
void selectIndex(int index);
QVariant dataForIndex(int index) const;
@@ -60,13 +61,13 @@ public slots:
virtual void clear();
signals:
void elementClicked(int debugId);
void elementClicked(const QVariant &data);
protected:
void resizeEvent(QResizeEvent *);
private slots:
void mapClickToIndex();
void emitElementClicked();
private:
void resizeButtons();

View File

@@ -52,10 +52,10 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
m_isEmpty = path.isEmpty();
if (m_isEmpty) {
pushElement(tr("[no context]"),QVariant(-1));
pushElement(tr("[no context]"), -1);
} else {
for (int i = 0; i < path.count(); i++)
pushElement(path[i], QVariant(debugIds[i]));
pushElement(path[i], debugIds[i]);
}
}
@@ -63,7 +63,7 @@ void ContextCrumblePath::addChildren(const QStringList &childrenNames, const QLi
{
Q_ASSERT(childrenNames.count() == childrenDebugIds.count());
for (int i = 0; i < childrenNames.count(); i++)
addChild(childrenNames[i], QVariant(childrenDebugIds[i]));
addChild(childrenNames[i], childrenDebugIds[i]);
}
void ContextCrumblePath::clear()

View File

@@ -726,7 +726,7 @@ void InspectorUi::setupDockWidgets()
m_crumblePath = new ContextCrumblePath;
m_crumblePath->setObjectName("QmlContextPath");
m_crumblePath->setWindowTitle(tr("Context Path"));
connect(m_crumblePath, SIGNAL(elementClicked(int)), SLOT(crumblePathElementClicked(int)));
connect(m_crumblePath, SIGNAL(elementClicked(QVariant)), SLOT(crumblePathElementClicked(QVariant)));
m_propertyInspector = new QmlJSPropertyInspector;
@@ -759,9 +759,11 @@ void InspectorUi::setupDockWidgets()
dock->setTitleBarWidget(new QWidget(dock));
}
void InspectorUi::crumblePathElementClicked(int debugId)
void InspectorUi::crumblePathElementClicked(const QVariant &data)
{
if (debugId == -1)
bool ok;
const int debugId = data.toInt(&ok);
if (!ok || debugId == -1)
return;
QList<int> debugIds;

View File

@@ -129,7 +129,7 @@ private slots:
QmlJSLiveTextPreview *createPreviewForEditor(Core::IEditor *newEditor);
void disableLivePreview();
void crumblePathElementClicked(int);
void crumblePathElementClicked(const QVariant &data);
void currentDebugProjectRemoved();
void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc);