forked from qt-creator/qt-creator
QmlJSInspector: Code cosmetics
This commit is contained in:
@@ -61,8 +61,9 @@ public:
|
||||
explicit CrumblePathButton(const QString &title, QWidget *parent = 0);
|
||||
void setSegmentType(int type);
|
||||
void select(bool s);
|
||||
void setData(QVariant data);
|
||||
void setData(const QVariant &data);
|
||||
QVariant data() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
@@ -148,7 +149,9 @@ void CrumblePathButton::paintEvent(QPaintEvent *)
|
||||
p.drawText(QRectF(m_textPos.x(), 4, geom.width(), geom.height()), textToDraw);
|
||||
|
||||
if (menu()) {
|
||||
p.drawImage(geom.width() - m_triangleIcon.width() - 6, geom.center().y() - m_triangleIcon.height()/2, m_triangleIcon);
|
||||
p.drawImage(geom.width() - m_triangleIcon.width() - 6,
|
||||
geom.center().y() - m_triangleIcon.height() / 2,
|
||||
m_triangleIcon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +206,7 @@ void CrumblePathButton::setSegmentType(int type)
|
||||
m_textPos.setX(useLeftPadding ? 18 : 4);
|
||||
}
|
||||
|
||||
void CrumblePathButton::setData(QVariant data)
|
||||
void CrumblePathButton::setData(const QVariant &data)
|
||||
{
|
||||
m_data = data;
|
||||
}
|
||||
@@ -329,14 +332,14 @@ void CrumblePath::resizeButtons()
|
||||
if (d->m_buttons.length() >= 1) {
|
||||
QPoint nextElementPosition(0, 0);
|
||||
|
||||
d->m_buttons[0]->raise();
|
||||
d->m_buttons.first()->raise();
|
||||
// rearrange all items so that the first item is on top (added last).
|
||||
|
||||
// compute relative sizes
|
||||
QList<int> sizes;
|
||||
int totalSize = 0;
|
||||
for (int i = 0; i < d->m_buttons.length() ; ++i) {
|
||||
CrumblePathButton *button = d->m_buttons[i];
|
||||
CrumblePathButton *button = d->m_buttons.at(i);
|
||||
|
||||
QFontMetrics fm(button->font());
|
||||
int originalSize = ArrowBorderSize + fm.width(button->text()) + ArrowBorderSize + 12;
|
||||
@@ -345,14 +348,13 @@ void CrumblePath::resizeButtons()
|
||||
}
|
||||
|
||||
for (int i = 0; i < d->m_buttons.length() ; ++i) {
|
||||
CrumblePathButton *button = d->m_buttons[i];
|
||||
CrumblePathButton *button = d->m_buttons.at(i);
|
||||
|
||||
int candidateSize = (sizes[i] * totalWidthLeft) / totalSize;
|
||||
int candidateSize = (sizes.at(i) * totalWidthLeft) / totalSize;
|
||||
if (candidateSize < ArrowBorderSize)
|
||||
candidateSize = ArrowBorderSize;
|
||||
if (candidateSize > sizes[i] * 1.3)
|
||||
candidateSize = sizes[i] * 1.3;
|
||||
|
||||
if (candidateSize > sizes.at(i) * 1.3)
|
||||
candidateSize = sizes.at(i) * 1.3;
|
||||
|
||||
button->setMinimumWidth(candidateSize);
|
||||
button->setMaximumWidth(candidateSize);
|
||||
@@ -370,12 +372,10 @@ void CrumblePath::resizeButtons()
|
||||
void CrumblePath::mapClickToIndex()
|
||||
{
|
||||
QObject *element = sender();
|
||||
if (QString("QAction") == element->metaObject()->className()) {
|
||||
if (QString("QAction") == element->metaObject()->className())
|
||||
emit elementClicked(static_cast<QAction *>(element)->data().toInt());
|
||||
} else
|
||||
if (QString("QPushButton") == element->metaObject()->className()) {
|
||||
else if (QString("QPushButton") == element->metaObject()->className())
|
||||
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -63,10 +63,9 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
|
||||
void ContextCrumblePath::addChildren(const QStringList &childrenNames, const QList<int> &childrenDebugIds)
|
||||
{
|
||||
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]));
|
||||
}
|
||||
}
|
||||
|
||||
bool ContextCrumblePath::isEmpty() const
|
||||
{
|
||||
|
||||
@@ -535,7 +535,7 @@ inline QDeclarativeDebugObjectReference findParentRecursive( int goalDebugId,
|
||||
|
||||
void InspectorUi::selectItems(const QList<QDeclarativeDebugObjectReference> &objectReferences)
|
||||
{
|
||||
foreach (const QDeclarativeDebugObjectReference &objref, objectReferences)
|
||||
foreach (const QDeclarativeDebugObjectReference &objref, objectReferences) {
|
||||
if (objref.debugId() != -1) {
|
||||
// select only the first valid element of the list
|
||||
|
||||
@@ -549,6 +549,7 @@ void InspectorUi::selectItems(const QList<QDeclarativeDebugObjectReference> &obj
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline QString displayName(const QDeclarativeDebugObjectReference &obj)
|
||||
{
|
||||
|
||||
@@ -44,14 +44,8 @@ InspectorSettings::InspectorSettings(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
InspectorSettings::~InspectorSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InspectorSettings::restoreSettings(QSettings *settings)
|
||||
{
|
||||
|
||||
settings->beginGroup(QLatin1String(QmlJSInspector::Constants::S_QML_INSPECTOR));
|
||||
m_showLivePreviewWarning = settings->value(QLatin1String(QmlJSInspector::Constants::S_LIVE_PREVIEW_WARNING_KEY), true).toBool();
|
||||
settings->endGroup();
|
||||
@@ -64,7 +58,6 @@ void InspectorSettings::saveSettings(QSettings *settings) const
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
|
||||
bool InspectorSettings::showLivePreviewWarning() const
|
||||
{
|
||||
return m_showLivePreviewWarning;
|
||||
|
||||
@@ -47,7 +47,7 @@ class InspectorSettings : public QObject
|
||||
|
||||
public:
|
||||
InspectorSettings(QObject *parent = 0);
|
||||
~InspectorSettings();
|
||||
|
||||
void restoreSettings(QSettings *settings);
|
||||
void saveSettings(QSettings *settings) const;
|
||||
|
||||
|
||||
@@ -149,9 +149,10 @@ private:
|
||||
// expressionEdit
|
||||
// *************************************************************************
|
||||
|
||||
ExpressionEdit::ExpressionEdit(const QString & title, QDialog *parent):QDialog(parent),
|
||||
m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel)),
|
||||
m_exprInput(new QLineEdit(this))
|
||||
ExpressionEdit::ExpressionEdit(const QString &title, QDialog *parent)
|
||||
: QDialog(parent)
|
||||
, m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel))
|
||||
, m_exprInput(new QLineEdit(this))
|
||||
{
|
||||
setWindowTitle(title);
|
||||
|
||||
@@ -166,7 +167,6 @@ ExpressionEdit::ExpressionEdit(const QString & title, QDialog *parent):QDialog(p
|
||||
connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
}
|
||||
|
||||
|
||||
QString ExpressionEdit::expression() const
|
||||
{
|
||||
return m_exprInput->text();
|
||||
@@ -178,7 +178,8 @@ void ExpressionEdit::setItemData(int objectId, const QString &propertyName)
|
||||
m_paramName = propertyName;
|
||||
}
|
||||
|
||||
void ExpressionEdit::accept() {
|
||||
void ExpressionEdit::accept()
|
||||
{
|
||||
QDialog::accept();
|
||||
emit dataChanged(m_debugId, m_paramName, expression());
|
||||
}
|
||||
@@ -187,7 +188,8 @@ void ExpressionEdit::accept() {
|
||||
// color chooser
|
||||
// *************************************************************************
|
||||
|
||||
ColorChooserDialog::ColorChooserDialog(const QString & title, QDialog *parent):QDialog(parent)
|
||||
ColorChooserDialog::ColorChooserDialog(const QString &title, QDialog *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle(title);
|
||||
|
||||
@@ -299,17 +301,17 @@ void QmlJSPropertyInspector::propertyValueChanged(int debugId, const QByteArray
|
||||
return;
|
||||
|
||||
QString propertyNameS = QString(propertyName);
|
||||
for (int ii=0; ii < m_model.rowCount(); ii++) {
|
||||
if (m_model.data(m_model.index(ii,0),Qt::DisplayRole).toString() == propertyNameS &&
|
||||
m_model.data(m_model.index(ii,0),Qt::UserRole).toInt() == debugId) {
|
||||
QVariant oldData = m_model.data(m_model.index(ii,1),Qt::DisplayRole);
|
||||
m_model.setData(m_model.index(ii,1),propertyValue.toString(), Qt::DisplayRole);
|
||||
for (int i = 0; i < m_model.rowCount(); i++) {
|
||||
if (m_model.data(m_model.index(i, 0), Qt::DisplayRole).toString() == propertyNameS &&
|
||||
m_model.data(m_model.index(i, 0), Qt::UserRole).toInt() == debugId) {
|
||||
QVariant oldData = m_model.data(m_model.index(i, 1), Qt::DisplayRole);
|
||||
m_model.setData(m_model.index(i, 1), propertyValue.toString(), Qt::DisplayRole);
|
||||
if (oldData != propertyValue) {
|
||||
m_model.item(ii,0)->setForeground(QBrush(Qt::red));
|
||||
m_model.item(ii,1)->setForeground(QBrush(Qt::red));
|
||||
m_model.item(ii,2)->setForeground(QBrush(Qt::red));
|
||||
if ((QmlJSPropertyInspector::PropertyType)m_model.item(ii,2)->data(Qt::UserRole).toInt() == QmlJSPropertyInspector::ColorType)
|
||||
setColorIcon(ii);
|
||||
m_model.item(i, 0)->setForeground(QBrush(Qt::red));
|
||||
m_model.item(i, 1)->setForeground(QBrush(Qt::red));
|
||||
m_model.item(i, 2)->setForeground(QBrush(Qt::red));
|
||||
if (getTypeFor(i) == QmlJSPropertyInspector::ColorType)
|
||||
setColorIcon(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -377,17 +379,17 @@ void QmlJSPropertyInspector::addRow(const QString &name,const QString &value, co
|
||||
QStandardItem *typeColumn = new QStandardItem(type);
|
||||
typeColumn->setToolTip(type);
|
||||
typeColumn->setEditable(false);
|
||||
|
||||
// encode type for easy lookup
|
||||
QVariant typeCode = QVariant(QmlJSPropertyInspector::OtherType);
|
||||
QmlJSPropertyInspector::PropertyType typeCode = QmlJSPropertyInspector::OtherType;
|
||||
if (type == "bool")
|
||||
typeCode = QVariant(QmlJSPropertyInspector::BooleanType);
|
||||
if (type == "qreal")
|
||||
typeCode = QVariant(QmlJSPropertyInspector::NumberType);
|
||||
if (type == "QString")
|
||||
typeCode = QVariant(QmlJSPropertyInspector::StringType);
|
||||
if (type == "QColor") {
|
||||
typeCode = QVariant(QmlJSPropertyInspector::ColorType);
|
||||
}
|
||||
typeCode = QmlJSPropertyInspector::BooleanType;
|
||||
else if (type == "qreal")
|
||||
typeCode = QmlJSPropertyInspector::NumberType;
|
||||
else if (type == "QString")
|
||||
typeCode = QmlJSPropertyInspector::StringType;
|
||||
else if (type == "QColor")
|
||||
typeCode = QmlJSPropertyInspector::ColorType;
|
||||
|
||||
typeColumn->setData(typeCode, Qt::UserRole);
|
||||
|
||||
@@ -395,10 +397,9 @@ void QmlJSPropertyInspector::addRow(const QString &name,const QString &value, co
|
||||
newRow << nameColumn << valueColumn << typeColumn;
|
||||
m_model.appendRow(newRow);
|
||||
|
||||
if (type == "QColor") {
|
||||
if (typeCode == QmlJSPropertyInspector::ColorType)
|
||||
setColorIcon(m_model.indexFromItem(valueColumn).row());
|
||||
}
|
||||
}
|
||||
|
||||
void QmlJSPropertyInspector::setColorIcon(int row)
|
||||
{
|
||||
@@ -444,7 +445,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
|
||||
openColorSelector(itemIndex);
|
||||
}
|
||||
|
||||
void QmlJSPropertyInspector::openExpressionEditor( QModelIndex &itemIndex )
|
||||
void QmlJSPropertyInspector::openExpressionEditor(const QModelIndex &itemIndex)
|
||||
{
|
||||
QString propertyName = getData(itemIndex.row(), 0, Qt::DisplayRole).toString();
|
||||
QString dialogText = tr("Javascript expression for ")+propertyName;
|
||||
@@ -453,12 +454,13 @@ void QmlJSPropertyInspector::openExpressionEditor( QModelIndex &itemIndex )
|
||||
ExpressionEdit *expressionDialog = new ExpressionEdit(dialogText);
|
||||
expressionDialog->setItemData(objectId, propertyName);
|
||||
|
||||
connect(expressionDialog,SIGNAL(dataChanged(int,QString,QString)), this, SLOT(propertyValueEdited(int,QString,QString)));
|
||||
connect(expressionDialog, SIGNAL(dataChanged(int,QString,QString)),
|
||||
this, SLOT(propertyValueEdited(int,QString,QString)));
|
||||
|
||||
expressionDialog->show();
|
||||
}
|
||||
|
||||
void QmlJSPropertyInspector::openColorSelector( QModelIndex &itemIndex )
|
||||
void QmlJSPropertyInspector::openColorSelector(const QModelIndex &itemIndex)
|
||||
{
|
||||
QString propertyName = getData(itemIndex.row(), 0, Qt::DisplayRole).toString();
|
||||
QString dialogText = tr("Color selection for ") + propertyName;
|
||||
@@ -468,7 +470,8 @@ void QmlJSPropertyInspector::openColorSelector( QModelIndex &itemIndex )
|
||||
ColorChooserDialog *colorDialog = new ColorChooserDialog(dialogText);
|
||||
colorDialog->setItemData(objectId, propertyName, propertyValue);
|
||||
|
||||
connect(colorDialog,SIGNAL(dataChanged(int,QString,QString)), this, SLOT(propertyValueEdited(int,QString,QString)));
|
||||
connect(colorDialog, SIGNAL(dataChanged(int,QString,QString)),
|
||||
this, SLOT(propertyValueEdited(int,QString,QString)));
|
||||
|
||||
colorDialog->show();
|
||||
}
|
||||
|
||||
@@ -56,8 +56,14 @@ class PropertiesFilter : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PropertiesFilter(QObject *parent=0):QSortFilterProxyModel(parent) { setDynamicSortFilter(true); }
|
||||
explicit PropertiesFilter(QObject *parent = 0)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
~PropertiesFilter() { }
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
};
|
||||
|
||||
@@ -129,8 +135,8 @@ public slots:
|
||||
void propertyValueChanged(int debugId, const QByteArray &propertyName, const QVariant &propertyValue);
|
||||
void filterBy(const QString &expression);
|
||||
|
||||
void openExpressionEditor( QModelIndex &itemIndex );
|
||||
void openColorSelector( QModelIndex &itemIndex );
|
||||
void openExpressionEditor(const QModelIndex &itemIndex);
|
||||
void openColorSelector(const QModelIndex &itemIndex);
|
||||
|
||||
private:
|
||||
friend class PropertyEditDelegate;
|
||||
|
||||
Reference in New Issue
Block a user