Commit 522ffd86 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

QmlJSInspector: Code cosmetics

parent 07014f82
......@@ -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;
}
......@@ -327,16 +330,16 @@ void CrumblePath::resizeButtons()
int totalWidthLeft = width();
if (d->m_buttons.length() >= 1) {
QPoint nextElementPosition(0,0);
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()) {
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
}
else if (QString("QPushButton") == element->metaObject()->className())
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
}
} // namespace Utils
......@@ -55,7 +55,7 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
if (m_isEmpty) {
pushElement(tr("[no context]"));
} else {
for (int i=0; i<path.count(); i++)
for (int i = 0; i < path.count(); i++)
pushElement(path[i], QVariant(debugIds[i]));
}
}
......@@ -63,9 +63,8 @@ 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++) {
addChild(childrenNames[i],QVariant(childrenDebugIds[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
......@@ -548,6 +548,7 @@ void InspectorUi::selectItems(const QList<QDeclarativeDebugObjectReference> &obj
gotoObjectReferenceDefinition(objref);
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;
......
......@@ -118,12 +118,12 @@ class PropertyEditDelegate : public QItemDelegate
QmlJSPropertyInspector::PropertyType propertyType = m_treeWidget->getTypeFor(index.row());
const QChar quote(QLatin1Char('\"'));
if ( propertyType == QmlJSPropertyInspector::StringType ) {
if (propertyType == QmlJSPropertyInspector::StringType) {
const QChar backslash(QLatin1Char('\\'));
propertyValue = propertyValue.replace(quote, QString(backslash) + quote);
}
if ( propertyType == QmlJSPropertyInspector::StringType || propertyType == QmlJSPropertyInspector::ColorType ) {
if (propertyType == QmlJSPropertyInspector::StringType || propertyType == QmlJSPropertyInspector::ColorType) {
propertyValue = quote + propertyValue + quote;
}
......@@ -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);
......@@ -285,7 +287,7 @@ void QmlJSPropertyInspector::setCurrentObjects(const QList<QDeclarativeDebugObje
QVariant QmlJSPropertyInspector::getData(int row, int column, int role) const
{
return m_filter->data(m_filter->index(row,column),role);
return m_filter->data(m_filter->index(row, column), role);
}
QmlJSPropertyInspector::PropertyType QmlJSPropertyInspector::getTypeFor(int row) const
......@@ -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,39 +379,38 @@ 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);
typeColumn->setData(typeCode, Qt::UserRole);
QList <QStandardItem *> newRow;
QList<QStandardItem *> newRow;
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)
{
QStandardItem *item = m_model.itemFromIndex(m_model.index(row,1));
QStandardItem *item = m_model.itemFromIndex(m_model.index(row, 1));
QColor color = QColor(item->data(Qt::DisplayRole).toString());
int recomendedLength = viewOptions().decorationSize.height() - 2;
QPixmap colorpix(recomendedLength, recomendedLength);
QPainter p(&colorpix);
p.fillRect(1,1,recomendedLength-2,recomendedLength-2, color);
p.fillRect(1, 1, recomendedLength - 2, recomendedLength - 2, color);
p.setPen(Qt::black);
p.drawRect(0, 0, recomendedLength - 1, recomendedLength - 1);
item->setIcon(colorpix);
......@@ -422,7 +423,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
bool isEditable = false;
bool isColor = false;
if (itemIndex.isValid()) {
isEditable = m_model.itemFromIndex(m_filter->mapToSource(m_filter->index(itemIndex.row(),1)))->isEditable();
isEditable = m_model.itemFromIndex(m_filter->mapToSource(m_filter->index(itemIndex.row(), 1)))->isEditable();
isColor = (getTypeFor(itemIndex.row()) == QmlJSPropertyInspector::ColorType);
}
......@@ -439,36 +440,38 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
return;
if (action == &exprAction)
openExpressionEditor( itemIndex );
openExpressionEditor(itemIndex);
if (action == &colorAction)
openColorSelector( itemIndex );
openColorSelector(itemIndex);
}
void QmlJSPropertyInspector::openExpressionEditor( QModelIndex &itemIndex )
void QmlJSPropertyInspector::openExpressionEditor(const QModelIndex &itemIndex)
{
QString propertyName = getData(itemIndex.row(),0,Qt::DisplayRole).toString();
QString propertyName = getData(itemIndex.row(), 0, Qt::DisplayRole).toString();
QString dialogText = tr("Javascript expression for ")+propertyName;
int objectId = getData(itemIndex.row(), 0, Qt::UserRole).toInt();
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;
QString propertyName = getData(itemIndex.row(), 0, Qt::DisplayRole).toString();
QString dialogText = tr("Color selection for ") + propertyName;
int objectId = getData(itemIndex.row(), 0, Qt::UserRole).toInt();
QString propertyValue = getData(itemIndex.row(),1,Qt::DisplayRole).toString();
QString propertyValue = getData(itemIndex.row(), 1, Qt::DisplayRole).toString();
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;
};
......@@ -65,10 +71,10 @@ class ExpressionEdit : public QDialog
{
Q_OBJECT
public:
explicit ExpressionEdit(const QString & title, QDialog *parent=0);
explicit ExpressionEdit(const QString &title, QDialog *parent = 0);
QString expression() const;
void setItemData(int objectId,const QString &propertyName);
void setItemData(int objectId, const QString &propertyName);
virtual void accept();
......@@ -86,7 +92,7 @@ class ColorChooserDialog : public QDialog
{
Q_OBJECT
public:
explicit ColorChooserDialog(const QString & title, QDialog *parent=0);
explicit ColorChooserDialog(const QString &title, QDialog *parent = 0);
void setItemData(int objectId,const QString &propertyName, const QString &colorName);
......@@ -125,18 +131,18 @@ signals:
public slots:
void setCurrentObjects(const QList<QDeclarativeDebugObjectReference> &);
void propertyValueEdited(const int objectId,const QString& propertyName, const QString& propertyValue);
void propertyValueEdited(const int objectId,const QString &propertyName, const QString &propertyValue);
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;
void buildPropertyTree(const QDeclarativeDebugObjectReference &);
void addRow(const QString &name, const QString &value, const QString &type,
const int debugId=-1, bool editable=true);
const int debugId = -1, bool editable = true);
void setColorIcon(int row);
QVariant getData(int row, int column, int role) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment