forked from qt-creator/qt-creator
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:
committed by
Christiaan Janssen
parent
61fc11b9c0
commit
38c798a642
@@ -50,6 +50,8 @@ static const int ArrowBorderSize = 12;
|
|||||||
|
|
||||||
class CrumblePathButton : public QPushButton
|
class CrumblePathButton : public QPushButton
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum SegmentType {
|
enum SegmentType {
|
||||||
LastSegment = 1,
|
LastSegment = 1,
|
||||||
@@ -201,11 +203,10 @@ void CrumblePathButton::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumblePathButton::changeEvent(QEvent * e)
|
void CrumblePathButton::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e && e->type() == QEvent::EnabledChange) {
|
if (e && e->type() == QEvent::EnabledChange)
|
||||||
update();
|
update();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumblePathButton::select(bool s)
|
void CrumblePathButton::select(bool s)
|
||||||
@@ -279,7 +280,7 @@ void CrumblePath::pushElement(const QString &title, const QVariant &data)
|
|||||||
{
|
{
|
||||||
CrumblePathButton *newButton = new CrumblePathButton(title, this);
|
CrumblePathButton *newButton = new CrumblePathButton(title, this);
|
||||||
newButton->hide();
|
newButton->hide();
|
||||||
connect(newButton, SIGNAL(clicked()), SLOT(mapClickToIndex()));
|
connect(newButton, SIGNAL(clicked()), SLOT(emitElementClicked()));
|
||||||
|
|
||||||
int segType = CrumblePathButton::MiddleSegment;
|
int segType = CrumblePathButton::MiddleSegment;
|
||||||
if (!d->m_buttons.isEmpty()) {
|
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)
|
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();
|
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);
|
QAction *childAction = new QAction(title, lastButton);
|
||||||
childAction->setData(data);
|
childAction->setData(data);
|
||||||
connect(childAction, SIGNAL(triggered()), this, SLOT(mapClickToIndex()));
|
connect(childAction, SIGNAL(triggered()), this, SLOT(emitElementClicked()));
|
||||||
childList->addAction(childAction);
|
childList->addAction(childAction);
|
||||||
lastButton->setMenu(childList);
|
lastButton->setMenu(childList);
|
||||||
}
|
}
|
||||||
@@ -344,7 +345,7 @@ void CrumblePath::resizeButtons()
|
|||||||
{
|
{
|
||||||
int totalWidthLeft = width();
|
int totalWidthLeft = width();
|
||||||
|
|
||||||
if (d->m_buttons.length() >= 1) {
|
if (!d->m_buttons.isEmpty()) {
|
||||||
QPoint nextElementPosition(0, 0);
|
QPoint nextElementPosition(0, 0);
|
||||||
|
|
||||||
d->m_buttons.first()->raise();
|
d->m_buttons.first()->raise();
|
||||||
@@ -389,13 +390,15 @@ void CrumblePath::resizeButtons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumblePath::mapClickToIndex()
|
void CrumblePath::emitElementClicked()
|
||||||
{
|
{
|
||||||
QObject *element = sender();
|
QObject *element = sender();
|
||||||
if (QString("QAction") == element->metaObject()->className())
|
if (QAction *action = qobject_cast<QAction*>(element))
|
||||||
emit elementClicked(static_cast<QAction *>(element)->data().toInt());
|
emit elementClicked(action->data());
|
||||||
else if (QString("QPushButton") == element->metaObject()->className())
|
else if (CrumblePathButton *button = qobject_cast<CrumblePathButton*>(element))
|
||||||
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
|
emit elementClicked(button->data());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
|
#include "crumblepath.moc"
|
||||||
|
@@ -50,6 +50,7 @@ class QTCREATOR_UTILS_EXPORT CrumblePath : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit CrumblePath(QWidget *parent = 0);
|
explicit CrumblePath(QWidget *parent = 0);
|
||||||
~CrumblePath();
|
~CrumblePath();
|
||||||
|
|
||||||
void selectIndex(int index);
|
void selectIndex(int index);
|
||||||
QVariant dataForIndex(int index) const;
|
QVariant dataForIndex(int index) const;
|
||||||
|
|
||||||
@@ -60,13 +61,13 @@ public slots:
|
|||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void elementClicked(int debugId);
|
void elementClicked(const QVariant &data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mapClickToIndex();
|
void emitElementClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeButtons();
|
void resizeButtons();
|
||||||
|
@@ -52,10 +52,10 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
|
|||||||
|
|
||||||
m_isEmpty = path.isEmpty();
|
m_isEmpty = path.isEmpty();
|
||||||
if (m_isEmpty) {
|
if (m_isEmpty) {
|
||||||
pushElement(tr("[no context]"),QVariant(-1));
|
pushElement(tr("[no context]"), -1);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < path.count(); i++)
|
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());
|
Q_ASSERT(childrenNames.count() == childrenDebugIds.count());
|
||||||
for (int i = 0; i < childrenNames.count(); i++)
|
for (int i = 0; i < childrenNames.count(); i++)
|
||||||
addChild(childrenNames[i], QVariant(childrenDebugIds[i]));
|
addChild(childrenNames[i], childrenDebugIds[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextCrumblePath::clear()
|
void ContextCrumblePath::clear()
|
||||||
|
@@ -726,7 +726,7 @@ void InspectorUi::setupDockWidgets()
|
|||||||
m_crumblePath = new ContextCrumblePath;
|
m_crumblePath = new ContextCrumblePath;
|
||||||
m_crumblePath->setObjectName("QmlContextPath");
|
m_crumblePath->setObjectName("QmlContextPath");
|
||||||
m_crumblePath->setWindowTitle(tr("Context Path"));
|
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;
|
m_propertyInspector = new QmlJSPropertyInspector;
|
||||||
|
|
||||||
@@ -759,9 +759,11 @@ void InspectorUi::setupDockWidgets()
|
|||||||
dock->setTitleBarWidget(new QWidget(dock));
|
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;
|
return;
|
||||||
|
|
||||||
QList<int> debugIds;
|
QList<int> debugIds;
|
||||||
|
@@ -129,7 +129,7 @@ private slots:
|
|||||||
QmlJSLiveTextPreview *createPreviewForEditor(Core::IEditor *newEditor);
|
QmlJSLiveTextPreview *createPreviewForEditor(Core::IEditor *newEditor);
|
||||||
|
|
||||||
void disableLivePreview();
|
void disableLivePreview();
|
||||||
void crumblePathElementClicked(int);
|
void crumblePathElementClicked(const QVariant &data);
|
||||||
|
|
||||||
void currentDebugProjectRemoved();
|
void currentDebugProjectRemoved();
|
||||||
void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc);
|
void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc);
|
||||||
|
Reference in New Issue
Block a user