diff -Nru gammaray-1.2.2/3rdparty/kde/kdebug.h gammaray-2.0.1/3rdparty/kde/kdebug.h --- gammaray-1.2.2/3rdparty/kde/kdebug.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kdebug.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,7 @@ +#ifndef KDEBUG_H +#define KDEBUG_H + +#include + +#define kDebug qDebug +#endif diff -Nru gammaray-1.2.2/3rdparty/kde/kdeui_export.h gammaray-2.0.1/3rdparty/kde/kdeui_export.h --- gammaray-1.2.2/3rdparty/kde/kdeui_export.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kdeui_export.h 2014-02-28 19:07:57.000000000 +0000 @@ -20,6 +20,8 @@ #ifndef KDEUI_EXPORT_H #define KDEUI_EXPORT_H +#include "ui/gammaray_ui_export.h" + #define KDEUI_EXPORT #endif diff -Nru gammaray-1.2.2/3rdparty/kde/kfilterproxysearchline.cpp gammaray-2.0.1/3rdparty/kde/kfilterproxysearchline.cpp --- gammaray-1.2.2/3rdparty/kde/kfilterproxysearchline.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kfilterproxysearchline.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -102,4 +102,4 @@ return d->searchLine; } -#include "kfilterproxysearchline.moc" +#include "moc_kfilterproxysearchline.cpp" diff -Nru gammaray-1.2.2/3rdparty/kde/kfilterproxysearchline.h gammaray-2.0.1/3rdparty/kde/kfilterproxysearchline.h --- gammaray-1.2.2/3rdparty/kde/kfilterproxysearchline.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kfilterproxysearchline.h 2014-02-28 19:07:57.000000000 +0000 @@ -21,6 +21,8 @@ #define KFILTERPROXYSEARCHLINE_H #include "kdeui_export.h" +#undef KDEUI_EXPORT +#define KDEUI_EXPORT GAMMARAY_UI_EXPORT #include diff -Nru gammaray-1.2.2/3rdparty/kde/klinkitemselectionmodel.cpp gammaray-2.0.1/3rdparty/kde/klinkitemselectionmodel.cpp --- gammaray-1.2.2/3rdparty/kde/klinkitemselectionmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/klinkitemselectionmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,183 @@ +/* + Copyright (C) 2010 Klarälvdalens Datakonsult AB, + a KDAB Group company, info@kdab.net, + author Stephen Kelly + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +#include "klinkitemselectionmodel.h" + +#include "kmodelindexproxymapper.h" + +#include "kdebug.h" + +#include + +class KLinkItemSelectionModelPrivate +{ +public: + KLinkItemSelectionModelPrivate(KLinkItemSelectionModel *proxySelectionModel, QAbstractItemModel *model, + QItemSelectionModel *linkedItemSelectionModel) + : q_ptr(proxySelectionModel), + m_model(model), + m_linkedItemSelectionModel(linkedItemSelectionModel), + m_ignoreCurrentChanged(false), + m_indexMapper(new KModelIndexProxyMapper(model, linkedItemSelectionModel->model(), proxySelectionModel)) + { + } + + Q_DECLARE_PUBLIC(KLinkItemSelectionModel) + KLinkItemSelectionModel * const q_ptr; + + + bool assertSelectionValid(const QItemSelection &selection) const { + foreach(const QItemSelectionRange &range, selection) { + if (!range.isValid()) { + kDebug() << selection; + } + Q_ASSERT(range.isValid()); + } + return true; + } + + void sourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); + void sourceCurrentChanged(const QModelIndex& current); + void slotCurrentChanged(const QModelIndex& current); + + QAbstractItemModel * const m_model; + QItemSelectionModel * const m_linkedItemSelectionModel; + bool m_ignoreCurrentChanged; + KModelIndexProxyMapper * const m_indexMapper; +}; + +KLinkItemSelectionModel::KLinkItemSelectionModel(QAbstractItemModel *model, QItemSelectionModel *proxySelector, QObject *parent) + : QItemSelectionModel(model, parent), + d_ptr(new KLinkItemSelectionModelPrivate(this, model, proxySelector)) +{ + connect(proxySelector, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(sourceSelectionChanged(QItemSelection,QItemSelection))); + connect(proxySelector, SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(sourceCurrentChanged(QModelIndex))); + connect(this, SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(slotCurrentChanged(QModelIndex))); +} + +KLinkItemSelectionModel::~KLinkItemSelectionModel() +{ + delete d_ptr; +} + +void KLinkItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) +{ + Q_D(KLinkItemSelectionModel); + // When an item is removed, the current index is set to the top index in the model. + // That causes a selectionChanged signal with a selection which we do not want. + if (d->m_ignoreCurrentChanged) { + return; + } + // Do *not* replace next line with: QItemSelectionModel::select(index, command) + // + // Doing so would end up calling KLinkItemSelectionModel::select(QItemSelection, QItemSelectionModel::SelectionFlags) + // + // This is because the code for QItemSelectionModel::select(QModelIndex, QItemSelectionModel::SelectionFlags) looks like this: + // { + // QItemSelection selection(index, index); + // select(selection, command); + // } + // So it calls KLinkItemSelectionModel overload of + // select(QItemSelection, QItemSelectionModel::SelectionFlags) + // + // When this happens and the selection flags include Toggle, it causes the + // selection to be toggled twice. + QItemSelectionModel::select(QItemSelection(index, index), command); + if (index.isValid()) + d->m_linkedItemSelectionModel->select(d->m_indexMapper->mapSelectionLeftToRight(QItemSelection(index, index)), command); + else { + d->m_linkedItemSelectionModel->clearSelection(); + } +} + +// QAbstractProxyModel::mapSelectionFromSource creates invalid ranges to we filter +// those out manually in a loop. Hopefully fixed in Qt 4.7.2, so we ifdef it out. +// http://qt.gitorious.org/qt/qt/merge_requests/2474 +// http://qt.gitorious.org/qt/qt/merge_requests/831 +#if QT_VERSION < 0x040702 +#define RANGE_FIX_HACK +#endif + +#ifdef RANGE_FIX_HACK +static QItemSelection klink_removeInvalidRanges(const QItemSelection &selection) +{ + QItemSelection result; + Q_FOREACH(const QItemSelectionRange &range, selection) + { + if (!range.isValid()) + continue; + result << range; + } + return result; +} +#endif + +void KLinkItemSelectionModel::select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) +{ + Q_D(KLinkItemSelectionModel); + d->m_ignoreCurrentChanged = true; +#ifdef RANGE_FIX_HACK + QItemSelection _selection = klink_removeInvalidRanges(selection); +#else + QItemSelection _selection = selection; +#endif + QItemSelectionModel::select(_selection, command); + Q_ASSERT(d->assertSelectionValid(_selection)); + QItemSelection mappedSelection = d->m_indexMapper->mapSelectionLeftToRight(_selection); + Q_ASSERT(d->assertSelectionValid(mappedSelection)); + d->m_linkedItemSelectionModel->select(mappedSelection, command); + d->m_ignoreCurrentChanged = false; +} + +void KLinkItemSelectionModelPrivate::slotCurrentChanged(const QModelIndex& current) +{ + const QModelIndex mappedCurrent = m_indexMapper->mapLeftToRight(current); + m_linkedItemSelectionModel->setCurrentIndex(mappedCurrent, QItemSelectionModel::NoUpdate); +} + +void KLinkItemSelectionModelPrivate::sourceSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +{ + Q_Q(KLinkItemSelectionModel); +#ifdef RANGE_FIX_HACK + QItemSelection _selected = klink_removeInvalidRanges(selected); + QItemSelection _deselected = klink_removeInvalidRanges(deselected); +#else + QItemSelection _selected = selected; + QItemSelection _deselected = deselected; +#endif + Q_ASSERT(assertSelectionValid(_selected)); + Q_ASSERT(assertSelectionValid(_deselected)); + const QItemSelection mappedDeselection = m_indexMapper->mapSelectionRightToLeft(_deselected); + const QItemSelection mappedSelection = m_indexMapper->mapSelectionRightToLeft(_selected); + + q->QItemSelectionModel::select(mappedDeselection, QItemSelectionModel::Deselect); + q->QItemSelectionModel::select(mappedSelection, QItemSelectionModel::Select); +} + +void KLinkItemSelectionModelPrivate::sourceCurrentChanged(const QModelIndex& current) +{ + Q_Q(KLinkItemSelectionModel); + const QModelIndex mappedCurrent = m_indexMapper->mapRightToLeft(current); + q->setCurrentIndex(mappedCurrent, QItemSelectionModel::NoUpdate); +} + +#include "moc_klinkitemselectionmodel.cpp" diff -Nru gammaray-1.2.2/3rdparty/kde/klinkitemselectionmodel.h gammaray-2.0.1/3rdparty/kde/klinkitemselectionmodel.h --- gammaray-1.2.2/3rdparty/kde/klinkitemselectionmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/klinkitemselectionmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,117 @@ +/* + Copyright (C) 2010 Klarälvdalens Datakonsult AB, + a KDAB Group company, info@kdab.net, + author Stephen Kelly + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef KLINKITEMSELECTIONMODEL_H +#define KLINKITEMSELECTIONMODEL_H + +#include +#include + +#include "kdeui_export.h" + +class KLinkItemSelectionModelPrivate; + +/** + @brief Makes it possible to share a selection in multiple views which do not have the same source model + + Although multiple views can share the same QItemSelectionModel, the views then need to have the same source model. + + If there is a proxy model between the model and one of the views, or different proxy models in each, this class makes + it possible to share the selection between the views. + + @image html kproxyitemselectionmodel-simple.png "Sharing a QItemSelectionModel between views on the same model is trivial" + @image html kproxyitemselectionmodel-error.png "If a proxy model is used, it is no longer possible to share the QItemSelectionModel directly" + @image html kproxyitemselectionmodel-solution.png "A KLinkItemSelectionModel can be used to map the selection through the proxy model" + + @code + QAbstractItemModel *model = getModel(); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(); + proxy->setSourceModel(model); + + QTreeView *view1 = new QTreeView(splitter); + view1->setModel(model); + + KLinkItemSelectionModel *view2SelectionModel = new KLinkItemSelectionModel( proxy, view1->selectionModel()); + + QTreeView *view2 = new QTreeView(splitter); + // Note that the QAbstractItemModel passed to KLinkItemSelectionModel must be the same as what is used in the view + view2->setModel(proxy); + view2->setSelectionModel( view2SelectionModel ); + @endcode + + @image html kproxyitemselectionmodel-complex.png "Arbitrarily complex proxy configurations on the same root model can be used" + + @code + QAbstractItemModel *model = getModel(); + + QSortFilterProxyModel *proxy1 = new QSortFilterProxyModel(); + proxy1->setSourceModel(model); + QSortFilterProxyModel *proxy2 = new QSortFilterProxyModel(); + proxy2->setSourceModel(proxy1); + QSortFilterProxyModel *proxy3 = new QSortFilterProxyModel(); + proxy3->setSourceModel(proxy2); + + QTreeView *view1 = new QTreeView(splitter); + view1->setModel(proxy3); + + QSortFilterProxyModel *proxy4 = new QSortFilterProxyModel(); + proxy4->setSourceModel(model); + QSortFilterProxyModel *proxy5 = new QSortFilterProxyModel(); + proxy5->setSourceModel(proxy4); + + KLinkItemSelectionModel *view2SelectionModel = new KLinkItemSelectionModel( proxy5, view1->selectionModel()); + + QTreeView *view2 = new QTreeView(splitter); + // Note that the QAbstractItemModel passed to KLinkItemSelectionModel must be the same as what is used in the view + view2->setModel(proxy5); + view2->setSelectionModel( view2SelectionModel ); + @endcode + + See also kdelibs/kdeui/tests/proxymodeltestapp/proxyitemselectionwidget.cpp. + + @since 4.5 + @author Stephen Kelly + +*/ +class KDEUI_EXPORT KLinkItemSelectionModel : public QItemSelectionModel +{ + Q_OBJECT +public: + /** + Constructor. + */ + KLinkItemSelectionModel(QAbstractItemModel *targetModel, QItemSelectionModel *linkedItemSelectionModel, QObject *parent = 0); + ~KLinkItemSelectionModel(); + /* reimp */ void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); + /* reimp */ void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command); + +protected: + KLinkItemSelectionModelPrivate * const d_ptr; + +private: + Q_DECLARE_PRIVATE(KLinkItemSelectionModel) + Q_PRIVATE_SLOT( d_func(), void sourceSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)) + Q_PRIVATE_SLOT( d_func(), void sourceCurrentChanged(const QModelIndex ¤t)) + Q_PRIVATE_SLOT( d_func(), void slotCurrentChanged(const QModelIndex ¤t)) +}; + +#endif diff -Nru gammaray-1.2.2/3rdparty/kde/kmodelindexproxymapper.cpp gammaray-2.0.1/3rdparty/kde/kmodelindexproxymapper.cpp --- gammaray-1.2.2/3rdparty/kde/kmodelindexproxymapper.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kmodelindexproxymapper.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,309 @@ +/* + Copyright (C) 2010 Klarälvdalens Datakonsult AB, + a KDAB Group company, info@kdab.net, + author Stephen Kelly + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "kmodelindexproxymapper.h" + +#include +#include +#include +#include + +#include "kdebug.h" + +class KModelIndexProxyMapperPrivate +{ + KModelIndexProxyMapperPrivate(const QAbstractItemModel *leftModel, const QAbstractItemModel *rightModel, KModelIndexProxyMapper *qq) + : q_ptr(qq), m_leftModel(leftModel), m_rightModel(rightModel) + { + createProxyChain(); + } + + void createProxyChain(); + bool assertValid(); + + bool assertSelectionValid(const QItemSelection &selection) const { + foreach(const QItemSelectionRange &range, selection) { + if (!range.isValid()) { + kDebug() << selection << m_leftModel << m_rightModel << m_proxyChainDown << m_proxyChainUp; + } + Q_ASSERT(range.isValid()); + } + return true; + } + + Q_DECLARE_PUBLIC(KModelIndexProxyMapper) + KModelIndexProxyMapper * const q_ptr; + + QList > m_proxyChainUp; + QList > m_proxyChainDown; + + QWeakPointer m_leftModel; + QWeakPointer m_rightModel; +}; + + +/* + + The idea here is that this selection model and proxySelectionModel might be in different parts of the + proxy chain. We need to build up to two chains of proxy models to create mappings between them. + + Example 1: + + Root model + | + / \ + Proxy 1 Proxy 3 + | | + Proxy 2 Proxy 4 + + Need Proxy 1 and Proxy 2 in one chain, and Proxy 3 and 4 in the other. + + Example 2: + + Root model + | + Proxy 1 + | + Proxy 2 + / \ + Proxy 3 Proxy 6 + | | + Proxy 4 Proxy 7 + | + Proxy 5 + + We first build the chain from 1 to 5, then start building the chain from 7 to 1. We stop when we find that proxy 2 is + already in the first chain. + + Stephen Kelly, 30 March 2010. +*/ + +void KModelIndexProxyMapperPrivate::createProxyChain() +{ + QWeakPointer targetModel = m_rightModel; + + if (!targetModel) + return; + + if (m_leftModel == targetModel) + return; + + QList > proxyChainDown; + QWeakPointer selectionTargetProxyModel = qobject_cast(targetModel.data()); + while( selectionTargetProxyModel ) + { + proxyChainDown.prepend( selectionTargetProxyModel ); + + selectionTargetProxyModel = qobject_cast(selectionTargetProxyModel.data()->sourceModel()); + + if (selectionTargetProxyModel.data() == m_leftModel.data()) + { + m_proxyChainDown = proxyChainDown; + return; + } + } + + QWeakPointer sourceModel = m_leftModel; + QWeakPointer sourceProxyModel = qobject_cast(sourceModel.data()); + + while(sourceProxyModel) + { + m_proxyChainUp.append(sourceProxyModel); + + sourceProxyModel = qobject_cast(sourceProxyModel.data()->sourceModel()); + + const int targetIndex = proxyChainDown.indexOf(sourceProxyModel); + + if (targetIndex != -1) + { + m_proxyChainDown = proxyChainDown.mid(targetIndex + 1, proxyChainDown.size()); + return; + } + } + m_proxyChainDown = proxyChainDown; + Q_ASSERT(assertValid()); +} + +bool KModelIndexProxyMapperPrivate::assertValid() +{ + if ( m_proxyChainDown.isEmpty()) + { + Q_ASSERT( !m_proxyChainUp.isEmpty() ); + Q_ASSERT( m_proxyChainUp.last().data()->sourceModel() == m_rightModel.data() ); + } + else if ( m_proxyChainUp.isEmpty()) + { + Q_ASSERT( !m_proxyChainDown.isEmpty() ); + Q_ASSERT( m_proxyChainDown.first().data()->sourceModel() == m_leftModel.data() ); + } else { + Q_ASSERT( m_proxyChainDown.first().data()->sourceModel() == m_proxyChainUp.last().data()->sourceModel() ); + } + return true; +} + +KModelIndexProxyMapper::KModelIndexProxyMapper(const QAbstractItemModel* leftModel, const QAbstractItemModel* rightModel, QObject* parent) + : QObject(parent), d_ptr( new KModelIndexProxyMapperPrivate(leftModel, rightModel, this) ) +{ + +} + +KModelIndexProxyMapper::~KModelIndexProxyMapper() +{ + delete d_ptr; +} + +QModelIndex KModelIndexProxyMapper::mapLeftToRight(const QModelIndex& index) const +{ + const QItemSelection selection = mapSelectionLeftToRight(QItemSelection(index, index)); + if (selection.isEmpty()) + return QModelIndex(); + + return selection.indexes().first(); +} + +QModelIndex KModelIndexProxyMapper::mapRightToLeft(const QModelIndex& index) const +{ + const QItemSelection selection = mapSelectionRightToLeft(QItemSelection(index, index)); + if (selection.isEmpty()) + return QModelIndex(); + + return selection.indexes().first(); +} + +// QAbstractProxyModel::mapSelectionFromSource creates invalid ranges to we filter +// those out manually in a loop. Hopefully fixed in Qt 4.7.2, so we ifdef it out. +// http://qt.gitorious.org/qt/qt/merge_requests/2474 +// http://qt.gitorious.org/qt/qt/merge_requests/831 +#if QT_VERSION < 0x040702 +#define RANGE_FIX_HACK +#endif + +#ifdef RANGE_FIX_HACK +static QItemSelection removeInvalidRanges(const QItemSelection &selection) +{ + QItemSelection result; + Q_FOREACH(const QItemSelectionRange &range, selection) + { + if (!range.isValid()) + continue; + result << range; + } + return result; +} +#endif + +QItemSelection KModelIndexProxyMapper::mapSelectionLeftToRight(const QItemSelection& selection) const +{ + Q_D(const KModelIndexProxyMapper); + + if (selection.isEmpty()) + return QItemSelection(); + + if (selection.first().model() != d->m_leftModel.data()) + kDebug() << "FAIL" << selection.first().model() << d->m_leftModel.data() << d->m_rightModel.data(); + Q_ASSERT(selection.first().model() == d->m_leftModel.data()); + + QItemSelection seekSelection = selection; + Q_ASSERT(d->assertSelectionValid(seekSelection)); + QListIterator > iUp(d->m_proxyChainUp); + + while (iUp.hasNext()) + { + const QWeakPointer proxy = iUp.next(); + if (!proxy.data()) + return QItemSelection(); + seekSelection = proxy.data()->mapSelectionToSource(seekSelection); + +#ifdef RANGE_FIX_HACK + seekSelection = removeInvalidRanges(seekSelection); +#endif + Q_ASSERT(d->assertSelectionValid(seekSelection)); + } + + QListIterator > iDown(d->m_proxyChainDown); + + while (iDown.hasNext()) + { + const QWeakPointer proxy = iDown.next(); + if (!proxy.data()) + return QItemSelection(); + seekSelection = proxy.data()->mapSelectionFromSource(seekSelection); + +#ifdef RANGE_FIX_HACK + seekSelection = removeInvalidRanges(seekSelection); +#endif + Q_ASSERT(d->assertSelectionValid(seekSelection)); + } + + Q_ASSERT( ( !seekSelection.isEmpty() && seekSelection.first().model() == d->m_rightModel.data() ) || true ); + return seekSelection; +} + +QItemSelection KModelIndexProxyMapper::mapSelectionRightToLeft(const QItemSelection& selection) const +{ + Q_D(const KModelIndexProxyMapper); + + if (selection.isEmpty()) + return QItemSelection(); + + if (selection.first().model() != d->m_rightModel.data()) + kDebug() << "FAIL" << selection.first().model() << d->m_leftModel.data() << d->m_rightModel.data(); + Q_ASSERT(selection.first().model() == d->m_rightModel.data()); + + QItemSelection seekSelection = selection; + Q_ASSERT(d->assertSelectionValid(seekSelection)); + QListIterator > iDown(d->m_proxyChainDown); + + iDown.toBack(); + while (iDown.hasPrevious()) + { + const QWeakPointer proxy = iDown.previous(); + if (!proxy.data()) + return QItemSelection(); + seekSelection = proxy.data()->mapSelectionToSource(seekSelection); + +#ifdef RANGE_FIX_HACK + seekSelection = removeInvalidRanges(seekSelection); +#endif + Q_ASSERT(d->assertSelectionValid(seekSelection)); + } + + QListIterator > iUp(d->m_proxyChainUp); + + iUp.toBack(); + while (iUp.hasPrevious()) + { + const QWeakPointer proxy = iUp.previous(); + if (!proxy.data()) + return QItemSelection(); + seekSelection = proxy.data()->mapSelectionFromSource(seekSelection); + +#ifdef RANGE_FIX_HACK + seekSelection = removeInvalidRanges(seekSelection); +#endif + Q_ASSERT(d->assertSelectionValid(seekSelection)); + } + + Q_ASSERT( ( !seekSelection.isEmpty() && seekSelection.first().model() == d->m_leftModel.data() ) || true ); + return seekSelection; +} + +#include "moc_kmodelindexproxymapper.cpp" diff -Nru gammaray-1.2.2/3rdparty/kde/kmodelindexproxymapper.h gammaray-2.0.1/3rdparty/kde/kmodelindexproxymapper.h --- gammaray-1.2.2/3rdparty/kde/kmodelindexproxymapper.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/kmodelindexproxymapper.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,117 @@ +/* + Copyright (C) 2010 Klarälvdalens Datakonsult AB, + a KDAB Group company, info@kdab.net, + author Stephen Kelly + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef KMODELINDEXPROXYMAPPER_H +#define KMODELINDEXPROXYMAPPER_H + +#include + +#include "kdeui_export.h" + +class QAbstractItemModel; +class QModelIndex; +class QItemSelection; +class KModelIndexProxyMapperPrivate; + +/** + * @brief This class facilitates easy mapping of indexes and selections through proxy models. + * + * In a complex system of proxy models there can be a need to map indexes and selections between them, + * and sometimes to do so without knowledge of the path from one model to another. + * + * For example, + * + * @verbatim + * Root model + * | + * / \ + * Proxy 1 Proxy 3 + * | | + * Proxy 2 Proxy 4 + * @endverbatim + * + * If there is a need to map indexes between proxy 2 and proxy 4, a KModelIndexProxyMapper can be created + * to facilitate mapping of indexes between them. + * + * @code + * m_indexMapper = new KModelIndexProxyMapper(proxy2, proxy4, this); + * + * ... + * + * const QModelIndex proxy4Index = m_mapLeftToRight(proxy2->index(0, 0)); + * Q_ASSERT(proxy4Index.model() == proxy4); + * @endcode + * + * Note that the aim is to achieve black box connections so that there is no need for application code to + * know the structure of proxy models in the path between left and right and attempt to manually map them. + * + * @verbatim + * Root model + * | + * --------------- + * | Black Box | + * --------------- + * | | + * Proxy 2 Proxy 4 + * @endverbatim + * + * @author Stephen Kelly + * + */ +class KDEUI_EXPORT KModelIndexProxyMapper : public QObject +{ + Q_OBJECT +public: + /** + * Constructor + */ + KModelIndexProxyMapper(const QAbstractItemModel *leftModel, const QAbstractItemModel *rightModel, QObject* parent = 0); + + ~KModelIndexProxyMapper(); + + /** + * Maps the @p index from the left model to the right model. + */ + QModelIndex mapLeftToRight(const QModelIndex &index) const; + + /** + * Maps the @p index from the right model to the left model. + */ + QModelIndex mapRightToLeft(const QModelIndex &index) const; + + /** + * Maps the @p selection from the left model to the right model. + */ + QItemSelection mapSelectionLeftToRight(const QItemSelection &selection) const; + + /** + * Maps the @p selection from the right model to the left model. + */ + QItemSelection mapSelectionRightToLeft(const QItemSelection &selection) const; + +private: + //@cond PRIVATE + Q_DECLARE_PRIVATE(KModelIndexProxyMapper) + KModelIndexProxyMapperPrivate * const d_ptr; + //@endcond +}; + +#endif diff -Nru gammaray-1.2.2/3rdparty/kde/krecursivefilterproxymodel.cpp gammaray-2.0.1/3rdparty/kde/krecursivefilterproxymodel.cpp --- gammaray-1.2.2/3rdparty/kde/krecursivefilterproxymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/krecursivefilterproxymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -438,4 +438,4 @@ } -#include "krecursivefilterproxymodel.moc" +#include "moc_krecursivefilterproxymodel.cpp" diff -Nru gammaray-1.2.2/3rdparty/kde/krecursivefilterproxymodel.h gammaray-2.0.1/3rdparty/kde/krecursivefilterproxymodel.h --- gammaray-1.2.2/3rdparty/kde/krecursivefilterproxymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/kde/krecursivefilterproxymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -24,6 +24,8 @@ #include #include "kdeui_export.h" +#undef KDEUI_EXPORT +#define KDEUI_EXPORT GAMMARAY_UI_EXPORT class KRecursiveFilterProxyModelPrivate; diff -Nru gammaray-1.2.2/3rdparty/other/modelutils.cpp gammaray-2.0.1/3rdparty/other/modelutils.cpp --- gammaray-1.2.2/3rdparty/other/modelutils.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/other/modelutils.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +#include "modelutils.h" + +#include + +using namespace GammaRay; + +QModelIndexList ModelUtils::match(const QAbstractItemModel* model, const QModelIndex& start, + int role, bool (*accept)(const QVariant&), int hits, Qt::MatchFlags flags) +{ + if (!model || !start.isValid() || role < 0) + return QModelIndexList(); + + const QModelIndex parentIndex = model->parent(start); + bool recurse = flags & Qt::MatchRecursive; + bool wrap = flags & Qt::MatchWrap; + bool allHits = (hits == -1); + int from = start.row(); + int to = model->rowCount(parentIndex); + + QModelIndexList result; + + // iterates twice if wrapping + for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { + for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) { + QModelIndex idx = model->index(r, start.column(), parentIndex); + if (!idx.isValid()) + continue; + + const QVariant v = model->data(idx, role); + if (accept(v)) + result << idx; + + // search the hierarchy + if (recurse && model->hasChildren(idx)) { + result += match(model, model->index(0, idx.column(), idx), role, + accept, (allHits ? -1 : hits - result.count()), flags); + } + } + + // prepare for the next iteration + from = 0; + to = start.row(); + } + + return result; +} diff -Nru gammaray-1.2.2/3rdparty/other/modelutils.h gammaray-2.0.1/3rdparty/other/modelutils.h --- gammaray-1.2.2/3rdparty/other/modelutils.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/3rdparty/other/modelutils.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + modelutils.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MODELUTILS_H +#define GAMMARAY_MODELUTILS_H + +#include "ui/gammaray_ui_export.h" + +#include + +namespace GammaRay { + +namespace ModelUtils { + + /** + * Return a list of items that are accepted by an acceptor function + * This class extends the functionality provided in QAbstractItemModel::match(...) + * + * If (accept(v)) for an item v in the model returns true, it will be appended + * to the result list + * + * @param accept Function in the form 'bool f(const QVariant&)' + * + * @see QAbstractItemModel::match(...) + */ + GAMMARAY_UI_EXPORT QModelIndexList match(const QAbstractItemModel* model, const QModelIndex& start, + int role, bool (*accept)(const QVariant&), + int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchWrap)); + +} + +} + +#endif // GAMMARAY_MODELUTILS_H diff -Nru gammaray-1.2.2/3rdparty/qt/resourcemodel.cpp gammaray-2.0.1/3rdparty/qt/resourcemodel.cpp --- gammaray-1.2.2/3rdparty/qt/resourcemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/qt/resourcemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -43,7 +43,6 @@ #include #include -#include #include #include #include @@ -51,13 +50,11 @@ #include #include #include -#include -#include +#include #include /*! \enum ResourceModel::Roles - \value FileIconRole \value FilePathRole \value FileNameRole */ @@ -76,7 +73,6 @@ ~QDirNode() { children.clear(); } QDirNode *parent; QFileInfo info; - QIcon icon; // cache the icon mutable QVector children; mutable bool populated; // have we read the children mutable bool stat; @@ -87,7 +83,6 @@ readOnly(true), lazyChildCount(false), allowAppendChild(true), - iconProvider(&defaultProvider), shouldStat(true), // ### This is set to false by QFileDialog q_ptr(qq) { } @@ -130,9 +125,6 @@ QDir::SortFlags sort; QStringList nameFilters; - QFileIconProvider *iconProvider; - QFileIconProvider defaultProvider; - struct SavedPersistent { QString path; int column; @@ -371,8 +363,6 @@ } if (index.column() == 0) { - if (role == FileIconRole) - return fileIcon(index); if (role == FilePathRole) return filePath(index); if (role == FileNameRole) @@ -626,27 +616,6 @@ } /*! - Sets the \a provider of file icons for the directory model. - -*/ - -void ResourceModel::setIconProvider(QFileIconProvider *provider) -{ - Q_D(ResourceModel); - d->iconProvider = provider; -} - -/*! - Returns the file icon provider for this directory model. -*/ - -QFileIconProvider *ResourceModel::iconProvider() const -{ - Q_D(const ResourceModel); - return d->iconProvider; -} - -/*! Sets the name \a filters for the directory model. */ @@ -1112,22 +1081,6 @@ } /*! - Returns the icons for the item stored in the model under the given - \a index. -*/ - -QIcon ResourceModel::fileIcon(const QModelIndex &index) const -{ - Q_D(const ResourceModel); - if (!d->indexValid(index)) - return d->iconProvider->icon(QFileIconProvider::Computer); - ResourceModelPrivate::QDirNode *node = d->node(index); - if (node->icon.isNull()) - node->icon = d->iconProvider->icon(node->info); - return node->icon; -} - -/*! Returns the file information for the specified model \a index. \bold{Note:} If the model index represents a symbolic link in the @@ -1166,7 +1119,6 @@ root.info = QFileInfo(":"); clear(&root); QHash roles = q->roleNames(); - roles.insertMulti(ResourceModel::FileIconRole, "fileIcon"); // == Qt::decoration roles.insert(ResourceModel::FilePathRole, "filePath"); roles.insert(ResourceModel::FileNameRole, "fileName"); q->setRoleNames(roles); @@ -1326,19 +1278,25 @@ const quint64 tb = 1024 * gb; quint64 bytes = n->info.size(); if (bytes >= tb) - return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); + return QObject::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); if (bytes >= gb) - return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); + return QObject::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); if (bytes >= mb) - return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); + return QObject::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); if (bytes >= kb) - return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); - return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes)); + return QObject::tr("%1 KB").arg(QLocale().toString(bytes / kb)); + return QObject::tr("%1 byte(s)").arg(QLocale().toString(bytes)); } QString ResourceModelPrivate::type(const QModelIndex &index) const { - return iconProvider->type(node(index)->info); + // poor interpolation of what QFileIconProvider::type() did + // TODO: for Qt5 QMimeType might actually be a better choice here + if (!index.parent().isValid()) + return QObject::tr("Root"); + if (node(index)->info.isDir()) + return QObject::tr("Folder"); + return QObject::tr("%1 File").arg(node(index)->info.suffix()); } QString ResourceModelPrivate::time(const QModelIndex &index) const @@ -1396,4 +1354,4 @@ QT_END_NAMESPACE -#include "resourcemodel.moc" +#include "moc_resourcemodel.cpp" diff -Nru gammaray-1.2.2/3rdparty/qt/resourcemodel.h gammaray-2.0.1/3rdparty/qt/resourcemodel.h --- gammaray-1.2.2/3rdparty/qt/resourcemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/3rdparty/qt/resourcemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -44,9 +44,6 @@ #include #include -#include - -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -63,8 +60,8 @@ public: enum Roles { - FileIconRole = Qt::DecorationRole, - FilePathRole = Qt::UserRole + 1, + // Qt4 uses 32, Qt5 256, for Qt::UserRole - use the latter globaly to allow combining Qt4/5 client/servers. + FilePathRole = 256 + 1, FileNameRole }; @@ -97,9 +94,6 @@ // ResourceModel specific API - void setIconProvider(QFileIconProvider *provider); - QFileIconProvider *iconProvider() const; - void setNameFilters(const QStringList &filters); QStringList nameFilters() const; @@ -127,7 +121,6 @@ QString filePath(const QModelIndex &index) const; QString fileName(const QModelIndex &index) const; - QIcon fileIcon(const QModelIndex &index) const; QFileInfo fileInfo(const QModelIndex &index) const; #ifdef Q_NO_USING_KEYWORD @@ -152,6 +145,4 @@ QT_END_NAMESPACE -QT_END_HEADER - #endif // QDIRMODEL_H diff -Nru gammaray-1.2.2/add_license_blurb.sh gammaray-2.0.1/add_license_blurb.sh --- gammaray-1.2.2/add_license_blurb.sh 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/add_license_blurb.sh 2014-02-28 19:07:57.000000000 +0000 @@ -44,7 +44,7 @@ # This file is part of GammaRay, the Qt application inspection and # manipulation tool. # -# Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +# Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com # Author: Volker Krause # # This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/CHANGES gammaray-2.0.1/CHANGES --- gammaray-1.2.2/CHANGES 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/CHANGES 2014-02-28 19:07:57.000000000 +0000 @@ -1,6 +1,51 @@ Release Highlights ================== +Version 2.0.1: +------------- + * LLDB injector (enables Mac OSX 10.9 support) + * Fix various cases where client and server states get out of sync + +Version 2.0.0: +------------- + * Out-of-process UI + * Remote Debugging + * Multi-probe support + * Probe usable on targets without QtWidget available + * Fix preload check on MIPS/MIPSel (issue #63) + * Support for displaying arguments of monitored signals + +Version 1.3.2: +------------- + * Support more Qt5-specific data types + * Fix crash on some QtQuick2 applications + * Support VTK6 + * Fix compilation with Mac OSX 10.6 + * Fix GDB injector on Mac OSX + * Fix launching of bundles on Mac OSX + * Fix crash in selection model inspector + * Add fallback if function overwriting fails in MSVC release builds + * Fix WinDLL injector with Qt5 + * Fix Qt version detection in the process list on Windows and Mac OSX + * Fix probe re-injections + * Fix plugin loading on MSVC release builds + +Version 1.3.1: +------------- + * Fix state machine viewer on Windows + * Fix crash in model cell viewer + * Fix crash in meta object browser caused by deleted dynamic meta objects + * Improve performance of the mime type browser + * Improvements in the state machine viewer image export + * Compile fixes for some Qt5 configurations + +Version 1.3: +----------- + * New KJob tracker plugin (requires KDE4) + * Qt5 support + * New Meta Object Browser tool + * New QStandardPaths and QMimeTypeDatabase browsers (Qt5 only) + Version 1.2: ----------- * Published API for writing your own plugin diff -Nru gammaray-1.2.2/client/clientconnectionmanager.cpp gammaray-2.0.1/client/clientconnectionmanager.cpp --- gammaray-1.2.2/client/clientconnectionmanager.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/clientconnectionmanager.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,114 @@ +/* + clientconnectionmanager.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "clientconnectionmanager.h" + +#include "client.h" + +#include + +#include +#include + +#include +#include +#include + +using namespace GammaRay; + +ClientConnectionManager::ClientConnectionManager(QObject* parent) : + QObject(parent), + m_port(0), + m_client(new Client(this)), + m_mainWindow(0), + m_toolModel(0) +{ + showSplashScreen(); + + connect(m_client, SIGNAL(disconnected()), QApplication::instance(), SLOT(quit())); + connect(m_client, SIGNAL(connectionEstablished()), SLOT(connectionEstablished())); + connect(m_client, SIGNAL(connectionError(QAbstractSocket::SocketError,QString)), SLOT(connectionError(QAbstractSocket::SocketError,QString))); +} + +ClientConnectionManager::~ClientConnectionManager() +{ +} + +void ClientConnectionManager::connectToHost(const QString& hostname, quint16 port) +{ + m_hostname = hostname; + m_port = port; + m_connectionTimeout.start(); + connectToHost(); +} + +void ClientConnectionManager::connectToHost() +{ + m_client->connectToHost(m_hostname, m_port); +} + +void ClientConnectionManager::connectionEstablished() +{ + m_toolModel = ObjectBroker::model("com.kdab.GammaRay.ToolModel"); + + if (m_toolModel->rowCount() <= 0) { + connect(m_toolModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(toolModelPopulated())); + connect(m_toolModel, SIGNAL(layoutChanged()), SLOT(toolModelPopulated())); + connect(m_toolModel, SIGNAL(modelReset()), SLOT(toolModelPopulated())); + } else { + toolModelPopulated(); + } +} + +void ClientConnectionManager::toolModelPopulated() +{ + if (m_toolModel->rowCount() <= 0) + return; + + disconnect(m_toolModel, 0, this, 0); + + m_mainWindow = new MainWindow; + m_mainWindow->show(); + hideSplashScreen(); +} + +void ClientConnectionManager::connectionError(QAbstractSocket::SocketError error, const QString& msg) +{ + if (m_connectionTimeout.elapsed() < 60 * 1000 && error == QAbstractSocket::ConnectionRefusedError) { + // client wasn't up yet, keep trying + QTimer::singleShot(1000, this, SLOT(connectToHost())); + return; + } + + hideSplashScreen(); + + QString errorMsg; + if (m_mainWindow) + errorMsg = tr("Lost connection to remote host: %1").arg(msg); + else + errorMsg = tr("Could not establish connection to remote host: %1").arg(msg); + + QMessageBox::critical(m_mainWindow, tr("GammaRay - Connection Error"), errorMsg); + QApplication::exit(1); +} + diff -Nru gammaray-1.2.2/client/clientconnectionmanager.h gammaray-2.0.1/client/clientconnectionmanager.h --- gammaray-1.2.2/client/clientconnectionmanager.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/clientconnectionmanager.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,66 @@ +/* + clientconnectionmanager.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CLIENTCONNECTIONMANAGER_H +#define GAMMARAY_CLIENTCONNECTIONMANAGER_H + +#include +#include +#include + +class QAbstractItemModel; + +namespace GammaRay { + +class Client; +class MainWindow; + +/** Pre-MainWindow connection setup logic. */ +class ClientConnectionManager : public QObject +{ + Q_OBJECT + public: + explicit ClientConnectionManager(QObject* parent = 0); + ~ClientConnectionManager(); + + void connectToHost(const QString &hostname, quint16 port); + + private slots: + void connectToHost(); + void connectionEstablished(); + void connectionError(QAbstractSocket::SocketError error, const QString &msg); + + void toolModelPopulated(); + + private: + QString m_hostname; + quint16 m_port; + Client *m_client; + MainWindow *m_mainWindow; + QAbstractItemModel *m_toolModel; + QTime m_connectionTimeout; +}; + +} + +#endif // GAMMARAY_CLIENTCONNECTIONMANAGER_H diff -Nru gammaray-1.2.2/client/client.cpp gammaray-2.0.1/client/client.cpp --- gammaray-1.2.2/client/client.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/client.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,194 @@ +/* + client.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "client.h" + +#include + +#include +#include +#include + +using namespace GammaRay; + +Client::Client(QObject* parent) + : Endpoint(parent) + , m_initState(0) +{ +} + +Client::~Client() +{ +} + +Client* Client::instance() +{ + return static_cast(s_instance); +} + +bool Client::isRemoteClient() const +{ + return true; +} + +QString Client::serverAddress() const +{ + return m_hostName; +} + +void Client::connectToHost(const QString &hostName, quint16 port) +{ + QTcpSocket *sock = new QTcpSocket(this); + connect(sock, SIGNAL(connected()), SLOT(socketConnected())); + connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError())); + sock->connectToHost(hostName, port); + m_initState = 0; + m_hostName = hostName; +} + +void Client::socketConnected() +{ + Q_ASSERT(qobject_cast(sender())); + setDevice(qobject_cast(sender())); +} + +void Client::socketError() +{ + QTcpSocket *socket = qobject_cast(sender()); + Q_ASSERT(socket); + emit connectionError(socket->error(), socket->errorString()); + socket->deleteLater(); +} + +void Client::messageReceived(const Message& msg) +{ + // server version must be the very first message we get + if (!(m_initState & VersionChecked)) { + if (msg.address() != endpointAddress() || msg.type() != Protocol::ServerVersion) { + qFatal("Protocol violation - first message is not the server version.\n"); + } + qint32 serverVersion; + msg.payload() >> serverVersion; + if (serverVersion != Protocol::version()) { + qFatal("Server version is %d, was expecting %d - aborting.\n", serverVersion, Protocol::version()); + } + m_initState |= VersionChecked; + return; + } + + if (msg.address() == endpointAddress()) { + switch (msg.type()) { + case Protocol::ObjectAdded: + { + QString name; + Protocol::ObjectAddress addr; + msg.payload() >> name >> addr; + registerObjectInternal(name, addr); + break; + } + case Protocol::ObjectRemoved: + { + QString name; + msg.payload() >> name; + unregisterObjectInternal(name); + break; + } + case Protocol::ObjectMapReply: + { + QVector > objects; + msg.payload() >> objects; + for (QVector >::const_iterator it = objects.constBegin(); it != objects.constEnd(); ++it) { + if (it->first != endpointAddress()) + registerObjectInternal(it->second, it->first); + } + m_initState |= ObjectMapReceived; + break; + } + case Protocol::ServerInfo: + { + QString label; + msg.payload() >> label; + setLabel(label); + m_initState |= ServerInfoReceived; + break; + } + default: + qWarning() << Q_FUNC_INFO << "Got unhandled message:" << msg.type(); + return; + } + if (m_initState == InitComplete) { + m_initState |= ConnectionEstablished; + emit connectionEstablished(); + } + } else { + dispatchMessage(msg); + } +} + +Protocol::ObjectAddress Client::registerObject(const QString &name, QObject *object) +{ + Q_ASSERT(isConnected()); + Protocol::ObjectAddress address = Endpoint::registerObject(name, object); + + Message msg(endpointAddress(), Protocol::ObjectMonitored); + msg.payload() << address; + send(msg); + + return address; +} + +/// TODO: get rid of this +void Client::registerForObject(Protocol::ObjectAddress objectAddress, QObject* handler, const char* slot) +{ + Q_ASSERT(isConnected()); + registerMessageHandlerInternal(objectAddress, handler, slot); + Message msg(endpointAddress(), Protocol::ObjectMonitored); + msg.payload() << objectAddress; + send(msg); +} + +void Client::unregisterForObject(Protocol::ObjectAddress objectAddress) +{ + unregisterMessageHandlerInternal(objectAddress); + unmonitorObject(objectAddress); +} + +void Client::objectDestroyed(Protocol::ObjectAddress objectAddress, const QString &/*objectName*/, QObject * /*object*/) +{ + unmonitorObject(objectAddress); +} + +void Client::handlerDestroyed(Protocol::ObjectAddress objectAddress, const QString& /*objectName*/) +{ + unmonitorObject(objectAddress); +} + +void Client::unmonitorObject(Protocol::ObjectAddress objectAddress) +{ + if (!isConnected()) + return; + Message msg(endpointAddress(), Protocol::ObjectUnmonitored); + msg.payload() << objectAddress; + send(msg); +} + diff -Nru gammaray-1.2.2/client/client.h gammaray-2.0.1/client/client.h --- gammaray-1.2.2/client/client.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/client.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,99 @@ +/* + client.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CLIENT_H +#define GAMMARAY_CLIENT_H + +#include +#include + +#include + +namespace GammaRay { + +/** Client-side connection endpoint. */ +class Client : public Endpoint +{ + Q_OBJECT +public: + explicit Client(QObject *parent = 0); + ~Client(); + + /** Connect to @p hostName on port @p port. */ + void connectToHost(const QString &hostName, quint16 port); + + /** + * Register a client-side QObject to send/receive messages to/from the server side. + */ + Protocol::ObjectAddress registerObject(const QString &name, QObject *object); + + /** Register a message handler for @p objectAddress on object @p handler. + * Once a message for this object is received, @p slot is called. + * + * TODO: get rid of this + */ + void registerForObject(Protocol::ObjectAddress objectAddress, QObject *handler, const char* slot); + + /** Unregister the message handler for @p objectAddress. */ + void unregisterForObject(Protocol::ObjectAddress objectAddress); + + /** Singleton accessor. */ + static Client* instance(); + + bool isRemoteClient() const; + QString serverAddress() const; + +signals: + /** Emitted when we successfully established a connection and passed the protocol version handshake step. */ + void connectionEstablished(); + /** Emitted on connection errors. */ + void connectionError(QAbstractSocket::SocketError error, const QString &msg); + +protected: + void messageReceived(const Message& msg); + void objectDestroyed(Protocol::ObjectAddress objectAddress, const QString &objectName, QObject *object); + void handlerDestroyed(Protocol::ObjectAddress objectAddress, const QString& objectName); + +private: + void unmonitorObject(Protocol::ObjectAddress objectAddress); + +private slots: + void socketConnected(); + void socketError(); + +private: + enum InitState { + VersionChecked = 1, + ObjectMapReceived = 2, + ServerInfoReceived = 4, + ConnectionEstablished = 8, + + InitComplete = VersionChecked | ObjectMapReceived | ServerInfoReceived + }; + QString m_hostName; + int m_initState; +}; + +} + +#endif // GAMMARAY_CLIENT_H diff -Nru gammaray-1.2.2/client/CMakeLists.txt gammaray-2.0.1/client/CMakeLists.txt --- gammaray-1.2.2/client/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,33 @@ +set(gammaray_client_srcs + main.cpp + client.cpp + remotemodel.cpp + selectionmodelclient.cpp + clientconnectionmanager.cpp + propertycontrollerclient.cpp + probecontrollerclient.cpp +) + +qt4_add_resources(gammaray_client_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc) + +add_executable(gammaray-client WIN32 ${gammaray_client_srcs}) + +target_link_libraries(gammaray-client + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTNETWORK_LIBRARIES} + gammaray_common + gammaray_ui + gammaray_ui_internal +) + +if(QNXNTO) + target_link_libraries(gammaray-client cpp) +endif() + +gammaray_embed_info_plist(gammaray-client ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in) +set_target_properties(gammaray-client PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${LIBEXEC_INSTALL_DIR}" +) + +install(TARGETS gammaray-client DESTINATION ${LIBEXEC_INSTALL_DIR}) diff -Nru gammaray-1.2.2/client/Info.plist.in gammaray-2.0.1/client/Info.plist.in --- gammaray-1.2.2/client/Info.plist.in 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/Info.plist.in 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,14 @@ + + + CFBundleIdentifier + com.kdab.GammaRay.client + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + GammaRay + CFBundleVersion + @GAMMARAY_VERSION_STRING@ + CFBundleShortVersion + @GAMMARAY_VERSION@ + + diff -Nru gammaray-1.2.2/client/main.cpp gammaray-2.0.1/client/main.cpp --- gammaray-1.2.2/client/main.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,88 @@ +/* + main.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#include "remotemodel.h" +#include "client.h" +#include "selectionmodelclient.h" +#include "clientconnectionmanager.h" +#include "propertycontrollerclient.h" +#include "probecontrollerclient.h" + +#include +#include +#include + +#include +#include + +using namespace GammaRay; + +static QAbstractItemModel* modelFactory(const QString &name) +{ + return new RemoteModel(name, qApp); +} + +static QItemSelectionModel* selectionModelFactory(QAbstractItemModel* model) +{ + return new SelectionModelClient(model->objectName() + ".selection", model, qApp); +} + +static QObject* createPropertyController(const QString &name, QObject *parent) +{ + return new PropertyControllerClient(name, parent); +} + +static QObject* createProbeController(const QString &name, QObject *parent) +{ + QObject *o = new ProbeControllerClient(parent); + ObjectBroker::registerObject(name, o); + return o; +} + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + Paths::setRelativeRootPath(GAMMARAY_INVERSE_LIBEXEC_DIR); + + StreamOperators::registerOperators(); + + QString hostName = QLatin1String("localhost"); + quint16 port = Client::defaultPort(); + + if (app.arguments().size() == 2) { + hostName = app.arguments().at(1); + } else if (app.arguments().size() == 3) { + hostName = app.arguments().at(1); + port = app.arguments().at(2).toUShort(); + } + + ObjectBroker::registerClientObjectFactoryCallback(createPropertyController); + ObjectBroker::registerClientObjectFactoryCallback(createProbeController); + ObjectBroker::setModelFactoryCallback(modelFactory); + ObjectBroker::setSelectionModelFactoryCallback(selectionModelFactory); + + ClientConnectionManager conMan; + conMan.connectToHost(hostName, port); + return app.exec(); +} diff -Nru gammaray-1.2.2/client/probecontrollerclient.cpp gammaray-2.0.1/client/probecontrollerclient.cpp --- gammaray-1.2.2/client/probecontrollerclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/probecontrollerclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + probecontrollerclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "probecontrollerclient.h" + +#include + +using namespace GammaRay; + +ProbeControllerClient::ProbeControllerClient(QObject* parent): QObject(parent) +{ +} + +void ProbeControllerClient::detachProbe() +{ + Endpoint::instance()->invokeObject(objectName(), "detachProbe"); +} + +void ProbeControllerClient::quitHost() +{ + Endpoint::instance()->invokeObject(objectName(), "quitHost"); +} + diff -Nru gammaray-1.2.2/client/probecontrollerclient.h gammaray-2.0.1/client/probecontrollerclient.h --- gammaray-1.2.2/client/probecontrollerclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/probecontrollerclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + probecontrollerclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROBECONTROLLERCLIENT_H +#define GAMMARAY_PROBECONTROLLERCLIENT_H + +#include + +namespace GammaRay { + +class ProbeControllerClient : public QObject, public GammaRay::ProbeControllerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ProbeControllerInterface) +public: + explicit ProbeControllerClient(QObject *parent = 0); + void detachProbe(); + void quitHost(); +}; + +} + +#endif // GAMMARAY_PROBECONTROLLERCLIENT_H diff -Nru gammaray-1.2.2/client/propertycontrollerclient.cpp gammaray-2.0.1/client/propertycontrollerclient.cpp --- gammaray-1.2.2/client/propertycontrollerclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/propertycontrollerclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + propertycontrollerinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertycontrollerclient.h" + +#include +#include + +using namespace GammaRay; + +PropertyControllerClient::PropertyControllerClient(const QString &name, QObject *parent) + : PropertyControllerInterface(name, parent) +{ + +} + +PropertyControllerClient::~PropertyControllerClient() +{ + +} + +void PropertyControllerClient::activateMethod() +{ + Endpoint::instance()->invokeObject(name(), "activateMethod"); +} + +void PropertyControllerClient::invokeMethod(Qt::ConnectionType type) +{ + Endpoint::instance()->invokeObject(name(), "invokeMethod", QVariantList() << QVariant::fromValue(type)); +} + diff -Nru gammaray-1.2.2/client/propertycontrollerclient.h gammaray-2.0.1/client/propertycontrollerclient.h --- gammaray-1.2.2/client/propertycontrollerclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/propertycontrollerclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + propertycontrollerinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYCONTROLLERCLIENT_H +#define GAMMARAY_PROPERTYCONTROLLERCLIENT_H + +#include + +namespace GammaRay { + +class PropertyControllerClient : public PropertyControllerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::PropertyControllerInterface) + public: + explicit PropertyControllerClient(const QString &name, QObject *parent = 0); + virtual ~PropertyControllerClient(); + + public slots: + virtual void activateMethod(); + virtual void invokeMethod(Qt::ConnectionType type); +}; + +} + +#endif // GAMMARAY_PROPERTYCONTROLLERCLIENT_H diff -Nru gammaray-1.2.2/client/remotemodel.cpp gammaray-2.0.1/client/remotemodel.cpp --- gammaray-1.2.2/client/remotemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/remotemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,610 @@ +/* + remotemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "remotemodel.h" +#include "client.h" + +#include + +#include +#include + +using namespace GammaRay; + +RemoteModel::Node::~Node() +{ + qDeleteAll(children); +} + + +RemoteModel::RemoteModel(const QString &serverObject, QObject *parent) : + QAbstractItemModel(parent), + m_serverObject(serverObject), + m_myAddress(Protocol::InvalidObjectAddress), + m_currentSyncBarrier(0), + m_targetSyncBarrier(0) +{ + m_root = new Node; + + m_myAddress = Client::instance()->objectAddress(serverObject); + connect(Client::instance(), SIGNAL(objectRegistered(QString,Protocol::ObjectAddress)), SLOT(serverRegistered(QString,Protocol::ObjectAddress))); + connect(Client::instance(), SIGNAL(objectUnregistered(QString,Protocol::ObjectAddress)), SLOT(serverUnregistered(QString,Protocol::ObjectAddress))); + + connectToServer(); +} + +RemoteModel::~RemoteModel() +{ + delete m_root; +} + +bool RemoteModel::isConnected() const +{ + return m_myAddress != Protocol::InvalidObjectAddress; +} + +QModelIndex RemoteModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!isConnected() || row < 0 || column < 0) + return QModelIndex(); + + Node *parentNode = nodeForIndex(parent); + Q_ASSERT(parentNode->children.size() >= parentNode->rowCount); + if (parentNode->rowCount == -1) + requestRowColumnCount(parent); // trying to traverse into a branch we haven't loaded yet + if (parentNode->rowCount <= row || parentNode->columnCount <= column) + return QModelIndex(); + return createIndex(row, column, parentNode->children.at(row)); +} + +QModelIndex RemoteModel::parent(const QModelIndex &index) const +{ + Node *currentNode = nodeForIndex(index); + Q_ASSERT(currentNode); + if (currentNode == m_root || currentNode->parent == m_root) + return QModelIndex(); + Q_ASSERT(currentNode->parent && currentNode->parent->parent); + Q_ASSERT(currentNode->parent->children.contains(currentNode)); + Q_ASSERT(currentNode->parent->parent->children.contains(currentNode->parent)); + return createIndex(currentNode->parent->parent->children.indexOf(currentNode->parent), 0, currentNode->parent); +} + +int RemoteModel::rowCount(const QModelIndex &index) const +{ + if (!isConnected() || index.column() > 0) + return 0; + + Node* node = nodeForIndex(index); + Q_ASSERT(node); + if (node->rowCount < 0) { + if (node->columnCount < 0) // not yet requested vs. in the middle of insertion + requestRowColumnCount(index); + return 0; + } + return node->rowCount; +} + +int RemoteModel::columnCount(const QModelIndex &index) const +{ + if (!isConnected()) + return 0; + + Node* node = nodeForIndex(index); + Q_ASSERT(node); + if (node->columnCount < 0) { + requestRowColumnCount(index); + return 0; + } + return node->columnCount; +} + +QVariant RemoteModel::data(const QModelIndex &index, int role) const +{ + if (!isConnected() || !index.isValid()) + return QVariant(); + + Node* node = nodeForIndex(index); + Q_ASSERT(node); + + if (node->loading.contains(index.column())) { // still waiting for data + if (role == Qt::DisplayRole) + return tr("Loading..."); + return QVariant(); + } + + if (!node->data.contains(index.column())) { + requestDataAndFlags(index); + } + + // note .value returns good defaults otherwise + return node->data.value(index.column()).value(role); +} + +bool RemoteModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + if (!isConnected()) + return false; + + Message msg(m_myAddress, Protocol::ModelSetDataRequest); + msg.payload() << Protocol::fromQModelIndex(index) << role << value; + Client::send(msg); + return false; +} + +Qt::ItemFlags RemoteModel::flags(const QModelIndex& index) const +{ + Node* node = nodeForIndex(index); + Q_ASSERT(node); + + const QHash::const_iterator it = node->flags.constFind(index.column()); + if (it == node->flags.constEnd()) { + // default flags if we don't know better, otherwise we can't select into non-expanded branches + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; + } + return it.value(); +} + +QVariant RemoteModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (!isConnected()) + return QVariant(); + + if (!m_headers.contains(orientation) || !m_headers.value(orientation).contains(section)) + requestHeaderData(orientation, section); + + return m_headers.value(orientation).value(section).value(role); +} + +void RemoteModel::newMessage(const GammaRay::Message& msg) +{ + if (!checkSyncBarrier(msg)) + return; + + switch (msg.type()) { + case Protocol::ModelRowColumnCountReply: + { + Protocol::ModelIndex index; + msg.payload() >> index; + Node *node = nodeForIndex(index); + if (!node) { + // This can happen e.g. when we called a blocking operation from the remote client + // via the method invocation with a direct connection. Then when the blocking + // operation creates e.g. a QObject it is directly added/removed to the ObjectTree + // and we get signals for that. When we then though ask for column counts we will + // only get responses once the blocking operation has finished, at which point + // the object may already have been invalidated. + break; + } + int rowCount, columnCount; + msg.payload() >> rowCount >> columnCount; + Q_ASSERT(rowCount >= 0 && columnCount >= 0); + if (rowCount == node->rowCount && columnCount == node->columnCount) { + // This can happen in similar racy conditions as below, when we request the row/col count + // for two different Node* at the same index (one was deleted inbetween and then the other + // was created). Anyhow, since the data is equal we can/should ignore it anyways. + break; + } + + if (node->rowCount == -1) + break; // we didn't ask for this, probably outdated response for a moved node + + Q_ASSERT(node->rowCount < -1 && node->columnCount == -1); + + const QModelIndex qmi = modelIndexForNode(node, 0); + + if (columnCount) { + beginInsertColumns(qmi, 0, columnCount - 1); + node->columnCount = columnCount; + endInsertColumns(); + } else { + node->columnCount = 0; + } + + if (rowCount) { + beginInsertRows(qmi, 0, rowCount - 1); + node->children.reserve(rowCount); + for (int i = 0; i < rowCount; ++i) { + Node *child = new Node; + child->parent = node; + node->children.push_back(child); + } + node->rowCount = rowCount; + endInsertRows(); + } else { + node->rowCount = 0; + } + break; + } + + case Protocol::ModelContentReply: + { + Protocol::ModelIndex index; + msg.payload() >> index; + Node *node = nodeForIndex(index); + if (!node || !node->loading.contains(index.last().second)) + break; // we didn't ask for this, probably outdated response for a moved cell + typedef QHash ItemData; + ItemData itemData; + qint32 flags; + msg.payload() >> itemData >> flags; + node->data[index.last().second] = itemData; + node->flags[index.last().second] = static_cast(flags); + node->loading.remove(index.last().second); + const QModelIndex qmi = modelIndexForNode(node, index.last().second); + emit dataChanged(qmi, qmi); + break; + } + + case Protocol::ModelHeaderReply: + { + qint8 orientation; + qint32 section; + QHash data; + msg.payload() >> orientation >> section >> data; + Q_ASSERT(orientation == Qt::Horizontal || orientation == Qt::Vertical); + Q_ASSERT(section >= 0); + m_headers[static_cast(orientation)][section] = data; + if ((orientation == Qt::Horizontal && m_root->columnCount > section) || (orientation == Qt::Vertical && m_root->rowCount > section)) + emit headerDataChanged(static_cast(orientation), section, section); + break; + } + + case Protocol::ModelContentChanged: + { + Protocol::ModelIndex beginIndex, endIndex; + msg.payload() >> beginIndex >> endIndex; + Node *node = nodeForIndex(beginIndex); + if (!node || node == m_root) + break; + + Q_ASSERT(beginIndex.last().first <= endIndex.last().first); + Q_ASSERT(beginIndex.last().second <= endIndex.last().second); + + // reset content for refetching + for (int row = beginIndex.last().first; row <= endIndex.last().first; ++row) { + Node *currentRow = node->parent->children.at(row); + for (int col = beginIndex.last().second; col <= endIndex.last().second; ++col) { + currentRow->data.remove(col); + currentRow->flags.remove(col); + } + } + + const QModelIndex qmiBegin = modelIndexForNode(node, beginIndex.last().second); + const QModelIndex qmiEnd = qmiBegin.sibling(endIndex.last().first, endIndex.last().second); + + emit dataChanged(qmiBegin, qmiEnd); + break; + } + + case Protocol::ModelHeaderChanged: + { + qint8 ori; + int first, last; + msg.payload() >> ori >> first >> last; + const Qt::Orientation orientation = static_cast(ori); + + for (int i = first; i < last; ++i) + m_headers[orientation].remove(i); + + emit headerDataChanged(orientation, first, last); + break; + } + + case Protocol::ModelRowsAdded: + { + Protocol::ModelIndex parentIndex; + int first, last; + msg.payload() >> parentIndex >> first >> last; + Q_ASSERT(last >= first); + + Node *parentNode = nodeForIndex(parentIndex); + if (!parentNode || parentNode->rowCount < 0) + return; // we don't know the parent yet, so we don't care about changes to it either + doInsertRows(parentNode, first, last); + break; + } + + case Protocol::ModelRowsRemoved: + { + Protocol::ModelIndex parentIndex; + int first, last; + msg.payload() >> parentIndex >> first >> last; + Q_ASSERT(last >= first); + + Node *parentNode = nodeForIndex(parentIndex); + if (!parentNode || parentNode->rowCount < 0) + return; // we don't know the parent yet, so we don't care about changes to it either + doRemoveRows(parentNode, first, last); + break; + } + + case Protocol::ModelRowsMoved: + { + Protocol::ModelIndex sourceParentIndex, destParentIndex; + int sourceFirst, sourceLast, destChild; + msg.payload() >> sourceParentIndex >> sourceFirst >> sourceLast >> destParentIndex >> destChild; + Q_ASSERT(sourceLast >= sourceFirst); + + Node *sourceParent = nodeForIndex(sourceParentIndex); + Node *destParent = nodeForIndex(destParentIndex); + + const bool sourceKnown = sourceParent && sourceParent->rowCount >= 0; + const bool destKnown = destParent && destParent->rowCount >= 0; + + // case 1: source and destination not locally cached -> nothing to do + if (!sourceKnown && !destKnown) + break; + + // case 2: only source is locally known -> remove + if (sourceKnown && !destKnown) { + doRemoveRows(sourceParent, sourceFirst, sourceLast); + break; + } + + // case 3: only destination is locally known -> added + if (!sourceKnown && destKnown) { + doInsertRows(destParent, destChild, destChild + sourceLast - sourceFirst); + break; + } + + // case 4: source and destination are locally known -> move + if (sourceKnown && destKnown) { + doMoveRows(sourceParent, sourceFirst, sourceLast, destParent, destChild); + break; + } + } + + case Protocol::ModelColumnsAdded: + case Protocol::ModelColumnsMoved: + case Protocol::ModelColumnsRemoved: + case Protocol::ModelLayoutChanged: + { + // TODO + qWarning() << Q_FUNC_INFO << "not implemented yet" << msg.type() << m_serverObject; + } + + case Protocol::ModelReset: + { + clear(); + break; + } + } +} + +void RemoteModel::serverRegistered(const QString& objectName, Protocol::ObjectAddress objectAddress) +{ + if (m_serverObject == objectName) { + m_myAddress = objectAddress; + connectToServer(); + } +} + +void RemoteModel::serverUnregistered(const QString& objectName, Protocol::ObjectAddress objectAddress) +{ + Q_UNUSED(objectName); + if (m_myAddress == objectAddress) { + m_myAddress = Protocol::InvalidObjectAddress; + clear(); + } +} + +RemoteModel::Node* RemoteModel::nodeForIndex(const QModelIndex &index) const +{ + if (!index.isValid()) + return m_root; + return reinterpret_cast(index.internalPointer()); +} + +RemoteModel::Node* RemoteModel::nodeForIndex(const Protocol::ModelIndex &index) const +{ + Node *node = m_root; + for (int i = 0; i < index.size(); ++i) { + if (node->children.size() <= index[i].first) + return 0; + node = node->children[index[i].first]; + } + return node; +} + +QModelIndex RemoteModel::modelIndexForNode(Node* node, int column) const +{ + Q_ASSERT(node); + if (node == m_root) + return QModelIndex(); + return createIndex(node->parent->children.indexOf(node), column, node); +} + +void RemoteModel::requestRowColumnCount(const QModelIndex &index) const +{ + Node *node = nodeForIndex(index); + Q_ASSERT(node); + Q_ASSERT(node->rowCount < 0 && node->columnCount < 0); + + if (node->rowCount < -1) // already requesting + return; + node->rowCount = -2; + + Message msg(m_myAddress, Protocol::ModelRowColumnCountRequest); + msg.payload() << Protocol::fromQModelIndex(index); + Client::send(msg); +} + +void RemoteModel::requestDataAndFlags(const QModelIndex& index) const +{ + Node *node = nodeForIndex(index); + Q_ASSERT(node); + Q_ASSERT(!node->data.contains(index.column())); + Q_ASSERT(!node->flags.contains(index.column())); + Q_ASSERT(!node->loading.contains(index.column())); + + node->loading.insert(index.column()); // mark pending request + + Message msg(m_myAddress, Protocol::ModelContentRequest); + msg.payload() << Protocol::fromQModelIndex(index); + Client::send(msg); +} + +void RemoteModel::requestHeaderData(Qt::Orientation orientation, int section) const +{ + Q_ASSERT(section >= 0); + Q_ASSERT(!m_headers.value(orientation).contains(section)); + m_headers[orientation][section][Qt::DisplayRole] = tr("Loading..."); + + Message msg(m_myAddress, Protocol::ModelHeaderRequest); + msg.payload() << qint8(orientation) << qint32(section); + Client::send(msg); +} + +void RemoteModel::clear() +{ + beginResetModel(); + + Message msg(m_myAddress, Protocol::ModelSyncBarrier); + msg.payload() << ++m_targetSyncBarrier; + Client::send(msg); + + delete m_root; + m_root = new Node; + m_headers.clear(); + endResetModel(); +} + +void RemoteModel::connectToServer() +{ + if (m_myAddress == Protocol::InvalidObjectAddress) + return; + + beginResetModel(); + Client::instance()->registerForObject(m_myAddress, this, "newMessage"); + endResetModel(); +} + +bool RemoteModel::checkSyncBarrier(const Message& msg) +{ + if (msg.type() == Protocol::ModelSyncBarrier) + msg.payload() >> m_currentSyncBarrier; + + return m_currentSyncBarrier == m_targetSyncBarrier; +} + +void RemoteModel::resetLoadingState(RemoteModel::Node* node, int startRow) const +{ + if (node->rowCount < 0) { + node->rowCount = -1; // reset row count loading state + return; + } + + Q_ASSERT(node->children.size() == node->rowCount); + for (int row = startRow; row < node->rowCount; ++row) { + Node *child = node->children[row]; + child->loading.clear(); + resetLoadingState(child, 0); + } +} + +void RemoteModel::doInsertRows(RemoteModel::Node* parentNode, int first, int last) +{ + Q_ASSERT(parentNode->rowCount == parentNode->children.size()); + + const QModelIndex qmiParent = modelIndexForNode(parentNode, 0); + beginInsertRows(qmiParent, first, last); + + // allocate rows in the right spot + if (first == parentNode->children.size()) + parentNode->children.resize(parentNode->children.size() + 1 + last - first); + else + parentNode->children.insert(first, last - first + 1, 0); + + // create nodes for the new rows + for (int i = first; i <= last; ++i) { + Node *child = new Node; + child->parent = parentNode; + parentNode->children[i] = child; + } + + // adjust row count + parentNode->rowCount += last - first + 1; + Q_ASSERT(parentNode->rowCount == parentNode->children.size()); + + endInsertRows(); + resetLoadingState(parentNode, last); +} + +void RemoteModel::doRemoveRows(RemoteModel::Node* parentNode, int first, int last) +{ + Q_ASSERT(parentNode->rowCount == parentNode->children.size()); + + const QModelIndex qmiParent = modelIndexForNode(parentNode, 0); + beginRemoveRows(qmiParent, first, last); + + // delete nodes + for (int i = first; i <= last; ++i) + delete parentNode->children.at(i); + parentNode->children.remove(first, last - first + 1); + + // adjust row count + parentNode->rowCount -= last - first + 1; + Q_ASSERT(parentNode->rowCount == parentNode->children.size()); + + endRemoveRows(); + resetLoadingState(parentNode, first); +} + +void RemoteModel::doMoveRows(RemoteModel::Node* sourceParentNode, int sourceStart, int sourceEnd, RemoteModel::Node* destParentNode, int destStart) +{ + Q_ASSERT(sourceParentNode->rowCount == sourceParentNode->children.size()); + Q_ASSERT(destParentNode->rowCount == destParentNode->children.size()); + + const int destEnd = destStart + sourceEnd - sourceStart; + const int amount = sourceEnd - sourceStart + 1; + + const QModelIndex qmiSourceParent = modelIndexForNode(sourceParentNode, 0); + const QModelIndex qmiDestParent = modelIndexForNode(destParentNode, 0); + beginMoveRows(qmiSourceParent, sourceStart, sourceEnd, qmiDestParent, destStart); + + // make room in the destination + if (destStart == destParentNode->children.size()) + destParentNode->children.resize(destParentNode->children.size() + amount); + else + destParentNode->children.insert(destStart, amount, 0); + + // move nodes + for (int i = 0; i < amount; ++i) { + Node *node = sourceParentNode->children.at(sourceStart + i); + node->parent = destParentNode; + destParentNode->children[destStart + i] = node; + } + + // shrink source + sourceParentNode->children.remove(sourceStart, amount); + + // adjust row count + sourceParentNode->rowCount -= amount; + destParentNode->rowCount += amount; + Q_ASSERT(sourceParentNode->rowCount == sourceParentNode->children.size()); + Q_ASSERT(destParentNode->rowCount == destParentNode->children.size()); + + endMoveRows(); + resetLoadingState(sourceParentNode, sourceStart); + resetLoadingState(destParentNode, destEnd); +} diff -Nru gammaray-1.2.2/client/remotemodel.h gammaray-2.0.1/client/remotemodel.h --- gammaray-1.2.2/client/remotemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/remotemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,109 @@ +/* + remotemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_REMOTEMODEL_H +#define GAMMARAY_REMOTEMODEL_H + +#include + +#include +#include +#include + +namespace GammaRay { + +class Message; + +class RemoteModel : public QAbstractItemModel +{ + Q_OBJECT + public: + explicit RemoteModel(const QString &serverObject, QObject *parent = 0); + ~RemoteModel(); + + bool isConnected() const; + + QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex& child) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; + int columnCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex& index) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + public slots: + void newMessage(const GammaRay::Message &msg); + void serverRegistered(const QString &objectName, Protocol::ObjectAddress objectAddress); + void serverUnregistered(const QString& objectName, Protocol::ObjectAddress objectAddress); + + private: + struct Node { // represents one row + Node() : parent(0), rowCount(-1), columnCount(-1) {} + ~Node(); + Node* parent; + QVector children; + qint32 rowCount; + qint32 columnCount; + QHash > data; // column -> role -> data + QHash flags; // column -> flags + QSet loading; // columns waiting for data (ie. showing "Loading...") + }; + + void clear(); + void connectToServer(); + + bool checkSyncBarrier(const Message &msg); + + Node* nodeForIndex(const QModelIndex &index) const; + Node* nodeForIndex(const Protocol::ModelIndex &index) const; + QModelIndex modelIndexForNode(GammaRay::RemoteModel::Node* node, int column) const; + + void requestRowColumnCount(const QModelIndex &index) const; + void requestDataAndFlags(const QModelIndex &index) const; + void requestHeaderData(Qt::Orientation orientation, int section) const; + /// Reset the loading state for all rows at @p startRow or later. + /// This is needed when rows have been added or removed before @p startRow, since + /// pending replies might have a wrong index. + void resetLoadingState(Node *node, int startRow) const; + + /// execute a insertRows() operation + void doInsertRows(Node *parentNode, int first, int last); + /// execute a removeRows() operation + void doRemoveRows(Node *parentNode, int first, int last); + /// execute a rowsMoved() operation + void doMoveRows(Node *sourceParentNode, int sourceStart, int sourceEnd, Node* destParentNode, int destStart); + + Node* m_root; + + mutable QHash > > m_headers; // orientation -> section -> role -> data + + QString m_serverObject; + Protocol::ObjectAddress m_myAddress; + + qint32 m_currentSyncBarrier, m_targetSyncBarrier; +}; + +} + +#endif diff -Nru gammaray-1.2.2/client/selectionmodelclient.cpp gammaray-2.0.1/client/selectionmodelclient.cpp --- gammaray-1.2.2/client/selectionmodelclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/selectionmodelclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,64 @@ +/* + selectionmodelclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "selectionmodelclient.h" +#include "client.h" + +using namespace GammaRay; + +SelectionModelClient::SelectionModelClient(const QString& objectName, QAbstractItemModel* model, QObject* parent) : + NetworkSelectionModel(objectName, model, parent) +{ + m_myAddress = Client::instance()->objectAddress(objectName); + connect(Client::instance(), SIGNAL(objectRegistered(QString,Protocol::ObjectAddress)), SLOT(serverRegistered(QString,Protocol::ObjectAddress))); + connect(Client::instance(), SIGNAL(objectUnregistered(QString,Protocol::ObjectAddress)), SLOT(serverUnregistered(QString,Protocol::ObjectAddress))); + connectToServer(); +} + +SelectionModelClient::~SelectionModelClient() +{ +} + +void SelectionModelClient::connectToServer() +{ + if (m_myAddress == Protocol::InvalidObjectAddress) + return; + Client::instance()->registerForObject(m_myAddress, this, "newMessage"); + // TODO: send initial selection? +} + +void SelectionModelClient::serverRegistered(const QString& objectName, Protocol::ObjectAddress objectAddress) +{ + if (objectName == m_objectName) { + m_myAddress = objectAddress; + connectToServer(); + } +} + +void SelectionModelClient::serverUnregistered(const QString& objectName, Protocol::ObjectAddress objectAddress) +{ + Q_UNUSED(objectAddress); + if (objectName == m_objectName) + m_myAddress = Protocol::InvalidObjectAddress; +} + diff -Nru gammaray-1.2.2/client/selectionmodelclient.h gammaray-2.0.1/client/selectionmodelclient.h --- gammaray-1.2.2/client/selectionmodelclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/client/selectionmodelclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + selectionmodelclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SELECTIONMODELCLIENT_H +#define GAMMARAY_SELECTIONMODELCLIENT_H + +#include + +namespace GammaRay { + +/** Client side of the network transparent QItemSelectionModel. */ +class SelectionModelClient : public NetworkSelectionModel +{ + Q_OBJECT +public: + SelectionModelClient(const QString& objectName, QAbstractItemModel* model, QObject* parent); + ~SelectionModelClient(); + +private slots: + void serverRegistered(const QString &objectName, Protocol::ObjectAddress objectAddress); + void serverUnregistered(const QString &objectName, Protocol::ObjectAddress objectAddress); + +private: + void connectToServer(); +}; + +} + +#endif // GAMMARAY_SELECTIONMODELCLIENT_H diff -Nru gammaray-1.2.2/cmake/CMakeLists.txt gammaray-2.0.1/cmake/CMakeLists.txt --- gammaray-1.2.2/cmake/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1 @@ +install(FILES GammaRayMacros.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR}) diff -Nru gammaray-1.2.2/cmake/ECMQt4To5Porting.cmake gammaray-2.0.1/cmake/ECMQt4To5Porting.cmake --- gammaray-1.2.2/cmake/ECMQt4To5Porting.cmake 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/cmake/ECMQt4To5Porting.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -30,125 +30,20 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #============================================================================= -# The automoc_qt4 macro is superceded by CMAKE_AUTOMOC from CMake 2.8.6 -# A Qt 5 version is not provided by CMake or Qt. - -include(MacroAddFileDependencies) - -MACRO (QT4_GET_MOC_FLAGS _moc_flags) - SET(${_moc_flags}) - GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES) - - FOREACH(_current ${_inc_DIRS}) - IF("${_current}" MATCHES "\\.framework/?$") - STRING(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}") - SET(${_moc_flags} ${${_moc_flags}} "-F${framework_path}") - ELSE("${_current}" MATCHES "\\.framework/?$") - SET(${_moc_flags} ${${_moc_flags}} "-I${_current}") - ENDIF("${_current}" MATCHES "\\.framework/?$") - ENDFOREACH(_current ${_inc_DIRS}) - - GET_DIRECTORY_PROPERTY(_defines COMPILE_DEFINITIONS) - FOREACH(_current ${_defines}) - SET(${_moc_flags} ${${_moc_flags}} "-D${_current}") - ENDFOREACH(_current ${_defines}) - - IF(Q_WS_WIN) - SET(${_moc_flags} ${${_moc_flags}} -DWIN32) - ENDIF(Q_WS_WIN) - -ENDMACRO(QT4_GET_MOC_FLAGS) - -# helper macro to set up a moc rule -MACRO (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options) - # For Windows, create a parameters file to work around command line length limit - IF (WIN32) - # Pass the parameters in a file. Set the working directory to - # be that containing the parameters file and reference it by - # just the file name. This is necessary because the moc tool on - # MinGW builds does not seem to handle spaces in the path to the - # file given with the @ syntax. - GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) - GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) - IF(_moc_outfile_dir) - SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) - ENDIF(_moc_outfile_dir) - SET (_moc_parameters_file ${outfile}_parameters) - SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") - STRING (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}") - FILE (WRITE ${_moc_parameters_file} "${_moc_parameters}") - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters - DEPENDS ${infile} - ${_moc_working_dir} - VERBATIM) - ELSE (WIN32) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} - ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} - DEPENDS ${infile} VERBATIM) - ENDIF (WIN32) -ENDMACRO (QT4_CREATE_MOC_COMMAND) - - -MACRO(QT4_AUTOMOC) - QT4_GET_MOC_FLAGS(_moc_INCS) - - SET(_matching_FILES ) - FOREACH (_current_FILE ${ARGN}) - - GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE) - # if "SKIP_AUTOMOC" is set to true, we will not handle this file here. - # This is required to make uic work correctly: - # we need to add generated .cpp files to the sources (to compile them), - # but we cannot let automoc handle them, as the .cpp files don't exist yet when - # cmake is run for the very first time on them -> however the .cpp files might - # exist at a later run. at that time we need to skip them, so that we don't add two - # different rules for the same moc file - GET_SOURCE_FILE_PROPERTY(_skip ${_abs_FILE} SKIP_AUTOMOC) - - IF ( NOT _skip AND EXISTS ${_abs_FILE} ) - - FILE(READ ${_abs_FILE} _contents) - - GET_FILENAME_COMPONENT(_abs_PATH ${_abs_FILE} PATH) - - STRING(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}") - IF(_match) - FOREACH (_current_MOC_INC ${_match}) - STRING(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") - - GET_FILENAME_COMPONENT(_basename ${_current_MOC} NAME_WE) - IF(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_header ${_abs_PATH}/${_basename}.hpp) - ELSE(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_header ${_abs_PATH}/${_basename}.h) - ENDIF(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) - QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "") - MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) - ENDFOREACH (_current_MOC_INC) - ENDIF(_match) - ENDIF ( NOT _skip AND EXISTS ${_abs_FILE} ) - ENDFOREACH (_current_FILE) -ENDMACRO(QT4_AUTOMOC) - - # Portability helpers. set(QT_QTGUI_LIBRARIES ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} - ${Qt5PrintSupport_LIBRARIES} - ${Qt5Svg_LIBRARIES} ) set(QT_INCLUDES - ${Qt5Gui_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} - ${Qt5PrintSupport_INCLUDE_DIRS} - ${Qt5Svg_INCLUDE_DIRS} + ${Qt5Gui_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5PrintSupport_INCLUDE_DIRS} + ${Qt5Svg_INCLUDE_DIRS} ) + set(QT_QTGUI_LIBRARY ${QT_QTGUI_LIBRARIES}) set(_qt_modules @@ -164,9 +59,10 @@ Xml UiTools Quick1 - WebKit + WebKitWidgets Sql OpenGL + Svg ) foreach(_module ${_qt_modules}) @@ -177,9 +73,6 @@ set(QT_QT${_module_upper}_FOUND ${Qt5${_module}_FOUND}) endforeach() -list(APPEND QT_QTCORE_LIBRARIES ${Qt5Concurrent_LIBRARIES}) -list(APPEND QT_QTCORE_LIBRARY ${Qt5Concurrent_LIBRARIES}) - set(QT_QTDECLARATIVE_LIBRARIES ${Qt5Quick1_LIBRARIES}) set(QT_QTDECLARATIVE_LIBRARY ${Qt5Quick1_LIBRARIES}) @@ -191,10 +84,6 @@ qt5_wrap_cpp(${ARGN}) endmacro() -macro(qt4_generate_moc) - qt5_generate_moc(${ARGN}) -endmacro() - macro(qt4_add_dbus_adaptor) qt5_add_dbus_adaptor(${ARGN}) endmacro() diff -Nru gammaray-1.2.2/cmake/FindGraphviz.cmake gammaray-2.0.1/cmake/FindGraphviz.cmake --- gammaray-1.2.2/cmake/FindGraphviz.cmake 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/cmake/FindGraphviz.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -8,25 +8,51 @@ # GRAPHVIZ_MAJOR_VERSION = The library major version number # GRAPHVIZ_MINOR_VERSION = The library minor version number # GRAPHVIZ_PATCH_VERSION = The library patch version number +# +# This module reads hints about search locations from the following env variables: +# GRAPHVIZ_ROOT - Graphviz installation prefix +# (containing bin/, include/, etc.) # Copyright (c) 2009, Adrien Bustany, +# Copyright (c) 2013-2014 Kevin Funk # Version computation and some cleanups by Allen Winter -# Copyright (c) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company +# Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company # Redistribution and use is allowed according to the terms of the GPLv3+ license. include(CheckIncludeFiles) +include(CMakePushCheckState) if(NOT GRAPHVIZ_MIN_VERSION) set(GRAPHVIZ_MIN_VERSION "2.00") endif() -if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_GRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY) +if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY + AND (GRAPHVIZ_CGRAPH_LIBRARY OR GRAPHVIZ_GRAPH_LIBRARY) AND GRAPHVIZ_PATHPLAN_LIBRARY) set(GRAPHVIZ_FIND_QUIETLY TRUE) endif() -find_path(GRAPHVIZ_INCLUDE_DIR graphviz/graph.h) +set(_GRAPHVIZ_ROOT $ENV{GRAPHVIZ_ROOT}) + +if(NOT _GRAPHVIZ_ROOT) + if(WIN32) + find_program(DOT_TOOL dot) + get_filename_component(_GRAPHVIZ_ROOT ${DOT_TOOL} PATH) + endif() +endif() + +if(_GRAPHVIZ_ROOT) + set(_GRAPHVIZ_INCLUDE_DIR ${_GRAPHVIZ_ROOT}/include) + set(_GRAPHVIZ_LIBRARY_DIR ${_GRAPHVIZ_ROOT}/lib) + set(_GRAPHVIZ_FIND_OPTS NO_DEFAULT_PATH) +else() + set(_GRAPHVIZ_FIND_OPTS "") +endif() + +find_path(GRAPHVIZ_INCLUDE_DIR NAMES graphviz/graph.h graphviz/cgraph.h + HINTS ${_GRAPHVIZ_INCLUDE_DIR} + ${_GRAPHVIZ_FIND_OPTS}) if(WIN32) if(CMAKE_BUILD_TYPE STREQUAL "Release") @@ -38,60 +64,83 @@ set(GRAPHVIZ_LIB_PATH_SUFFIX) endif() -find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX}) -find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX}) -find_library(GRAPHVIZ_CGRAPH_LIBRARY NAMES cgraph PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX}) -find_library(GRAPHVIZ_GRAPH_LIBRARY NAMES graph PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX}) -find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX}) +find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt + HINTS ${_GRAPHVIZ_LIBRARY_DIR} PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX} + ${_GRAPHVIZ_FIND_OPTS}) +find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc + HINTS ${_GRAPHVIZ_LIBRARY_DIR} PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX} + ${_GRAPHVIZ_FIND_OPTS}) +find_library(GRAPHVIZ_CGRAPH_LIBRARY NAMES cgraph + HINTS ${_GRAPHVIZ_LIBRARY_DIR} PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX} + ${_GRAPHVIZ_FIND_OPTS}) +find_library(GRAPHVIZ_GRAPH_LIBRARY NAMES graph + HINTS ${_GRAPHVIZ_LIBRARY_DIR} PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX} + ${_GRAPHVIZ_FIND_OPTS}) +find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan + HINTS ${_GRAPHVIZ_LIBRARY_DIR} PATH_SUFFIXES ${GRAPHVIZ_LIB_PATH_SUFFIX} + ${_GRAPHVIZ_FIND_OPTS}) +cmake_push_check_state() +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${GRAPHVIZ_INCLUDE_DIR}) check_include_files(graphviz/graphviz_version.h HAVE_GRAPHVIZ_VERSION_H) +cmake_pop_check_state() if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GVC_LIBRARY - AND GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_GRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY - AND HAVE_GRAPHVIZ_VERSION_H) - set(GRAPHVIZ_FOUND TRUE) + AND (GRAPHVIZ_CGRAPH_LIBRARY OR GRAPHVIZ_GRAPH_LIBRARY) AND GRAPHVIZ_PATHPLAN_LIBRARY) + if(HAVE_GRAPHVIZ_VERSION_H OR WIN32) + set(GRAPHVIZ_FOUND TRUE) + endif() else() set(GRAPHVIZ_FOUND FALSE) endif() # Ok, now compute the version and make sure its greater then the min required if(GRAPHVIZ_FOUND) - set(FIND_GRAPHVIZ_VERSION_SOURCE - "#include \n#include \n int main()\n {\n printf(\"%s\",PACKAGE_VERSION);return 1;\n }\n") - set(FIND_GRAPHVIZ_VERSION_SOURCE_FILE ${CMAKE_BINARY_DIR}/CMakeTmp/FindGRAPHVIZ.cxx) - file(WRITE "${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}" "${FIND_GRAPHVIZ_VERSION_SOURCE}") - - set(FIND_GRAPHVIZ_VERSION_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${GRAPHVIZ_INCLUDE_DIR}") - - if(NOT CMAKE_CROSSCOMPILING) - try_run(RUN_RESULT COMPILE_RESULT - ${CMAKE_BINARY_DIR} - ${FIND_GRAPHVIZ_VERSION_SOURCE_FILE} - CMAKE_FLAGS "${FIND_GRAPHVIZ_VERSION_ADD_INCLUDES}" - RUN_OUTPUT_VARIABLE GRAPHVIZ_VERSION) - endif() + if(NOT WIN32) + set(FIND_GRAPHVIZ_VERSION_SOURCE + "#include \n#include \n int main()\n {\n printf(\"%s\",PACKAGE_VERSION);return 1;\n }\n") + set(FIND_GRAPHVIZ_VERSION_SOURCE_FILE ${CMAKE_BINARY_DIR}/CMakeTmp/FindGRAPHVIZ.cxx) + file(WRITE "${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}" "${FIND_GRAPHVIZ_VERSION_SOURCE}") + + set(FIND_GRAPHVIZ_VERSION_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${GRAPHVIZ_INCLUDE_DIR}") - if(COMPILE_RESULT AND RUN_RESULT EQUAL 1 AND NOT CMAKE_CROSSCOMPILING) - message(STATUS "Found Graphviz version ${GRAPHVIZ_VERSION}") - if(${GRAPHVIZ_VERSION} VERSION_LESS ${GRAPHVIZ_MIN_VERSION}) - message(STATUS "Graphviz version ${GRAPHVIZ_VERSION} is too old. At least version ${GRAPHVIZ_MIN_VERSION} is needed.") - set(GRAPHVIZ_FOUND FALSE) - set(GRAPHVIZ_INCLUDE_DIR "") - set(GRAPHVIZ_CDT_LIBRARY "") - set(GRAPHVIZ_GVC_LIBRARY "") - set(GRAPHVIZ_CGRAPH_LIBRARY "") - set(GRAPHVIZ_GRAPH_LIBRARY "") - set(GRAPHVIZ_PATHPLAN_LIBRARY "") - endif(${GRAPHVIZ_VERSION} VERSION_LESS ${GRAPHVIZ_MIN_VERSION}) - else() if(NOT CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "Unable to compile or run the graphviz version detection program.") + try_run(RUN_RESULT COMPILE_RESULT + ${CMAKE_BINARY_DIR} + ${FIND_GRAPHVIZ_VERSION_SOURCE_FILE} + CMAKE_FLAGS "${FIND_GRAPHVIZ_VERSION_ADD_INCLUDES}" + RUN_OUTPUT_VARIABLE GRAPHVIZ_VERSION) endif() - endif() - # Compute the major and minor version numbers - if(NOT CMAKE_CROSSCOMPILING) + if(COMPILE_RESULT AND RUN_RESULT EQUAL 1 AND NOT CMAKE_CROSSCOMPILING) + message(STATUS "Found Graphviz version ${GRAPHVIZ_VERSION}") + if(${GRAPHVIZ_VERSION} VERSION_LESS ${GRAPHVIZ_MIN_VERSION}) + message(STATUS "Graphviz version ${GRAPHVIZ_VERSION} is too old. At least version ${GRAPHVIZ_MIN_VERSION} is needed.") + set(GRAPHVIZ_FOUND FALSE) + set(GRAPHVIZ_INCLUDE_DIR "") + set(GRAPHVIZ_CDT_LIBRARY "") + set(GRAPHVIZ_GVC_LIBRARY "") + set(GRAPHVIZ_CGRAPH_LIBRARY "") + set(GRAPHVIZ_GRAPH_LIBRARY "") + set(GRAPHVIZ_PATHPLAN_LIBRARY "") + else(${GRAPHVIZ_VERSION} VERSION_LESS ${GRAPHVIZ_MIN_VERSION}) + # Compute the major and minor version numbers + if(NOT CMAKE_CROSSCOMPILING) + string(REPLACE "." ";" VL ${GRAPHVIZ_VERSION}) + list(GET VL 0 GRAPHVIZ_MAJOR_VERSION) + list(GET VL 1 GRAPHVIZ_MINOR_VERSION) + list(GET VL 2 GRAPHVIZ_PATCH_VERSION) + endif() + endif(${GRAPHVIZ_VERSION} VERSION_LESS ${GRAPHVIZ_MIN_VERSION}) + else() + if(NOT CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "Unable to compile or run the graphviz version detection program.") + endif() + endif() + elseif(WIN32) + execute_process(COMMAND ${DOT_TOOL} -V OUTPUT_VARIABLE DOT_VERSION_OUTPUT ERROR_VARIABLE DOT_VERSION_OUTPUT OUTPUT_QUIET) + string(REGEX MATCH "([0-9]*\\.[0-9]*\\.[0-9]*)" GRAPHVIZ_VERSION "${DOT_VERSION_OUTPUT}") string(REPLACE "." ";" VL ${GRAPHVIZ_VERSION}) list(GET VL 0 GRAPHVIZ_MAJOR_VERSION) list(GET VL 1 GRAPHVIZ_MINOR_VERSION) diff -Nru gammaray-1.2.2/cmake/FindQt5Transitional.cmake gammaray-2.0.1/cmake/FindQt5Transitional.cmake --- gammaray-1.2.2/cmake/FindQt5Transitional.cmake 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/cmake/FindQt5Transitional.cmake 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ - -find_package(Qt5Core QUIET) - -if (Qt5Core_FOUND) - if (NOT Qt5Transitional_FIND_COMPONENTS) - foreach(_component - Core - Gui - DBus - Designer - Script - ScriptTools - Network - Test - Xml - Svg - Sql - Widgets - PrintSupport - Concurrent - UiTools - Quick1 - WebKit - OpenGL - ) - find_package(Qt5${_component}) - endforeach() - else() - foreach(_component ${Qt5Transitional_FIND_COMPONENTS}) - if ("${_component}" STREQUAL "Declarative") - set(_component Quick1) - endif() - find_package(Qt5${_component} REQUIRED) - if ("${_component}" STREQUAL "Gui") - find_package(Qt5Widgets REQUIRED) - find_package(Qt5PrintSupport REQUIRED) - find_package(Qt5Svg REQUIRED) - endif() - if ("${_component}" STREQUAL "Core") - find_package(Qt5Concurrent REQUIRED) - endif() - endforeach() - endif() - - set(Qt5Transitional_FOUND TRUE) - set(QT5_BUILD TRUE) - - include("${CMAKE_CURRENT_LIST_DIR}/ECMQt4To5Porting.cmake") # TODO: Port away from this. - include_directories(${QT_INCLUDES}) # TODO: Port away from this. -else() - foreach(_component ${Qt5Transitional_FIND_COMPONENTS}) - if("${_component}" STREQUAL "Widgets") # new in Qt5 - set(_component Gui) - elseif("${_component}" STREQUAL "Concurrent") # new in Qt5 - set(_component Core) - endif() - list(APPEND _components Qt${_component}) - endforeach() - find_package(Qt4 REQUIRED ${_components}) - include_directories(${QT_INCLUDES}) - - if(QT4_FOUND) - set(Qt5Transitional_FOUND TRUE) - endif() -endif() diff -Nru gammaray-1.2.2/cmake/GammaRayMacros.cmake gammaray-2.0.1/cmake/GammaRayMacros.cmake --- gammaray-1.2.2/cmake/GammaRayMacros.cmake 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/cmake/GammaRayMacros.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -2,14 +2,25 @@ # GAMMARAY_ADD_PLUGIN: create a gammaray plugin, install at the right place, etc # +# Copyright (c) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Author: Volker Krause +# +# Redistribution and use is allowed according to the terms of the BSD license. + macro(gammaray_add_plugin _target_name _desktop_file) + if(NOT PLUGIN_INSTALL_DIR) # HACK for external plugins that don't set PLUGIN_INSTALL_DIR + set(PLUGIN_INSTALL_DIR ${GAMMARAY_PLUGIN_INSTALL_DIR}) + endif() + set(_install_target_dir "${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}") + set(_build_target_dir "${PROJECT_BINARY_DIR}/${_install_target_dir}") + add_library(${_target_name} MODULE ${ARGN}) - set_target_properties(${_target_name} PROPERTIES + set_target_properties(${_target_name} PROPERTIES PREFIX "" - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/plugins/gammaray + LIBRARY_OUTPUT_DIRECTORY ${_build_target_dir} ) - install(TARGETS ${_target_name} DESTINATION ${PLUGIN_INSTALL_DIR}/gammaray/) - install(FILES ${_desktop_file} DESTINATION ${PLUGIN_INSTALL_DIR}/gammaray/) - #execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/${_desktop_file}" "${PROJECT_BINARY_DIR}/lib/plugins/gammaray") - file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${_desktop_file}" DESTINATION "${PROJECT_BINARY_DIR}/lib/plugins/gammaray") + install(TARGETS ${_target_name} DESTINATION ${_install_target_dir}) + install(FILES ${_desktop_file} DESTINATION ${_install_target_dir}) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${_desktop_file}" "${_build_target_dir}/${_desktop_file}") endmacro() diff -Nru gammaray-1.2.2/cmake/GammaRayMacrosInternal.cmake gammaray-2.0.1/cmake/GammaRayMacrosInternal.cmake --- gammaray-1.2.2/cmake/GammaRayMacrosInternal.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/GammaRayMacrosInternal.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +# GammaRay-specific CMake macros that don't make sense outside of the GammaRay source tree. + +# Copyright (c) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Author: Volker Krause +# +# Redistribution and use is allowed according to the terms of the BSD license. + +macro(gammaray_install_headers) + get_filename_component(_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME) + if(NOT GAMMARAY_PROBE_ONLY_BUILD) + install(FILES ${ARGN} DESTINATION ${INCLUDE_INSTALL_DIR}/${_dir}) + endif() + set_directory_properties(PROPERTIES GAMMARAY_INSTALLED_HEADERS "${ARGN}") + + get_property(_include_dirs GLOBAL PROPERTY GAMMARAY_HEADER_DIRS) + list(APPEND _include_dirs "${_dir}") + set_property(GLOBAL PROPERTY GAMMARAY_HEADER_DIRS "${_include_dirs}") +endmacro() + +macro(gammaray_all_installed_headers _var) + set(${_var} "") + get_property(_include_dirs GLOBAL PROPERTY GAMMARAY_HEADER_DIRS) + foreach(_dir ${_include_dirs}) + get_directory_property(_hdrs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_dir} GAMMARAY_INSTALLED_HEADERS) + foreach(_hdr ${_hdrs}) + list(APPEND ${_var} "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/${_hdr}") + endforeach() + endforeach() +endmacro() + +macro(gammaray_join_list _var _sep) + set(${_var} "") + foreach(_element ${ARGN}) + set(${_var} "${${_var}}${_sep}${_element}") + endforeach() +endmacro() + +macro(gammaray_inverse_dir _var _prefix) + file(RELATIVE_PATH ${_var} "${CMAKE_INSTALL_PREFIX}/${_prefix}" "${CMAKE_INSTALL_PREFIX}") +endmacro() + +# embed an Info.plist file into a non-bundled Mac executable +macro(gammaray_embed_info_plist _target _plist) + configure_file(${_plist} ${CMAKE_CURRENT_BINARY_DIR}/${_target}_Info.plist) + if(APPLE) + set_target_properties(${_target} PROPERTIES LINK_FLAGS "-sectcreate __TEXT __info_plist ${CMAKE_CURRENT_BINARY_DIR}/${_target}_Info.plist") + endif() +endmacro() diff -Nru gammaray-1.2.2/cmake/GammaRayProbeABI.cmake gammaray-2.0.1/cmake/GammaRayProbeABI.cmake --- gammaray-1.2.2/cmake/GammaRayProbeABI.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/GammaRayProbeABI.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,64 @@ +# Determine probe ABI identifier +# + +# Copyright (c) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Author: Volker Krause +# +# Redistribution and use is allowed according to the terms of the BSD license. + +# This contains all properties that define ABI compatibility of a probe with a target + +# Qt version +if(Qt5Core_FOUND) + set(GAMMARAY_PROBE_ABI "qt${Qt5Core_VERSION_MAJOR}.${Qt5Core_VERSION_MINOR}") +else() + set(GAMMARAY_PROBE_ABI "qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}") +endif() + + +# on Windows, the compiler also matters +if(WIN32) + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-${CMAKE_CXX_COMPILER_ID}") +endif() + + +# debug vs. release (Windows only) +if(WIN32) + if(CMAKE_BUILD_TYPE MATCHES "^[Rr]el") + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-release") + else() + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-debug") + endif() +endif() + + +# processor architecture +# this is a bit messy since CMAKE_SYSTEM_PROCESSOR seems to contain the host CPU rather than the target architecture sometimes +# and is empty on cross-builds by default +if(NOT CMAKE_SYSTEM_PROCESSOR) + message(FATAL_ERROR "Unknown target architecture. Make sure to specify CMAKE_SYSTEM_PROCESSOR in your toolchain file!") +endif() + +# on Windows our best bet is CMAKE_SIZEOF_VOID_P and assuming a x86 host==target build +if(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-x86_64") + else() + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-i686") + endif() + +# on Mac we apparently always get i386 on x86 +elseif(APPLE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386" AND CMAKE_SIZEOF_VOID_P EQUAL 8) + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-x86_64") + else() + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-${CMAKE_SYSTEM_PROCESSOR}") + endif() + +else() + set(GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}-${CMAKE_SYSTEM_PROCESSOR}") +endif() + + +message(STATUS "Building probe for ABI: ${GAMMARAY_PROBE_ABI}") diff -Nru gammaray-1.2.2/cmake/Toolchain-blackberry-armv7le.cmake gammaray-2.0.1/cmake/Toolchain-blackberry-armv7le.cmake --- gammaray-1.2.2/cmake/Toolchain-blackberry-armv7le.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/Toolchain-blackberry-armv7le.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,33 @@ +# Basic cmake toolchain file for BlackBerry 10 + +# Copyright (c) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Author: Rafael Roquetto +# +# Redistribution and use is allowed according to the terms of the BSD license. + +# the name of the target operating system +set(CMAKE_SYSTEM_NAME QNX) +set(CMAKE_SYSTEM_PROCESSOR "armv7le") + +# which compilers to use for C and C++ +set(arch gcc_ntoarmv7le) +set(CMAKE_C_COMPILER qcc -V${arch}) +set(CMAKE_CXX_COMPILER QCC -V${arch}) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH $ENV{QNX_TARGET}/armle-v7 $ENV{QNX_TARGET}) + +if(CMAKE_HOST_WIN32) + set(HOST_EXECUTABLE_SUFFIX ".exe") +endif() + +set(CMAKE_AR "$ENV{QNX_HOST}/usr/bin/ntoarmv7-ar${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX ar Program") +set(CMAKE_RANLIB "$ENV{QNX_HOST}/usr/bin/ntoarmv7-ranlib${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX ar Program") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff -Nru gammaray-1.2.2/cmake/Toolchain-QNX65.cmake gammaray-2.0.1/cmake/Toolchain-QNX65.cmake --- gammaray-1.2.2/cmake/Toolchain-QNX65.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/Toolchain-QNX65.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,88 @@ +# +# (C) Copyright 2009 Johns Hopkins University (JHU), All Rights +# Reserved. +# +# --- begin cisst license - do not edit --- +# +# This software is provided "as is" under an open source license, with +# no warranty. The complete license can be found in license.txt and +# http://www.cisst.org/cisst/license.txt. +# +# --- end cisst license --- + +SET(CMAKE_SYSTEM_NAME QNX) +SET(CMAKE_SYSTEM_VERSION 6.5.0) +SET(CMAKE_SYSTEM_PROCESSOR x86) +SET(TOOLCHAIN QNX) + +#SET(CMAKE_IMPORT_LIBRARY_SUFFIX ".a") + +SET(CMAKE_SHARED_LIBRARY_PREFIX "lib") +SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so") +SET(CMAKE_STATIC_LIBRARY_PREFIX "lib") +SET(CMAKE_STATIC_LIBRARY_SUFFIX ".a") + +IF(CMAKE_HOST_WIN32) + SET(HOST_EXECUTABLE_SUFFIX ".exe") +ENDIF(CMAKE_HOST_WIN32) + +FIND_PATH(QNX_HOST + NAME usr/bin/qcc${HOST_EXECUTABLE_SUFFIX} + PATHS $ENV{QNX_HOST} C:/QNX650/host/win32/x86 + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH +) + +FIND_PATH(QNX_TARGET + NAME usr/include/qnx_errno.h + PATHS $ENV{QNX_TARGET} C:/QNX650/target/qnx6 + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH +) + +IF(CMAKE_HOST_WIN32) + FIND_PATH(QNX_CONFIGURATION + NAME bin/qnxactivate.exe + PATHS $ENV{QNX_CONFIGURATION} + "C:/Program Files/QNX Software Systems/qconfig" + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + ) +ENDIF(CMAKE_HOST_WIN32) + +SET(ENV{QNX_HOST} ${QNX_HOST}) +SET(ENV{QNX_TARGET} ${QNX_TARGET}) +IF(CMAKE_HOST_WIN32) + SET(ENV{QNX_CONFIGURATION} ${QNX_CONFIGURATION}) + SET(ENV{PATH} "$ENV{PATH};${QNX_HOST}/usr/bin") +ENDIF(CMAKE_HOST_WIN32) + +SET(CMAKE_MAKE_PROGRAM "${QNX_HOST}/usr/bin/make${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX Make Program") +SET(CMAKE_SH "${QNX_HOST}/usr/bin/sh${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX shell Program") +SET(CMAKE_AR "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ar${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX ar Program") +SET(CMAKE_RANLIB "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ranlib${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX ranlib Program") +SET(CMAKE_NM "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-nm${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX nm Program") +SET(CMAKE_OBJCOPY "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objcopy${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX objcopy Program") +SET(CMAKE_OBJDUMP "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-objdump${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX objdump Program") +SET(CMAKE_LINKER "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-ld" CACHE PATH "QNX Linker Program") +SET(CMAKE_STRIP "${QNX_HOST}/usr/bin/nto${CMAKE_SYSTEM_PROCESSOR}-strip${HOST_EXECUTABLE_SUFFIX}" CACHE PATH "QNX Strip Program") + +SET(CMAKE_C_COMPILER ${QNX_HOST}/usr/bin/qcc) +SET(CMAKE_C_FLAGS_DEBUG "-g") +SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") +SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") +SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") + +SET(CMAKE_CXX_COMPILER ${QNX_HOST}/usr/bin/qcc) +SET(CMAKE_CXX_FLAGS_DEBUG "-g") +SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") +SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") +SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") + +SET(CMAKE_FIND_ROOT_PATH ${QNX_TARGET}) +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +SET(CMAKE_C_FLAGS "-Vgcc_ntoarmv7le" CACHE STRING "qcc c flags" FORCE) +SET(CMAKE_CXX_FLAGS "-Vgcc_ntoarmv7le -lang-c++" CACHE STRING "qcc cxx flags" FORCE) diff -Nru gammaray-1.2.2/cmake/Toolchain-RPI.cmake gammaray-2.0.1/cmake/Toolchain-RPI.cmake --- gammaray-1.2.2/cmake/Toolchain-RPI.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/cmake/Toolchain-RPI.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,24 @@ +# Basic cmake toolchain file for RaspberryPi +# Assumptions: toolchain is in path, $SYSROOT points to the sysroot +# + +# Copyright (c) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Author: Volker Krause +# +# Redistribution and use is allowed according to the terms of the BSD license. + +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "armv6l") +set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=$ENV{SYSROOT}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=$ENV{SYSROOT}") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=$ENV{SYSROOT}") +set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=$ENV{SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH "$ENV{SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff -Nru gammaray-1.2.2/CMakeLists.txt gammaray-2.0.1/CMakeLists.txt --- gammaray-1.2.2/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,38 +1,43 @@ # This is the top-level CMakeLists.txt file for the GammaRay project. # -# Pass the following variables to cmake to control the build: -# -# -DGAMMARAY_UNKNOWN_CXX_MANGLED_NAMES=[on|off] -# Set this if your compiler uses an unsupported C++ name mangling scheme -# Default=off -# # To build the man page from POD, run 'make man' after CMake (assumes perl is available) # To install the resulting man page, run 'make install' # Not available on Windows. # # To build the apidox, run 'make docs' after CMake (assumes doxygen is available) -# Not available on Windows. # project(GammaRay) -cmake_minimum_required(VERSION 2.8) + +if(WIN32) + # needed for automoc and QtMain to work correctly + cmake_minimum_required(VERSION 2.8.11) + cmake_policy(SET CMP0020 NEW) +else() + cmake_minimum_required(VERSION 2.8.9) +endif() if(NOT Prog_NAME) set(Prog_NAME "GammaRay") endif() set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ ${CMAKE_MODULE_PATH}) +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(POLICY CMP0022) + cmake_policy(SET CMP0022 OLD) # until we require 2.8.12 +endif() -set(GAMMARAY_VERSION_MAJOR "1") -set(GAMMARAY_VERSION_MINOR "2") -set(GAMMARAY_VERSION_PATCH "2") +set(GAMMARAY_VERSION_MAJOR "2") +set(GAMMARAY_VERSION_MINOR "0") +set(GAMMARAY_VERSION_PATCH "1") set(GAMMARAY_VERSION "${GAMMARAY_VERSION_MAJOR}.${GAMMARAY_VERSION_MINOR}.${GAMMARAY_VERSION_PATCH}") set(GAMMARAY_VERSION_STRING "${GAMMARAY_VERSION}") +set(GAMMARAY_SOVERSION "${GAMMARAY_VERSION}") +set(GAMMARAY_PLUGIN_VERSION "2.0") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) - enable_testing() if(EXISTS "${CMAKE_SOURCE_DIR}/.git") @@ -54,49 +59,156 @@ message(STATUS "Building ${Prog_NAME} ${GAMMARAY_VERSION_STRING} in ${CMAKE_BUILD_TYPE} mode") add_definitions(-DPROGRAM_NAME=\"${Prog_NAME}\") -add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DQT_STRICT_ITERATORS) +add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) include(CheckCXXCompilerFlag) include(CheckLibraryExists) include(GammaRayMacros) +include(GammaRayMacrosInternal) include(MacroLogFeature) set(QT_MIN_VERSION "4.7.0") -find_package(Qt5Transitional REQUIRED - Core - Gui - Svg - Test + +option( + GAMMARAY_ENFORCE_QT4_BUILD + "Enable if you want to enfore a build with Qt4" + OFF ) -# TODO: Remove me once fixed in ECM module +option( + GAMMARAY_PROBE_ONLY_BUILD + "Build only the probe, not the host tools (client, launcher, etc)." + OFF +) + +# try Qt5 first, and prefer that (if found), but only if not disabled via option +if(NOT GAMMARAY_ENFORCE_QT4_BUILD) + find_package(Qt5Core QUIET) +endif() + if(Qt5Core_FOUND) - # Avoid errors and build in PIC mode: - # qt5/qtbase/include/QtCore/qglobal.h:1765:4: error: - # #error "You must build your code with position independent code if Qt was - # built with -reduce-relocations. " "Compile your code with -fPIC or -fPIE." - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + # Qt5 COMPONENT x y z only works with Qt >= 5.1 ... + find_package(Qt5Gui NO_MODULE REQUIRED) + find_package(Qt5Network NO_MODULE REQUIRED) + find_package(Qt5Concurrent NO_MODULE QUIET) + find_package(Qt5Test NO_MODULE QUIET) + find_package(Qt5Widgets NO_MODULE QUIET) + find_package(Qt5PrintSupport NO_MODULE QUIET) + find_package(Qt5Svg NO_MODULE QUIET) + find_package(Qt5Script NO_MODULE QUIET) + find_package(Qt5ScriptTools NO_MODULE QUIET) + find_package(Qt5Location NO_MODULE QUIET) # workaround for 5.1 webkit that tries to find a qtlocation with a matching version if none (with any version) has been found before... + find_package(Qt5Designer NO_MODULE QUIET) + find_package(Qt5WebKitWidgets 5.0.2 NO_MODULE QUIET) # 5.0.[01] has a code generation bug in uic that fails to generate proper code for webkitwidget classes + + include("cmake/ECMQt4To5Porting.cmake") + # only needed for Qt <= 5.1 and/or some older CMake versions (exact combination unknown unfortunately) + include_directories(${QT_INCLUDES}) + + set(HAVE_QT_CONCURRENT ${Qt5Concurrent_FOUND}) + set(HAVE_QT_WIDGETS ${Qt5Widgets_FOUND}) + set(HAVE_QT_SVG ${Qt5Svg_FOUND}) + set(HAVE_QT_DESIGNER ${Qt5Designer_FOUND}) + set(HAVE_QT_PRINTSUPPORT ${Qt5PrintSupport_FOUND}) + set(HAVE_QT_WEBKIT1 ${Qt5WebKitWidgets_FOUND}) + + if(Qt5_POSITION_INDEPENDENT_CODE AND NOT WIN32) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() + +# Qt4 +else() + set(QT_USE_IMPORTED_TARGETS true) + find_package(Qt4 ${QT_MIN_VERSION} REQUIRED QtCore QtGui QtNetwork) + find_package(Qt4 ${QT_MIN_VERSION} QUIET COMPONENTS QtScript QtScriptTools QtWebKit QtDesigner QtSvg QtTest) + + include(${QT_USE_FILE}) + set(HAVE_QT_CONCURRENT true) + set(HAVE_QT_WIDGETS true) + set(HAVE_QT_SVG true) + if(QT_QTDESIGNER_FOUND) + set(HAVE_QT_DESIGNER true) + endif() + set(HAVE_QT_PRINTSUPPORT true) + set(HAVE_QT_WEBKIT1 ${QT_QTWEBKIT_FOUND}) +endif() +# TODO: Remove me once fixed in ECM module +if(Qt5Core_FOUND) # more hacks: find qpa/... includes # also see https://codereview.qt-project.org/#change,30483 include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) + + # TODO warnings rather than build errors for the deprecated methods would be nice... + add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) +endif() + +# disable QT_STRICT_ITERATORS on the Qt5+Windows combo +# see: https://bugreports.qt-project.org/browse/QTBUG-29608 +if(NOT (Qt5Core_FOUND AND WIN32)) + add_definitions(-DQT_STRICT_ITERATORS) endif() if(CMAKE_BUILD_TYPE MATCHES "^[Rr]elease$") add_definitions(-DQT_NO_DEBUG_OUTPUT) endif() +set(BIN_INSTALL_DIR "bin") set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}") -set(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/qt4/plugins") +set(INCLUDE_INSTALL_DIR "include/gammaray") +set(CMAKECONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/GammaRay) +if(WIN32) + set(PLUGIN_INSTALL_DIR "plugins") + set(LIBEXEC_INSTALL_DIR "${BIN_INSTALL_DIR}") +else() + set(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/gammaray") + set(LIBEXEC_INSTALL_DIR "${LIB_INSTALL_DIR}/gammaray/libexec") +endif() + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${BIN_INSTALL_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIB_INSTALL_DIR}) + +# set RPATH only when installing to a non-default location +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" _isSystemPlatformLibDir) +list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" _isSystemCLibDir) +list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" _isSystemCxxLibDir) +if(${_isSystemPlatformLibDir} EQUAL -1 AND ${_isSystemCLibDir} EQUAL -1 AND ${_isSystemCxxLibDir} EQUAL -1) + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") +endif() set( INSTALL_TARGETS_DEFAULT_ARGS - RUNTIME DESTINATION bin + RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT Devel ) +# "inverse" install dirs, to find the base location again +gammaray_inverse_dir(GAMMARAY_INVERSE_BIN_DIR "${BIN_INSTALL_DIR}") +gammaray_inverse_dir(GAMMARAY_INVERSE_PROBE_DIR "${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/GAMMARAY_PROBE_ABI_DUMMY") +gammaray_inverse_dir(GAMMARAY_INVERSE_LIBEXEC_DIR "${LIBEXEC_INSTALL_DIR}") + +macro_log_feature( + HAVE_QT_CONCURRENT + "QtConcurrent" + "Qt concurrency library" + "included with Qt" + FALSE + "" + "Required for the GammaRay launcher process list" +) + +macro_log_feature( + HAVE_QT_WIDGETS + "Qt Widgets" + "Qt Widgets" + "included with Qt" + FALSE + "" + "Required for the GammaRay client UI and widget-related tools" +) + macro_log_feature( QT_QTSCRIPTTOOLS_FOUND "Script engine debugger in Qt" @@ -108,7 +220,7 @@ ) macro_log_feature( - QT_QTWEBKIT_FOUND + HAVE_QT_WEBKIT1 "WebKit in Qt" "A Qt-based web browser engine" "included with Qt" @@ -117,6 +229,37 @@ "Required for the webinspector tool" ) +macro_log_feature( + HAVE_QT_SVG + "Qt SVG" + "Qt SVG renderer and generator" + "http://qt-project.org/" + FALSE + "" + "Required for widget SVG export" +) + +macro_log_feature( + HAVE_QT_DESIGNER + "Qt Designer Library" + "Qt graphical widget editor" + "http://qt-project.org/" + FALSE + "" + "Required for widget .ui file export" +) + +macro_log_feature( + HAVE_QT_PRINTSUPPORT + "Qt Print Support" + "Qt PDF generation" + "http://qt-project.org/" + FALSE + "" + "Required for widget PDF export" +) + +if(NOT Qt5Core_FOUND) find_path( QT_PRIVATE_INCLUDE_DIR private/qobject_p.h PATHS ${QT_INCLUDES} @@ -138,6 +281,13 @@ # needs to go before Qt includes, in case we have non-working headers with the same name there include_directories(BEFORE ${CMAKE_SOURCE_DIR}/3rdparty/qt) endif() +else() # Qt 5 + find_path(QT_PRIVATE_INCLUDE_DIR private/qobject_p.h PATHS ${Qt5Core_PRIVATE_INCLUDE_DIRS}) + if(QT_PRIVATE_INCLUDE_DIR) + set(HAVE_PRIVATE_QT_HEADERS true) + endif() +endif() + macro_log_feature( HAVE_PRIVATE_QT_HEADERS "Qt internals" @@ -148,12 +298,18 @@ "You must have a build version of Qt available. Make sure the qmake found first in your execute comes from this build version." ) -if(WIN32 OR APPLE) - set(BUILD_TIMER_PLUGIN TRUE) +if(Qt5Core_FOUND AND Qt5Core_VERSION VERSION_LESS 5.2.2) + # https://codereview.qt-project.org/75530 + message(STATUS "Disabling timer profiler plug-in due to a bug in Qt5 <= 5.2.1.") + set(BUILD_TIMER_PLUGIN FALSE) else() - check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME) - macro_log_feature(HAVE_CLOCK_GETTIME "librt" "High resolution clock for the timer profiler plugin." "part of glibc" FALSE) - set(BUILD_TIMER_PLUGIN ${HAVE_CLOCK_GETTIME}) + if(WIN32 OR APPLE) + set(BUILD_TIMER_PLUGIN TRUE) + else() + check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME) + macro_log_feature(HAVE_CLOCK_GETTIME "librt" "High resolution clock for the timer profiler plugin." "part of glibc" FALSE) + set(BUILD_TIMER_PLUGIN ${HAVE_CLOCK_GETTIME}) + endif() endif() if(WIN32) @@ -189,74 +345,90 @@ include(CheckIncludeFiles) check_include_files(stdint.h HAVE_STDINT_H) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/config-gammaray.h.cmake - ${CMAKE_CURRENT_BINARY_DIR}/config-gammaray.h -) +include(GammaRayProbeABI) # this needs to be run after we know what exactly we are building + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-gammaray-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-gammaray-version.h ) -if(CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") check_cxx_compiler_flag(-Wunused-but-set-variable HAVE_GCC_UNUSED_BUT_SET) check_cxx_compiler_flag(-Wlogical-op HAVE_GCC_LOGICAL_OP) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wextra -Woverloaded-virtual -Winit-self -Wmissing-include-dirs -Wunused -Wno-div-by-zero -Wundef -Wpointer-arith -Wcast-qual -Wcast-align -Wmissing-noreturn -Werror=return-type -fvisibility=hidden") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wextra -Woverloaded-virtual -Winit-self -Wmissing-include-dirs -Wunused -Wno-div-by-zero -Wundef -Wpointer-arith -Wcast-qual -Wmissing-noreturn -Werror=return-type") if(HAVE_GCC_UNUSED_BUT_SET) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-but-set-variable") endif() if(HAVE_GCC_LOGICAL_OP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op") endif() -endif() - -if(MINGW) - # mingw will error out on the crazy casts in probe.cpp without this - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + if(MINGW) + # mingw will error out on the crazy casts in probe.cpp without this + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + else() + # visibility attributes not supported on mingw, don't use -fvisibility option + # see: http://stackoverflow.com/questions/7994415/mingw-fvisibility-hidden-does-not-seem-to-work + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") + endif() endif() # linker flags if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME STREQUAL GNU) - if(CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined -lc ${CMAKE_MODULE_LINKER_FLAGS}") endif() endif() -add_subdirectory(core) -add_subdirectory(launcher) - -set(GRAPHVIZ_MIN_VERSION "2.20") -find_package(Graphviz) -macro_log_feature( - GRAPHVIZ_FOUND - "Graphviz" - "Graph visualization software" - "http://www.graphviz.org/" - FALSE - ${GRAPHVIZ_MIN_VERSION} - "Needed for the state machine visualizer plugin" -) +if(NOT CMAKE_DISABLE_FIND_PACKAGE_GRAPHVIZ) + set(GRAPHVIZ_MIN_VERSION "2.20") + find_package(Graphviz) + macro_log_feature( + GRAPHVIZ_FOUND + "Graphviz" + "Graph visualization software" + "http://www.graphviz.org/" + FALSE + ${GRAPHVIZ_MIN_VERSION} + "Needed for the state machine visualizer plugin" + ) +else() + set(GRAPHVIZ_FOUND False) +endif() +set(HAVE_GRAPHVIZ ${GRAPHVIZ_FOUND}) if(GRAPHVIZ_FOUND) add_definitions(-DGRAPHVIZ_MAJOR_VERSION=${GRAPHVIZ_MAJOR_VERSION} -DGRAPHVIZ_MINOR_VERSION=${GRAPHVIZ_MINOR_VERSION}) endif() -#VTK discovery works a lot better if you give CMake a hint using the VTK_DIR variable -find_path(VTK_DIR VTKConfig.cmake - /usr/lib64/vtk /usr/lib/vtk /usr/local/lib64/vtk /usr/local/lib/vtk -) -find_package(VTK) -macro_log_feature( - VTK_FOUND - "VTK" - "Visualization Toolkit" - "http://www.vtk.org" - FALSE - "" - "Needed for the object visualization plugin" -) +if(NOT CMAKE_DISABLE_FIND_PACKAGE_VTK) + #VTK discovery works a lot better if you give CMake a hint using the VTK_DIR variable + find_path(VTK_DIR VTKConfig.cmake + /usr/lib64/vtk /usr/lib/vtk /usr/local/lib64/vtk /usr/local/lib/vtk + ) + find_package(VTK) + set(VTK_MESSAGE "Needed for the object visualizer plugin") + if(VTK_FOUND) + find_path(VTK_QT_INCLUDE_DIR NAMES QVTKWidget.h HINTS ${VTK_INCLUDE_DIRS}) + if(NOT VTK_QT_INCLUDE_DIR) + set(VTK_FOUND FALSE) + set(VTK_MESSAGE "Looks like VTK was not built with Qt (QVTKWidget is missing). Object visualizer plugin will not be built") + endif() + endif() + macro_log_feature( + VTK_FOUND + "VTK" + "Visualization Toolkit" + "http://www.vtk.org" + FALSE + "" + ${VTK_MESSAGE} + ) +else() + set(VTK_FOUND False) +endif() +set(HAVE_VTK ${VTK_FOUND}) -if(UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE AND NOT GAMMARAY_PROBE_ONLY_BUILD) set(XDG_APPS_INSTALL_DIR share/applications) install(FILES GammaRay.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) @@ -288,7 +460,7 @@ set(LICENSE_FILE "License.txt") set(README_FILE "ReadMe.txt") -if(NOT APPLE) +if(NOT APPLE AND NOT GAMMARAY_PROBE_ONLY_BUILD) install(FILES "${LICENSE_FILE}" "${README_FILE}" DESTINATION ${DOC_INSTALL_DIR}) endif() @@ -314,32 +486,78 @@ ) endif() -if(UNIX) +find_program(POD2MAN_EXECUTABLE pod2man) + +if(POD2MAN_EXECUTABLE AND NOT GAMMARAY_PROBE_ONLY_BUILD) #man page generation using pod2man add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/gammaray.1 - COMMAND pod2man -c "KDAB Products" -r "\"${GAMMARAY_VERSION}\"" -s 1 ${CMAKE_SOURCE_DIR}/gammaray.pod ${CMAKE_BINARY_DIR}/gammaray.1 + COMMAND ${POD2MAN_EXECUTABLE} -c "KDAB Products" -r "\"${GAMMARAY_VERSION}\"" -s 1 ${CMAKE_SOURCE_DIR}/gammaray.pod ${CMAKE_BINARY_DIR}/gammaray.1 DEPENDS ${CMAKE_SOURCE_DIR}/gammaray.pod ) add_custom_target(man ALL DEPENDS ${CMAKE_BINARY_DIR}/gammaray.1) install(FILES ${CMAKE_BINARY_DIR}/gammaray.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/config-gammaray.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/config-gammaray.h +) + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/3rdparty + ${CMAKE_BINARY_DIR} +) - file(GLOB API_LIST include/*.h include/*.dox images/*.html) +include(ExternalProject) + +add_subdirectory(cmake) +add_subdirectory(common) +add_subdirectory(core) +add_subdirectory(hooking) +if(NOT GAMMARAY_PROBE_ONLY_BUILD) + add_subdirectory(launcher) +endif() +if(Qt5Widgets_FOUND OR QT_QTGUI_FOUND) + add_subdirectory(ui) + add_subdirectory(inprocessui) + if(NOT GAMMARAY_PROBE_ONLY_BUILD) + add_subdirectory(client) + endif() +endif() +if((Qt5Test_FOUND OR QT_QTTEST_FOUND) AND NOT CMAKE_CROSSCOMPILING) + add_subdirectory(tests) +endif() +add_subdirectory(plugins) + +find_package(Doxygen) +macro_log_feature( + DOXYGEN_FOUND + "Doxygen" + "Documentation system" + "http://www.doxygen.org" + FALSE + "" + "Needed to build the optional API documention" +) +if(DOXYGEN_FOUND) + file(GLOB _dox_deps docs/*.dox docs/*.html) + gammaray_all_installed_headers(_all_hdrs) + list(APPEND _all_hdrs ${_dox_deps}) + gammaray_join_list(DOXYGEN_INPUT " " ${_all_hdrs}) #apidox generation using doxygen + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake + ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + ) + add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/apidocs/html/index.html - COMMAND echo \"PROJECT_NUMBER = ${GAMMARAY_VERSION}\" > ${CMAKE_BINARY_DIR}/versfoo - COMMAND echo \"INPUT = ${CMAKE_SOURCE_DIR}/include\" > ${CMAKE_BINARY_DIR}/inputfoo - COMMAND echo \"IMAGE_PATH = ${CMAKE_SOURCE_DIR}/images\" > ${CMAKE_BINARY_DIR}/imgfoo - COMMAND echo \"HTML_FOOTER = ${CMAKE_SOURCE_DIR}/images/footer.html\" > ${CMAKE_BINARY_DIR}/footfoo - COMMAND cat ${CMAKE_SOURCE_DIR}/Doxyfile - ${CMAKE_BINARY_DIR}/versfoo - ${CMAKE_BINARY_DIR}/inputfoo - ${CMAKE_BINARY_DIR}/imgfoo - ${CMAKE_BINARY_DIR}/footfoo | doxygen - - DEPENDS ${API_LIST} ${CMAKE_SOURCE_DIR}/Doxyfile + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile + DEPENDS ${_all_hdrs} ${_dox_deps} ${CMAKE_SOURCE_DIR}/Doxyfile.cmake WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(docs @@ -348,10 +566,35 @@ endif() -include(ExternalProject) +macro_display_feature_log() +if(CMAKE_DISABLE_FIND_PACKAGE_VTK) + message(STATUS "Skipped VTK discovery due to the CMAKE_DISABLE_FIND_PACKAGE_VTK option. Object visualizer plugin will not be built") +endif() +if(CMAKE_DISABLE_FIND_PACKAGE_GRAPHVIZ) + message(STATUS "Skipped Graphviz discovery due to the CMAKE_DISABLE_FIND_PACKAGE_GRAPHVIZ option. State machine visualizer plugin will not be built") +endif() -add_subdirectory(include) -add_subdirectory(tests) -add_subdirectory(plugins) -macro_display_feature_log() +# +# CMake package config file generation +# +include(CMakePackageConfigHelpers) +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/GammaRayConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/GammaRayConfig.cmake + INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} + PATH_VARS INCLUDE_INSTALL_DIR) +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/GammaRayConfigVersion.cmake + VERSION ${GAMMARAY_VERSION} + COMPATIBILITY SameMajorVersion) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/GammaRayConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/GammaRayConfigVersion.cmake + DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) + +install( + EXPORT GammaRayTargets + DESTINATION "${CMAKECONFIG_INSTALL_DIR}" + FILE GammaRayTarget.cmake +# NAMESPACE GammaRay:: +) diff -Nru gammaray-1.2.2/common/CMakeLists.txt gammaray-2.0.1/common/CMakeLists.txt --- gammaray-1.2.2/common/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,74 @@ +# +# Shared non-UI code between probe and client +# +set(gammaray_common_srcs + ${CMAKE_SOURCE_DIR}/3rdparty/kde/klinkitemselectionmodel.cpp + ${CMAKE_SOURCE_DIR}/3rdparty/kde/kmodelindexproxymapper.cpp + + methodargument.cpp + objectbroker.cpp + protocol.cpp + message.cpp + endpoint.cpp + paths.cpp +) + +add_library(gammaray_common SHARED ${gammaray_common_srcs}) +set_target_properties(gammaray_common PROPERTIES + DEFINE_SYMBOL MAKE_GAMMARAY_COMMON_LIB + SOVERSION ${GAMMARAY_SOVERSION} + VERSION ${GAMMARAY_SOVERSION} + OUTPUT_NAME gammaray_common-${GAMMARAY_PROBE_ABI} +) + +if(Qt5Core_FOUND) + target_link_libraries(gammaray_common Qt5::Core Qt5::Network) +else() + target_link_libraries(gammaray_common + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTNETWORK_LIBRARIES} + ) +endif() + +install(TARGETS gammaray_common EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) + +set(gammaray_common_internal_srcs + pluginmanager.cpp + proxyfactorybase.cpp + propertycontrollerinterface.cpp + probecontrollerinterface.cpp + modelinspectorinterface.cpp + resourcebrowserinterface.cpp + networkselectionmodel.cpp + streamoperators.cpp +) + +if(NOT WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +endif() + +add_library(gammaray_common_internal STATIC ${gammaray_common_internal_srcs}) + +target_link_libraries(gammaray_common_internal gammaray_common) +if(Qt5Core_FOUND) + target_link_libraries(gammaray_common_internal Qt5::Gui Qt5::Network) +else() + target_link_libraries(gammaray_common_internal + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTNETWORK_LIBRARIES} + ) +endif() + +gammaray_install_headers( + gammaray_common_export.h + endpoint.h + enums.h + metatypedeclarations.h + modelroles.h + objectbroker.h + objectmodel.h + propertycontrollerinterface.h + protocol.h +) diff -Nru gammaray-1.2.2/common/endpoint.cpp gammaray-2.0.1/common/endpoint.cpp --- gammaray-1.2.2/common/endpoint.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/endpoint.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,319 @@ +/* + endpoint.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "endpoint.h" +#include "message.h" +#include "methodargument.h" + +#include + +using namespace GammaRay; +using namespace std; + +Endpoint* Endpoint::s_instance = 0; + +Endpoint::Endpoint(QObject* parent): QObject(parent), m_socket(0), m_myAddress(Protocol::InvalidObjectAddress +1) +{ + Q_ASSERT(!s_instance); + s_instance = this; + + ObjectInfo *endpointObj = new ObjectInfo; + endpointObj->address = m_myAddress; + endpointObj->name = QLatin1String("com.kdab.GammaRay.Server"); + // TODO: we could set this as message handler here and use the same dispatch mechanism + insertObjectInfo(endpointObj); +} + +Endpoint::~Endpoint() +{ + for (QHash::const_iterator it = m_addressMap.constBegin(); it != m_addressMap.constEnd(); ++it) + delete it.value(); + + s_instance = 0; +} + +Endpoint* Endpoint::instance() +{ + return s_instance; +} + +void Endpoint::send(const Message& msg) +{ + Q_ASSERT(s_instance); + Q_ASSERT(msg.address() != Protocol::InvalidObjectAddress); + msg.write(s_instance->m_socket); +} + +void Endpoint::waitForMessagesWritten() +{ + m_socket->waitForBytesWritten(-1); +} + +bool Endpoint::isConnected() +{ + return s_instance && s_instance->m_socket; +} + +quint16 Endpoint::defaultPort() +{ + return 11732; +} + +quint16 Endpoint::broadcastPort() +{ + return 13325; +} + +void Endpoint::setDevice(QIODevice* device) +{ + Q_ASSERT(!m_socket); + Q_ASSERT(device); + m_socket = device; + connect(m_socket.data(), SIGNAL(readyRead()), SLOT(readyRead())); + connect(m_socket.data(), SIGNAL(disconnected()), SLOT(connectionClosed())); + if (m_socket->bytesAvailable()) + readyRead(); +} + +Protocol::ObjectAddress Endpoint::endpointAddress() const +{ + return m_myAddress; +} + +void Endpoint::readyRead() +{ + while (Message::canReadMessage(m_socket.data())) { + messageReceived(Message::readMessage(m_socket.data())); + } +} + +void Endpoint::connectionClosed() +{ + m_socket->deleteLater(); + m_socket = 0; + emit disconnected(); +} + +Protocol::ObjectAddress Endpoint::objectAddress(const QString& objectName) const +{ + const QHash::const_iterator it = m_nameMap.constFind(objectName); + if (it != m_nameMap.constEnd()) + return it.value()->address; + return Protocol::InvalidObjectAddress; +} + +Protocol::ObjectAddress Endpoint::registerObject(const QString &name, QObject *object) +{ + ObjectInfo* obj = m_nameMap.value(name, 0); + Q_ASSERT(obj); + Q_ASSERT(!obj->object); + Q_ASSERT(obj->address != Protocol::InvalidObjectAddress); + obj->object = object; + + Q_ASSERT(!m_objectMap.contains(object)); + m_objectMap[object] = obj; + + connect(object, SIGNAL(destroyed(QObject*)), SLOT(objectDestroyed(QObject*))); + + return obj->address; +} + +void Endpoint::invokeObject(const QString &objectName, const char *method, const QVariantList &args) const +{ + if (!isConnected()) { + return; + } + + ObjectInfo* obj = m_nameMap.value(objectName, 0); + Q_ASSERT(obj); + Q_ASSERT(obj->address != Protocol::InvalidObjectAddress); + + Message msg(obj->address, Protocol::MethodCall); + const QByteArray name(method); + Q_ASSERT(!name.isEmpty()); + msg.payload() << name << args; + send(msg); +} + +void Endpoint::invokeObjectLocal(QObject *object, const char *method, const QVariantList &args) const +{ + Q_ASSERT(args.size() <= 10); + QVector a(10); + for (int i = 0; i < args.size(); ++i) { + a[i] = MethodArgument(args.at(i)); + } + + QMetaObject::invokeMethod(object, method, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]); +} + +void Endpoint::registerObjectInternal(const QString& objectName, Protocol::ObjectAddress objectAddress) +{ + Q_ASSERT(objectAddress != Protocol::InvalidObjectAddress); + + ObjectInfo *obj = new ObjectInfo; + obj->address = objectAddress; + obj->name = objectName; + insertObjectInfo(obj); + + emit objectRegistered(objectName, objectAddress); +} + +void Endpoint::unregisterObjectInternal(const QString& objectName) +{ + Q_ASSERT(m_nameMap.contains(objectName)); + ObjectInfo *obj = m_nameMap.value(objectName); + + emit objectUnregistered(objectName, obj->address); + removeObjectInfo(obj); +} + +void Endpoint::registerMessageHandlerInternal(Protocol::ObjectAddress objectAddress, QObject* receiver, const char* messageHandlerName) +{ + Q_ASSERT(m_addressMap.contains(objectAddress)); + ObjectInfo *obj = m_addressMap.value(objectAddress); + Q_ASSERT(obj); + Q_ASSERT(!obj->receiver); + Q_ASSERT(obj->messageHandler.isEmpty()); + obj->receiver = receiver; + obj->messageHandler = messageHandlerName; + Q_ASSERT(!m_handlerMap.contains(receiver, obj)); + m_handlerMap.insert(receiver, obj); + connect(receiver, SIGNAL(destroyed(QObject*)), SLOT(handlerDestroyed(QObject*))); +} + +void Endpoint::unregisterMessageHandlerInternal(Protocol::ObjectAddress objectAddress) +{ + Q_ASSERT(m_addressMap.contains(objectAddress)); + ObjectInfo *obj = m_addressMap.value(objectAddress); + Q_ASSERT(obj); + Q_ASSERT(obj->receiver); + disconnect(obj->receiver, SIGNAL(destroyed(QObject*)), this, SLOT(handlerDestroyed(QObject*))); + m_handlerMap.remove(obj->receiver, obj); + obj->receiver = 0; + obj->messageHandler.clear(); +} + +void Endpoint::objectDestroyed(QObject *obj) +{ + ObjectInfo* info = m_objectMap.value(obj, 0); + Q_ASSERT(info); + Q_ASSERT(info->object == obj); + info->object = 0; + m_objectMap.remove(obj); + objectDestroyed(info->address, QString(info->name), obj); // copy the name, in case unregisterMessageHandlerInternal() is called inside +} + +void Endpoint::handlerDestroyed(QObject* obj) +{ + const QList objs = m_handlerMap.values(obj); // copy, the virtual method below likely changes the maps. + m_handlerMap.remove(obj); + foreach (ObjectInfo *obj, objs) { + obj->receiver = 0; + obj->messageHandler.clear(); + handlerDestroyed(obj->address, QString(obj->name)); // copy the name, in case unregisterMessageHandlerInternal() is called inside + } +} + +void Endpoint::dispatchMessage(const Message& msg) +{ + const QHash::const_iterator it = m_addressMap.constFind(msg.address()); + if (it == m_addressMap.constEnd()) { + cerr << "message for unknown object address received: " << quint64(msg.address()) << endl; + return; + } + + ObjectInfo* obj = it.value(); + if (msg.type() == Protocol::MethodCall) { + QByteArray method; + msg.payload() >> method; + if (obj->object) { + Q_ASSERT(!method.isEmpty()); + QVariantList args; + msg.payload() >> args; + + invokeObjectLocal(obj->object, method.constData(), args); + } else { + cerr << "cannot call method " << method.constData() << " on unknown object of name " << qPrintable(obj->name) << " with address " << quint64(obj->address) + << " - did you forget to register it?" << endl; + } + } + + if (obj->receiver) { + QMetaObject::invokeMethod(obj->receiver, obj->messageHandler, Q_ARG(GammaRay::Message, msg)); + } + + if (!obj->receiver && (msg.type() != Protocol::MethodCall || !obj->object)) { + cerr << "Cannot dispatch message " << quint64(msg.type()) << " - no handler registered." + << " Receiver: " << qPrintable(obj->name) << ", address " << quint64(obj->address) << endl; + } +} + +QVector< QPair< Protocol::ObjectAddress, QString > > Endpoint::objectAddresses() const +{ + QVector > addrs; + addrs.reserve(m_addressMap.size()); + for (QHash::const_iterator it = m_addressMap.constBegin(); it != m_addressMap.constEnd(); ++it) + addrs.push_back(qMakePair(it.key(), it.value()->name)); + return addrs; +} + +void Endpoint::insertObjectInfo(Endpoint::ObjectInfo* oi) +{ + Q_ASSERT(!m_addressMap.contains(oi->address)); + m_addressMap.insert(oi->address, oi); + Q_ASSERT(!m_nameMap.contains(oi->name)); + m_nameMap.insert(oi->name, oi); + + if (oi->receiver) + m_handlerMap.insert(oi->receiver, oi); + + if (oi->object) + m_objectMap.insert(oi->object, oi); +} + +void Endpoint::removeObjectInfo(Endpoint::ObjectInfo* oi) +{ + Q_ASSERT(m_addressMap.contains(oi->address)); + m_addressMap.remove(oi->address); + Q_ASSERT(m_nameMap.contains(oi->name)); + m_nameMap.remove(oi->name); + + if (oi->receiver) + m_handlerMap.remove(oi->receiver, oi); + + if (oi->object) + m_objectMap.remove(oi->object); + + delete oi; +} + +QString Endpoint::label() const +{ + return m_label; +} + +void Endpoint::setLabel(const QString &label) +{ + m_label = label; +} + diff -Nru gammaray-1.2.2/common/endpoint.h gammaray-2.0.1/common/endpoint.h --- gammaray-1.2.2/common/endpoint.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/endpoint.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,209 @@ +/* + endpoint.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ENDPOINT_H +#define GAMMARAY_ENDPOINT_H + +#include "gammaray_common_export.h" +#include "protocol.h" + +#include +#include + +class QIODevice; + +namespace GammaRay { + +class Message; + +/** @brief Network protocol endpoint. + * + * Contains: + * - object address <-> object name mapping + * - message handler registration and message dispatching + */ +class GAMMARAY_COMMON_EXPORT Endpoint : public QObject +{ + Q_OBJECT +public: + ~Endpoint(); + + /** Send @p msg to the connected endpoint. */ + static void send(const Message &msg); + + /** Returns @c true if we are currently connected to another endpoint. */ + static bool isConnected(); + + static quint16 defaultPort(); + static quint16 broadcastPort(); + + /** Returns the object address for @p objectName, or @c Protocol::InvalidObjectAddress if not known. */ + Protocol::ObjectAddress objectAddress(const QString &objectName) const; + + /** Singleton accessor. */ + static Endpoint* instance(); + + /** + * Register an object of the given name for transparent server/client communication. + */ + virtual Protocol::ObjectAddress registerObject(const QString &name, QObject *object); + + /** + * Invoke @p method on the object called @p objectName with the given @p args. + * + * This also works with signals. + * + * The default implementation forwards the object calls to remote side when the + * endpoint is connected. The Server implementation is furthermore expected to + * call the method directly on the local object to support the in-process mode. + */ + virtual void invokeObject(const QString &objectName, const char *method, const QVariantList &args = QVariantList()) const; + + /** + * Write all pending data and block until this is done. + * + * This should only be used in very rare situations. + */ + void waitForMessagesWritten(); + + /** + * Returns a human-readable string describing the host program. + */ + QString label() const; + + /** + * Sets the human-readable label of this instance used e.g. when advertising on the network. + */ + void setLabel(const QString &label); + + /** + * Returns true for remote clients and false for the in-probe server endpoint. + */ + virtual bool isRemoteClient() const = 0; + + /** + * Returns the address of the server, in case you need to connect to a different service there + * (such as the web inspector server). + */ + virtual QString serverAddress() const = 0; + +signals: + /** Emitted when we lost the connection to the other endpoint. */ + void disconnected(); + + /** Emitted when a new object with name @p objectName has been registered at address @p objectAddress. */ + void objectRegistered(const QString &objectName, Protocol::ObjectAddress objectAddress); + void objectUnregistered(const QString &objectName, Protocol::ObjectAddress objectAddress); + +protected: + Endpoint(QObject* parent = 0); + /** Call with the socket once you have established a connection to another endpoint, takes ownership of @p device. */ + void setDevice(QIODevice* device); + + /** The object address of the other endpoint. */ + Protocol::ObjectAddress endpointAddress() const; + + /** Called for every incoming message. + * @see dispatchMessage(). + */ + virtual void messageReceived(const Message &msg) = 0; + + /** Call this when learning about a new object <-> address mapping. */ + void registerObjectInternal(const QString &objectName, Protocol::ObjectAddress objectAddress); + /** Call this when learning about a dissolved object <-> address mapping. */ + void unregisterObjectInternal(const QString& objectName); + + /** Register the slot @p messageHandlerName on @p receiver as the handler for messages to/from @p objectAddress. + * @see dispatchMessage() + */ + void registerMessageHandlerInternal(Protocol::ObjectAddress objectAddress, QObject *receiver, const char* messageHandlerName); + + /** Unregister the message handler for @p objectAddress. */ + void unregisterMessageHandlerInternal(Protocol::ObjectAddress objectAddress); + + /** Called when the current handler of the object identified by @p objectAddress has been destroyed. */ + virtual void handlerDestroyed(Protocol::ObjectAddress objectAddress, const QString &objectName) = 0; + + /** Called when a registered object identified by @p objectAddress has been destroyed. */ + virtual void objectDestroyed(Protocol::ObjectAddress objectAddress, const QString &objectName, QObject *object) = 0; + + /** Calls the message handler registered for the receiver of @p msg. */ + void dispatchMessage(const GammaRay::Message& msg); + + /** All current object name/address pairs. */ + QVector > objectAddresses() const; + + /** Singleton instance. */ + static Endpoint *s_instance; + + /** + * Invoke @p method on @p object with the given @p args. + * + * This is invokes the method directly on the local object. + */ + void invokeObjectLocal(QObject *object, const char *method, const QVariantList &args) const; + +private slots: + void readyRead(); + void connectionClosed(); + void handlerDestroyed(QObject* obj); + void objectDestroyed(QObject* obj); + +private: + struct ObjectInfo + { + ObjectInfo() + : object(0) + , receiver(0) + { + } + QString name; + Protocol::ObjectAddress address; + // the locally registered object + QObject *object; + + // custom message handling support + // TODO: obsolete this + QObject *receiver; + QByteArray messageHandler; + }; + + /** Inserts @p oi into all maps. */ + void insertObjectInfo(ObjectInfo *oi); + /** Removes @p oi from all maps and destroys it. */ + void removeObjectInfo(ObjectInfo *oi); + + QHash m_nameMap; + QHash m_addressMap; + QHash m_objectMap; + QMultiHash m_handlerMap; + + QPointer m_socket; + Protocol::ObjectAddress m_myAddress; + + QString m_label; +}; + +} + +#endif // GAMMARAY_ENDPOINT_H diff -Nru gammaray-1.2.2/common/enums.h gammaray-2.0.1/common/enums.h --- gammaray-1.2.2/common/enums.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/enums.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + enums.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ENUMS_H +#define GAMMARAY_ENUMS_H + +#include + +namespace GammaRay { + +/** @brief Display mode settings of the property widget. */ +namespace PropertyWidgetDisplayState { + enum State { + QObject, ///< full QObject instance + Object, ///< non-QObject instance + MetaObject ///< QMetaObject instance only + }; +} + +} + +Q_DECLARE_METATYPE(GammaRay::PropertyWidgetDisplayState::State) + +#endif diff -Nru gammaray-1.2.2/common/gammaray_common_export.h gammaray-2.0.1/common/gammaray_common_export.h --- gammaray-1.2.2/common/gammaray_common_export.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/gammaray_common_export.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +/* + gammaray_common_export.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_COMMON_EXPORT_H +#define GAMMARAY_COMMON_EXPORT_H + +#include + +#ifdef GAMMARAY_COMMON_STATICLIB +# undef GAMMARAY_COMMON_SHAREDLIB +# define GAMMARAY_COMMON_EXPORT +#else +# ifdef MAKE_GAMMARAY_COMMON_LIB +# define GAMMARAY_COMMON_EXPORT Q_DECL_EXPORT +# else +# define GAMMARAY_COMMON_EXPORT Q_DECL_IMPORT +# endif +#endif + +#endif /* GAMMARAY_COMMON_EXPORT_H */ diff -Nru gammaray-1.2.2/common/message.cpp gammaray-2.0.1/common/message.cpp --- gammaray-1.2.2/common/message.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/message.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,150 @@ +/* + message.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "message.h" + +#include +#include + +static const QDataStream::Version StreamVersion = QDataStream::Qt_4_7; + +template static T readNumber(QIODevice *device) +{ + T buffer; + const int readSize = device->read((char*)&buffer, sizeof(T)); + Q_UNUSED(readSize); + Q_ASSERT(readSize == sizeof(T)); + return qFromBigEndian(buffer); +} + +template static void writeNumber(QIODevice *device, T value) +{ + value = qToBigEndian(value); + const int writeSize = device->write((char*)&value, sizeof(T)); + Q_UNUSED(writeSize); + Q_ASSERT(writeSize == sizeof(T)); +} + +using namespace GammaRay; + +Message::Message() : + m_objectAddress(Protocol::InvalidObjectAddress), + m_messageType(Protocol::InvalidMessageType) +{ +} + +Message::Message(Protocol::ObjectAddress objectAddress, Protocol::MessageType type) : + m_objectAddress(objectAddress), + m_messageType(type) +{ +} + +#ifdef Q_COMPILER_RVALUE_REFS +Message::Message(Message&& other) : + m_buffer(std::move(other.m_buffer)), + m_objectAddress(other.m_objectAddress), + m_messageType(other.m_messageType) +{ + m_stream.swap(other.m_stream); +} +#endif + +Message::~Message() +{ +} + +Protocol::ObjectAddress Message::address() const +{ + return m_objectAddress; +} + +Protocol::MessageType Message::type() const +{ + return m_messageType; +} + + +QDataStream& Message::payload() const +{ + if (!m_stream) { + if (m_buffer.isEmpty()) + m_stream.reset(new QDataStream(&m_buffer, QIODevice::WriteOnly)); + else + m_stream.reset(new QDataStream(m_buffer)); + m_stream->setVersion(StreamVersion); + } + return *m_stream; +} + +bool Message::canReadMessage(QIODevice* device) +{ + static const int minimumSize = sizeof(Protocol::PayloadSize) + sizeof(Protocol::ObjectAddress) + sizeof(Protocol::MessageType); + if (device->bytesAvailable() < minimumSize) + return false; + + Protocol::PayloadSize payloadSize; + const int peekSize = device->peek((char*)&payloadSize, sizeof(Protocol::PayloadSize)); + if (peekSize < (int)sizeof(Protocol::PayloadSize)) + return false; + payloadSize = qFromBigEndian(payloadSize); + if (payloadSize < 0 && !device->isSequential()) // input end on shared memory + return false; + Q_ASSERT(payloadSize >= 0); + return device->bytesAvailable() >= payloadSize + minimumSize; +} + +Message Message::readMessage(QIODevice* device) +{ + Message msg; + QDataStream stream(device); + + const Protocol::PayloadSize payloadSize = readNumber(device); + Q_ASSERT(payloadSize >= 0); + + msg.m_objectAddress = readNumber(device); + msg.m_messageType = readNumber(device); + Q_ASSERT(msg.m_messageType != Protocol::InvalidMessageType); + Q_ASSERT(msg.m_objectAddress != Protocol::InvalidObjectAddress); + + if (payloadSize) + msg.m_buffer = device->read(payloadSize); + Q_ASSERT(payloadSize == msg.m_buffer.size()); + + return msg; +} + +void Message::write(QIODevice* device) const +{ + Q_ASSERT(m_objectAddress != Protocol::InvalidObjectAddress); + Q_ASSERT(m_messageType != Protocol::InvalidMessageType); + + writeNumber(device, m_buffer.size()); + writeNumber(device, m_objectAddress); + writeNumber(device, m_messageType); + + if (!m_buffer.isEmpty()) { + const int s = device->write(m_buffer); + Q_ASSERT(s == m_buffer.size()); + Q_UNUSED(s); + } +} diff -Nru gammaray-1.2.2/common/message.h gammaray-2.0.1/common/message.h --- gammaray-1.2.2/common/message.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/message.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,87 @@ +/* + message.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MESSAGE_H +#define GAMMARAY_MESSAGE_H + +#include "gammaray_common_export.h" +#include "protocol.h" + +#include +#include + +namespace GammaRay { + +/** + * Single message send between client and server. + * Binary format: + * - sizeof(Protocol::PayloadSize) byte size of the message payload (not including the size and other fixed fields itself) in netowork byte order (big endian) + * - sizeof(Protocol::ObjectAddress) server object address (big endian) + * - sizeof(Protocol::MessageType) command type (big endian) + * - size bytes message payload (encoding is user defined, QDataStream provided for convenience) + */ +class GAMMARAY_COMMON_EXPORT Message +{ + public: + /** + * Construct a new message to/from @p address and message type @p type. + */ + explicit Message(Protocol::ObjectAddress address, Protocol::MessageType type); +#ifdef Q_COMPILER_RVALUE_REFS + Message(Message &&other); //krazy:exclude=explicit +#else + // this is only needed to make readMessage compile (due to RVO there is no actual copy though) + // semantically we don't want to support copying, due to the datastream state + Message(const Message &other); +#endif + ~Message(); + + Protocol::ObjectAddress address() const; + Protocol::MessageType type() const; + + /** Access to the message payload. This is read-only for received messages + * and write-only for messages to be sent. + */ + QDataStream& payload() const; + + /** Checks if there is a full message waiting in @p device. */ + static bool canReadMessage(QIODevice *device); + /** Read the next message from @p device. */ + static Message readMessage(QIODevice *device); + + /** Write this message to @p device. */ + void write(QIODevice *device) const; + + private: + Message(); + + mutable QByteArray m_buffer; + mutable QScopedPointer m_stream; + + Protocol::ObjectAddress m_objectAddress; + Protocol::MessageType m_messageType; +}; + +} + +#endif diff -Nru gammaray-1.2.2/common/metatypedeclarations.h gammaray-2.0.1/common/metatypedeclarations.h --- gammaray-1.2.2/common/metatypedeclarations.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/metatypedeclarations.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + metatypedeclarations.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares the various metatypes. + + @brief + Declares the various metatypes. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_METATYPEDECLARATIONS_H +#define GAMMARAY_METATYPEDECLARATIONS_H + +#include +#include +#include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include +#include +#endif + +Q_DECLARE_METATYPE(Qt::ConnectionType) +Q_DECLARE_METATYPE(Qt::FillRule) +Q_DECLARE_METATYPE(Qt::InputMethodHints) +Q_DECLARE_METATYPE(Qt::MouseButtons) +Q_DECLARE_METATYPE(Qt::TransformationMode) +Q_DECLARE_METATYPE(QPainterPath) +Q_DECLARE_METATYPE(QPolygonF) +Q_DECLARE_METATYPE(QMetaMethod::MethodType) +Q_DECLARE_METATYPE(QMargins) +Q_DECLARE_METATYPE(Qt::WindowType) +Q_DECLARE_METATYPE(Qt::WindowState) + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +Q_DECLARE_METATYPE(QSurfaceFormat) +Q_DECLARE_METATYPE(QSurface::SurfaceClass) +Q_DECLARE_METATYPE(QSurface::SurfaceType) +#endif + +#endif diff -Nru gammaray-1.2.2/common/methodargument.cpp gammaray-2.0.1/common/methodargument.cpp --- gammaray-1.2.2/common/methodargument.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/methodargument.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,86 @@ +/* + methodargument.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "methodargument.h" + +#include +#include + +using namespace GammaRay; + +class GammaRay::MethodArgumentPrivate : public QSharedData +{ + public: + MethodArgumentPrivate() : QSharedData(), data(0) {} + + MethodArgumentPrivate(const MethodArgumentPrivate &other) : QSharedData(other) + { + value = other.value; + name = other.name; + data = 0; + } + + ~MethodArgumentPrivate() + { + if (data) + QMetaType::destroy(value.type(), data); + } + + QVariant value; + QByteArray name; + void *data; +}; + +MethodArgument::MethodArgument() : d(new MethodArgumentPrivate) +{ +} + +MethodArgument::MethodArgument(const QVariant& v) : d(new MethodArgumentPrivate) +{ + d->value = v; + d->name = v.typeName(); +} + +MethodArgument::MethodArgument(const MethodArgument& other) : d(other.d) +{ +} + +MethodArgument::~MethodArgument() +{ +} + +MethodArgument& MethodArgument::operator=(const MethodArgument& other) +{ + d = other.d; + return *this; +} + +MethodArgument::operator QGenericArgument() const +{ + if (d->value.isValid()) { + d->data = QMetaType::construct(d->value.userType(), d->value.constData()); + Q_ASSERT(d->data); + return QGenericArgument(d->name.data(), d->data); + } + return QGenericArgument(); +} diff -Nru gammaray-1.2.2/common/methodargument.h gammaray-2.0.1/common/methodargument.h --- gammaray-1.2.2/common/methodargument.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/methodargument.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + methodargument.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METHODARGUMENT_H +#define GAMMARAY_METHODARGUMENT_H + +#include "gammaray_common_export.h" +#include +#include + +namespace GammaRay { + +class MethodArgumentPrivate; + +/** Q[Generic]Argument that works on a QVariant, with some memory handling safety. */ +class GAMMARAY_COMMON_EXPORT MethodArgument +{ + public: + MethodArgument(); + explicit MethodArgument(const QVariant &v); + MethodArgument(const MethodArgument &other); + ~MethodArgument(); + + MethodArgument& operator=(const MethodArgument &other); + operator QGenericArgument() const; + + private: + QExplicitlySharedDataPointer d; +}; + +} + +#endif // GAMMARAY_METHODARGUMENT_H diff -Nru gammaray-1.2.2/common/modelinspectorinterface.cpp gammaray-2.0.1/common/modelinspectorinterface.cpp --- gammaray-1.2.2/common/modelinspectorinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/modelinspectorinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + modelinspectorinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "modelinspectorinterface.h" +#include "objectbroker.h" + +using namespace GammaRay; + +ModelInspectorInterface::ModelInspectorInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +ModelInspectorInterface::~ModelInspectorInterface() +{ + +} + diff -Nru gammaray-1.2.2/common/modelinspectorinterface.h gammaray-2.0.1/common/modelinspectorinterface.h --- gammaray-1.2.2/common/modelinspectorinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/modelinspectorinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + modelinspectorinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MODELINSPECTORINTERFACE_H +#define GAMMARAY_MODELINSPECTORINTERFACE_H + +#include + +namespace GammaRay { + +class ModelInspectorInterface : public QObject +{ + Q_OBJECT + public: + explicit ModelInspectorInterface(QObject *parent = 0); + virtual ~ModelInspectorInterface(); + + signals: + void cellSelected(int row, int col, const QString &internalId, const QString &internalPtr); +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::ModelInspectorInterface, "com.kdab.GammaRay.ModelInspectorInterface") + +#endif // GAMMARAY_MODELINSPECTORINTERFACE_H diff -Nru gammaray-1.2.2/common/modelroles.h gammaray-2.0.1/common/modelroles.h --- gammaray-1.2.2/common/modelroles.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/modelroles.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + modelroles.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MODELROLES_H +#define GAMMARAY_MODELROLES_H + +#include + +/** + * @file modelroles.h + * @brief A collection of custom model roles shared between client and server. + */ +namespace GammaRay { + +/** Portable replacement for Qt::UserRole. + * Qt4 uses 32, Qt5 256, use the latter globally to allow combining Qt4/5 client/servers. + */ +static const int UserRole = 256; + +/** @brief Custom roles for GammaRay::ToolModel. + * @todo These can be split again, between core tool model and UI tool model. + */ +namespace ToolModelRole { + enum Role { + ToolFactory = UserRole + 1, + ToolWidget, + ToolId, + ToolWidgetParent + }; +} + +/** @brief Custom roles for GammaRay::ObjectMethodModel. */ +namespace ObjectMethodModelRole { + enum Role { + MetaMethod = UserRole + 1, + MetaMethodType + }; +} + +} + +#endif diff -Nru gammaray-1.2.2/common/networkselectionmodel.cpp gammaray-2.0.1/common/networkselectionmodel.cpp --- gammaray-1.2.2/common/networkselectionmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/networkselectionmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,148 @@ +/* + networkselectionmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "networkselectionmodel.h" +#include "message.h" +#include "endpoint.h" +#include "settempvalue.h" + +#include + +using namespace GammaRay; + +static QItemSelection readSelection(const Message &msg, const QAbstractItemModel *model) +{ + QItemSelection selection; + qint32 size = 0; + msg.payload() >> size; + for (int i = 0; i < size; ++i) { + Protocol::ModelIndex topLeft, bottomRight; + msg.payload() >> topLeft >> bottomRight; + const QModelIndex qmiTopLeft = Protocol::toQModelIndex(model, topLeft); + const QModelIndex qmiBottomRight = Protocol::toQModelIndex(model, bottomRight); + if (!qmiTopLeft.isValid() && !qmiBottomRight.isValid()) + continue; + selection.push_back(QItemSelectionRange(qmiTopLeft, qmiBottomRight)); + } + return selection; +} + +static void writeSelection(Message *msg, const QItemSelection &selection) +{ + msg->payload() << qint32(selection.size()); + foreach(const QItemSelectionRange& range, selection) { + msg->payload() << Protocol::fromQModelIndex(range.topLeft()) << Protocol::fromQModelIndex(range.bottomRight()); + } +} + +NetworkSelectionModel::NetworkSelectionModel(const QString &objectName, QAbstractItemModel* model, QObject* parent): + QItemSelectionModel(model, parent), + m_objectName(objectName), + m_myAddress(Protocol::InvalidObjectAddress), + m_handlingRemoteMessage(false) +{ + connect(this, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex))); + connect(this, SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)), this, SLOT(slotCurrentColumnChanged(QModelIndex,QModelIndex))); + connect(this, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(slotCurrentRowChanged(QModelIndex,QModelIndex))); + connect(this, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged(QItemSelection,QItemSelection))); +} + +NetworkSelectionModel::~NetworkSelectionModel() +{ +} + +void NetworkSelectionModel::newMessage(const Message& msg) +{ + Q_ASSERT(msg.address() == m_myAddress); + switch (msg.type()) { + case Protocol::SelectionModelSelect: + { + QItemSelection selected = readSelection(msg, model()); + QItemSelection deselected = readSelection(msg, model()); + Util::SetTempValue guard(m_handlingRemoteMessage, true); + if (!deselected.isEmpty()) { + select(deselected, Deselect); + } + if (!selected.isEmpty()) { + select(selected, Select); + } + break; + } + case Protocol::SelectionModelCurrent: + { + qint32 flags; + Protocol::ModelIndex index; + msg.payload() >> flags >> index; + const QModelIndex qmi = Protocol::toQModelIndex(model(), index); + if (!qmi.isValid()) + break; + Util::SetTempValue guard(m_handlingRemoteMessage, true); + setCurrentIndex(qmi, QItemSelectionModel::SelectionFlags(flags)); + break; + } + default: + Q_ASSERT(false); + } +} + +void NetworkSelectionModel::slotCurrentChanged(const QModelIndex& current, const QModelIndex& previous) +{ + Q_UNUSED(previous); + if (m_handlingRemoteMessage || !Endpoint::isConnected()) + return; + Message msg(m_myAddress, Protocol::SelectionModelCurrent); + msg.payload() << qint32(QItemSelectionModel::Current) << Protocol::fromQModelIndex(current); + Endpoint::send(msg); +} + +void NetworkSelectionModel::slotCurrentColumnChanged(const QModelIndex& current, const QModelIndex& previous) +{ + Q_UNUSED(previous); + if (m_handlingRemoteMessage ||!Endpoint::isConnected()) + return; + Message msg(m_myAddress, Protocol::SelectionModelCurrent); + msg.payload() << qint32(QItemSelectionModel::Current|QItemSelectionModel::Columns) << Protocol::fromQModelIndex(current); + Endpoint::send(msg); +} + +void NetworkSelectionModel::slotCurrentRowChanged(const QModelIndex& current, const QModelIndex& previous) +{ + Q_UNUSED(previous); + if (m_handlingRemoteMessage ||!Endpoint::isConnected()) + return; + Message msg(m_myAddress, Protocol::SelectionModelCurrent); + msg.payload() << qint32(QItemSelectionModel::Current|QItemSelectionModel::Rows) << Protocol::fromQModelIndex(current); + Endpoint::send(msg); +} + +void NetworkSelectionModel::slotSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +{ + if (m_handlingRemoteMessage ||!Endpoint::isConnected()) + return; + + Message msg(m_myAddress, Protocol::SelectionModelSelect); + writeSelection(&msg, selected); + writeSelection(&msg, deselected); + Endpoint::send(msg); +} + diff -Nru gammaray-1.2.2/common/networkselectionmodel.h gammaray-2.0.1/common/networkselectionmodel.h --- gammaray-1.2.2/common/networkselectionmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/networkselectionmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + networkselectionmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_NETWORKSELECTIONMODEL_H +#define GAMMARAY_NETWORKSELECTIONMODEL_H + +#include +#include "protocol.h" + +namespace GammaRay { + +class Message; + +/** Base class for network-transparent item selection models, do not use directly. */ +class NetworkSelectionModel : public QItemSelectionModel +{ + Q_OBJECT +public: + ~NetworkSelectionModel(); + +protected: + explicit NetworkSelectionModel(const QString &objectName, QAbstractItemModel *model, QObject *parent = 0); + QString m_objectName; + Protocol::ObjectAddress m_myAddress; + +private slots: + void newMessage(const GammaRay::Message &msg); + + void slotCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous); + void slotCurrentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous); + void slotCurrentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); + void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + +private: + bool m_handlingRemoteMessage; +}; + +} + +#endif // GAMMARAY_NETWORKSELECTIONMODEL_H diff -Nru gammaray-1.2.2/common/objectbroker.cpp gammaray-2.0.1/common/objectbroker.cpp --- gammaray-1.2.2/common/objectbroker.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/objectbroker.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,191 @@ +/* + objectbroker.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "objectbroker.h" +#include "endpoint.h" + +#include + +#include +#include +#include +#include +#include +#include + +namespace GammaRay { + +struct ObjectlBrokerData { + ObjectlBrokerData() : modelCallback(0), selectionCallback(0) {} + QHash objects; + QHash models; + QHash selectionModels; + QHash clientObjectFactories; + ObjectBroker::ModelFactoryCallback modelCallback; + ObjectBroker::selectionModelFactoryCallback selectionCallback; +}; + +Q_GLOBAL_STATIC(ObjectlBrokerData, s_objectBroker) + +void ObjectBroker::registerObject(const QString &name, QObject *object) +{ + Q_ASSERT(!name.isEmpty()); + Q_ASSERT(object->objectName().isEmpty()); + object->setObjectName(name); + + Q_ASSERT(!s_objectBroker()->objects.contains(name)); + s_objectBroker()->objects.insert(name, object); + + Q_ASSERT(Endpoint::instance()); + Endpoint::instance()->registerObject(name, object); +} + +QObject* ObjectBroker::objectInternal(const QString& name, const QByteArray &type) +{ + const QHash::const_iterator it = s_objectBroker()->objects.constFind(name); + if (it != s_objectBroker()->objects.constEnd()) { + return it.value(); + } + + // Below here only valid for clients! + // Remote/probe side should have registered the object directly + QObject* obj = 0; + + if (!type.isEmpty()) { + Q_ASSERT(s_objectBroker()->clientObjectFactories.contains(type)); + obj = s_objectBroker()->clientObjectFactories[type](name, qApp); + } else { + // fallback + obj = new QObject(qApp); + registerObject(name, obj); + } + + Q_ASSERT(obj); + // ensure it was registered + Q_ASSERT_X(s_objectBroker()->objects.value(name, 0) == obj, Q_FUNC_INFO, qPrintable(QString("Object %1 was not registered in the broker.").arg(name))); + + return obj; +} + +void ObjectBroker::registerClientObjectFactoryCallbackInternal(const QByteArray &type, ObjectBroker::ClientObjectFactoryCallback callback) +{ + Q_ASSERT(!type.isEmpty()); + s_objectBroker()->clientObjectFactories[type] = callback; +} + +void ObjectBroker::registerModelInternal(const QString& name, QAbstractItemModel* model) +{ + Q_ASSERT(!s_objectBroker()->models.contains(name)); + model->setObjectName(name); + s_objectBroker()->models.insert(name, model); +} + +QAbstractItemModel* ObjectBroker::model(const QString& name) +{ + const QHash::const_iterator it = s_objectBroker()->models.constFind(name); + if (it != s_objectBroker()->models.constEnd()) + return it.value(); + + if (s_objectBroker()->modelCallback) { + QAbstractItemModel* model = s_objectBroker()->modelCallback(name); + if (model) { + model->setObjectName(name); + s_objectBroker()->models.insert(name, model); + return model; + } + } + return 0; +} + +void ObjectBroker::setModelFactoryCallback(ObjectBroker::ModelFactoryCallback callback) +{ + s_objectBroker()->modelCallback = callback; +} + +void ObjectBroker::registerSelectionModel(QItemSelectionModel* selectionModel) +{ + Q_ASSERT(!s_objectBroker()->selectionModels.contains(const_cast(selectionModel->model()))); + s_objectBroker()->selectionModels.insert(const_cast(selectionModel->model()), selectionModel); +} + +void ObjectBroker::unregisterSelectionModel(QItemSelectionModel *selectionModel) +{ + Q_ASSERT(s_objectBroker()->selectionModels.contains(const_cast(selectionModel->model()))); + s_objectBroker()->selectionModels.remove(const_cast(selectionModel->model())); +} + +bool ObjectBroker::hasSelectionModel(QAbstractItemModel* model) +{ + return s_objectBroker()->selectionModels.contains(model); +} + +static QAbstractItemModel* sourceModelForProxy(QAbstractItemModel* model) +{ + // stop once we found a registered model, this is what network communication is based on + if (s_objectBroker()->models.values().contains(model)) + return model; + + QAbstractProxyModel *proxy = qobject_cast(model); + if (!proxy) + return model; + return sourceModelForProxy(proxy->sourceModel()); +} + +QItemSelectionModel* ObjectBroker::selectionModel(QAbstractItemModel* model) +{ + const QHash::const_iterator it = s_objectBroker()->selectionModels.constFind(model); + if (it != s_objectBroker()->selectionModels.constEnd()) + return it.value(); + + if (s_objectBroker()->selectionCallback) { + QAbstractItemModel *sourceModel = sourceModelForProxy(model); + + QItemSelectionModel* selectionModel = 0; + if (sourceModel == model) { + selectionModel = s_objectBroker()->selectionCallback(sourceModel); + } else { + QItemSelectionModel *sourceSelectionModel = ObjectBroker::selectionModel(sourceModel); + selectionModel = new KLinkItemSelectionModel(model, sourceSelectionModel, model); + } + + if (selectionModel) { + registerSelectionModel(selectionModel); + return selectionModel; + } + } + return 0; +} + +void ObjectBroker::setSelectionModelFactoryCallback(ObjectBroker::selectionModelFactoryCallback callback) +{ + s_objectBroker()->selectionCallback = callback; +} + +void ObjectBroker::clear() +{ + s_objectBroker()->objects.clear(); + s_objectBroker()->models.clear(); + s_objectBroker()->selectionModels.clear(); +} + +} diff -Nru gammaray-1.2.2/common/objectbroker.h gammaray-2.0.1/common/objectbroker.h --- gammaray-1.2.2/common/objectbroker.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/objectbroker.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,138 @@ +/* + objectbroker.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_OBJECTBROKER_H +#define GAMMARAY_OBJECTBROKER_H + +#include "gammaray_common_export.h" + +#include + +class QItemSelectionModel; +class QAbstractItemModel; + +namespace GammaRay { + +/** @brief Retrieve/expose objects independent of whether using in-process or out-of-process UI. */ +namespace ObjectBroker { + + /** Register a newly created QObject under the given name. */ + GAMMARAY_COMMON_EXPORT void registerObject(const QString &name, QObject *object); + template + void registerObject(QObject *object) + { + const QString interface = QString::fromUtf8(qobject_interface_iid()); + registerObject(interface, object); + } + + /** Retrieve object by name. */ + GAMMARAY_COMMON_EXPORT QObject* objectInternal(const QString &name, const QByteArray &type = QByteArray()); + + /** + * Retrieve an object by name implementing interface @p T. + * + * Use this if multiple objects of the given type have been registered. + * Otherwise the function below is simpler and more failsafe. + * + * NOTE: the "T = 0" is just to ensure a pointer type is given. + */ + template + T object(const QString &name, T = 0) + { + T ret = qobject_cast(objectInternal(name, QByteArray(qobject_interface_iid()))); + Q_ASSERT(ret); + return ret; + } + + /** + * Retrieve object implementing interface @p T. + * + * This only works if a single type was registered implementing this interface + * using qobject_interface_iid as object name. + * + * In most cases this is the simplest way for tools to get an object. + * + * NOTE: the "T = 0" is just to ensure a pointer type is given. + */ + template + T object(T = 0) + { + const QByteArray interface(qobject_interface_iid()); + T ret = qobject_cast(objectInternal(QString::fromUtf8(interface), interface)); + Q_ASSERT(ret); + return ret; + } + + typedef QObject*(*ClientObjectFactoryCallback)(const QString &, QObject *parent); + + /** Register a callback for a factory to create remote object stubs for the given type. */ + GAMMARAY_COMMON_EXPORT void registerClientObjectFactoryCallbackInternal(const QByteArray &type, ClientObjectFactoryCallback callback); + + /** + * Register a callback for a factory of a given interface to create remote object stubs for the given type. + * + * NOTE: the "T = 0" is just to ensure a pointer type is given. + */ + template + void registerClientObjectFactoryCallback(ClientObjectFactoryCallback callback, T = 0) + { + registerClientObjectFactoryCallbackInternal(QByteArray(qobject_interface_iid()), callback); + } + + /** + * Register a newly created model with the given name. + * + * NOTE: This must not be called directly by anything but the probe/server side. + * User code must use Probe::registerModel() instead! + */ + GAMMARAY_COMMON_EXPORT void registerModelInternal(const QString &name, QAbstractItemModel* model); + + /** Retrieve a model by name. */ + GAMMARAY_COMMON_EXPORT QAbstractItemModel* model(const QString &name); + + typedef QAbstractItemModel*(*ModelFactoryCallback)(const QString &); + + /** Set a callback for the case that a model was requested but had not been registered before. */ + GAMMARAY_COMMON_EXPORT void setModelFactoryCallback(ModelFactoryCallback callback); + + /** Register a newly created selection model. */ + GAMMARAY_COMMON_EXPORT void registerSelectionModel(QItemSelectionModel *selectionModel); + /** Unregisters a selection model. You have to take care of deletion yourself. */ + GAMMARAY_COMMON_EXPORT void unregisterSelectionModel(QItemSelectionModel *selectionModel); + /** Checks whether a selection model for the given @p model is registered already. */ + GAMMARAY_COMMON_EXPORT bool hasSelectionModel(QAbstractItemModel* model); + + /** Retrieve the selection model for @p model. */ + GAMMARAY_COMMON_EXPORT QItemSelectionModel* selectionModel(QAbstractItemModel *model); + + typedef QItemSelectionModel*(*selectionModelFactoryCallback)(QAbstractItemModel*); + + /** Set a callback for the case that a selection model was requested but had not been registered before. */ + GAMMARAY_COMMON_EXPORT void setSelectionModelFactoryCallback(selectionModelFactoryCallback callback); + + /** Clear all registered objects. Useful when the probe is deleted. */ + GAMMARAY_COMMON_EXPORT void clear(); +} +} + +#endif // GAMMARAY_OBJECTBROKER_H diff -Nru gammaray-1.2.2/common/objectmodel.h gammaray-2.0.1/common/objectmodel.h --- gammaray-1.2.2/common/objectmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/objectmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + objectmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares the public object model roles. + + @brief + Declares the public object model roles. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_OBJECTMODEL_H +#define GAMMARAY_OBJECTMODEL_H + +#include + +namespace GammaRay { + +/** + * @brief GammaRay Object Models. + * + * Public object model roles, for use by tool plugins without needing access + * to the real object model classes. + */ +namespace ObjectModel { + + /** Role enum, to be used with the object list and tree models. */ + enum Role { + // Qt4 uses 32, Qt5 256, for Qt::UserRole - use the latter globally to allow combining Qt4/5 client/servers. + ObjectRole = 256 + 1, /**< the Object role */ + UserRole /**< the UserRole, as defined by Qt */ + }; +} + +} + +#endif diff -Nru gammaray-1.2.2/common/paths.cpp gammaray-2.0.1/common/paths.cpp --- gammaray-1.2.2/common/paths.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/paths.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ +/* + paths.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#include "paths.h" + +#include +#include +#include +#include + +namespace GammaRay { +namespace Paths { + +static QString s_rootPath; + +QString rootPath() +{ + Q_ASSERT(!s_rootPath.isEmpty()); + return s_rootPath; +} + +void setRootPath(const QString& rootPath) +{ + Q_ASSERT(!rootPath.isEmpty()); + Q_ASSERT(QDir(rootPath).exists()); + Q_ASSERT(QDir(rootPath).isAbsolute()); + + s_rootPath = rootPath; +} + +void setRelativeRootPath(const char* relativeRootPath) +{ + Q_ASSERT(relativeRootPath); + setRootPath(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String(relativeRootPath)); +} + +QString probePath(const QString& probeABI) +{ + return rootPath() + QDir::separator() + + QLatin1String(GAMMARAY_PLUGIN_INSTALL_DIR) + QDir::separator() + + QLatin1String(GAMMARAY_PLUGIN_VERSION) + QDir::separator() + + probeABI; +} + +QString binPath() +{ + return rootPath() + QDir::separator() + QLatin1String(GAMMARAY_BIN_INSTALL_DIR); +} + +QString libexecPath() +{ + return rootPath() + QDir::separator() + QLatin1String(GAMMARAY_LIBEXEC_INSTALL_DIR); +} + +QString currentProbePath() +{ + return probePath(GAMMARAY_PROBE_ABI); +} + +} +} diff -Nru gammaray-1.2.2/common/paths.h gammaray-2.0.1/common/paths.h --- gammaray-1.2.2/common/paths.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/paths.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + paths.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PATHS_H +#define GAMMARAY_PATHS_H + +#include "gammaray_common_export.h" + +class QString; + +namespace GammaRay { + +/** Methods to determine install locations of the various bits of GammaRay. */ +namespace Paths +{ + /** Absolute path to the root of the GammaRay installation, anything else + * is relative to this. + */ + GAMMARAY_COMMON_EXPORT QString rootPath(); + + /** Call this to set the root of the GammaRay install location, as early as + * possible. The install location is usually determined by using + * QCoreApplication::applicationDirPath() or the probe path, and the known relative + * install location of the corresponding component. + */ + GAMMARAY_COMMON_EXPORT void setRootPath(const QString &rootPath); + + /** Convenience version of the above, for root paths relative to + * QCoreApplication::applicationDirPath(). + */ + GAMMARAY_COMMON_EXPORT void setRelativeRootPath(const char* relativeRootPath); + + /** Returns the probe and plugin base path for the given probe ABI. + * If @p probeABI is empty, the path containing the probes is returned. + */ + GAMMARAY_COMMON_EXPORT QString probePath(const QString& probeABI); + + /** Returns the path containing the GammaRay injector executable. */ + GAMMARAY_COMMON_EXPORT QString binPath(); + + /** Returns the path containing helper executables. */ + GAMMARAY_COMMON_EXPORT QString libexecPath(); + + /** Returns the path to the current probe location, probePath(GAMMARAY_PROBE_ABI). */ + GAMMARAY_COMMON_EXPORT QString currentProbePath(); +} +} + +#endif // GAMMARAY_PATHS_H diff -Nru gammaray-1.2.2/common/pluginmanager.cpp gammaray-2.0.1/common/pluginmanager.cpp --- gammaray-1.2.2/common/pluginmanager.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/pluginmanager.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,86 @@ +/* + pluginmanager.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "pluginmanager.h" +#include "paths.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define IF_DEBUG(x) + +using namespace GammaRay; +using namespace std; + +PluginManagerBase::PluginManagerBase(QObject *parent) : m_parent(parent) +{ +} + +PluginManagerBase::~PluginManagerBase() +{ +} + +QStringList PluginManagerBase::pluginPaths() const +{ + QStringList pluginPaths; + pluginPaths.push_back(Paths::currentProbePath()); + return pluginPaths; +} + +void PluginManagerBase::scan(const QString &serviceType) +{ + m_errors.clear(); + QStringList loadedPluginNames; + + foreach (const QString &pluginPath, pluginPaths()) { + const QDir dir(pluginPath); + IF_DEBUG(cout << "checking plugin path: " << qPrintable(dir.absolutePath()) << endl); + foreach (const QString &plugin, dir.entryList(QStringList() << "*.desktop", QDir::Files)) { + const QString pluginFile = dir.absoluteFilePath(plugin); + const QFileInfo pluginInfo(pluginFile); + const QString pluginName = pluginInfo.baseName(); + + if (loadedPluginNames.contains(pluginName)) { + continue; + } + + QSettings desktopFile(pluginFile, QSettings::IniFormat); + desktopFile.beginGroup("Desktop Entry"); + const QStringList serviceTypes = desktopFile.value("X-GammaRay-ServiceTypes", QString()).toString().split(';', QString::SkipEmptyParts); + if (!serviceTypes.contains(serviceType)) { + IF_DEBUG(qDebug() << Q_FUNC_INFO << "skipping" << pluginFile << "not supporting service type" << serviceType << "service types are: " << serviceTypes;) + continue; + } + + if (createProxyFactory(pluginFile, m_parent)) + loadedPluginNames.push_back(pluginName); + } + } +} diff -Nru gammaray-1.2.2/common/pluginmanager.h gammaray-2.0.1/common/pluginmanager.h --- gammaray-1.2.2/common/pluginmanager.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/pluginmanager.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,122 @@ +/* + pluginmanager.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PLUGINMANAGER_H +#define GAMMARAY_PLUGINMANAGER_H + +#include +#include +#include +#include + +#include + +namespace GammaRay { + +class PluginLoadError; + +typedef QList PluginLoadErrors; + +class PluginLoadError +{ + public: + PluginLoadError(const QString &_pluginFile, const QString &_errorString) + : pluginFile(_pluginFile), errorString(_errorString) + { + } + + QString pluginName() const + { + return QFileInfo(pluginFile).baseName(); + } + + public: + QString pluginFile; + QString errorString; +}; + +class PluginManagerBase +{ + public: + /** + * @param parent This is the parent object for all objects created by the plugins + */ + explicit PluginManagerBase(QObject *parent = 0); + ~PluginManagerBase(); + + QList errors() const + { + return m_errors; + } + + protected: + virtual bool createProxyFactory(const QString& desktopFilePath, QObject* parent) = 0; + + void scan(const QString& serviceType); + QStringList pluginPaths() const; + + QList m_errors; + QObject *m_parent; +}; + +template +class PluginManager : public PluginManagerBase +{ +public: + explicit inline PluginManager(QObject *parent = 0) : PluginManagerBase(parent) + { + const QString iid = QString::fromLatin1(qobject_interface_iid()); + Q_ASSERT(!iid.isEmpty()); + const QString serviceType = iid.split('/').first(); + scan(serviceType); + } + + inline ~PluginManager() {} + + inline QVector plugins() + { + return m_plugins; + } + +protected: + bool createProxyFactory(const QString& desktopFilePath, QObject* parent) + { + Proxy *proxy = new Proxy(desktopFilePath, parent); + if (!proxy->isValid()) { + m_errors << PluginLoadError(desktopFilePath, QObject::tr("Failed to load plugin: %1").arg(proxy->errorString())); + std::cerr << "invalid plugin " << qPrintable(desktopFilePath) << std::endl; + delete proxy; + } else { + m_plugins.push_back(proxy); + return true; + } + return false; + } + +private: + QVector m_plugins; +}; + +} + +#endif // GAMMARAY_PLUGINMANAGER_H diff -Nru gammaray-1.2.2/common/probecontrollerinterface.cpp gammaray-2.0.1/common/probecontrollerinterface.cpp --- gammaray-1.2.2/common/probecontrollerinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/probecontrollerinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,30 @@ +/* + probecontrollerinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "probecontrollerinterface.h" + +using namespace GammaRay; + +ProbeControllerInterface::~ProbeControllerInterface() +{ +} diff -Nru gammaray-1.2.2/common/probecontrollerinterface.h gammaray-2.0.1/common/probecontrollerinterface.h --- gammaray-1.2.2/common/probecontrollerinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/probecontrollerinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + probecontrollerinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROBECONTROLLERINTERFACE_H +#define GAMMARAY_PROBECONTROLLERINTERFACE_H + +#include + +namespace GammaRay { + +/** Probe and host process remote control functions. */ +class ProbeControllerInterface +{ +public: + virtual ~ProbeControllerInterface(); + + /** Terminate host application. */ + virtual void quitHost() = 0; + + /** Detach GammaRay but keep host application running. */ + virtual void detachProbe() = 0; +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::ProbeControllerInterface, "com.kdab.GammaRay.ProbeControllerInterface") + +#endif // GAMMARAY_PROBECONTROLLERINTERFACE_H diff -Nru gammaray-1.2.2/common/propertycontrollerinterface.cpp gammaray-2.0.1/common/propertycontrollerinterface.cpp --- gammaray-1.2.2/common/propertycontrollerinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/propertycontrollerinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + propertycontrollerinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertycontrollerinterface.h" +#include "objectbroker.h" + +using namespace GammaRay; + +PropertyControllerInterface::PropertyControllerInterface(const QString &name, QObject *parent) + : QObject(parent) + , m_name(name) +{ + ObjectBroker::registerObject(name, this); +} + +PropertyControllerInterface::~PropertyControllerInterface() +{ + +} + +QString PropertyControllerInterface::name() const +{ + return m_name; +} diff -Nru gammaray-1.2.2/common/propertycontrollerinterface.h gammaray-2.0.1/common/propertycontrollerinterface.h --- gammaray-1.2.2/common/propertycontrollerinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/propertycontrollerinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + propertycontrollerinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYCONTROLLERINTERFACE_H +#define GAMMARAY_PROPERTYCONTROLLERINTERFACE_H + +#include + +#include "enums.h" + +namespace GammaRay { + +/** @brief Client/Server interface of the property editor. */ +class PropertyControllerInterface : public QObject +{ + Q_OBJECT + public: + explicit PropertyControllerInterface(const QString &name, QObject *parent = 0); + virtual ~PropertyControllerInterface(); + + QString name() const; + + public slots: + virtual void activateMethod() = 0; + virtual void invokeMethod(Qt::ConnectionType type) = 0; + + signals: + void displayStateChanged(GammaRay::PropertyWidgetDisplayState::State displayState); + + private: + QString m_name; +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::PropertyControllerInterface, "com.kdab.GammaRay.PropertyControllerInterface") + +#endif // GAMMARAY_PROPERTYCONTROLLERINTERFACE_H diff -Nru gammaray-1.2.2/common/protocol.cpp gammaray-2.0.1/common/protocol.cpp --- gammaray-1.2.2/common/protocol.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/protocol.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,65 @@ +/* + protocol.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "protocol.h" + +namespace GammaRay { + +namespace Protocol { + +Protocol::ModelIndex fromQModelIndex(const QModelIndex& index) +{ + if (!index.isValid()) + return ModelIndex(); + ModelIndex result = fromQModelIndex(index.parent()); + result.push_back(qMakePair(index.row(), index.column())); + return result; +} + +QModelIndex toQModelIndex(const QAbstractItemModel* model, const Protocol::ModelIndex& index) +{ + QModelIndex qmi; + + for (int i = 0; i < index.size(); ++i) { + qmi = model->index(index.at(i).first, index.at(i).second, qmi); + if (!qmi.isValid()) { + return QModelIndex(); // model isn't loaded to the full depth, so don't restart from the top + } + } + + return qmi; +} + +qint32 version() +{ + return 6; +} + +qint32 broadcastFormatVersion() +{ + return 1; +} + +} + +} diff -Nru gammaray-1.2.2/common/protocol.h gammaray-2.0.1/common/protocol.h --- gammaray-1.2.2/common/protocol.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/protocol.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,113 @@ +/* + protocol.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROTOCOL_H +#define GAMMARAY_PROTOCOL_H + +#include "gammaray_common_export.h" +#include +#include +#include +#include + +namespace GammaRay { + +/** @brief Helper functions and constants defining the communication protocol between client and server. */ +namespace Protocol { + +typedef qint32 PayloadSize; +typedef quint8 ObjectAddress; +typedef quint8 MessageType; + +static const ObjectAddress InvalidObjectAddress = 0; +static const ObjectAddress LauncherAddress = 255; +static const MessageType InvalidMessageType = 0; + +enum BuildInMessageType { + // object management + // client -> server + ObjectMonitored = InvalidMessageType + 1, + ObjectUnmonitored, + + // server -> client + ServerVersion, + + ObjectMapReply, + ObjectAdded, + ObjectRemoved, + + // remote model messages + // client -> server + ModelRowColumnCountRequest, + ModelContentRequest, + ModelHeaderRequest, + ModelSetDataRequest, + ModelSyncBarrier, + + // server -> client + ModelRowColumnCountReply, + ModelContentReply, + ModelContentChanged, + ModelHeaderReply, + ModelHeaderChanged, + ModelRowsAdded, + ModelRowsMoved, + ModelRowsRemoved, + ModelColumnsAdded, + ModelColumnsMoved, + ModelColumnsRemoved, + ModelReset, + ModelLayoutChanged, + + // server <-> client + SelectionModelSelect, + SelectionModelCurrent, + + MethodCall, + + ServerInfo, + + // probe settings provided by the launcher + ProbeSettings, + ServerPort +}; + +typedef QVector > ModelIndex; + +/** Serializes a QModelIndex. */ +GAMMARAY_COMMON_EXPORT ModelIndex fromQModelIndex(const QModelIndex &index); + +/** Deserializes a QModelIndex. */ +GAMMARAY_COMMON_EXPORT QModelIndex toQModelIndex(const QAbstractItemModel *model, const ModelIndex &index); + +/** Protocol version, must match exactly between client and server. */ +GAMMARAY_COMMON_EXPORT qint32 version(); + +/** Broadcast format version. */ +GAMMARAY_COMMON_EXPORT qint32 broadcastFormatVersion(); + +} + +} + +#endif diff -Nru gammaray-1.2.2/common/proxyfactorybase.cpp gammaray-2.0.1/common/proxyfactorybase.cpp --- gammaray-1.2.2/common/proxyfactorybase.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/proxyfactorybase.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,89 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "proxyfactorybase.h" + +#include +#include +#include +#include + +#include + +using namespace GammaRay; + +ProxyFactoryBase::ProxyFactoryBase(const QString& desktopFilePath, QObject* parent): + QObject(parent), + m_factory(0), + m_desktopFile(0) +{ + const QFileInfo pluginInfo(desktopFilePath); + m_desktopFile = new QSettings(desktopFilePath, QSettings::IniFormat); + m_desktopFile->beginGroup(QLatin1String("Desktop Entry")); + + m_id = value("X-GammaRay-Id", pluginInfo.baseName()).toString(); + + const QString dllBaseName = value(QLatin1String("Exec")).toString(); + if (dllBaseName.isEmpty()) { + m_errorString = tr("Invalid 'Exec' line in plugin spec file"); + return; + } + + foreach (const QString &entry, pluginInfo.dir().entryList(QStringList(dllBaseName + QLatin1Char('*')), QDir::Files)) { + const QString path = pluginInfo.dir().absoluteFilePath(entry); + if (QLibrary::isLibrary(path)) { + m_pluginPath = path; + break; + } + } + +} + +ProxyFactoryBase::~ProxyFactoryBase() +{ + +} + +QVariant ProxyFactoryBase::value(const QString& key, const QVariant &defaultValue) const +{ + return m_desktopFile->value(key, defaultValue); +} + + +QString ProxyFactoryBase::errorString() const +{ + return m_errorString; +} + +void ProxyFactoryBase::loadPlugin() +{ + if (m_factory) + return; + QPluginLoader loader(m_pluginPath, this); + m_factory = loader.instance(); + if (m_factory) { + m_factory->setParent(this); + } else { + m_errorString = loader.errorString(); + std::cerr << "error loading plugin " << qPrintable(m_pluginPath) + << ": " << qPrintable(loader.errorString()) << std::endl; + } +} diff -Nru gammaray-1.2.2/common/proxyfactorybase.h gammaray-2.0.1/common/proxyfactorybase.h --- gammaray-1.2.2/common/proxyfactorybase.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/proxyfactorybase.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,88 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROXYFACTORYBASE_H +#define GAMMARAY_PROXYFACTORYBASE_H + +#include +#include +#include + +#include + +namespace GammaRay +{ + +/** Base class for wrappers for potentially not yet loaded plugins. */ +class ProxyFactoryBase : public QObject +{ + Q_OBJECT +public: + explicit ProxyFactoryBase(const QString &desktopFilePath, QObject *parent = 0); + ~ProxyFactoryBase(); + + QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; + QString errorString() const; + +protected: + void loadPlugin(); + + QString m_id; + QObject *m_factory; + QString m_errorString; + QString m_pluginPath; + +private: + QSettings *m_desktopFile; +}; + +template +class ProxyFactory : public ProxyFactoryBase, public IFace +{ +public: + explicit inline ProxyFactory(const QString &desktopFilePath, QObject *parent = 0) + : ProxyFactoryBase(desktopFilePath, parent) {} + inline ~ProxyFactory() {} + + inline /*override*/ QString id() const + { + return m_id; + } + +protected: + IFace *factory() + { + loadPlugin(); + IFace *iface = qobject_cast(m_factory); + if (!iface) { + m_errorString = + QObject::tr("Plugin does not provide an instance of %1."). + arg(qobject_interface_iid()); + std::cerr << "Failed to cast object from " << qPrintable(m_pluginPath) + << " to " << qobject_interface_iid(); + } + return iface; + } +}; + +} + +#endif // GAMMARAY_PROXYFACTORYBASE_H diff -Nru gammaray-1.2.2/common/resourcebrowserinterface.cpp gammaray-2.0.1/common/resourcebrowserinterface.cpp --- gammaray-1.2.2/common/resourcebrowserinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/resourcebrowserinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + resourcebrowserinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "resourcebrowserinterface.h" +#include "objectbroker.h" + +using namespace GammaRay; + +ResourceBrowserInterface::ResourceBrowserInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +ResourceBrowserInterface::~ResourceBrowserInterface() +{ + +} + diff -Nru gammaray-1.2.2/common/resourcebrowserinterface.h gammaray-2.0.1/common/resourcebrowserinterface.h --- gammaray-1.2.2/common/resourcebrowserinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/resourcebrowserinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + resourcebrowserinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_RESOURCEBROWSERINTERFACE_H +#define GAMMARAY_RESOURCEBROWSERINTERFACE_H + +#include + +class QPixmap; + +namespace GammaRay { + +class ResourceBrowserInterface : public QObject +{ + Q_OBJECT + public: + explicit ResourceBrowserInterface(QObject *parent = 0); + virtual ~ResourceBrowserInterface(); + + signals: + void resourceDeselected(); + void resourceSelected(const QPixmap &pixmap); + void resourceSelected(const QByteArray &contents); +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::ResourceBrowserInterface, "com.kdab.GammaRay.ResourceBrowserInterface") + +#endif // GAMMARAY_RESOURCEBROWSERINTERFACE_H diff -Nru gammaray-1.2.2/common/settempvalue.h gammaray-2.0.1/common/settempvalue.h --- gammaray-1.2.2/common/settempvalue.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/settempvalue.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SETTEMPVALUE_H +#define GAMMARAY_SETTEMPVALUE_H + +namespace GammaRay { + +/** + * @brief GammaRay utilities. + */ +namespace Util { + + /** + * Temporarily overwrite a given object with a new value and reset the value + * when the scope is exited. + */ + template + struct SetTempValue + { + SetTempValue(T& obj, T newValue) + : obj(obj) + , oldValue(obj) + { + obj = newValue; + } + ~SetTempValue() + { + obj = oldValue; + } + T& obj; + T oldValue; + }; +} + +} + +#endif // GAMMARAY_SETTEMPVALUE_H diff -Nru gammaray-1.2.2/common/sharedmemorylocker.h gammaray-2.0.1/common/sharedmemorylocker.h --- gammaray-1.2.2/common/sharedmemorylocker.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/sharedmemorylocker.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ +/* + sharedmemorylocker.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +namespace GammaRay +{ + +#ifndef QT_NO_SHAREDMEMORY +/** RAII helper class for locking QSharedMemory. + * @todo this should be upstream + */ +class SharedMemoryLocker +{ +public: + explicit inline SharedMemoryLocker(QSharedMemory *shm) : m_shm(shm) + { + Q_ASSERT(shm); + shm->lock(); + } + + inline ~SharedMemoryLocker() + { + m_shm->unlock(); + } + +private: + QSharedMemory *m_shm; +}; +#endif + +} diff -Nru gammaray-1.2.2/common/streamoperators.cpp gammaray-2.0.1/common/streamoperators.cpp --- gammaray-1.2.2/common/streamoperators.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/streamoperators.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + streamoperators.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "streamoperators.h" +#include "enums.h" +#include "metatypedeclarations.h" + +#include +#include + +using namespace GammaRay; + +#define MAKE_ENUM_OPERATORS(enumType) \ + QDataStream &operator<<(QDataStream &out, enumType value) \ + { \ + out << qint32(value); \ + return out; \ + } \ + \ + QDataStream &operator>>(QDataStream &in, enumType &value) \ + { \ + qint32 t; \ + in >> t; \ + value = static_cast(t); \ + return in; \ + } + +MAKE_ENUM_OPERATORS(QMetaMethod::MethodType) +MAKE_ENUM_OPERATORS(PropertyWidgetDisplayState::State) +MAKE_ENUM_OPERATORS(Qt::ConnectionType) + +void StreamOperators::registerOperators() +{ + qRegisterMetaTypeStreamOperators(); + qRegisterMetaTypeStreamOperators(); + qRegisterMetaTypeStreamOperators(); +} diff -Nru gammaray-1.2.2/common/streamoperators.h gammaray-2.0.1/common/streamoperators.h --- gammaray-1.2.2/common/streamoperators.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/common/streamoperators.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ +/* + streamoperators.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STREAMOPERATORS_H +#define GAMMARAY_STREAMOPERATORS_H + +namespace GammaRay { + +/** Custom QDataStream streaming operators. */ +namespace StreamOperators +{ + /** Call once early during startup. */ + void registerOperators(); +} + +} + +#endif // GAMMARAY_STREAMOPERATORS_H diff -Nru gammaray-1.2.2/config-gammaray.h.cmake gammaray-2.0.1/config-gammaray.h.cmake --- gammaray-1.2.2/config-gammaray.h.cmake 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/config-gammaray.h.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -1,10 +1,34 @@ -#define GAMMARAY_LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" -#define GAMMARAY_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_DIR}" -// for finding the probe during automatic tests -#define GAMMARAY_BUILD_DIR "${CMAKE_BINARY_DIR}" +// relative install dirs +#define GAMMARAY_PLUGIN_INSTALL_DIR "${PLUGIN_INSTALL_DIR}" +#define GAMMARAY_LIBEXEC_INSTALL_DIR "${LIBEXEC_INSTALL_DIR}" +#define GAMMARAY_BIN_INSTALL_DIR "${BIN_INSTALL_DIR}" +#define GAMMARAY_PLUGIN_VERSION "${GAMMARAY_PLUGIN_VERSION}" +#define GAMMARAY_PROBE_ABI "${GAMMARAY_PROBE_ABI}" + +// relative inverse install dirs +#define GAMMARAY_INVERSE_BIN_DIR "${GAMMARAY_INVERSE_BIN_DIR}" +#define GAMMARAY_INVERSE_PROBE_DIR "${GAMMARAY_INVERSE_PROBE_DIR}" +#define GAMMARAY_INVERSE_LIBEXEC_DIR "${GAMMARAY_INVERSE_LIBEXEC_DIR}" + + +// build options #cmakedefine BUILD_TIMER_PLUGIN #cmakedefine HAVE_PRIVATE_QT_HEADERS #cmakedefine HAVE_STDINT_H + +#cmakedefine HAVE_QT_WIDGETS +#cmakedefine HAVE_QT_SVG +#cmakedefine HAVE_QT_DESIGNER +#cmakedefine HAVE_QT_PRINTSUPPORT +#cmakedefine HAVE_QT_WEBKIT1 + +#cmakedefine HAVE_VTK +#cmakedefine HAVE_GRAPHVIZ + +#include +#if !defined(QT_NO_SHAREDMEMORY) && !defined(QT_NO_SYSTEMSEMAPHORE) +#define HAVE_SHM +#endif diff -Nru gammaray-1.2.2/core/aboutpluginsdialog.cpp gammaray-2.0.1/core/aboutpluginsdialog.cpp --- gammaray-1.2.2/core/aboutpluginsdialog.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/aboutpluginsdialog.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,205 +0,0 @@ -/* - aboutpluginsdialog.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "aboutpluginsdialog.h" -#include "pluginmanager.h" - -#include "include/toolfactory.h" - -#include -#include -#include -#include -#include - -using namespace GammaRay; - -class ErrorModel : public QAbstractTableModel -{ - public: - explicit ErrorModel(PluginLoadErrors &errors, QObject *parent = 0) - : QAbstractTableModel(parent), m_errors(errors) {} - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return 3; - } - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return m_errors.size(); - } - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const - { - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - switch (section) { - case 0: - return tr("Plugin Name"); - case 1: - return tr("Plugin File"); - case 2: - return tr("Error Message"); - } - } - return QAbstractTableModel::headerData(section, orientation, role); - } - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const - { - if (!index.isValid()) { - return QVariant(); - } - - const int row = index.row(); - const int column = index.column(); - if (role == Qt::DisplayRole) { - switch (column) { - case 0: - return m_errors[row].pluginName(); - case 1: - return m_errors[row].pluginFile; - case 2: - return m_errors[row].errorString; - } - } - return QVariant(); - } - - private: - PluginLoadErrors m_errors; -}; - -class ToolModel : public QAbstractTableModel -{ - public: - explicit ToolModel(const QVector& tools, QObject* parent = 0) - : QAbstractTableModel(parent), m_tools(tools) {} - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return 3; - } - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return m_tools.size(); - } - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const - { - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - switch (section) { - case 0: - return tr("Id"); - case 1: - return tr("Name"); - case 2: - return tr("Supported types"); - } - } - return QAbstractTableModel::headerData(section, orientation, role); - } - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const - { - if (!index.isValid()) { - return QVariant(); - } - - const int row = index.row(); - const int column = index.column(); - if (role == Qt::DisplayRole) { - ToolFactory *factory = m_tools[row]; - switch (column) { - case 0: - return factory->id(); - case 1: - return factory->name(); - case 2: - return factory->supportedTypes(); - } - } - return QVariant(); - } - - private: - QVector m_tools; -}; - -AboutPluginsDialog::AboutPluginsDialog(QWidget *parent, Qt::WindowFlags f) - : QDialog(parent, f) -{ - QLayout *layout = 0; - QVBoxLayout *vbox = new QVBoxLayout(this); - - { - QVector tools = PluginManager::instance()->plugins(); - ToolModel *toolModel = new ToolModel(tools, this); - QTableView *toolView = new QTableView(this); - toolView->setShowGrid(false); - toolView->setSelectionBehavior(QAbstractItemView::SelectRows); - toolView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - toolView->verticalHeader()->hide(); - toolView->setModel(toolModel); - - QGroupBox *toolBox = new QGroupBox(tr("Loaded Plugins"), this); - layout = new QHBoxLayout(toolBox); - layout->addWidget(toolView); - vbox->addWidget(toolBox); - - toolBox->setEnabled(toolModel->rowCount() > 0); - } - - { - PluginLoadErrors errors = PluginManager::instance()->errors(); - ErrorModel *errorModel = new ErrorModel(errors, this); - QTableView *errorView = new QTableView(this); - errorView->setShowGrid(false); - errorView->setSelectionBehavior(QAbstractItemView::SelectRows); - errorView->setModel(errorModel); - errorView->verticalHeader()->hide(); - errorView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - - QGroupBox *errorBox = new QGroupBox(tr("Failed Plugins"), this); - layout = new QHBoxLayout(errorBox); - layout->addWidget(errorView); - vbox->addWidget(errorBox); - - errorBox->setEnabled(errorModel->rowCount() > 0); - } - - setWindowTitle(tr("GammaRay: Plugin Info")); -} - -void AboutPluginsDialog::init() -{ -} - -#include "aboutpluginsdialog.moc" diff -Nru gammaray-1.2.2/core/aboutpluginsdialog.h gammaray-2.0.1/core/aboutpluginsdialog.h --- gammaray-1.2.2/core/aboutpluginsdialog.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/aboutpluginsdialog.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -/* - aboutpluginsdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_ABOUTPLUGINSDIALOG_H -#define GAMMARAY_ABOUTPLUGINSDIALOG_H - -#include - -namespace GammaRay { - -class AboutPluginsDialog : public QDialog -{ - Q_OBJECT - - public: - explicit AboutPluginsDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - - private: - void init(); -}; - -} - -#endif // GAMMARAY_ABOUTPLUGINSDIALOG_H diff -Nru gammaray-1.2.2/core/CMakeLists.txt gammaray-2.0.1/core/CMakeLists.txt --- gammaray-1.2.2/core/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,29 +1,15 @@ -add_subdirectory(tools) - -include_directories( - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/3rdparty - ${CMAKE_CURRENT_SOURCE_DIR} - - ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR} -) - set(gammaray_srcs - ../3rdparty/kde/krecursivefilterproxymodel.cpp - ../3rdparty/kde/kfilterproxysearchline.cpp - ../3rdparty/qt/resourcemodel.cpp + ${CMAKE_SOURCE_DIR}/3rdparty/qt/resourcemodel.cpp - util.cpp - aboutpluginsdialog.cpp - mainwindow.cpp metaobject.cpp + metaobjecttreemodel.cpp metaobjectrepository.cpp metaproperty.cpp metapropertymodel.cpp - pluginmanager.cpp probe.cpp - proxydetacher.cpp + probesettings.cpp + probecontroller.cpp +# proxydetacher.cpp objectlistmodel.cpp objectpropertymodel.cpp objectdynamicpropertymodel.cpp @@ -34,88 +20,50 @@ objecttreemodel.cpp connectionmodel.cpp connectionfilterproxymodel.cpp - methodinvocationdialog.cpp methodargumentmodel.cpp multisignalmapper.cpp toolmodel.cpp - proxydetacher.cpp + toolpluginmodel.cpp + toolpluginerrormodel.cpp + propertycontroller.cpp proxytoolfactory.cpp - sidepane.cpp - palettemodel.cpp - propertywidget.cpp - - propertyeditor/propertycoloreditor.cpp - propertyeditor/propertydoublepaireditor.cpp - propertyeditor/propertyeditorfactory.cpp - propertyeditor/propertyextendededitor.cpp - propertyeditor/propertyfonteditor.cpp - propertyeditor/propertyintpaireditor.cpp - propertyeditor/propertypaletteeditor.cpp - propertyeditor/palettedialog.cpp + util.cpp + varianthandler.cpp tools/modelinspector/modeltester.cpp tools/modelinspector/modelmodel.cpp tools/modelinspector/modelcellmodel.cpp - tools/sceneinspector/graphicsview.cpp - tools/sceneinspector/graphicssceneview.cpp - tools/sceneinspector/scenemodel.cpp tools/metatypebrowser/metatypesmodel.cpp - tools/fontbrowser/fontmodel.cpp tools/localeinspector/localemodel.cpp tools/localeinspector/localedataaccessor.cpp tools/localeinspector/localeaccessormodel.cpp - tools/codecbrowser/codecmodel.cpp tools/textdocumentinspector/textdocumentmodel.cpp tools/textdocumentinspector/textdocumentformatmodel.cpp - tools/textdocumentinspector/textdocumentcontentview.cpp tools/messagehandler/messagehandler.cpp + tools/messagehandler/messagehandlerinterface.cpp tools/messagehandler/messagemodel.cpp - tools/codecbrowser/codecbrowser.cpp tools/connectioninspector/connectioninspector.cpp - tools/fontbrowser/fontbrowser.cpp tools/localeinspector/localeinspector.cpp + tools/metaobjectbrowser/metaobjectbrowser.cpp tools/metatypebrowser/metatypebrowser.cpp tools/modelinspector/modelinspector.cpp - tools/modelinspector/modelinspectorwidget.cpp tools/objectinspector/objectinspector.cpp tools/resourcebrowser/resourcebrowser.cpp tools/resourcebrowser/resourcefiltermodel.cpp - tools/sceneinspector/sceneinspector.cpp - tools/selectionmodelinspector/selectionmodelinspector.cpp tools/textdocumentinspector/textdocumentinspector.cpp - tools/widgetinspector/widgetinspector.cpp - tools/widgetinspector/overlaywidget.cpp - tools/widgetinspector/widgettreemodel.cpp - tools/widgetinspector/widgetpreviewwidget.cpp - tools/styleinspector/styleinspector.cpp - tools/styleinspector/pixelmetricmodel.cpp - tools/styleinspector/standardiconmodel.cpp - tools/styleinspector/primitivemodel.cpp - tools/styleinspector/controlmodel.cpp - tools/styleinspector/styleoption.cpp - tools/styleinspector/abstractstyleelementmodel.cpp - tools/styleinspector/abstractstyleelementstatetable.cpp - tools/styleinspector/styleelementstatetablepage.cpp - tools/styleinspector/complexcontrolmodel.cpp - tools/styleinspector/dynamicproxystyle.cpp -) -if(WIN32 OR APPLE) - set(gammaray_srcs - ${gammaray_srcs} - hooking/abstractfunctionoverwriter.cpp - hooking/functionoverwriterfactory.cpp - hooking/winfunctionoverwriter.cpp - hooking/unixfunctionoverwriter.cpp - ) -endif() + remote/server.cpp + remote/remotemodelserver.cpp + remote/selectionmodelserver.cpp +) -if(HAVE_PRIVATE_QT_HEADERS) +if(Qt5Core_FOUND) set(gammaray_srcs ${gammaray_srcs} - paintbuffermodel.cpp - paintbufferviewer.cpp - paintbufferreplaywidget.cpp + tools/mimetypes/mimetypes.cpp + tools/mimetypes/mimetypesmodel.cpp + tools/standardpaths/standardpaths.cpp + tools/standardpaths/standardpathsmodel.cpp ) endif() @@ -129,49 +77,50 @@ tools/messagehandler/StackWalker.cpp) endif() -qt4_automoc(${gammaray_srcs}) -qt4_wrap_ui(gammaray_srcs - mainwindow.ui - propertywidget.ui - methodinvocationdialog.ui - paintbufferviewer.ui - - propertyeditor/propertydoublepaireditor.ui - propertyeditor/propertyextendededitor.ui - propertyeditor/propertyintpaireditor.ui - propertyeditor/palettedialog.ui - - tools/sceneinspector/graphicssceneview.ui - tools/codecbrowser/codecbrowser.ui - tools/connectioninspector/connectioninspector.ui - tools/fontbrowser/fontbrowser.ui - tools/localeinspector/localeinspector.ui - tools/messagehandler/messagehandler.ui - tools/metatypebrowser/metatypebrowser.ui - tools/modelinspector/modelinspectorwidget.ui - tools/objectinspector/objectinspector.ui - tools/resourcebrowser/resourcebrowser.ui - tools/sceneinspector/sceneinspector.ui - tools/selectionmodelinspector/selectionmodelinspector.ui - tools/styleinspector/styleinspector.ui - tools/textdocumentinspector/textdocumentinspector.ui - tools/widgetinspector/widgetinspector.ui - tools/styleinspector/styleelementstatetablepage.ui -) - +qt4_wrap_cpp(gammaray_srcs tools/modelinspector/modeltest.h) qt4_add_resources(gammaray_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc) -add_definitions(-DMAKE_GAMMARAY_LIB) -add_library(gammaray_probe - SHARED ${gammaray_srcs} +add_definitions(-DMAKE_GAMMARAY_CORE_LIB) + +# core lib +add_library(gammaray_core SHARED + ${gammaray_srcs} ) -target_link_libraries(gammaray_probe - ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} + +target_link_libraries(gammaray_core + gammaray_common + gammaray_common_internal ) -if(NOT WIN32) - target_link_libraries(gammaray_probe dl) +set_target_properties(gammaray_core PROPERTIES + SOVERSION ${GAMMARAY_SOVERSION} + VERSION ${GAMMARAY_SOVERSION} + OUTPUT_NAME gammaray_core-${GAMMARAY_PROBE_ABI} +) + +if(Qt5Core_FOUND) + target_link_libraries(gammaray_core Qt5::Gui) +else() + target_link_libraries(gammaray_core + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTNETWORK_LIBRARIES} + ) endif() -set_target_properties(gammaray_probe PROPERTIES PREFIX "") -install(TARGETS gammaray_probe ${INSTALL_TARGETS_DEFAULT_ARGS}) +target_link_libraries(gammaray_core LINK_INTERFACE_LIBRARIES gammaray_common ${QT_QTCORE_LIBRARIES}) +install(TARGETS gammaray_core EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) + +gammaray_install_headers( + gammaray_core_export.h + metaobject.h + metaobjectrepository.h + metaproperty.h + objectmodelbase.h + objecttypefilterproxymodel.h + probeinterface.h + propertycontroller.h + singlecolumnobjectproxymodel.h + toolfactory.h + util.h + varianthandler.h +) diff -Nru gammaray-1.2.2/core/connectionfilterproxymodel.cpp gammaray-2.0.1/core/connectionfilterproxymodel.cpp --- gammaray-1.2.2/core/connectionfilterproxymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/connectionfilterproxymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -29,17 +29,31 @@ ConnectionFilterProxyModel::ConnectionFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent), m_receiver(0), - m_sender(0) + m_sender(0), + m_filterOnReceiver(false), + m_filterOnSender(false) { setDynamicSortFilter(true); } +void ConnectionFilterProxyModel::setFilterOnReceiver(bool filter) +{ + m_filterOnReceiver = filter; + invalidateFilter(); +} + void ConnectionFilterProxyModel::filterReceiver(QObject *receiver) { m_receiver = receiver; invalidateFilter(); } +void ConnectionFilterProxyModel::setFilterOnSender(bool filter) +{ + m_filterOnSender = filter; + invalidateFilter(); +} + void ConnectionFilterProxyModel::filterSender(QObject *sender) { m_sender = sender; @@ -50,12 +64,12 @@ const QModelIndex &source_parent) const { const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent); - if (m_sender && - sourceIndex.data(ConnectionModel::SenderRole).value() != m_sender) { + if (m_filterOnSender && (!m_sender || + sourceIndex.data(ConnectionModel::SenderRole).value() != m_sender)) { return false; } - if (m_receiver && - sourceIndex.data(ConnectionModel::ReceiverRole).value() != m_receiver) { + if (m_filterOnReceiver && (!m_receiver || + sourceIndex.data(ConnectionModel::ReceiverRole).value() != m_receiver)) { return false; } return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); @@ -64,10 +78,10 @@ bool ConnectionFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const { - if (m_sender && source_column == 0) { + if (m_filterOnSender && source_column == 0) { return false; } - if (m_receiver && source_column == 2) { + if (m_filterOnReceiver && source_column == 2) { return false; } return QSortFilterProxyModel::filterAcceptsColumn(source_column, source_parent); @@ -84,4 +98,3 @@ } } -#include "connectionfilterproxymodel.moc" diff -Nru gammaray-1.2.2/core/connectionfilterproxymodel.h gammaray-2.0.1/core/connectionfilterproxymodel.h --- gammaray-1.2.2/core/connectionfilterproxymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/connectionfilterproxymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -32,9 +32,11 @@ { Q_OBJECT public: - ConnectionFilterProxyModel(QObject *parent = 0); + explicit ConnectionFilterProxyModel(QObject *parent = 0); + void setFilterOnReceiver(bool filter); void filterReceiver(QObject *receiver); + void setFilterOnSender(bool filter); void filterSender(QObject *sender); protected: @@ -46,6 +48,8 @@ private: QObject *m_receiver; QObject *m_sender; + bool m_filterOnReceiver; + bool m_filterOnSender; }; } diff -Nru gammaray-1.2.2/core/connectionmodel.cpp gammaray-2.0.1/core/connectionmodel.cpp --- gammaray-1.2.2/core/connectionmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/connectionmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -25,34 +25,15 @@ #include "probe.h" #include "readorwritelocker.h" -#include "include/util.h" +#include +#include "util.h" +#include #include #include #include #include -namespace GammaRay { - -struct Connection -{ - Connection() - : sender(0), receiver(0), type(Qt::AutoConnection), valid(false) - { - } - QObject *sender; - QByteArray signal; - QObject *receiver; - QByteArray method; - QByteArray location; - Qt::ConnectionType type; - bool valid; -}; - -} - -Q_DECLARE_TYPEINFO(GammaRay::Connection, Q_MOVABLE_TYPE); - using namespace GammaRay; static bool checkMethodForObject(QObject *obj, const QByteArray &signature, bool isSender) @@ -61,7 +42,7 @@ return false; } const QMetaObject *mo = obj->metaObject(); - const int methodIndex = mo->indexOfMethod(signature.mid(1)); + const int methodIndex = mo->indexOfMethod(signature.constData() + 1); if (methodIndex < 0) { return false; } @@ -78,48 +59,40 @@ return true; } +static QByteArray normalize(QObject *obj, const char *signature) +{ + int idx = obj->metaObject()->indexOfMethod(signature + 1); + if (idx == -1) { + return QMetaObject::normalizedSignature(signature); + } else { + // oh how I'd like to use ::fromRawData here reliably ;-) + return QByteArray(signature); + } +} + ConnectionModel::ConnectionModel(QObject *parent) : QAbstractTableModel(parent) { qRegisterMetaType("const char*"); qRegisterMetaType("Qt::ConnectionType"); + qRegisterMetaType(); } void ConnectionModel::connectionAdded(QObject *sender, const char *signal, QObject *receiver, const char *method, Qt::ConnectionType type) { - if (sender == this || receiver == this) { + if (sender == this || receiver == this || !sender || !receiver) { return; } - // when called from background, delay into foreground, otherwise call directly - QMetaObject::invokeMethod(this, "connectionAddedMainThread", Qt::AutoConnection, - Q_ARG(QObject *, sender), Q_ARG(const char *, signal), - Q_ARG(QObject *, receiver), Q_ARG(const char *, method), - Q_ARG(Qt::ConnectionType, type)); -} - -void ConnectionModel::connectionAddedMainThread(QObject *sender, const char *signal, - QObject *receiver, const char *method, - Qt::ConnectionType type) -{ - Q_ASSERT(thread() == QThread::currentThread()); - - ReadOrWriteLocker objectLock(Probe::instance()->objectLock()); - if (!Probe::instance()->isValidObject(sender) || - !Probe::instance()->isValidObject(receiver)) { - return; - } - - beginInsertRows(QModelIndex(), m_connections.size(), m_connections.size()); Connection c; c.sender = sender; - c.signal = QMetaObject::normalizedSignature(signal); + c.signal = normalize(sender, signal); c.receiver = receiver; - c.method = QMetaObject::normalizedSignature(method); + c.method = normalize(receiver, method); c.type = type; - c.location = Probe::connectLocation(signal); + c.location = SignalSlotsLocationStore::extractLocation(signal); // check if that's actually a valid connection if (checkMethodForObject(sender, c.signal, true) && @@ -131,7 +104,25 @@ //TODO: we could check more stuff here eg. if queued connection is possible etc. //and use verktygs heuristics to detect likely misconnects - m_connections.push_back(c); + // when called from background, delay into foreground, otherwise call directly + QMetaObject::invokeMethod(this, "connectionAddedMainThread", Qt::AutoConnection, + Q_ARG(GammaRay::Connection, c)); +} + +void ConnectionModel::connectionAddedMainThread(const Connection& connection) +{ + Q_ASSERT(thread() == QThread::currentThread()); + + { + ReadOrWriteLocker objectLock(Probe::instance()->objectLock()); + if (!Probe::instance()->isValidObject(connection.sender) || + !Probe::instance()->isValidObject(connection.receiver)) { + return; + } + } + + beginInsertRows(QModelIndex(), m_connections.size(), m_connections.size()); + m_connections.push_back(connection); endInsertRows(); } @@ -142,17 +133,6 @@ return; } - // when called from background, delay into foreground, otherwise call directly - QMetaObject::invokeMethod(this, "connectionRemovedMainThread", Qt::AutoConnection, - Q_ARG(QObject *, sender), Q_ARG(const char *, signal), - Q_ARG(QObject *, receiver), Q_ARG(const char *, method)); -} - -void ConnectionModel::connectionRemovedMainThread(QObject *sender, const char *signal, - QObject *receiver, const char *method) -{ - Q_ASSERT(thread() == QThread::currentThread()); - QByteArray normalizedSignal, normalizedMethod; if (signal) { normalizedSignal = QMetaObject::normalizedSignature(signal); @@ -161,6 +141,17 @@ normalizedMethod = QMetaObject::normalizedSignature(method); } + // when called from background, delay into foreground, otherwise call directly + QMetaObject::invokeMethod(this, "connectionRemovedMainThread", Qt::AutoConnection, + Q_ARG(QObject*, sender), Q_ARG(QByteArray, normalizedSignal), + Q_ARG(QObject*, receiver), Q_ARG(QByteArray, normalizedMethod)); +} + +void ConnectionModel::connectionRemovedMainThread(QObject *sender, const QByteArray &normalizedSignal, + QObject *receiver, const QByteArray &normalizedMethod) +{ + Q_ASSERT(thread() == QThread::currentThread()); + for (int i = 0; i < m_connections.size();) { bool remove = false; @@ -169,16 +160,23 @@ // might be invalidated from a background thread remove = true; } else if ((sender == 0 || con.sender == sender) && - (signal == 0 || con.signal == normalizedSignal) && (receiver == 0 || con.receiver == receiver) && - (method == 0 || con.method == normalizedMethod)) { + (normalizedSignal.isEmpty() || con.signal == normalizedSignal) && + (normalizedMethod.isEmpty() || con.method == normalizedMethod)) { // the connection was actually removed remove = true; } if (remove) { - beginRemoveRows(QModelIndex(), i, i); - m_connections.remove(i); + // note: QVector in Qt4 does not move objects when erasing, even though Connection is marked as movable. + // To workaround this issue, we swap with the last entry and pop from the back which is cheap. + if (i < m_connections.size() - 1) { + qSwap(m_connections[i], m_connections.last()); + emit dataChanged(index(i, 0), index(i, columnCount())); + } + + beginRemoveRows(QModelIndex(), m_connections.size() - 1, m_connections. size() - 1); + m_connections.pop_back(); endRemoveRows(); } else { ++i; @@ -252,7 +250,7 @@ return QVariant::fromValue(con.receiver); } else if (role == Qt::ForegroundRole) { if (!con.valid) { - return Qt::red; + return QVariant::fromValue(Qt::red); } } else if (role == ConnectionValidRole) { return con.valid; @@ -295,4 +293,3 @@ return m_connections.size(); } -#include "connectionmodel.moc" diff -Nru gammaray-1.2.2/core/connectionmodel.h gammaray-2.0.1/core/connectionmodel.h --- gammaray-1.2.2/core/connectionmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/connectionmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -28,16 +28,38 @@ #include #include +#include "gammaray_core_export.h" +#include + namespace GammaRay { -struct Connection; +struct Connection +{ + Connection() + : sender(0), receiver(0), type(Qt::AutoConnection), valid(false) + { } + QObject *sender; + QByteArray signal; + QObject *receiver; + QByteArray method; + QByteArray location; + Qt::ConnectionType type; + bool valid; +}; + +} + +Q_DECLARE_TYPEINFO(GammaRay::Connection, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(GammaRay::Connection) + +namespace GammaRay { -class ConnectionModel : public QAbstractTableModel +class GAMMARAY_CORE_EXPORT ConnectionModel : public QAbstractTableModel { Q_OBJECT public: enum Role { - SenderRole = Qt::UserRole + 1, + SenderRole = UserRole + 1, ReceiverRole, ConnectionValidRole }; @@ -56,11 +78,9 @@ int rowCount(const QModelIndex &parent = QModelIndex()) const; private slots: - void connectionAddedMainThread(QObject *sender, const char *signal, - QObject *receiver, const char *method, - Qt::ConnectionType type); - void connectionRemovedMainThread(QObject *sender, const char *signal, - QObject *receiver, const char *method); + void connectionAddedMainThread(const GammaRay::Connection &connection); + void connectionRemovedMainThread(QObject *sender, const QByteArray &normalizedSignal, + QObject *receiver, const QByteArray &normalizedMethod); private: QVector m_connections; diff -Nru gammaray-1.2.2/core/gammaray_core_export.h gammaray-2.0.1/core/gammaray_core_export.h --- gammaray-1.2.2/core/gammaray_core_export.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/gammaray_core_export.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +/* + gammaray_core_export.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CORE_EXPORT_H +#define GAMMARAY_CORE_EXPORT_H + +#include + +#ifdef GAMMARAY_CORE_STATICLIB +# undef GAMMARAY_CORE_SHAREDLIB +# define GAMMARAY_CORE_EXPORT +#else +# ifdef MAKE_GAMMARAY_CORE_LIB +# define GAMMARAY_CORE_EXPORT Q_DECL_EXPORT +# else +# define GAMMARAY_CORE_EXPORT Q_DECL_IMPORT +# endif +#endif + +#endif /* GAMMARAY_CORE_EXPORT_H */ diff -Nru gammaray-1.2.2/core/hooking/abstractfunctionoverwriter.cpp gammaray-2.0.1/core/hooking/abstractfunctionoverwriter.cpp --- gammaray-1.2.2/core/hooking/abstractfunctionoverwriter.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/abstractfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,215 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "abstractfunctionoverwriter.h" -#include - -#ifdef ARCH_X86 -const long worstSizeForLongJump = 10; -#elif defined(ARCH_64) -const long worstSizeForLongJump = 14; -#else -# error "Unsupported hardware architecture!" -#endif - -using namespace GammaRay; - -bool AbstractFunctionOverwriter::writeShortJump(void *target, void *const func) -{ - quint8 *cur = (quint8 *) target; - - //E9 relative short jump is 5 bytes long - bool ret = unprotectMemory(page_align(target), roundToNextPage(5)); - - if (!ret) { - std::cerr << "Failed to unprotect memory: " << page_align(target); - return false; - } - - *cur = 0xE9; - cur++; - *((quint32 *)cur) = (unsigned long)func - (unsigned long)(cur + 4); - - ret = reprotectMemory(page_align(target), roundToNextPage(5)); - - if (!ret) { - std::cerr << "Failed to reprotect memory: " << page_align(target); - return false; - } - - return true; -} - -bool AbstractFunctionOverwriter::writeLongJump(void *target, void *const func) -{ - quint8 *cur = (quint8 *) target; - - bool ret = unprotectMemory(page_align(target), roundToNextPage(worstSizeForLongJump)); - - if (!ret) { - std::cerr << "Failed to unprotect memory: " << page_align(target); - return false; - } - - *cur = 0xff; - *(++cur) = 0x25; - -#ifdef ARCH_X86 - *((quint32 *) ++cur) = (quint32)(((quint32) cur) + sizeof (quint32)); - cur += sizeof (quint32); - *((quint32 *)cur) = (quint32)func; -#elif defined(ARCH_64) - *((quint32 *) ++cur) = 0; - cur += sizeof (quint32); - *((quint64*)cur) = (quint64)func; -#else -# error "Unsupported hardware architecture!" -#endif - - ret = reprotectMemory(page_align(target), roundToNextPage(worstSizeForLongJump)); - - if (!ret) { - std::cerr << "Failed to reprotect memory: " << page_align(target); - return false; - } - - return true; -} - -void *AbstractFunctionOverwriter::getMemoryNearAddress(void *const addr, size_t size) -{ - Q_ASSERT(blocksize() > size); - -#if defined(ARCH_64) - intptr_t minAddr; - intptr_t maxAddr; - - getAddressRange(minAddr, maxAddr); - - minAddr = std::max(minAddr, reinterpret_cast(addr) - 0x20000000); - maxAddr = std::min(maxAddr, reinterpret_cast(addr) + 0x20000000); -#endif - - for (QList::Iterator it = memoryPool.begin(); it != memoryPool.end(); ++it) { - if (it->free >= size) { -#if defined(ARCH_64) - if (!((intptr_t)it->mem > minAddr && (intptr_t)it->mem < maxAddr)) { - continue; - } -#endif - quint8 *mem = (quint8 *)it->mem + (it->size - it->free); - it->free -= size; - return mem; - } - } - - void *mem = 0; -#ifdef ARCH_X86 - Q_UNUSED(addr); - mem = reserveMemory(0, blocksize()); -#elif defined(ARCH_64) - intptr_t min = minAddr / blocksize(); - intptr_t max = maxAddr / blocksize(); - int rel = 0; - for (int i = 0; i < (max - min + 1); ++i) { - rel = -rel + (i & 1); - void* query = reinterpret_cast(((min + max) / 2 + rel) * blocksize()); - - Q_ASSERT(!((size_t)query & (pagesize() - 1))); - - if (isMemoryFree(query, blocksize())) { - mem = reserveMemory(query, blocksize()); - if (mem != 0 && - reinterpret_cast(mem) > minAddr && - reinterpret_cast(mem) < maxAddr) { - break; - } - } - } -#else -#error "Unsupported hardware architecture!" -#endif - if (!mem) { - std::cerr << "Error could not find memory close to: " << addr; - return 0; - } - if (!commitMemory(mem, blocksize())) { - return 0; - } - MemorySegment memSegment; - memSegment.mem = mem; - memSegment.size = blocksize(); - memSegment.free = blocksize() - size; - memoryPool.append(memSegment); - return mem; -} - -void *AbstractFunctionOverwriter::createTrampoline(void *const func, void *const replacement) -{ - void *mem = getMemoryNearAddress(func, worstSizeForLongJump); - if (!mem) { - return 0; - } - bool ret = writeLongJump(mem, replacement); - if (!ret) { - return 0; - } - return mem; -} - -AbstractFunctionOverwriter::~AbstractFunctionOverwriter() -{ -} - -bool AbstractFunctionOverwriter::overwriteFunction(const QString &orignalFunc, - void * const replacementFunc) -{ - void *func = qtCoreFunctionLookup(orignalFunc); - if (!func) { - std::cerr << "Failed to lookup: " << orignalFunc.toLatin1().data(); - return false; - } - void *mem = createTrampoline(func, replacementFunc); - if (!mem) { - return false; - } - - bool ret = writeShortJump(func, mem); - - return ret; -} - -void *AbstractFunctionOverwriter::page_align(void *addr) const -{ - Q_ASSERT(addr != 0); - return (void *)((size_t)addr & ~(pagesize() - 1)); -} - -size_t AbstractFunctionOverwriter::roundToNextPage(size_t addr) const -{ - Q_ASSERT(addr != 0); - return (size_t)page_align((void*)(addr + (pagesize() - 1))); -} - -size_t GammaRay::AbstractFunctionOverwriter::blocksize() -{ - return roundToNextPage(std::max((worstSizeForLongJump * 4), pagesize())); -} diff -Nru gammaray-1.2.2/core/hooking/abstractfunctionoverwriter.h gammaray-2.0.1/core/hooking/abstractfunctionoverwriter.h --- gammaray-1.2.2/core/hooking/abstractfunctionoverwriter.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/abstractfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,157 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_ABSTRACTFUNCTIONOVERWRITER_H -#define GAMMARAY_ABSTRACTFUNCTIONOVERWRITER_H - -#include "config-gammaray.h" - -#include -#include - -#define __STDC_LIMIT_MACROS -#if defined(HAVE_STDINT_H) -#include -#endif - -#if defined(_M_X64) || defined(__amd64) || defined(__x86_64) -#define ARCH_64 -#elif defined(_M_IX86) || defined(__i386__) -#define ARCH_X86 -#endif - -namespace GammaRay { - -class AbstractFunctionOverwriter -{ - public: - virtual ~AbstractFunctionOverwriter(); - - /** - * Overwrites a given Qt Core 4 function with a replacement function. - * @param orignalFunc original Qt Core 4 function - * @param replacementFunc replacement function - */ - bool overwriteFunction(const QString &orignalFunc, - void * const replacementFunc); - - protected: - /** - * Unprotects a memory region so that the memory can get written - * @param mem start address of the memory that should be unprotected - * @param size size of the memory region - */ - virtual bool unprotectMemory(void *mem, size_t size) = 0; - - /** - * Restore the protection of the memory region that has been - * unproteced before with unprotectMemory - * @param mem start address of the memory that should be protected - * @param size size of the memory region - */ - virtual bool reprotectMemory(void *mem, size_t size) = 0; - - /** - * Writes a short jump at a given target to jump to a function. - * NOTE: A short jump takes 5 bytes, so make sure these 5 bytes - * can be written. - * @param target position where the jump should be written to - * @param size size of the memory region - */ - virtual bool writeShortJump(void *target, void * const func); - - /** - * Writes a long jump at a given target to jump to a function. - * NOTE: A short jump takes 10 bytes for x86 and 14 bytes for x64, - * so make sure these 5 bytes can be written. - * @param target position where the jump should be written to - * @param size size of the memory region - */ - virtual bool writeLongJump(void *target, void * const func); - - /** - * Get memory close to a target address. - * @param addr position that should the memory be close to - * @param size size of the memory region - */ - virtual void *getMemoryNearAddress(void * const addr, size_t size); - - /** - * Creates a tranpoline function close to another function. - * @param func function that the tranpoline should be close to - * @param replacement function that the trampoline should point to - */ - virtual void *createTrampoline(void * const func, void * const replacement); - - /** - * Get address range in which the program resists. - * @param min min address - * @param max max address - */ - virtual bool getAddressRange(intptr_t &min, intptr_t &max) = 0; - - /** - * Check if the memory region is not already taken. - * @param mem start address - * @param size size of the memory region - */ - virtual bool isMemoryFree(void * const mem, size_t size) = 0; - - /** - * Allocate memory at the griven position - * @param mem start address - * @param size size of the memory region - */ - virtual void *reserveMemory(void *mem, size_t size) = 0; - - /** - * Commit memory at the griven position - * @param mem start address - * @param size size of the memory region - */ - virtual bool commitMemory(void *mem, size_t size) = 0; - - /** - * Lookup function address of a given Qt Core 4 function. - * @param function function name - */ - virtual void *qtCoreFunctionLookup(const QString &function) = 0; - - virtual long pagesize() const = 0; - - virtual size_t blocksize(); - - private: - void *page_align(void *addr) const; - size_t roundToNextPage(size_t addr) const; - - struct MemorySegment { - void *mem; - size_t size; - size_t free; - }; - - QList memoryPool; -}; - -} - -#endif // ABSTRACTFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/core/hooking/functionoverwriterfactory.cpp gammaray-2.0.1/core/hooking/functionoverwriterfactory.cpp --- gammaray-1.2.2/core/hooking/functionoverwriterfactory.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/functionoverwriterfactory.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "functionoverwriterfactory.h" -#include "winfunctionoverwriter.h" -#include "unixfunctionoverwriter.h" - -using namespace GammaRay; - -AbstractFunctionOverwriter *FunctionOverwriterFactory::createFunctionOverwriter() -{ - static AbstractFunctionOverwriter *overwriter = 0; - -#ifdef Q_OS_WIN - if (!overwriter) { - overwriter = new WinFunctionOverwriter(); - } -#else - if (!overwriter) { - overwriter = new UnixFunctionOverwriter(); - } -#endif - return overwriter; -} diff -Nru gammaray-1.2.2/core/hooking/functionoverwriterfactory.h gammaray-2.0.1/core/hooking/functionoverwriterfactory.h --- gammaray-1.2.2/core/hooking/functionoverwriterfactory.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/functionoverwriterfactory.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_FUNCTIONOVERWRITERFACTORY_H -#define GAMMARAY_FUNCTIONOVERWRITERFACTORY_H - -#include "abstractfunctionoverwriter.h" - -namespace GammaRay { - -class FunctionOverwriterFactory -{ - public: - static AbstractFunctionOverwriter *createFunctionOverwriter(); - - private: - FunctionOverwriterFactory() - { - } -}; - -} - -#endif // FUNCTIONOVERWRITERFACTORY_H diff -Nru gammaray-1.2.2/core/hooking/unixfunctionoverwriter.cpp gammaray-2.0.1/core/hooking/unixfunctionoverwriter.cpp --- gammaray-1.2.2/core/hooking/unixfunctionoverwriter.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/unixfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,117 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "unixfunctionoverwriter.h" - -#if !defined(Q_OS_WIN) - -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace GammaRay; - -UnixFunctionOverwriter::UnixFunctionOverwriter() -{ - m_pagesize = sysconf(_SC_PAGESIZE); -} - -bool UnixFunctionOverwriter::unprotectMemory(void *mem, size_t size) -{ - Q_ASSERT(!((size_t)mem & (pagesize() - 1))); - Q_ASSERT(!((size_t)size & (pagesize() - 1))); - const bool writable = (mprotect(mem, size, PROT_READ|PROT_WRITE|PROT_EXEC) == 0); - Q_ASSERT(writable); - return writable; -} - -bool UnixFunctionOverwriter::reprotectMemory(void *mem, size_t size) -{ - Q_ASSERT(!((size_t)mem & (pagesize() - 1))); - Q_ASSERT(!((size_t)size & (pagesize() - 1))); - const bool readOnly = (mprotect(mem, size, PROT_READ|PROT_EXEC) == 0); - Q_ASSERT(readOnly); - return readOnly; -} - -bool UnixFunctionOverwriter::getAddressRange(intptr_t &min, intptr_t &max) -{ - min = INTPTR_MIN; - max = INTPTR_MAX; - - return true; -} - -bool UnixFunctionOverwriter::isMemoryFree(void * const mem, size_t size) -{ - Q_ASSERT(!((size_t)mem & (pagesize() - 1))); - Q_ASSERT(!((size_t)size & (pagesize() - 1))); - Q_UNUSED(mem); - Q_UNUSED(size); - - //under unix there is no easy way to find out if a region is free or not - - return true; -} - -void *UnixFunctionOverwriter::reserveMemory(void *mem, size_t size) -{ - Q_ASSERT(!((size_t)mem & (pagesize() - 1))); - Q_ASSERT(!((size_t)size & (pagesize() - 1))); - - // reserve a memory region with a hint and hope that it is close to the other address - void *retmem = mmap(mem, size, PROT_READ|PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); - - if (retmem == MAP_FAILED) { - return 0; - } - - return retmem; -} - -bool UnixFunctionOverwriter::commitMemory(void *mem, size_t size) -{ - Q_ASSERT(!((size_t)mem & (pagesize() - 1))); - Q_ASSERT(!((size_t)size & (pagesize() - 1))); - Q_UNUSED(mem); - Q_UNUSED(size); - - //under unix we don't have a commit - return true; -} - -void *UnixFunctionOverwriter::qtCoreFunctionLookup(const QString &function) -{ - return dlsym(RTLD_NEXT, function.toLatin1()); -} - -long GammaRay::UnixFunctionOverwriter::pagesize() const -{ - return m_pagesize; -} - -#endif // Q_OS_WIN diff -Nru gammaray-1.2.2/core/hooking/unixfunctionoverwriter.h gammaray-2.0.1/core/hooking/unixfunctionoverwriter.h --- gammaray-1.2.2/core/hooking/unixfunctionoverwriter.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/unixfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_UNIXFUNCTIONOVERWRITER_H -#define GAMMARAY_UNIXFUNCTIONOVERWRITER_H - -#include - -#if !defined(Q_OS_WIN) - -#include "abstractfunctionoverwriter.h" - -namespace GammaRay { - -class UnixFunctionOverwriter : public AbstractFunctionOverwriter -{ - protected: - virtual bool unprotectMemory(void *mem, size_t size); - virtual bool reprotectMemory(void *mem, size_t size); - - virtual bool getAddressRange(intptr_t &min, intptr_t &max); - - virtual bool isMemoryFree(void * const mem, size_t size); - virtual void *reserveMemory(void *mem, size_t size); - virtual bool commitMemory(void *mem, size_t size); - - virtual void *qtCoreFunctionLookup(const QString &function); - virtual long pagesize() const; - - private: - UnixFunctionOverwriter(); - - long m_pagesize; - - friend class FunctionOverwriterFactory; -}; - -} - -#endif // !Q_OS_WIN - -#endif // UNIXFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/core/hooking/winfunctionoverwriter.cpp gammaray-2.0.1/core/hooking/winfunctionoverwriter.cpp --- gammaray-1.2.2/core/hooking/winfunctionoverwriter.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/winfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,114 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -//krazy:excludeall=null since the WinAPI likes to use NULL - -#include "winfunctionoverwriter.h" - -#ifdef Q_OS_WIN - -#include - -using namespace std; -using namespace GammaRay; - -WinFunctionOverwriter::WinFunctionOverwriter():oldProtect(0) -{ -} - -bool WinFunctionOverwriter::unprotectMemory(void *mem, size_t size) -{ - BOOL ret = VirtualProtect(mem, size, PAGE_EXECUTE_READWRITE, &oldProtect); - return ret; -} - -bool WinFunctionOverwriter::reprotectMemory(void *mem, size_t size) -{ - BOOL ret = VirtualProtect(mem, size, oldProtect, &oldProtect); - return ret; -} - -bool WinFunctionOverwriter::getAddressRange(intptr_t &min, intptr_t &max) -{ - SYSTEM_INFO si; - GetSystemInfo(&si); - - min = reinterpret_cast(si.lpMinimumApplicationAddress); - max = reinterpret_cast(si.lpMaximumApplicationAddress); - - return true; -} - -bool WinFunctionOverwriter::isMemoryFree(void * const mem, size_t size) -{ - Q_UNUSED(size); - static MEMORY_BASIC_INFORMATION mi = { 0 }; - - VirtualQuery(mem, &mi, sizeof(mi)); - if (mi.State != MEM_FREE) { - return false; - } - - return true; -} - -void *WinFunctionOverwriter::reserveMemory(void *mem, size_t size) -{ - void *retmem = 0; - - retmem = VirtualAlloc(mem, size, MEM_RESERVE, PAGE_EXECUTE_READ); - - return retmem; -} - -bool WinFunctionOverwriter::commitMemory(void *mem, size_t size) -{ - void *retmem = 0; - - retmem = VirtualAlloc(mem, size, MEM_COMMIT, PAGE_EXECUTE_READ); - - return retmem != 0; -} - -void *WinFunctionOverwriter::qtCoreFunctionLookup(const QString &function) -{ - static HMODULE qtCoreDllHandle = GetModuleHandle(L"QtCore4"); - if (qtCoreDllHandle == NULL) { - qtCoreDllHandle = GetModuleHandle(L"QtCored4"); - } - - if (qtCoreDllHandle == NULL) { - cerr << "no handle for QtCore found!" << endl; - return 0; - } - - FARPROC qtfuncaddr = GetProcAddress(qtCoreDllHandle, function.toLatin1()); - - return (void*)qtfuncaddr; -} - -long WinFunctionOverwriter::pagesize() const -{ - SYSTEM_INFO si; - GetSystemInfo(&si); - return si.dwPageSize; -} - -#endif // Q_OS_WIN diff -Nru gammaray-1.2.2/core/hooking/winfunctionoverwriter.h gammaray-2.0.1/core/hooking/winfunctionoverwriter.h --- gammaray-1.2.2/core/hooking/winfunctionoverwriter.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/hooking/winfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Andreas Holzammer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WINFUNCTIONOVERWRITER_H -#define GAMMARAY_WINFUNCTIONOVERWRITER_H - -#include - -#ifdef Q_OS_WIN - -#include "abstractfunctionoverwriter.h" -#include - -namespace GammaRay { - -class WinFunctionOverwriter : public AbstractFunctionOverwriter -{ - protected: - virtual bool unprotectMemory(void *mem, size_t size); - virtual bool reprotectMemory(void *mem, size_t size); - - virtual bool getAddressRange(intptr_t &min, intptr_t &max); - - virtual bool isMemoryFree(void * const mem, size_t size); - virtual void *reserveMemory(void *mem, size_t size); - virtual bool commitMemory(void *mem, size_t size); - - virtual void *qtCoreFunctionLookup(const QString &function); - virtual long pagesize() const; - - private: - WinFunctionOverwriter(); - DWORD oldProtect; - - friend class FunctionOverwriterFactory; -}; - -} - -#endif // Q_OS_WIN - -#endif // WINFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/core/mainwindow.cpp gammaray-2.0.1/core/mainwindow.cpp --- gammaray-1.2.2/core/mainwindow.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/mainwindow.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,225 +0,0 @@ -/* - mainwindow.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "config-gammaray-version.h" -#include "mainwindow.h" -#include "aboutpluginsdialog.h" -#include "objectlistmodel.h" -#include "objecttreemodel.h" -#include "probe.h" -#include "toolmodel.h" - -#include "include/objecttypefilterproxymodel.h" -#include "include/toolfactory.h" - -#include "kde/krecursivefilterproxymodel.h" - -#include //krazy:exclude=camelcase - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace GammaRay; - -static const char progName[] = PROGRAM_NAME; -static const char progVersion[] = GAMMARAY_VERSION_STRING; -static const char progDesc[] = "The Qt application inspection and manipulation tool"; -static const char progURL[] = "http://www.kdab.com/gammaray"; - -MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) -{ - // we don't want application styles to propagate to the GammaRay window, - // so set the platform default one. - // unfortunately, that's not recursive by default, unless we have a style sheet set - setStyleSheet(QLatin1String("I_DONT_EXIST {}")); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QGuiPlatformPlugin defaultGuiPlatform; - if (QStyle *defaultStyle = QStyleFactory::create(defaultGuiPlatform.styleName())) { - // do not set parent of default style - // this will cause the style being deleted too early through ~QObject() - // other objects (e.g. the script engine debugger) still might have a - // reference on the style during destruction - setStyle(defaultStyle); - } -#endif - - ui.setupUi(this); - - connect(ui.actionRetractProbe, SIGNAL(triggered(bool)), SLOT(close())); - - connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(close())); - connect(ui.actionQuit, SIGNAL(triggered(bool)), - QApplication::instance(), SLOT(quit())); - ui.actionQuit->setIcon(QIcon::fromTheme("application-exit")); - - connect(ui.actionPlugins, SIGNAL(triggered(bool)), - this, SLOT(aboutPlugins())); - connect(ui.actionAboutQt, SIGNAL(triggered(bool)), - QApplication::instance(), SLOT(aboutQt())); - connect(ui.actionAboutGammaRay, SIGNAL(triggered(bool)), SLOT(about())); - connect(ui.actionAboutKDAB, SIGNAL(triggered(bool)), SLOT(aboutKDAB())); - - setWindowIcon(QIcon(":gammaray/GammaRay-128x128.png")); - - ToolModel *model = Probe::instance()->toolModel(); - QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this); - proxyModel->setDynamicSortFilter(true); - proxyModel->setSourceModel(model); - proxyModel->sort(0); - ui.toolSelector->setModel(proxyModel); - ui.toolSelector->resize(ui.toolSelector->minimumSize()); - connect(ui.toolSelector->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(toolSelected())); - - // hide unused tool bar for now - ui.mainToolBar->setHidden(true); - - QString appName = qApp->applicationName(); - if (appName.isEmpty() && !qApp->arguments().isEmpty()) { - appName = qApp->arguments().first().remove(qApp->applicationDirPath()); - if (appName.startsWith('.')) { - appName = appName.right(appName.length() - 1); - } - if (appName.startsWith('/')) { - appName = appName.right(appName.length() - 1); - } - } else { - appName = tr("PID %1").arg(qApp->applicationPid()); - } - setWindowTitle(tr("%1 (%2)").arg(progName).arg(appName)); - - selectInitialTool(); - - // get some sane size on startup - resize(1024, 768); -} - -void MainWindow::about() -{ - QMessageBox mb(this); - mb.setWindowTitle(tr("About %1").arg(progName)); - mb.setText(tr("%1 %2

%3").arg(progName).arg(progVersion).arg(progDesc)); - mb.setInformativeText( - trUtf8("" - "

Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, " - "a KDAB Group company, info@kdab.com

" - "

Authors:
" - "Allen Winter <allen.winter@kdab.com>
" - "Andreas Holzammer <andreas.holzammer@kdab.com>
" - "David Faure <david.faure@kdab.com>
" - "Kevin Funk <kevin.funk@kdab.com>
" - "Milian Wolff <milian.wolff@kdab.com>
" - "Patrick Spendrin <patrick.spendrin@kdab.com>
" - "Stephen Kelly <stephen.kelly@kdab.com>
" - "Till Adam <till@kdab.com>
" - "Thomas McGuire <thomas.mcguire@kdab.com>
" - "Tobias Koenig <tobias.koenig@kdab.com>
" - "Volker Krause <volker.krause@kdab.com>

" - "

StackWalker code Copyright (c) 2005-2009, Jochen Kalmbach, All rights reserved

" - "
")); - mb.setIconPixmap(QPixmap(":gammaray/GammaRay-128x128.png")); - mb.addButton(QMessageBox::Close); - mb.exec(); -} - -void MainWindow::aboutPlugins() -{ - AboutPluginsDialog dlg(this); - dlg.setFixedSize(800, 600); - dlg.exec(); -} - -void MainWindow::aboutKDAB() -{ - QMessageBox mb(this); - mb.setWindowTitle(tr("About KDAB")); - mb.setText(trUtf8("Klarälvdalens Datakonsult AB (KDAB)")); - mb.setInformativeText( - tr("

%1 is supported and maintained by KDAB

" - "KDAB, the Qt experts, provide consulting and mentoring for developing " - "Qt applications from scratch and in porting from all popular and legacy " - "frameworks to Qt. Our software products increase Qt productivity and our " - "Qt trainers have trained 50% of commercial Qt developers globally.

" - "

Please visit http://www.kdab.com " - "to meet the people who write code like this. " - "We also offer Qt training courses." - "

").arg(progName)); - mb.setIconPixmap(QPixmap(":gammaray/kdablogo160.png")); - mb.addButton(QMessageBox::Close); - mb.exec(); -} - -void MainWindow::selectInitialTool() -{ - static const QString initialTool("GammaRay::ObjectInspector"); - - QAbstractItemModel *model = ui.toolSelector->model(); - QModelIndexList matches = - model->match(model->index(0, 0), ToolModel::ToolIdRole, initialTool); - if (matches.isEmpty()) { - return; - } - - ui.toolSelector->setCurrentIndex(matches.first()); - toolSelected(); -} - -void MainWindow::toolSelected() -{ - ui.actionsMenu->clear(); - const int row = ui.toolSelector->currentIndex().row(); - if (row == -1) { - return; - } - - const QModelIndex mi = ui.toolSelector->model()->index(row, 0); - QWidget *toolWidget = mi.data(ToolModel::ToolWidgetRole).value(); - if (!toolWidget) { - ToolFactory *toolIface = mi.data(ToolModel::ToolFactoryRole).value(); - Q_ASSERT(toolIface); -// qDebug() << Q_FUNC_INFO << "creating new probe: " -// << toolIface->name() << toolIface->supportedTypes(); - toolWidget = toolIface->createWidget(Probe::instance(), this); - if (toolWidget->layout()) { - toolWidget->layout()->setContentsMargins(11, 0, 0, 0); - } - ui.toolStack->addWidget(toolWidget); - ui.toolSelector->model()->setData(mi, QVariant::fromValue(toolWidget)); - } - ui.toolStack->setCurrentIndex(ui.toolStack->indexOf(toolWidget)); - - foreach (QAction *action, toolWidget->actions()) { - ui.actionsMenu->addAction(action); - } - ui.actionsMenu->setEnabled(!ui.actionsMenu->isEmpty()); -} - -#include "mainwindow.moc" diff -Nru gammaray-1.2.2/core/mainwindow.h gammaray-2.0.1/core/mainwindow.h --- gammaray-1.2.2/core/mainwindow.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/mainwindow.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - mainwindow.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_MAINWINDOW_H -#define GAMMARAY_MAINWINDOW_H - -#include "ui_mainwindow.h" - -#include - -namespace GammaRay { - -class MainWindow : public QMainWindow -{ - Q_OBJECT - public: - explicit MainWindow(QWidget *parent = 0); - - private slots: - void about(); - void aboutPlugins(); - void aboutKDAB(); - - void toolSelected(); - - private: - void selectInitialTool(); - - Ui::MainWindow ui; -}; - -} - -#endif // MAINWINDOW_H diff -Nru gammaray-1.2.2/core/mainwindow.ui gammaray-2.0.1/core/mainwindow.ui --- gammaray-1.2.2/core/mainwindow.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/mainwindow.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,203 +0,0 @@ - - - GammaRay::MainWindow - - - - 0 - 0 - 829 - 600 - - - - - - 0 - - - - - - - - - 0 - - - - - - 0 - 0 - - - - - 180 - 0 - - - - background-image: url(:/gammaray/kdab-gammary-logo.png); -background-repeat: no-repeat; -background-attachment:fixed; -background-position:bottom right; - - - - QFrame::NoFrame - - - QFrame::Plain - - - Qt::ElideRight - - - QListView::TopToBottom - - - false - - - QListView::Fixed - - - QListView::ListMode - - - true - - - false - - - true - - - - - - - - - - - 0 - 0 - - - - - - - - - - 0 - 0 - 829 - 21 - - - - - &GammaRay - - - - - - - - &Help - - - - - - - - - - &Actions - - - - - - - - - Main Toolbar - - - false - - - Qt::BottomToolBarArea|Qt::TopToolBarArea - - - false - - - TopToolBarArea - - - false - - - - - &Detach - - - Retract probe from application. - - - - - &Quit - - - Quit probed application. - - - - - - :/gammaray/GammaRay-32x32.png:/gammaray/GammaRay-32x32.png - - - About &GammaRay - - - - - About &Qt - - - - - About &KDAB - - - - - Plugins... - - - - - - SidePane - QListView -
sidepane.h
-
-
- - - - -
diff -Nru gammaray-1.2.2/core/metaobject.cpp gammaray-2.0.1/core/metaobject.cpp --- gammaray-1.2.2/core/metaobject.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaobject.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/metaobject.h gammaray-2.0.1/core/metaobject.h --- gammaray-1.2.2/core/metaobject.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaobject.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,14 +24,16 @@ #ifndef GAMMARAY_METAOBJECT_H #define GAMMARAY_METAOBJECT_H +#include "gammaray_core_export.h" + #include "metaproperty.h" #include namespace GammaRay { -/** Compile-time introspection adaptor for non-QObject classes. */ -class MetaObject +/** @brief Compile-time introspection adaptor for non-QObject classes. */ +class GAMMARAY_CORE_EXPORT MetaObject { public: MetaObject(); @@ -62,6 +64,8 @@ */ void *castForPropertyAt(void *object, int index) const; + void setClassName(const QString &className); + protected: /** Casts down to base class @p baseClassIndex. * This is important when traversing multi-inheritance trees. @@ -72,15 +76,11 @@ QVector m_baseClasses; private: - friend class MetaObjectRepository; - void setClassName(const QString &className); - - private: QVector m_properties; QString m_className; }; -/** Template implementation of MetaObject. */ +/** @brief Template implementation of MetaObject. */ template class MetaObjectImpl : public MetaObject { diff -Nru gammaray-1.2.2/core/metaobjectmodel.h gammaray-2.0.1/core/metaobjectmodel.h --- gammaray-1.2.2/core/metaobjectmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaobjectmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -26,7 +26,6 @@ #include #include -#include namespace GammaRay { @@ -37,24 +36,27 @@ class MetaObjectModel : public QAbstractItemModel { public: - explicit MetaObjectModel(QObject *parent = 0) : QAbstractItemModel(parent) {} + explicit MetaObjectModel(QObject *parent = 0) + : QAbstractItemModel(parent), m_metaObject(0) + { + } - virtual void setObject(QObject *object) + virtual void setMetaObject(const QMetaObject *metaObject) { - m_object = object; + m_metaObject = metaObject; reset(); } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { - if (!index.isValid() || !m_object || + if (!index.isValid() || !m_metaObject || index.row() < 0 || index.row() >= rowCount(index.parent())) { return QVariant(); } - const MetaThing metaThing = (m_object.data()->metaObject()->*MetaAccessor)(index.row()); + const MetaThing metaThing = (m_metaObject->*MetaAccessor)(index.row()); if (index.column() == columnCount(index) - 1 && role == Qt::DisplayRole) { - const QMetaObject *mo = m_object.data()->metaObject(); + const QMetaObject *mo = m_metaObject; while ((mo->*MetaOffset)() > index.row()) { mo = mo->superClass(); } @@ -76,10 +78,10 @@ int rowCount(const QModelIndex &parent = QModelIndex()) const { - if (!m_object || parent.isValid()) { + if (!m_metaObject || parent.isValid()) { return 0; } - return (m_object.data()->metaObject()->*MetaCount)(); + return (m_metaObject->*MetaCount)(); } QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const @@ -103,8 +105,11 @@ virtual QString columnHeader(int index) const = 0; + typedef MetaObjectModel super; + protected: - QPointer m_object; + // let's assume that meta objects never get destroyed + const QMetaObject *m_metaObject; }; } diff -Nru gammaray-1.2.2/core/metaobjectrepository.cpp gammaray-2.0.1/core/metaobjectrepository.cpp --- gammaray-1.2.2/core/metaobjectrepository.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaobjectrepository.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,58 +24,28 @@ #include "metaobjectrepository.h" #include "metaobject.h" -#include "include/metatypedeclarations.h" +#include -#include -#include -#include -#include +#include +#include +#include #include #include #include -#include -#include +#include +#include -#define MO_ADD_BASECLASS(Base) \ - Q_ASSERT( hasMetaObject( QLatin1String( #Base ) ) ); \ - mo->addBaseClass( metaObject( QLatin1String( #Base ) ) ); - -#define MO_ADD_METAOBJECT0(Class) \ - mo = new MetaObjectImpl; \ - mo->setClassName( QLatin1String( #Class ) ); \ - addMetaObject(mo); - -#define MO_ADD_METAOBJECT1(Class, Base1) \ - mo = new MetaObjectImpl; \ - mo->setClassName( QLatin1String( #Class ) ); \ - MO_ADD_BASECLASS( Base1 ) \ - addMetaObject(mo); - -#define MO_ADD_METAOBJECT2(Class, Base1, Base2) \ - mo = new MetaObjectImpl; \ - mo->setClassName( QLatin1String( #Class ) ); \ - MO_ADD_BASECLASS( Base1 ) \ - MO_ADD_BASECLASS( Base2 ) \ - addMetaObject(mo); - -#define MO_ADD_PROPERTY(Class, Type, Getter, Setter) \ - mo->addProperty( new MetaPropertyImpl( \ - QLatin1String( #Getter ), \ - &Class::Getter, \ - static_cast(&Class::Setter) ) \ - ); - -#define MO_ADD_PROPERTY_CR(Class, Type, Getter, Setter) \ - mo->addProperty( new MetaPropertyImpl( \ - QLatin1String( #Getter ), \ - &Class::Getter, \ - static_cast(&Class::Setter) ) \ - ); - -#define MO_ADD_PROPERTY_RO(Class, Type, Getter) \ - mo->addProperty( new MetaPropertyImpl( \ - QLatin1String( #Getter ), \ - &Class::Getter ) ); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include +#include +#include +#include +#include +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) +#include +#endif using namespace GammaRay; @@ -84,16 +54,17 @@ class StaticMetaObjectRepository : public MetaObjectRepository { public: - StaticMetaObjectRepository() : MetaObjectRepository() {} + StaticMetaObjectRepository() : MetaObjectRepository() + { + } }; } Q_GLOBAL_STATIC(StaticMetaObjectRepository, s_instance) -MetaObjectRepository::MetaObjectRepository() +MetaObjectRepository::MetaObjectRepository() : m_initialized(false) { - initBuiltInTypes(); } MetaObjectRepository::~MetaObjectRepository() @@ -103,146 +74,220 @@ void MetaObjectRepository::initBuiltInTypes() { + m_initialized = true; initQObjectTypes(); - initGraphicsViewTypes(); + initIOTypes(); + initNetworkTypes(); + initGuiTypes(); + initOpenGLTypes(); } void MetaObjectRepository::initQObjectTypes() { MetaObject *mo = 0; MO_ADD_METAOBJECT0(QObject); + MO_ADD_PROPERTY_RO(QObject, QObject*, parent); MO_ADD_PROPERTY_RO(QObject, bool, signalsBlocked); // TODO setter has non-void return type MO_ADD_METAOBJECT0(QPaintDevice); - MO_ADD_PROPERTY_RO(QPaintDevice, int, colorCount); - MO_ADD_PROPERTY_RO(QPaintDevice, int, heightMM); - MO_ADD_PROPERTY_RO(QPaintDevice, int, logicalDpiX); - MO_ADD_PROPERTY_RO(QPaintDevice, int, logicalDpiY); + MO_ADD_PROPERTY_RO(QPaintDevice, int, colorCount); + MO_ADD_PROPERTY_RO(QPaintDevice, int, heightMM); + MO_ADD_PROPERTY_RO(QPaintDevice, int, logicalDpiX); + MO_ADD_PROPERTY_RO(QPaintDevice, int, logicalDpiY); MO_ADD_PROPERTY_RO(QPaintDevice, bool, paintingActive); - MO_ADD_PROPERTY_RO(QPaintDevice, int, physicalDpiX); - MO_ADD_PROPERTY_RO(QPaintDevice, int, physicalDpiY); - MO_ADD_PROPERTY_RO(QPaintDevice, int, widthMM); - - MO_ADD_METAOBJECT2(QWidget, QObject, QPaintDevice); - MO_ADD_PROPERTY_RO(QWidget, QWidget*, focusProxy); - - MO_ADD_METAOBJECT1(QStyle, QObject); - MO_ADD_PROPERTY_RO(QStyle, const QStyle*, proxy); - MO_ADD_PROPERTY_RO(QStyle, QPalette, standardPalette); -} - -void MetaObjectRepository::initGraphicsViewTypes() -{ - MetaObject *mo = 0; //createMetaObject( "QGraphicsItem" ); - MO_ADD_METAOBJECT0(QGraphicsItem); - MO_ADD_PROPERTY (QGraphicsItem, bool, acceptDrops, setAcceptDrops); - MO_ADD_PROPERTY (QGraphicsItem, bool, acceptHoverEvents, setAcceptHoverEvents); - MO_ADD_PROPERTY (QGraphicsItem, bool, acceptTouchEvents, setAcceptTouchEvents); - MO_ADD_PROPERTY (QGraphicsItem, Qt::MouseButtons, acceptedMouseButtons, setAcceptedMouseButtons); - MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, boundingRect); - MO_ADD_PROPERTY (QGraphicsItem, qreal, boundingRegionGranularity, setBoundingRegionGranularity); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem::CacheMode, cacheMode); - MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, childrenBoundingRect); - MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, clipPath); - MO_ADD_PROPERTY_CR(QGraphicsItem, QCursor, cursor, setCursor); - MO_ADD_PROPERTY_RO(QGraphicsItem, qreal, effectiveOpacity); - MO_ADD_PROPERTY (QGraphicsItem, bool, filtersChildEvents, setFiltersChildEvents); - MO_ADD_PROPERTY (QGraphicsItem, QGraphicsItem::GraphicsItemFlags, flags, setFlags); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, focusItem); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, focusProxy); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsEffect*, graphicsEffect); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItemGroup*, group); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, hasCursor); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, hasFocus); - MO_ADD_PROPERTY (QGraphicsItem, Qt::InputMethodHints, inputMethodHints, setInputMethodHints); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isActive); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isClipped); - MO_ADD_PROPERTY (QGraphicsItem, bool, isEnabled, setEnabled); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isObscured); -#endif - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isPanel); - MO_ADD_PROPERTY (QGraphicsItem, bool, isSelected, setSelected); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isUnderMouse); - MO_ADD_PROPERTY (QGraphicsItem, bool, isVisible, setVisible); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isWidget); - MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isWindow); - MO_ADD_PROPERTY (QGraphicsItem, qreal, opacity, setOpacity); - MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, opaqueArea); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, panel); - MO_ADD_PROPERTY (QGraphicsItem, QGraphicsItem::PanelModality, panelModality, setPanelModality); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, parentItem); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsObject*, parentObject); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, parentWidget); - MO_ADD_PROPERTY_CR(QGraphicsItem, QPointF, pos, setPos); - MO_ADD_PROPERTY (QGraphicsItem, qreal, rotation, setRotation); - MO_ADD_PROPERTY (QGraphicsItem, qreal, scale, setScale); - MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, sceneBoundingRect); - MO_ADD_PROPERTY_RO(QGraphicsItem, QPointF, scenePos); - MO_ADD_PROPERTY_RO(QGraphicsItem, QTransform, sceneTransform); - MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, shape); - MO_ADD_PROPERTY_CR(QGraphicsItem, QString, toolTip, setToolTip); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, topLevelItem); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, topLevelWidget); - MO_ADD_PROPERTY_RO(QGraphicsItem, QTransform, transform/*, setTransform*/); // TODO: support setTransform - MO_ADD_PROPERTY_CR(QGraphicsItem, QPointF, transformOriginPoint, setTransformOriginPoint); - MO_ADD_PROPERTY_RO(QGraphicsItem, int, type); - MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, window); - MO_ADD_PROPERTY (QGraphicsItem, qreal, x, setX); - MO_ADD_PROPERTY (QGraphicsItem, qreal, y, setY); - MO_ADD_PROPERTY (QGraphicsItem, qreal, zValue, setZValue); - - MO_ADD_METAOBJECT1(QAbstractGraphicsShapeItem, QGraphicsItem); - MO_ADD_PROPERTY_CR(QAbstractGraphicsShapeItem, QBrush, brush, setBrush); - MO_ADD_PROPERTY_CR(QAbstractGraphicsShapeItem, QPen, pen, setPen); - - MO_ADD_METAOBJECT1(QGraphicsEllipseItem, QAbstractGraphicsShapeItem); - MO_ADD_PROPERTY_CR(QGraphicsEllipseItem, QRectF, rect, setRect); - MO_ADD_PROPERTY (QGraphicsEllipseItem, int, spanAngle, setSpanAngle); - MO_ADD_PROPERTY (QGraphicsEllipseItem, int, startAngle, setStartAngle); - - MO_ADD_METAOBJECT1(QGraphicsPathItem, QAbstractGraphicsShapeItem); - MO_ADD_PROPERTY_CR(QGraphicsPathItem, QPainterPath, path, setPath); - - MO_ADD_METAOBJECT1(QGraphicsPolygonItem, QAbstractGraphicsShapeItem); - MO_ADD_PROPERTY (QGraphicsPolygonItem, Qt::FillRule, fillRule, setFillRule); - MO_ADD_PROPERTY_CR(QGraphicsPolygonItem, QPolygonF, polygon, setPolygon); - - MO_ADD_METAOBJECT1(QGraphicsSimpleTextItem, QAbstractGraphicsShapeItem); - MO_ADD_PROPERTY_CR(QGraphicsSimpleTextItem, QFont, font, setFont); - MO_ADD_PROPERTY_CR(QGraphicsSimpleTextItem, QString, text, setText); - - MO_ADD_METAOBJECT1(QGraphicsRectItem, QAbstractGraphicsShapeItem); - MO_ADD_PROPERTY_CR(QGraphicsRectItem, QRectF, rect, setRect); - - MO_ADD_METAOBJECT1(QGraphicsLineItem, QGraphicsItem); - MO_ADD_PROPERTY_CR(QGraphicsLineItem, QLineF, line, setLine); - MO_ADD_PROPERTY_CR(QGraphicsLineItem, QPen, pen, setPen); - - MO_ADD_METAOBJECT1(QGraphicsPixmapItem, QGraphicsItem); - MO_ADD_PROPERTY_CR(QGraphicsPixmapItem, QPointF, offset, setOffset); - MO_ADD_PROPERTY_CR(QGraphicsPixmapItem, QPixmap, pixmap, setPixmap); - MO_ADD_PROPERTY (QGraphicsPixmapItem, QGraphicsPixmapItem::ShapeMode, shapeMode, setShapeMode); - MO_ADD_PROPERTY (QGraphicsPixmapItem, Qt::TransformationMode, transformationMode, setTransformationMode); - - // no extra properties, but we need the inheritance connection for anything above to work - MO_ADD_METAOBJECT2(QGraphicsObject, QGraphicsItem, QObject); - - MO_ADD_METAOBJECT0(QGraphicsLayoutItem); - MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, QRectF, contentsRect); - MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, bool, isLayout); - MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, bool, ownedByLayout); - - MO_ADD_METAOBJECT2(QGraphicsWidget, QGraphicsObject, QGraphicsLayoutItem); - MO_ADD_PROPERTY_RO(QGraphicsWidget, QRectF, windowFrameGeometry); - MO_ADD_PROPERTY_RO(QGraphicsWidget, QRectF, windowFrameRect); + MO_ADD_PROPERTY_RO(QPaintDevice, int, physicalDpiX); + MO_ADD_PROPERTY_RO(QPaintDevice, int, physicalDpiY); + MO_ADD_PROPERTY_RO(QPaintDevice, int, widthMM); +} + + +Q_DECLARE_METATYPE(QAbstractSocket::SocketType) +Q_DECLARE_METATYPE(QHostAddress) +Q_DECLARE_METATYPE(QIODevice::OpenMode) +Q_DECLARE_METATYPE(QSocketNotifier::Type) + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +Q_DECLARE_METATYPE(QAbstractSocket::PauseModes) +Q_DECLARE_METATYPE(QFileDevice::FileError) +Q_DECLARE_METATYPE(QFileDevice::Permissions) +#else // !Qt5 +Q_DECLARE_METATYPE(QAbstractSocket::SocketError) +Q_DECLARE_METATYPE(QAbstractSocket::SocketState) +#ifndef QT_NO_NETWORKPROXY +Q_DECLARE_METATYPE(QNetworkProxy) +#endif +#endif + +void MetaObjectRepository::initIOTypes() +{ + MetaObject *mo = 0; + MO_ADD_METAOBJECT1(QIODevice, QObject); + MO_ADD_PROPERTY_RO(QIODevice, QIODevice::OpenMode, openMode); + MO_ADD_PROPERTY (QIODevice, bool, isTextModeEnabled, setTextModeEnabled); + MO_ADD_PROPERTY_RO(QIODevice, bool, isOpen); + MO_ADD_PROPERTY_RO(QIODevice, bool, isReadable); + MO_ADD_PROPERTY_RO(QIODevice, bool, isWritable); + MO_ADD_PROPERTY_RO(QIODevice, bool, isSequential); + MO_ADD_PROPERTY_RO(QIODevice, qint64, pos); + MO_ADD_PROPERTY_RO(QIODevice, qint64, size); + MO_ADD_PROPERTY_RO(QIODevice, bool, atEnd); + MO_ADD_PROPERTY_RO(QIODevice, qint64, bytesAvailable); + MO_ADD_PROPERTY_RO(QIODevice, qint64, bytesToWrite); + MO_ADD_PROPERTY_RO(QIODevice, bool, canReadLine); + MO_ADD_PROPERTY_RO(QIODevice, QString, errorString); + + // FIXME: QIODevice::readAll() would be nice to have + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MO_ADD_METAOBJECT1(QFileDevice, QIODevice); + MO_ADD_PROPERTY_RO(QFileDevice, QFileDevice::FileError, error); + MO_ADD_PROPERTY_RO(QFileDevice, QString, fileName); + MO_ADD_PROPERTY_RO(QFileDevice, int, handle); + MO_ADD_PROPERTY_RO(QFileDevice, QFileDevice::Permissions, permissions); + + MO_ADD_METAOBJECT1(QFile, QFileDevice); + MO_ADD_PROPERTY_RO(QFile, bool, exists); + MO_ADD_PROPERTY_RO(QFile, QString, symLinkTarget); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + MO_ADD_METAOBJECT1(QSaveFile, QFileDevice); +#endif +#endif +} + + +void MetaObjectRepository::initNetworkTypes() +{ + MetaObject *mo = 0; + MO_ADD_METAOBJECT1(QAbstractSocket, QIODevice); + MO_ADD_PROPERTY_RO(QAbstractSocket, bool, isValid); + MO_ADD_PROPERTY_RO(QAbstractSocket, quint16, localPort); + MO_ADD_PROPERTY_RO(QAbstractSocket, QHostAddress, localAddress); + MO_ADD_PROPERTY_RO(QAbstractSocket, quint16, peerPort); + MO_ADD_PROPERTY_RO(QAbstractSocket, QHostAddress, peerAddress); + MO_ADD_PROPERTY_RO(QAbstractSocket, QString, peerName); + MO_ADD_PROPERTY (QAbstractSocket, qint64, readBufferSize, setReadBufferSize); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MO_ADD_PROPERTY (QAbstractSocket, QAbstractSocket::PauseModes, pauseMode, setPauseMode); + MO_ADD_PROPERTY_RO(QAbstractSocket, qintptr, socketDescriptor); +#else // !Qt5 + MO_ADD_PROPERTY_RO(QAbstractSocket, int, socketDescriptor); +#endif + MO_ADD_PROPERTY_RO(QAbstractSocket, QAbstractSocket::SocketType, socketType); + MO_ADD_PROPERTY_RO(QAbstractSocket, QAbstractSocket::SocketState, state); + MO_ADD_PROPERTY_RO(QAbstractSocket, QAbstractSocket::SocketError, error); +#ifndef QT_NO_NETWORKPROXY + MO_ADD_PROPERTY_RO(QAbstractSocket, QNetworkProxy, proxy); +#endif - MO_ADD_METAOBJECT1(QGraphicsProxyWidget, QGraphicsWidget); - MO_ADD_PROPERTY_RO(QGraphicsProxyWidget, QWidget*, widget); + // FIXME: QAbstractSocket::setSocketOption() would be nice to have + // FIXME: QQAbstractSocket::socketOption() would be nice to have + + MO_ADD_METAOBJECT1(QTcpServer, QObject); + MO_ADD_PROPERTY_RO(QTcpServer, bool, isListening); + MO_ADD_PROPERTY (QTcpServer, int, maxPendingConnections, setMaxPendingConnections); + MO_ADD_PROPERTY_RO(QTcpServer, quint16, serverPort); + MO_ADD_PROPERTY_RO(QTcpServer, QHostAddress, serverAddress); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MO_ADD_PROPERTY_RO(QTcpServer, qintptr, socketDescriptor); +#else // !QT5 + MO_ADD_PROPERTY_RO(QTcpServer, int, socketDescriptor); +#endif + MO_ADD_PROPERTY_RO(QTcpServer, bool, hasPendingConnections); + MO_ADD_PROPERTY_RO(QTcpServer, QAbstractSocket::SocketError, serverError); + MO_ADD_PROPERTY_RO(QTcpServer, QString, errorString); +#ifndef QT_NO_NETWORKPROXY + MO_ADD_PROPERTY_RO(QTcpServer, QNetworkProxy, proxy); +#endif + + MO_ADD_METAOBJECT1(QSocketNotifier, QObject); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MO_ADD_PROPERTY_RO(QSocketNotifier, qintptr, socket); +#else // !Qt5 + MO_ADD_PROPERTY_RO(QSocketNotifier, int, socket); +#endif + MO_ADD_PROPERTY_RO(QSocketNotifier, QSocketNotifier::Type, type); + MO_ADD_PROPERTY (QSocketNotifier, bool, isEnabled, setEnabled); +} + +void MetaObjectRepository::initGuiTypes() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MetaObject *mo = 0; + MO_ADD_METAOBJECT0(QSurface); + MO_ADD_PROPERTY_RO(QSurface, QSurfaceFormat, format); + MO_ADD_PROPERTY_RO(QSurface, QSize, size); + MO_ADD_PROPERTY_RO(QSurface, QSurface::SurfaceClass, surfaceClass); + MO_ADD_PROPERTY_RO(QSurface, QSurface::SurfaceType, surfaceType); + + MO_ADD_METAOBJECT2(QWindow, QObject, QSurface); + MO_ADD_PROPERTY_CR(QWindow, QSize, baseSize, setBaseSize); +#ifndef QT_NO_CURSOR + MO_ADD_PROPERTY_CR(QWindow, QCursor, cursor, setCursor); +#endif + MO_ADD_PROPERTY_RO(QWindow, qreal, devicePixelRatio); + MO_ADD_PROPERTY_CR(QWindow, QString, filePath, setFilePath); + MO_ADD_PROPERTY_RO(QWindow, QObject*, focusObject); + MO_ADD_PROPERTY_RO(QWindow, QRect, frameGeometry); + MO_ADD_PROPERTY_RO(QWindow, QMargins, frameMargins); + MO_ADD_PROPERTY_CR(QWindow, QPoint, framePosition, setFramePosition); + MO_ADD_PROPERTY_CR(QWindow, QRect, geometry, setGeometry); + MO_ADD_PROPERTY_CR(QWindow, QIcon, icon, setIcon); + MO_ADD_PROPERTY_RO(QWindow, bool, isExposed); + MO_ADD_PROPERTY_RO(QWindow, bool, isTopLevel); +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + MO_ADD_PROPERTY_CR(QWindow, QRegion, mask, setMask); +#endif + MO_ADD_PROPERTY_CR(QWindow, QPoint, position, setPosition); + MO_ADD_PROPERTY_RO(QWindow, QSurfaceFormat, requestedFormat); + MO_ADD_PROPERTY_RO(QWindow, QScreen*, screen); + MO_ADD_PROPERTY_CR(QWindow, QSize, sizeIncrement, setSizeIncrement); + MO_ADD_PROPERTY (QWindow, Qt::WindowState, windowState, setWindowState); + MO_ADD_PROPERTY_RO(QWindow, QWindow*, transientParent); + MO_ADD_PROPERTY_RO(QWindow, Qt::WindowType, type); +#endif +} + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +Q_DECLARE_METATYPE(QOpenGLShader::ShaderType) +#endif + +void MetaObjectRepository::initOpenGLTypes() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MetaObject *mo = 0; + MO_ADD_METAOBJECT1(QOpenGLShader, QObject); + MO_ADD_PROPERTY_RO(QOpenGLShader, bool, isCompiled); + MO_ADD_PROPERTY_RO(QOpenGLShader, QString, log); + MO_ADD_PROPERTY_RO(QOpenGLShader, uint, shaderId); + MO_ADD_PROPERTY_RO(QOpenGLShader, QOpenGLShader::ShaderType, shaderType); + MO_ADD_PROPERTY_RO(QOpenGLShader, QByteArray, sourceCode); + + MO_ADD_METAOBJECT1(QOpenGLShaderProgram, QObject); + MO_ADD_PROPERTY_RO(QOpenGLShaderProgram, bool, isLinked); + MO_ADD_PROPERTY_RO(QOpenGLShaderProgram, QString, log); +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + MO_ADD_PROPERTY_RO(QOpenGLShaderProgram, int, maxGeometryOutputVertices); + MO_ADD_PROPERTY (QOpenGLShaderProgram, int, patchVertexCount, setPatchVertexCount); +#endif + MO_ADD_PROPERTY_RO(QOpenGLShaderProgram, uint, programId); + + MO_ADD_METAOBJECT1(QOpenGLContext, QObject); + MO_ADD_PROPERTY_RO(QOpenGLContext, uint, defaultFramebufferObject); + MO_ADD_PROPERTY_RO(QOpenGLContext, QSet, extensions); + MO_ADD_PROPERTY_RO(QOpenGLContext, QSurfaceFormat, format); + MO_ADD_PROPERTY_RO(QOpenGLContext, bool, isValid); + MO_ADD_PROPERTY_RO(QOpenGLContext, QScreen*, screen); + MO_ADD_PROPERTY_RO(QOpenGLContext, QOpenGLContext*, shareContext); + MO_ADD_PROPERTY_RO(QOpenGLContext, QOpenGLContextGroup*, shareGroup); +// MO_ADD_PROPERTY_RO(QOpenGLContext, QSurface*, surface); +#endif } MetaObjectRepository *MetaObjectRepository::instance() { + if (!s_instance()->m_initialized) + s_instance()->initBuiltInTypes(); return s_instance(); } diff -Nru gammaray-1.2.2/core/metaobjectrepository.h gammaray-2.0.1/core/metaobjectrepository.h --- gammaray-1.2.2/core/metaobjectrepository.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaobjectrepository.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,9 +21,14 @@ along with this program. If not, see . */ +/** @file metaobjectrepository.h + * @brief MetaObject repository macros. + */ + #ifndef GAMMARAY_METAOBJECTREPOSITORY_H #define GAMMARAY_METAOBJECTREPOSITORY_H +#include "gammaray_core_export.h" #include class QString; @@ -33,10 +38,12 @@ class MetaObject; /** + * @brief MetaObject repository. + * * Repository of compile-time introspection information for stuff * not covered by the Qt meta object system. */ -class MetaObjectRepository +class GAMMARAY_CORE_EXPORT MetaObjectRepository { public: ~MetaObjectRepository(); @@ -65,12 +72,70 @@ private: void initBuiltInTypes(); void initQObjectTypes(); - void initGraphicsViewTypes(); + void initIOTypes(); + void initNetworkTypes(); + void initGuiTypes(); + void initOpenGLTypes(); private: QHash m_metaObjects; + bool m_initialized; }; } +///@cond internal +#define MO_ADD_BASECLASS(Base) \ + Q_ASSERT(GammaRay::MetaObjectRepository::instance()->hasMetaObject(QLatin1String(#Base))); \ + mo->addBaseClass(GammaRay::MetaObjectRepository::instance()->metaObject(QLatin1String(#Base))); +///@endcond + +/** Register @p Class with the MetaObjectRepository. + * Use this if @p Class has no base class. + */ +#define MO_ADD_METAOBJECT0(Class) \ + mo = new GammaRay::MetaObjectImpl; \ + mo->setClassName(QLatin1String(#Class)); \ + GammaRay::MetaObjectRepository::instance()->addMetaObject(mo); + +/** Register @p Class with the MetaObjectRepository. + * Use this if @p Class has one base class. + */ +#define MO_ADD_METAOBJECT1(Class, Base1) \ + mo = new GammaRay::MetaObjectImpl; \ + mo->setClassName(QLatin1String(#Class)); \ + MO_ADD_BASECLASS(Base1) \ + GammaRay::MetaObjectRepository::instance()->addMetaObject(mo); + +/** Register @p Class with the MetaObjectRepository. + * Use this if @p Class has two base classes. + */ +#define MO_ADD_METAOBJECT2(Class, Base1, Base2) \ + mo = new GammaRay::MetaObjectImpl; \ + mo->setClassName(QLatin1String(#Class)); \ + MO_ADD_BASECLASS(Base1) \ + MO_ADD_BASECLASS(Base2) \ + GammaRay::MetaObjectRepository::instance()->addMetaObject(mo); + +/** Register a read/write property for class @p Class. */ +#define MO_ADD_PROPERTY(Class, Type, Getter, Setter) \ + mo->addProperty(new GammaRay::MetaPropertyImpl( \ + QLatin1String(#Getter), \ + &Class::Getter, \ + static_cast(&Class::Setter)) \ + ); + +/** Register a read/write property for class @p Class with a type that is passed as const reference. */ +#define MO_ADD_PROPERTY_CR(Class, Type, Getter, Setter) \ + mo->addProperty(new GammaRay::MetaPropertyImpl( \ + QLatin1String(#Getter), \ + &Class::Getter, \ + static_cast(&Class::Setter)) \ + ); + +/** Register a read-only property for class @p Class. */ +#define MO_ADD_PROPERTY_RO(Class, Type, Getter) \ + mo->addProperty(new GammaRay::MetaPropertyImpl( \ + QLatin1String(#Getter), \ + &Class::Getter)); #endif // GAMMARAY_METAOBJECTREPOSITORY_H diff -Nru gammaray-1.2.2/core/metaobjecttreemodel.cpp gammaray-2.0.1/core/metaobjecttreemodel.cpp --- gammaray-1.2.2/core/metaobjecttreemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/metaobjecttreemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,240 @@ +/* + metaobjecttreemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "metaobjecttreemodel.h" + +#include "probe.h" +#include "readorwritelocker.h" + +#include +#include + +using namespace GammaRay; + +#define IF_DEBUG(x) + +namespace GammaRay { +/** + * Open QObject for access to protected data members + */ +class UnprotectedQObject : public QObject +{ +public: + inline QObjectData* data() const { return d_ptr.data(); } +}; +} + +/** + * Return true in case the object has a dynamic meta object + * + * If you look at the code generated by moc you'll see this: + * @code + * const QMetaObject *GammaRay::MessageModel::metaObject() const + * { + * return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; + * } + * @endcode + * + * QtQuick uses dynamic meta objects (subclasses of QAbstractDynamicMetaObject, defined in qobject_h.p) + * for QML types. It's possible that these meta objects get destroyed + * at runtime, so we need to protect against this. + * + * @note We cannot say if a specific QMetaObject* is dynamic or not + * (QMetaObject is non-polymorphic, so we cannot dynamic_cast to QAbstractDynamicMetaObject*), + * we can just judge by looking at QObjectData of QObject* + * -- hence the QObject* parameter in hasDynamicMetaObject. + * + * @return Return true in case metaObject() does not point to staticMetaObject. + */ +static inline bool hasDynamicMetaObject(const QObject* object) +{ + return reinterpret_cast(object)->data()->metaObject != 0; +} + +MetaObjectTreeModel::MetaObjectTreeModel(QObject *parent) + : QAbstractItemModel(parent) +{ +} + +QVariant MetaObjectTreeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case ObjectColumn: + return tr("Meta Object Class Hierarchy"); + default: + return QVariant(); + } + } + + return QAbstractItemModel::headerData(section, orientation, role); +} + +QVariant MetaObjectTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const int column = index.column(); + const QMetaObject *object = metaObjectForIndex(index); + if (role == Qt::DisplayRole) { + switch(column) { + case ObjectColumn: + return object->className(); + default: + break; + } + } else if (role == MetaObjectRole) { + return QVariant::fromValue(object); + } + return QVariant(); +} + +int MetaObjectTreeModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 1; +} + +int MetaObjectTreeModel::rowCount(const QModelIndex &parent) const +{ + const QMetaObject *metaObject = metaObjectForIndex(parent); + return m_parentChildMap.value(metaObject).size(); +} + +QModelIndex MetaObjectTreeModel::parent(const QModelIndex &child) const +{ + if (!child.isValid()) { + return QModelIndex(); + } + + const QMetaObject *object = metaObjectForIndex(child); + Q_ASSERT(object); + const QMetaObject *parentObject = object->superClass(); + return indexForMetaObject(parentObject); +} + +QModelIndex MetaObjectTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + const QMetaObject *parentObject = metaObjectForIndex(parent); + const QVector children = m_parentChildMap.value(parentObject); + if (row < 0 || column < 0 || row >= children.size() || column >= columnCount()) { + return QModelIndex(); + } + + const QMetaObject *object = children.at(row); + return createIndex(row, column, const_cast(object)); +} + +void MetaObjectTreeModel::objectAdded(QObject *obj) +{ + // slot, hence should always land in main thread due to auto connection + Q_ASSERT(thread() == QThread::currentThread()); + + ReadOrWriteLocker objectLock(Probe::instance()->objectLock()); + if (!Probe::instance()->isValidObject(obj)) { + return; + } + Q_ASSERT(!obj->parent() || Probe::instance()->isValidObject(obj->parent())); + + if (hasDynamicMetaObject(obj)) { + // Encountered dynamic meta object, ignoring for now + return; + } + + const QMetaObject *metaObject = obj->metaObject(); + addMetaObject(metaObject); +} + +void MetaObjectTreeModel::addMetaObject(const QMetaObject *metaObject) +{ + if (indexForMetaObject(metaObject).isValid()) { + return; + } + + const QMetaObject *parentMetaObject = metaObject->superClass(); + if (parentMetaObject) { + const QModelIndex parentIndex = indexForMetaObject(parentMetaObject); + if (!parentIndex.isValid()) { + // add parent first + addMetaObject(metaObject->superClass()); + } + } + + const QModelIndex parentIndex = indexForMetaObject(parentMetaObject); + // either we get a proper parent and hence valid index or there is no parent + Q_ASSERT(parentIndex.isValid() || !parentMetaObject); + + QVector &children = m_parentChildMap[ parentMetaObject ]; + + beginInsertRows(parentIndex, children.size(), children.size()); + children.push_back(metaObject); + m_childParentMap.insert(metaObject, parentMetaObject); + + endInsertRows(); +} + +void MetaObjectTreeModel::removeMetaObject(const QMetaObject *metaObject) +{ + Q_UNUSED(metaObject); + // TODO: Meta objects may be deleted, find a way to detect this +} + +void MetaObjectTreeModel::objectRemoved(QObject *obj) +{ + Q_UNUSED(obj); + // TODO +} + +QModelIndex MetaObjectTreeModel::indexForMetaObject(const QMetaObject *metaObject) const +{ + if (!metaObject) { + return QModelIndex(); + } + + const QMetaObject *parentObject = m_childParentMap.value(metaObject); + const QModelIndex parentIndex = indexForMetaObject(parentObject); + if (!parentIndex.isValid() && parentObject) { + return QModelIndex(); + } + + const int row = m_parentChildMap[parentObject].indexOf(metaObject); + if (row < 0) { + return QModelIndex(); + } + + return index(row, 0, parentIndex); +} + +const QMetaObject *MetaObjectTreeModel::metaObjectForIndex(const QModelIndex &index) const +{ + if (!index.isValid()) { + return 0; + } + + void *internalPointer = index.internalPointer(); + const QMetaObject* metaObject = reinterpret_cast(internalPointer); + return metaObject; +} + diff -Nru gammaray-1.2.2/core/metaobjecttreemodel.h gammaray-2.0.1/core/metaobjecttreemodel.h --- gammaray-1.2.2/core/metaobjecttreemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/metaobjecttreemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,86 @@ +/* + metaobjecttreemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METAOBJECTTREEMODEL_H +#define GAMMARAY_METAOBJECTTREEMODEL_H + +#include +#include +#include +#include + +namespace GammaRay { + +class MetaObjectTreeModel : public QAbstractItemModel +{ + Q_OBJECT + + public: + enum Role { + MetaObjectRole = UserRole + 1 + }; + + enum Column { + ObjectColumn + }; + + explicit MetaObjectTreeModel(QObject *parent = 0); + + // reimplemented methods + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex parent(const QModelIndex &child) const; + + virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + + // headers + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + // Probe callbacks + void objectAdded(QObject *obj); + void objectRemoved(QObject *obj); + + private: + void addMetaObject(const QMetaObject *metaObject); + void removeMetaObject(const QMetaObject *metaObject); + + QModelIndex indexForMetaObject(const QMetaObject *metaObject) const; + const QMetaObject *metaObjectForIndex(const QModelIndex &index) const; + + mutable QReadWriteLock m_lock; + + // data + QHash m_childParentMap; + QHash > m_parentChildMap; +}; + +} + +Q_DECLARE_METATYPE(const QMetaObject *) + +#endif // GAMMARAY_METAOBJECTTREEMODEL_H diff -Nru gammaray-1.2.2/core/metaproperty.cpp gammaray-2.0.1/core/metaproperty.cpp --- gammaray-1.2.2/core/metaproperty.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaproperty.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/metaproperty.h gammaray-2.0.1/core/metaproperty.h --- gammaray-1.2.2/core/metaproperty.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metaproperty.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,6 +24,8 @@ #ifndef GAMMARAY_METAPROPERTY_H #define GAMMARAY_METAPROPERTY_H +#include "gammaray_core_export.h" + #include #include @@ -31,8 +33,8 @@ class MetaObject; -/** Introspectable adaptor to non-QObject properties. */ -class MetaProperty +/** @brief Introspectable adaptor to non-QObject properties. */ +class GAMMARAY_CORE_EXPORT MetaProperty { public: MetaProperty(); @@ -63,7 +65,7 @@ MetaObject *m_class; }; -/** Template-ed implementation of MetaProperty. */ +/** @brief Template-ed implementation of MetaProperty. */ template class MetaPropertyImpl : public MetaProperty { diff -Nru gammaray-1.2.2/core/metapropertymodel.cpp gammaray-2.0.1/core/metapropertymodel.cpp --- gammaray-1.2.2/core/metapropertymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metapropertymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,8 +24,7 @@ #include "metapropertymodel.h" #include "metaobjectrepository.h" #include "metaobject.h" - -#include "include/util.h" +#include "varianthandler.h" using namespace GammaRay; @@ -121,9 +120,9 @@ const QVariant value = property->value(m_metaObject->castForPropertyAt(m_object, index.row())); switch (role) { case Qt::DisplayRole: - return Util::variantToString(value); + return VariantHandler::displayString(value); case Qt::DecorationRole: - return Util::decorationForVariant(value); + return VariantHandler::decoration(value); case Qt::EditRole: return value; } @@ -136,6 +135,7 @@ if (index.isValid() && index.column() == 1 && m_metaObject && m_object && role == Qt::EditRole) { MetaProperty *property = m_metaObject->propertyAt(index.row()); property->setValue(m_metaObject->castForPropertyAt(m_object, index.row()), value); + emit dataChanged(index, index); return true; } return QAbstractItemModel::setData(index, value, role); @@ -155,4 +155,3 @@ return f | Qt::ItemIsEditable; } -#include "metapropertymodel.moc" diff -Nru gammaray-1.2.2/core/metapropertymodel.h gammaray-2.0.1/core/metapropertymodel.h --- gammaray-1.2.2/core/metapropertymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/metapropertymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/methodargumentmodel.cpp gammaray-2.0.1/core/methodargumentmodel.cpp --- gammaray-1.2.2/core/methodargumentmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/methodargumentmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,35 +22,9 @@ */ #include "methodargumentmodel.h" -#include using namespace GammaRay; -// TODO: this should be implicitly shared to avoid m_data double deletion -SafeArgument::SafeArgument() : m_data(0) -{ -} - -SafeArgument::SafeArgument(const QVariant &v) : m_value(v), m_name(v.typeName()), m_data(0) -{ -} - -SafeArgument::~SafeArgument() -{ - if (m_data) { - QMetaType::destroy(m_value.type(), m_data); - } -} - -SafeArgument::operator QGenericArgument() const -{ - if (m_value.isValid()) { - m_data = QMetaType::construct(m_value.type(), m_value.constData()); - return QGenericArgument(m_name.data(), m_data); - } - return QGenericArgument(); -} - MethodArgumentModel::MethodArgumentModel(QObject *parent) : QAbstractTableModel(parent) { } @@ -70,15 +44,14 @@ QVariant MethodArgumentModel::data(const QModelIndex &index, int role) const { - if ( #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - !m_method.signature() + if(!m_method.signature() || #else - m_method.methodSignature().isEmpty() + if(m_method.methodSignature().isEmpty() || #endif - || m_arguments.isEmpty() || - index.row() < 0 || - index.row() >= m_arguments.size()) { + m_arguments.isEmpty() || + index.row() < 0 || + index.row() >= m_arguments.size()) { return QVariant(); } @@ -119,6 +92,7 @@ { if (index.row() >= 0 && index.row() < m_arguments.size() && role == Qt::EditRole) { m_arguments[index.row()] = value; + emit dataChanged(index, index); return true; } return QAbstractItemModel::setData(index, value, role); @@ -148,13 +122,12 @@ return flags; } -QVector MethodArgumentModel::arguments() const +QVector MethodArgumentModel::arguments() const { - QVector args(10); + QVector args(10); for (int i = 0; i < rowCount(); ++i) { - args[i] = SafeArgument(m_arguments.at(i)); + args[i] = MethodArgument(m_arguments.at(i)); } return args; } -#include "methodargumentmodel.moc" diff -Nru gammaray-1.2.2/core/methodargumentmodel.h gammaray-2.0.1/core/methodargumentmodel.h --- gammaray-1.2.2/core/methodargumentmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/methodargumentmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,33 +24,21 @@ #ifndef GAMMARAY_METHODARGUMENTMODEL_H #define GAMMARAY_METHODARGUMENTMODEL_H +#include + #include #include #include namespace GammaRay { -class SafeArgument -{ - public: - SafeArgument(); - SafeArgument(const QVariant &v); - ~SafeArgument(); - operator QGenericArgument () const; - - private: - QVariant m_value; - QByteArray m_name; - mutable void *m_data; -}; - class MethodArgumentModel : public QAbstractTableModel { Q_OBJECT public: - MethodArgumentModel(QObject *parent = 0); + explicit MethodArgumentModel(QObject *parent = 0); void setMethod(const QMetaMethod &method); - QVector arguments() const; + QVector arguments() const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; diff -Nru gammaray-1.2.2/core/methodinvocationdialog.cpp gammaray-2.0.1/core/methodinvocationdialog.cpp --- gammaray-1.2.2/core/methodinvocationdialog.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/methodinvocationdialog.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -/* - methodinvocationdialog.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "methodinvocationdialog.h" -#include "methodargumentmodel.h" -#include -#include - -using namespace GammaRay; - -Q_DECLARE_METATYPE(Qt::ConnectionType) - -MethodInvocationDialog::MethodInvocationDialog(QWidget *parent) - : QDialog(parent), - m_argumentModel(new MethodArgumentModel(this)) -{ - setAttribute(Qt::WA_DeleteOnClose); - - ui.setupUi(this); - - ui.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Invoke")); - connect(ui.buttonBox, SIGNAL(accepted()), SLOT(accept())); - connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject())); - - ui.connectionTypeComboBox->addItem(tr("Auto"), Qt::AutoConnection); - ui.connectionTypeComboBox->addItem(tr("Direct"), Qt::DirectConnection); - ui.connectionTypeComboBox->addItem(tr("Queued"), Qt::QueuedConnection); - - ui.argumentView->setModel(m_argumentModel); -} - -void MethodInvocationDialog::setMethod(QObject *object, const QMetaMethod &method) -{ - m_object = object; - m_method = method; - m_argumentModel->setMethod(method); -} - -void MethodInvocationDialog::accept() -{ - if (!m_object) { - QMessageBox::warning(this, - tr("Invocation Failed"), - tr("Invalid object, probably got deleted in the meantime.")); - QDialog::reject(); - return; - } - - const Qt::ConnectionType connectionType = - ui.connectionTypeComboBox->itemData( - ui.connectionTypeComboBox->currentIndex()).value(); - const QVector args = m_argumentModel->arguments(); - - const bool result = m_method.invoke( - m_object.data(), connectionType, - args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); - - if (!result) { - QMessageBox::warning(this, - tr("Invocation Failed"), - tr("Invocation failed, possibly due to mismatching/invalid arguments.")); - } - - QDialog::accept(); -} - -#include "methodinvocationdialog.moc" diff -Nru gammaray-1.2.2/core/methodinvocationdialog.h gammaray-2.0.1/core/methodinvocationdialog.h --- gammaray-1.2.2/core/methodinvocationdialog.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/methodinvocationdialog.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -/* - methodinvocationdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_METHODINVOCATIONDIALOG_H -#define GAMMARAY_METHODINVOCATIONDIALOG_H - -#include "ui_methodinvocationdialog.h" - -#include -#include -#include -#include - -namespace GammaRay { - -class MethodArgumentModel; - -class MethodInvocationDialog : public QDialog -{ - Q_OBJECT - public: - MethodInvocationDialog(QWidget *parent = 0); - void setMethod(QObject *object, const QMetaMethod &method); - void accept(); - - private: - QMetaMethod m_method; - QPointer m_object; - Ui::MethodInvocationDialog ui; - MethodArgumentModel *m_argumentModel; -}; - -} - -#endif // GAMMARAY_METHODINVOCATIONDIALOG_H diff -Nru gammaray-1.2.2/core/methodinvocationdialog.ui gammaray-2.0.1/core/methodinvocationdialog.ui --- gammaray-1.2.2/core/methodinvocationdialog.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/methodinvocationdialog.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ - - - GammaRay::MethodInvocationDialog - - - - 0 - 0 - 400 - 300 - - - - - - - - - &Connection type: - - - connectionTypeComboBox - - - - - - - - - - - - false - - - true - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - diff -Nru gammaray-1.2.2/core/multisignalmapper.cpp gammaray-2.0.1/core/multisignalmapper.cpp --- gammaray-1.2.2/core/multisignalmapper.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/multisignalmapper.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,49 +24,75 @@ #include "multisignalmapper.h" #include -#include +#include #include -#include +#include -using namespace GammaRay; +namespace GammaRay { -MultiSignalMapper::MultiSignalMapper(QObject *parent) : QObject(parent) +class MultiSignalMapperPrivate : public QObject { + public: + explicit MultiSignalMapperPrivate(MultiSignalMapper* parent) : QObject(parent), q(parent) {} + ~MultiSignalMapperPrivate() {} + + int qt_metacall(QMetaObject::Call call, int methodId, void** args) + { + methodId = QObject::qt_metacall(call, methodId, args); + if (methodId < 0) + return methodId; + + if (call == QMetaObject::InvokeMetaMethod) { + if (methodId == 0) { + Q_ASSERT(sender()); + Q_ASSERT(senderSignalIndex() != -1); + const QVector v = convertArguments(sender(), senderSignalIndex(), args); + emit q->signalEmitted(sender(), senderSignalIndex(), v); + } + --methodId; // our method offset is 1 + } + return methodId; + } + + QVector convertArguments(QObject *sender, int signalIndex, void** args) + { + Q_ASSERT(sender); + Q_ASSERT(signalIndex >= 0); + + const QMetaMethod signal = sender->metaObject()->method(signalIndex); + Q_ASSERT(signal.methodType() == QMetaMethod::Signal); + + QVector v; + const QList paramTypes = signal.parameterTypes(); + for (int i = 0; i < paramTypes.size(); ++i) { + int type = QMetaType::type(paramTypes[i]); + if (type == QMetaType::Void) { + qWarning() << Q_FUNC_INFO << "unknown metatype for signal argument type" << paramTypes[i]; + continue; + } + v.push_back(QVariant(type, args[i + 1])); + } + + return v; + } + + private: + MultiSignalMapper* q; +}; + } -MultiSignalMapper::~MultiSignalMapper() +using namespace GammaRay; + +MultiSignalMapper::MultiSignalMapper(QObject *parent) : QObject(parent), d(new MultiSignalMapperPrivate(this)) { - qDeleteAll(m_mappers); - m_mappers.clear(); } -void MultiSignalMapper::connectToSignal(QObject *sender, const QMetaMethod &signal) +MultiSignalMapper::~MultiSignalMapper() { - if (m_mappers.size() <= signal.methodIndex()) { - m_mappers.resize(signal.methodIndex() + 1); - } - - QSignalMapper *mapper = m_mappers.at(signal.methodIndex()); - if (!mapper) { - mapper = new QSignalMapper(this); - connect(mapper, SIGNAL(mapped(QObject*)), SLOT(slotMapped(QObject*))); - m_mappers[signal.methodIndex()] = mapper; - } - - mapper->setMapping(sender, sender); - connect(sender, QByteArray::number(QSIGNAL_CODE) + -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - signal.signature() -#else - signal.methodSignature() -#endif - , - mapper, SLOT(map()), Qt::UniqueConnection); } -void MultiSignalMapper::slotMapped(QObject *object) +void MultiSignalMapper::connectToSignal(QObject *sender, const QMetaMethod &signal) { - emit signalEmitted(object, m_mappers.indexOf(static_cast(sender()))); + QMetaObject::connect(sender, signal.methodIndex(), d, QObject::metaObject()->methodCount(), Qt::AutoConnection | Qt::UniqueConnection, 0); } - -#include "multisignalmapper.moc" diff -Nru gammaray-1.2.2/core/multisignalmapper.h gammaray-2.0.1/core/multisignalmapper.h --- gammaray-1.2.2/core/multisignalmapper.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/multisignalmapper.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -25,12 +25,11 @@ #define GAMMARAY_MULTISIGNALMAPPER_H #include -#include - -class QSignalMapper; namespace GammaRay { +class MultiSignalMapperPrivate; + /** * A signal mapper that can deal with multiple signals from the same sender. */ @@ -44,13 +43,11 @@ void connectToSignal(QObject *sender, const QMetaMethod &signal); signals: - void signalEmitted(QObject *sender, int signalIndex); - - private slots: - void slotMapped(QObject *object); + void signalEmitted(QObject *sender, int signalIndex, const QVector &arguments); private: - QVector m_mappers; + friend class MultiSignalMapperPrivate; + MultiSignalMapperPrivate* const d; }; } diff -Nru gammaray-1.2.2/core/objectclassinfomodel.cpp gammaray-2.0.1/core/objectclassinfomodel.cpp --- gammaray-1.2.2/core/objectclassinfomodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectclassinfomodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/objectclassinfomodel.h gammaray-2.0.1/core/objectclassinfomodel.h --- gammaray-1.2.2/core/objectclassinfomodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectclassinfomodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/objectdynamicpropertymodel.cpp gammaray-2.0.1/core/objectdynamicpropertymodel.cpp --- gammaray-1.2.2/core/objectdynamicpropertymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectdynamicpropertymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,12 +22,16 @@ */ #include "objectdynamicpropertymodel.h" +#include "varianthandler.h" + +#include using namespace GammaRay; ObjectDynamicPropertyModel::ObjectDynamicPropertyModel(QObject *parent) : ObjectPropertyModel(parent) { + connect(this, SIGNAL(modelReset()), SLOT(updatePropertyCount())); } QVariant ObjectDynamicPropertyModel::data(const QModelIndex &index, int role) const @@ -48,7 +52,7 @@ if (index.column() == 0) { return QString::fromUtf8(propName); } else if (index.column() == 1) { - return propValue; + return role == Qt::EditRole ? propValue : VariantHandler::displayString(propValue); } else if (index.column() == 2) { return propValue.typeName(); } @@ -71,6 +75,7 @@ if (role == Qt::EditRole) { const QByteArray propName = propNames.at(index.row()); m_obj.data()->setProperty(propName, value); + emit dataChanged(index, index); return true; } @@ -104,4 +109,32 @@ return m_obj.data()->dynamicPropertyNames().size(); } -#include "objectdynamicpropertymodel.moc" +void ObjectDynamicPropertyModel::monitorObject(QObject* obj) +{ + obj->installEventFilter(this); +} + +void ObjectDynamicPropertyModel::unmonitorObject(QObject* obj) +{ + obj->removeEventFilter(this); +} + +bool ObjectDynamicPropertyModel::eventFilter(QObject* receiver, QEvent* event) +{ + if (receiver == m_obj && event->type() == QEvent::DynamicPropertyChange) { + const int newPropertyCount = m_obj->dynamicPropertyNames().size(); + if (newPropertyCount != m_propertyCount) { + // FIXME: this can be done more efficiently... + reset(); + } else { + // FIXME: send dataChanged for the affected cell only + updateAll(); + } + } + return ObjectPropertyModel::eventFilter(receiver, event); +} + +void ObjectDynamicPropertyModel::updatePropertyCount() +{ + m_propertyCount = rowCount(); +} diff -Nru gammaray-1.2.2/core/objectdynamicpropertymodel.h gammaray-2.0.1/core/objectdynamicpropertymodel.h --- gammaray-1.2.2/core/objectdynamicpropertymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectdynamicpropertymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -39,6 +39,18 @@ Qt::ItemFlags flags(const QModelIndex &index) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; + + bool eventFilter(QObject *receiver, QEvent *event); + +protected: + void monitorObject(QObject *obj); + void unmonitorObject(QObject *obj); + +private slots: + void updatePropertyCount(); + +private: + int m_propertyCount; }; } diff -Nru gammaray-1.2.2/core/objectenummodel.cpp gammaray-2.0.1/core/objectenummodel.cpp --- gammaray-1.2.2/core/objectenummodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectenummodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -45,7 +45,7 @@ if (parent.parent().isValid()) { return 0; } - const QMetaEnum e = m_object.data()->metaObject()->enumerator(parent.row()); + const QMetaEnum e = m_metaObject->enumerator(parent.row()); return e.keyCount(); } @@ -62,7 +62,7 @@ } if (role == Qt::DisplayRole) { - const QMetaEnum e = m_object.data()->metaObject()->enumerator(index.parent().row()); + const QMetaEnum e = m_metaObject->enumerator(index.parent().row()); if (index.column() == 0) { return e.key(index.row()); } @@ -109,7 +109,8 @@ QModelIndex GammaRay::ObjectEnumModel::parent(const QModelIndex &child) const { - if (child.internalId() == -1) { + // note: Qt4 doesn't have qintptr + if (static_cast(child.internalId()) == -1) { return SuperClass::parent(child); } return SuperClass::index(child.internalId(), 0, QModelIndex()); diff -Nru gammaray-1.2.2/core/objectenummodel.h gammaray-2.0.1/core/objectenummodel.h --- gammaray-1.2.2/core/objectenummodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectenummodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -33,7 +33,7 @@ &QMetaObject::enumeratorOffset> { public: - ObjectEnumModel(QObject *parent = 0); + explicit ObjectEnumModel(QObject *parent = 0); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QString columnHeader(int index) const; diff -Nru gammaray-1.2.2/core/objectlistmodel.cpp gammaray-2.0.1/core/objectlistmodel.cpp --- gammaray-1.2.2/core/objectlistmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectlistmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -28,20 +28,22 @@ #include #include "probe.h" +#include + using namespace GammaRay; +using namespace std; ObjectListModel::ObjectListModel(QObject *parent) - : ObjectModelBase< QAbstractTableModel >(parent), - m_lock(QReadWriteLock::Recursive) + : ObjectModelBase< QAbstractTableModel >(parent) { } QVariant ObjectListModel::data(const QModelIndex &index, int role) const { - ReadOrWriteLocker lock(&m_lock); + QMutexLocker lock(&m_mutex); if (index.row() >= 0 && index.row() < m_objects.size()) { QObject *obj = m_objects.at(index.row()); - if (obj) { + if (!m_invalidatedObjects.contains(obj)) { return dataForObject(obj, index, role); } } @@ -62,61 +64,98 @@ return 0; } - ReadOrWriteLocker lock(&m_lock); return m_objects.size(); } void ObjectListModel::objectAdded(QObject *obj) { // when called from background, delay into foreground, otherwise call directly - QMetaObject::invokeMethod(this, "objectAddedMainThread", Qt::AutoConnection, - Q_ARG(QObject *, obj)); + if (thread() != QThread::currentThread()) { + { + // revalidate data + QMutexLocker lock(&m_mutex); + m_invalidatedObjects.remove(obj); + } + QMetaObject::invokeMethod(this, "objectAddedMainThread", Qt::QueuedConnection, + Q_ARG(QObject*, obj)); + } else { + objectAddedMainThread(obj); + } } void ObjectListModel::objectAddedMainThread(QObject *obj) { - ReadOrWriteLocker objectLock(Probe::instance()->objectLock()); - if (!Probe::instance()->isValidObject(obj)) { - return; + { + QMutexLocker lock(&m_mutex); + if (m_invalidatedObjects.contains(obj)) { + return; + } } - QWriteLocker lock(&m_lock); - if (m_objects.contains(obj)) { - return; - } + Q_ASSERT(obj); + + QVector::iterator it = std::lower_bound(m_objects.begin(), m_objects.end(), obj); + Q_ASSERT(it == m_objects.end() || *it != obj); + + const int row = std::distance(m_objects.begin(), it); + Q_ASSERT(row >= 0 && row <= m_objects.size()); - beginInsertRows(QModelIndex(), m_objects.size(), m_objects.size()); - m_objects << obj; + beginInsertRows(QModelIndex(), row, row); + m_objects.insert(it, obj); + Q_ASSERT(m_objects.at(row) == obj); endInsertRows(); } void ObjectListModel::objectRemoved(QObject *obj) { + // when called from background, delay into foreground, otherwise call directly if (thread() != QThread::currentThread()) { - // invalidate data - QWriteLocker lock(&m_lock); - const int index = m_objects.indexOf(obj); - if (index != -1) { - m_objects[index] = 0; + { + // invalidate data + QMutexLocker lock(&m_mutex); + m_invalidatedObjects.insert(obj); } + QMetaObject::invokeMethod(this, "objectRemovedMainThread", Qt::QueuedConnection, + Q_ARG(QObject*, obj), Q_ARG(bool, true)); + } else { + objectRemovedMainThread(obj, false); } - - // when called from background, delay into foreground, otherwise call directly - QMetaObject::invokeMethod(this, "objectRemovedMainThread", Qt::AutoConnection, - Q_ARG(QObject *, obj)); } -void ObjectListModel::objectRemovedMainThread(QObject *obj) +void ObjectListModel::objectRemovedMainThread(QObject *obj, bool fromBackground) { - QWriteLocker lock(&m_lock); + Q_ASSERT(thread() == QThread::currentThread()); - for (int i = 0; i < m_objects.size(); ++i) { - if (!m_objects.at(i) || m_objects.at(i) == obj) { - beginRemoveRows(QModelIndex(), i, i); - m_objects.remove(i); - endRemoveRows(); + if (fromBackground) { + QMutexLocker lock(&m_mutex); + bool removed = m_invalidatedObjects.remove(obj); + if (!removed) { + Q_ASSERT(!m_objects.contains(obj)); + return; } + } else { +#ifndef NDEBUG + QMutexLocker lock(&m_mutex); + Q_ASSERT(!m_invalidatedObjects.contains(obj)); +#endif + } + + if (m_objects.isEmpty()) { + return; } + + QVector::iterator it = std::lower_bound(m_objects.begin(), m_objects.end(), obj); + if (it == m_objects.end() || *it != obj) { + // not found + return; + } + + const int row = std::distance(m_objects.begin(), it); + Q_ASSERT(row >= 0 && row < m_objects.size()); + Q_ASSERT(m_objects.at(row) == obj); + + beginRemoveRows(QModelIndex(), row, row); + m_objects.erase(it); + endRemoveRows(); } -#include "objectlistmodel.moc" diff -Nru gammaray-1.2.2/core/objectlistmodel.h gammaray-2.0.1/core/objectlistmodel.h --- gammaray-1.2.2/core/objectlistmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectlistmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,10 +24,11 @@ #ifndef GAMMARAY_OBJECTLISTMODEL_H #define GAMMARAY_OBJECTLISTMODEL_H -#include "include/objectmodelbase.h" +#include "objectmodelbase.h" -#include +#include #include +#include namespace GammaRay { @@ -56,12 +57,16 @@ private slots: void objectAddedMainThread(QObject *obj); - void objectRemovedMainThread(QObject *obj); + void objectRemovedMainThread(QObject *obj, bool fromBackground); private: - mutable QReadWriteLock m_lock; - // vector for stable iterators/indexes, esp. for the model methods + void removeObject(QObject *obj); + + // sorted vector for stable iterators/indexes, esp. for the model methods QVector m_objects; + + mutable QMutex m_mutex; + QSet m_invalidatedObjects; }; } diff -Nru gammaray-1.2.2/core/objectmethodmodel.cpp gammaray-2.0.1/core/objectmethodmodel.cpp --- gammaray-1.2.2/core/objectmethodmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectmethodmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -34,7 +34,11 @@ int GammaRay::ObjectMethodModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); - return 4; +#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) + return 5; +#else + return 6; +#endif } QVariant ObjectMethodModel::metaData(const QModelIndex &index, @@ -74,8 +78,18 @@ return tr("Unknown"); } } - } else if (role == MetaMethodRole) { + if (index.column() == 3) { + return method.tag(); + } +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + if (index.column() == 4) { + return QString::number(method.revision()); + } +#endif + } else if (role == ObjectMethodModelRole::MetaMethod) { return QVariant::fromValue(method); + } else if (role == ObjectMethodModelRole::MetaMethodType) { + return QVariant::fromValue(method.methodType()); } return QVariant(); } @@ -89,6 +103,17 @@ return tr("Type"); case 2: return tr("Access"); + case 3: + return tr("Tag"); + case 4: + return tr("Revision"); } return QString(); } + +QMap< int, QVariant > ObjectMethodModel::itemData(const QModelIndex& index) const +{ + QMap m = super::itemData(index); + m.insert(ObjectMethodModelRole::MetaMethodType, data(index, ObjectMethodModelRole::MetaMethodType)); + return m; +} diff -Nru gammaray-1.2.2/core/objectmethodmodel.h gammaray-2.0.1/core/objectmethodmodel.h --- gammaray-1.2.2/core/objectmethodmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectmethodmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -26,6 +26,9 @@ #include "metaobjectmodel.h" +#include +#include + #include namespace GammaRay { @@ -35,12 +38,9 @@ &QMetaObject::methodCount, &QMetaObject::methodOffset> { public: - enum Role { - MetaMethodRole = Qt::UserRole + 1 - }; - explicit ObjectMethodModel(QObject *parent = 0); int columnCount(const QModelIndex &parent = QModelIndex()) const; + QMap< int, QVariant > itemData(const QModelIndex& index) const; protected: QVariant metaData(const QModelIndex &index, diff -Nru gammaray-1.2.2/core/objectmodelbase.h gammaray-2.0.1/core/objectmodelbase.h --- gammaray-1.2.2/core/objectmodelbase.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/objectmodelbase.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,135 @@ +/* + objectmodelbase.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares a template for an ObjectModelBase class. + + @brief + Declares a template for an ObjectModelBase class. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_OBJECTMODELBASE_H +#define GAMMARAY_OBJECTMODELBASE_H + +#include "util.h" +#include + +#include +#include + +namespace GammaRay { + +/** + * @brief A container for a generic Object Model derived from some Base. + */ +template +class ObjectModelBase : public Base +{ + public: + /** + * Constructor. + * @param parent is the parent object for this instance. + */ + explicit ObjectModelBase(QObject *parent) : Base(parent) + { + } + + /** + * Returns the number of columns in the specified model (currently this is + * always 2). + * @param parent is the model QModelIndex. + * @return the column count for specified model. + */ + int columnCount(const QModelIndex &parent = QModelIndex()) const + { + Q_UNUSED(parent); + return 2; + } + + /** + * Returns the data for the specified object. + * @param object is a pointer to a QObject. + * @param index is the model QModelIndex. + * @param role is the Qt role. + * + * @return on success, a QVariant containing the data for the specified QObject; + * QVariant() if some anamoly occurs. + */ + QVariant dataForObject(QObject *object, const QModelIndex &index, int role) const + { + if (role == Qt::DisplayRole) { + if (index.column() == 0) { + return + object->objectName().isEmpty() ? + Util::addressToString(object) : + object->objectName(); + } else if (index.column() == 1) { + return object->metaObject()->className(); + } + } else if (role == ObjectModel::ObjectRole) { + return QVariant::fromValue(object); + } else if (role == Qt::ToolTipRole) { + return + QObject::tr("Object name: %1\nType: %2\nParent: %3 (Address: %4)\nNumber of children: %5"). + arg(object->objectName().isEmpty() ? "" : object->objectName()). + arg(object->metaObject()->className()). + arg(object->parent() ? object->parent()->metaObject()->className() : ""). + arg(Util::addressToString(object->parent())). + arg(object->children().size()); + } else if (role == Qt::DecorationRole && index.column() == 0) { + return Util::iconForObject(object); + } + + return QVariant(); + } + + /** + * Returns the header data for the Object, given a section (column), + * orientation and role. + * @param section an integer (either 0 or 1) corresponding to the section (column). + * @param orientation is the Qt::Orientation. + * @param role is the Qt role. + * + * @return on success, a QVariant containing the header data; + * QVariant() if some anamoly occurs. + * + */ + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const + { + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QObject::tr("Object"); + case 1: + return QObject::tr("Type"); + } + } + return Base::headerData(section, orientation, role); + } +}; + +} + +#endif diff -Nru gammaray-1.2.2/core/objectpropertymodel.cpp gammaray-2.0.1/core/objectpropertymodel.cpp --- gammaray-1.2.2/core/objectpropertymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectpropertymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -39,12 +39,14 @@ void ObjectPropertyModel::setObject(QObject *object) { if (m_obj) { + unmonitorObject(m_obj.data()); disconnect(m_obj.data(), 0, this, SLOT(updateAll())); disconnect(m_obj.data(), 0, this, SLOT(slotReset())); } m_obj = object; if (object) { connect(object, SIGNAL(destroyed(QObject*)), SLOT(slotReset())); + monitorObject(object); for (int i = 0; i < object->metaObject()->propertyCount(); ++i) { const QMetaProperty prop = object->metaObject()->property(i); if (prop.hasNotifySignal()) { @@ -91,4 +93,3 @@ emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } -#include "objectpropertymodel.moc" diff -Nru gammaray-1.2.2/core/objectpropertymodel.h gammaray-2.0.1/core/objectpropertymodel.h --- gammaray-1.2.2/core/objectpropertymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectpropertymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -41,11 +41,18 @@ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; protected: + /** Reimplement to set up watching property change notifications. */ + // TODO make these pure virtual once property signal handling is moved to the static property model + virtual void monitorObject(QObject* obj) { Q_UNUSED(obj); }; + virtual void unmonitorObject(QObject* obj) { Q_UNUSED(obj); }; + QPointer m_obj; + protected slots: + void updateAll(); + private slots: void slotReset() { reset(); } - void updateAll(); void doEmitChanged(); private: diff -Nru gammaray-1.2.2/core/objectstaticpropertymodel.cpp gammaray-2.0.1/core/objectstaticpropertymodel.cpp --- gammaray-1.2.2/core/objectstaticpropertymodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectstaticpropertymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,8 +22,8 @@ */ #include "objectstaticpropertymodel.h" - -#include "include/util.h" +#include "varianthandler.h" +#include "util.h" #include @@ -58,7 +58,7 @@ if (!enumStr.isEmpty()) { return enumStr; } - return Util::variantToString(value); + return VariantHandler::displayString(value); } else if (index.column() == 2) { return prop.typeName(); } else if (index.column() == 3) { @@ -70,7 +70,7 @@ } } else if (role == Qt::DecorationRole) { if (index.column() == 1) { - return Util::decorationForVariant(prop.read(m_obj.data())); + return VariantHandler::decoration(prop.read(m_obj.data())); } } else if (role == Qt::EditRole) { if (index.column() == 1) { @@ -100,7 +100,11 @@ if (index.isValid() && m_obj && index.column() == 1 && index.row() >= 0 && index.row() < m_obj.data()->metaObject()->propertyCount() && role == Qt::EditRole) { const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row()); - return prop.write(m_obj.data(), value); + const bool result = prop.write(m_obj.data(), value); + if (result) { + emit dataChanged(index, index); + } + return result; } return ObjectPropertyModel::setData(index, value, role); } @@ -137,4 +141,3 @@ return flags; } -#include "objectstaticpropertymodel.moc" diff -Nru gammaray-1.2.2/core/objectstaticpropertymodel.h gammaray-2.0.1/core/objectstaticpropertymodel.h --- gammaray-1.2.2/core/objectstaticpropertymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objectstaticpropertymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/objecttreemodel.cpp gammaray-2.0.1/core/objecttreemodel.cpp --- gammaray-1.2.2/core/objecttreemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objecttreemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -45,19 +45,26 @@ this, SLOT(objectAdded(QObject*))); connect(probe, SIGNAL(objectDestroyed(QObject*)), this, SLOT(objectRemoved(QObject*))); - connect(probe, SIGNAL(objectReparanted(QObject*)), - this, SLOT(objectReparanted(QObject*))); + connect(probe, SIGNAL(objectReparented(QObject*)), + this, SLOT(objectReparented(QObject*))); } -static QObject* parentObject(QObject *obj) +static QObject *parentObject(QObject *obj) { - if (obj->parent()) + if (obj->parent()) { return obj->parent(); + } + // FIXME: this is still valid, but way too unstable since we miss reparentings + // so for now rather live with the wrong hierarchy than crashes/asserts +#if 0 // QQuickItem does very ugly things with its parent, so we have to try harder to get hold of it... if (obj->inherits("QQuickItem")) { - return obj->property("parent").value(); + QObject *p = obj->property("parent").value(); + if (Probe::instance()->isValidObject(p)) + return p; } +#endif return 0; } @@ -99,10 +106,12 @@ Q_ASSERT(index.isValid() || !parentObject(obj)); QVector &children = m_parentChildMap[ parentObject(obj) ]; + QVector::iterator it = std::lower_bound(children.begin(), children.end(), obj); + const int row = std::distance(children.begin(), it); - beginInsertRows(index, children.size(), children.size()); + beginInsertRows(index, row, row); - children.push_back(obj); + children.insert(it, obj); m_childParentMap.insert(obj, parentObject(obj)); endInsertRows(); @@ -133,22 +142,22 @@ QVector &siblings = m_parentChildMap[ parentObj ]; - int index = siblings.indexOf(obj); - - if (index == -1) { + QVector::iterator it = std::lower_bound(siblings.begin(), siblings.end(), obj); + if (it == siblings.end() || *it != obj) { return; } + const int row = std::distance(siblings.begin(), it); - beginRemoveRows(parentIndex, index, index); + beginRemoveRows(parentIndex, row, row); - siblings.remove(index); + siblings.erase(it); m_childParentMap.remove(obj); m_parentChildMap.remove(obj); endRemoveRows(); } -void ObjectTreeModel::objectReparanted(QObject *obj) +void ObjectTreeModel::objectReparented(QObject *obj) { // slot, hence should always land in main thread due to auto connection Q_ASSERT(thread() == QThread::currentThread()); @@ -218,11 +227,13 @@ if (!parentIndex.isValid() && parent) { return QModelIndex(); } - int row = m_parentChildMap[ parent ].indexOf(object); - if (row < 0) { + const QVector &siblings = m_parentChildMap[ parent ]; + QVector::const_iterator it = std::lower_bound(siblings.constBegin(), siblings.constEnd(), object); + if (it == siblings.constEnd() || *it != object) { return QModelIndex(); } + + const int row = std::distance(siblings.constBegin(), it); return index(row, 0, parentIndex); } -#include "objecttreemodel.moc" diff -Nru gammaray-1.2.2/core/objecttreemodel.h gammaray-2.0.1/core/objecttreemodel.h --- gammaray-1.2.2/core/objecttreemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/objecttreemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #ifndef GAMMARAY_OBJECTTREEMODEL_H #define GAMMARAY_OBJECTTREEMODEL_H -#include "include/objectmodelbase.h" +#include "objectmodelbase.h" #include @@ -46,7 +46,7 @@ private slots: void objectAdded(QObject *obj); void objectRemoved(QObject *obj); - void objectReparanted(QObject *obj); + void objectReparented(QObject *obj); private: QModelIndex indexForObject(QObject *object) const; diff -Nru gammaray-1.2.2/core/objecttypefilterproxymodel.h gammaray-2.0.1/core/objecttypefilterproxymodel.h --- gammaray-1.2.2/core/objecttypefilterproxymodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/objecttypefilterproxymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,115 @@ +/* + objecttypefilterproxymodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares a template + for an ObjectTypeFilterProxyModel class. + + @brief + Declares a template for an ObjectTypeFilterProxyModel class. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H +#define GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H + +#include "objectmodelbase.h" + +#include + +namespace GammaRay { + +/** + * @brief A QSortFilterProxyModel for generic Objects. + */ +class ObjectFilterProxyModelBase : public QSortFilterProxyModel +{ + public: + /** + * Constructor. + * @param parent is the parent object for this instance. + */ + explicit ObjectFilterProxyModelBase(QObject *parent = 0) : QSortFilterProxyModel(parent) + { + setDynamicSortFilter(true); + } + + protected: + /** + * Determines if the item in the specified row can be included in the model. + * @param source_row is a non-zero integer representing the row of the item. + * @param source_parent is the parent QModelIndex for this model. + * @return true if the item in the row can be included in the model; + * otherwise returns false. + */ + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const + { + const QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent); + if (!source_index.isValid()) { + return false; + } + + QObject *obj = source_index.data(ObjectModel::ObjectRole).value(); + Q_ASSERT(obj); + if (!filterAcceptsObject(obj)) { + return false; + } + + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); + } + + /** + * Determines if the specified QObject can be included in the model. + * @param object is a pointer to the QObject to test. + * @return true if the QObject can be included in the model; false otherwise. + */ + virtual bool filterAcceptsObject(QObject *object) const = 0; +}; + +/** + * @brief A templated generic ObjectFilterProxyModelBase for some data type. + */ +template +class ObjectTypeFilterProxyModel : public ObjectFilterProxyModelBase +{ + public: + /** + * Constructor. + * @param parent is the parent object for this instance. + */ + explicit ObjectTypeFilterProxyModel(QObject *parent = 0) + : ObjectFilterProxyModelBase(parent) + { + } + + protected: + virtual bool filterAcceptsObject(QObject *object) const + { + return qobject_cast(object); + } +}; + +} + +#endif // GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H diff -Nru gammaray-1.2.2/core/paintbuffermodel.cpp gammaray-2.0.1/core/paintbuffermodel.cpp --- gammaray-1.2.2/core/paintbuffermodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbuffermodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,172 +0,0 @@ -/* - paintbuffermodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "config-gammaray.h" -#ifdef HAVE_PRIVATE_QT_HEADERS -#include "paintbuffermodel.h" - -using namespace GammaRay; - -struct cmd_t { - QPaintBufferPrivate::Command cmd; - const char *name; -}; - -#define CMD(cmd) { QPaintBufferPrivate::Cmd_ ## cmd, #cmd } - -static cmd_t cmdTypes[] = { - CMD(Save), - CMD(Restore), - CMD(SetBrush), - CMD(SetBrushOrigin), - CMD(SetClipEnabled), - CMD(SetCompositionMode), - CMD(SetOpacity), - CMD(SetPen), - CMD(SetRenderHints), - CMD(SetTransform), - CMD(SetBackgroundMode), - CMD(ClipPath), - CMD(ClipRect), - CMD(ClipRegion), - CMD(ClipVectorPath), - CMD(DrawVectorPath), - CMD(FillVectorPath), - CMD(StrokeVectorPath), - CMD(DrawConvexPolygonF), - CMD(DrawConvexPolygonI), - CMD(DrawEllipseF), - CMD(DrawEllipseI), - CMD(DrawLineF), - CMD(DrawLineI), - CMD(DrawPath), - CMD(DrawPointsF), - CMD(DrawPointsI), - CMD(DrawPolygonF), - CMD(DrawPolygonI), - CMD(DrawPolylineF), - CMD(DrawPolylineI), - CMD(DrawRectF), - CMD(DrawRectI), - CMD(FillRectBrush), - CMD(FillRectColor), - CMD(DrawText), - CMD(DrawTextItem), - CMD(DrawImagePos), - CMD(DrawImageRect), - CMD(DrawPixmapPos), - CMD(DrawPixmapRect), - CMD(DrawTiledPixmap), - CMD(SystemStateChanged), - CMD(Translate), - CMD(DrawStaticText) -}; - -class PaintBufferPrivacyViolater : public QPainterReplayer -{ - public: - QPaintBufferPrivate *extract() const { return d; } -}; - -PaintBufferModel::PaintBufferModel(QObject *parent) - : QAbstractTableModel(parent), m_privateBuffer(0) -{ -} - -void PaintBufferModel::setPaintBuffer(const QPaintBuffer &buffer) -{ - beginResetModel(); - m_buffer = buffer; - PaintBufferPrivacyViolater p; - p.processCommands(buffer, 0, 0, -1); // end < begin -> no processing - m_privateBuffer = p.extract(); - endResetModel(); -} - -QVariant PaintBufferModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || !m_privateBuffer) { - return QVariant(); - } - - if (role == Qt::DisplayRole) { - const QPaintBufferCommand cmd = m_privateBuffer->commands.at(index.row()); - switch (index.column()) { - case 0: - return cmdTypes[cmd.id].name; - case 1: - { -#ifndef QT_NO_DEBUG_STREAM - QString desc = m_buffer.commandDescription(index.row()); - const QString prefix = QLatin1String("Cmd_") + QLatin1String(cmdTypes[cmd.id].name); - - if (desc.startsWith(prefix)) { - desc = desc.mid(prefix.length()); - } - - if (desc.startsWith(QLatin1String(": ")) || desc.startsWith(QLatin1String(", "))) { - desc = desc.mid(2); - } - return desc; -#endif - } - } - } - - return QVariant(); -} - -int PaintBufferModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); -#ifndef QT_NO_DEBUG_STREAM - return 2; -#else - return 1; -#endif -} - -int PaintBufferModel::rowCount(const QModelIndex &parent) const -{ - if (!m_privateBuffer || parent.isValid()) { - return 0; - } - return m_privateBuffer->commands.size(); -} - -QVariant PaintBufferModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Command"); - case 1: - return tr("Arguments"); - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -#include "paintbuffermodel.moc" - -#endif diff -Nru gammaray-1.2.2/core/paintbuffermodel.h gammaray-2.0.1/core/paintbuffermodel.h --- gammaray-1.2.2/core/paintbuffermodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbuffermodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - paintbuffermodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PAINTBUFFERMODEL_H -#define GAMMARAY_PAINTBUFFERMODEL_H - -#include "config-gammaray.h" - -#ifdef HAVE_PRIVATE_QT_HEADERS -#include - -#include //krazy:exclude=camelcase - -class QPaintBuffer; - -namespace GammaRay { - -/** - * Model that shows commands stored in a QPaintBuffer. - */ -class PaintBufferModel : public QAbstractTableModel -{ - Q_OBJECT - public: - explicit PaintBufferModel(QObject *parent = 0); - - void setPaintBuffer(const QPaintBuffer &buffer); - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - private: - QPaintBuffer m_buffer; - QPaintBufferPrivate *m_privateBuffer; -}; - -} - -#endif - -#endif // GAMMARAY_PAINTBUFFERMODEL_H diff -Nru gammaray-1.2.2/core/paintbufferreplaywidget.cpp gammaray-2.0.1/core/paintbufferreplaywidget.cpp --- gammaray-1.2.2/core/paintbufferreplaywidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbufferreplaywidget.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,99 +0,0 @@ -/* - paintbufferreplaywidget.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "paintbufferreplaywidget.h" - -#ifdef HAVE_PRIVATE_QT_HEADERS -using namespace GammaRay; - -PaintBufferReplayWidget::PaintBufferReplayWidget(QWidget *parent) - : QWidget(parent), - m_endCommandIndex(0), - m_zoomFactor(1) -{ - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); -} - -void PaintBufferReplayWidget::setPaintBuffer(const QPaintBuffer &buffer) -{ - m_buffer = buffer; - update(); -} - -void PaintBufferReplayWidget::setEndCommandIndex(int index) -{ - m_endCommandIndex = index; - update(); -} - -void PaintBufferReplayWidget::setZoomFactor(int zoom) -{ - m_zoomFactor = zoom; - resize(sizeHint()); -} - -QSize PaintBufferReplayWidget::sizeHint() const -{ - const QSize s = m_buffer.boundingRect().size().toSize(); - return QSize(s.width() * m_zoomFactor, s.height() * m_zoomFactor); -} - -// TODO: factor out into util namespace, similar code exists in the style tool -void PaintBufferReplayWidget::drawTransparencyPattern(QPainter *painter, - const QRect &rect, - int squareSize) -{ - QPixmap bgPattern(2 * squareSize, 2 * squareSize); - bgPattern.fill(Qt::lightGray); - QPainter bgPainter(&bgPattern); - bgPainter.fillRect(squareSize, 0, squareSize, squareSize, Qt::gray); - bgPainter.fillRect(0, squareSize, squareSize, squareSize, Qt::gray); - - QBrush bgBrush; - bgBrush.setTexture(bgPattern); - painter->fillRect(rect, bgBrush); -} - -void PaintBufferReplayWidget::paintEvent(QPaintEvent *event) -{ - // didn't manage painting on the widget directly, even with the correct - // translation it is always clipping as if the widget was at 0,0 of its parent - const QSize sourceSize = m_buffer.boundingRect().size().toSize(); - QImage img(sourceSize, QImage::Format_ARGB32); - QPainter imgPainter(&img); - drawTransparencyPattern(&imgPainter, QRect(QPoint(0, 0), sourceSize)); - int depth = m_buffer.processCommands(&imgPainter, m_buffer.frameStartIndex(0), - m_buffer.frameStartIndex(0) + m_endCommandIndex); - for (; depth > 0; --depth) { - imgPainter.restore(); - } - imgPainter.end(); - - QPainter p(this); - p.setRenderHint(QPainter::SmoothPixmapTransform, false); - p.drawImage(QRect(QPoint(0, 0), sizeHint()), img); -} - -#include "paintbufferreplaywidget.moc" - -#endif diff -Nru gammaray-1.2.2/core/paintbufferreplaywidget.h gammaray-2.0.1/core/paintbufferreplaywidget.h --- gammaray-1.2.2/core/paintbufferreplaywidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbufferreplaywidget.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - paintbufferreplaywidget.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PAINTBUFFERREPLAYWIDGET_H -#define GAMMARAY_PAINTBUFFERREPLAYWIDGET_H - -#include "config-gammaray.h" - -#ifdef HAVE_PRIVATE_QT_HEADERS -#include - -#include //krazy:exclude=camelcase - -namespace GammaRay { - -/** - * A widget painting a certain sub-set of a QPaintBuffer. - */ -class PaintBufferReplayWidget : public QWidget -{ - Q_OBJECT - public: - explicit PaintBufferReplayWidget(QWidget *parent = 0); - - void setPaintBuffer(const QPaintBuffer &buffer); - void setEndCommandIndex(int index); - void setZoomFactor(int zoom); - - virtual QSize sizeHint() const; - - protected: - virtual void paintEvent(QPaintEvent *event); - - private: - static void drawTransparencyPattern(QPainter *painter, const QRect &rect, int squareSize = 16); - - private: - QPaintBuffer m_buffer; - int m_endCommandIndex; - int m_zoomFactor; -}; - -} - -#endif - -#endif // GAMMARAY_PAINTBUFFERREPLAYWIDGET_H diff -Nru gammaray-1.2.2/core/paintbufferviewer.cpp gammaray-2.0.1/core/paintbufferviewer.cpp --- gammaray-1.2.2/core/paintbufferviewer.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbufferviewer.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -/* - paintbufferviewer.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "paintbufferviewer.h" - -#ifdef HAVE_PRIVATE_QT_HEADERS -#include "ui_paintbufferviewer.h" - -#include "paintbuffermodel.h" - -using namespace GammaRay; - -PaintBufferViewer::PaintBufferViewer(QWidget *parent) - : QWidget(parent), - ui(new Ui::PaintBufferViewer), - m_bufferModel(new PaintBufferModel(this)) -{ - ui->setupUi(this); - - ui->commandView->setModel(m_bufferModel); - connect(ui->commandView->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(commandSelected())); - - ui->splitter->setStretchFactor(0, 0); - ui->splitter->setStretchFactor(1, 1); - - connect(ui->zoomSlider, SIGNAL(valueChanged(int)), SLOT(zoomChanged(int))); -} - -PaintBufferViewer::~PaintBufferViewer() -{ -} - -void PaintBufferViewer::setPaintBuffer(const QPaintBuffer &buffer) -{ - m_buffer = buffer; - m_bufferModel->setPaintBuffer(buffer); - ui->replayWidget->setPaintBuffer(buffer); - commandSelected(); -} - -void PaintBufferViewer::commandSelected() -{ - if (!ui->commandView->selectionModel()->hasSelection()) { - ui->replayWidget->setEndCommandIndex(m_bufferModel->rowCount()); - return; - } - - const QModelIndex index = ui->commandView->selectionModel()->selectedRows().first(); - ui->replayWidget->setEndCommandIndex(index.row() + 1); // include the current row -} - -void PaintBufferViewer::zoomChanged(int value) -{ - ui->replayWidget->setZoomFactor(value); -} - -#include "paintbufferviewer.moc" -#endif diff -Nru gammaray-1.2.2/core/paintbufferviewer.h gammaray-2.0.1/core/paintbufferviewer.h --- gammaray-1.2.2/core/paintbufferviewer.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbufferviewer.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,69 +0,0 @@ -/* - paintbufferviewer.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PAINTBUFFERVIEWER_H -#define GAMMARAY_PAINTBUFFERVIEWER_H - -#include "config-gammaray.h" - -#ifdef HAVE_PRIVATE_QT_HEADERS - -#include //krazy:exclude=camelcase - -#include - -namespace GammaRay { - -class PaintBufferModel; - -namespace Ui { - class PaintBufferViewer; -} - -/** - * A widget to look at the command list in a QPaintBuffer. - */ -class PaintBufferViewer : public QWidget -{ - Q_OBJECT - public: - explicit PaintBufferViewer(QWidget *parent = 0); - virtual ~PaintBufferViewer(); - - void setPaintBuffer(const QPaintBuffer &buffer); - - private slots: - void commandSelected(); - void zoomChanged(int value); - - private: - QScopedPointer ui; - QPaintBuffer m_buffer; - PaintBufferModel *m_bufferModel; -}; - -} - -#endif - -#endif // GAMMARAY_PAINTBUFFERVIEWER_H diff -Nru gammaray-1.2.2/core/paintbufferviewer.ui gammaray-2.0.1/core/paintbufferviewer.ui --- gammaray-1.2.2/core/paintbufferviewer.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/paintbufferviewer.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,108 +0,0 @@ - - - GammaRay::PaintBufferViewer - - - - 0 - 0 - 591 - 378 - - - - - 0 - - - - - Qt::Horizontal - - - - false - - - - - - - - - - &Zoom: - - - zoomSlider - - - - - - - 1 - - - 8 - - - 1 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - true - - - Qt::AlignCenter - - - - - 0 - 0 - 227 - 341 - - - - - - - - - - - - - - GammaRay::PaintBufferReplayWidget - QWidget -
paintbufferreplaywidget.h
- 1 -
-
- - -
diff -Nru gammaray-1.2.2/core/palettemodel.cpp gammaray-2.0.1/core/palettemodel.cpp --- gammaray-1.2.2/core/palettemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/palettemodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,177 +0,0 @@ -/* - palettemodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010 Ariya Hidayat - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "palettemodel.h" - -#include -#include - -using namespace GammaRay; - -struct role_t { - const char *name; - QPalette::ColorRole role; -}; - -static role_t paletteRoles[] = { - { "Window", QPalette::Window }, - { "WindowText", QPalette::WindowText }, - { "Base", QPalette::Base }, - { "AlternateBase", QPalette::AlternateBase }, - { "Text", QPalette::Text }, - { "ToolTipBase", QPalette::ToolTipBase }, - { "ToolTipText", QPalette::ToolTipText }, - { "Button", QPalette::Button }, - { "ButtonText", QPalette::ButtonText }, - { "BrightText", QPalette::BrightText }, - { "Light", QPalette::Light }, - { "Midlight", QPalette::Midlight }, - { "Dark", QPalette::Dark }, - { "Mid", QPalette::Mid }, - { "Shadow", QPalette::Shadow }, - { "Highlight", QPalette::Highlight }, - { "HighlightedText", QPalette::HighlightedText }, - { "Link", QPalette::Link }, - { "LinkVisited", QPalette::LinkVisited } -}; - -struct group_t { - const char *name; - QPalette::ColorGroup group; -}; - -static group_t paletteGroups[] = { - { "Active", QPalette::Active }, - { "Inactive", QPalette::Inactive }, - { "Disabled", QPalette::Disabled }, -}; - -PaletteModel::PaletteModel(QObject *parent) - : QAbstractTableModel(parent), m_editable(false) -{ -} - -QPalette PaletteModel::palette() const -{ - return m_palette; -} - -void PaletteModel::setPalette(const QPalette &palette) -{ - beginResetModel(); - m_palette = palette; - endResetModel(); -} - -void PaletteModel::setEditable(bool editable) -{ - m_editable = editable; -} - -QVariant PaletteModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - - if (role == Qt::DisplayRole) { - if (index.column() == 0) { - return paletteRoles[index.row()].name; - } - - return - m_palette.color(paletteGroups[index.column()-1].group, - paletteRoles[index.row()].role).name(); - - } else if (role == Qt::EditRole) { - // TODO return QBrush once we have an editor for that - return - m_palette.color(paletteGroups[index.column()-1].group, - paletteRoles[index.row()].role); - } else if (role == Qt::DecorationRole && index.column() != 0) { - const QBrush brush = m_palette.brush(paletteGroups[index.column()-1].group, - paletteRoles[index.row()].role); - QPixmap pixmap(32, 32); - QPainter painter(&pixmap); - painter.fillRect(pixmap.rect(), Qt::black); - painter.fillRect(pixmap.rect().adjusted(1, 1, -1, -1), brush); - return QIcon(pixmap); - } - - return QVariant(); -} - -bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (!m_editable) { - return false; - } - - if (index.isValid() && role == Qt::EditRole) { - if (value.type() == QVariant::Color) { - m_palette.setColor(paletteGroups[index.column()-1].group, - paletteRoles[index.row()].role, value.value()); - } else if (value.type() == QVariant::Brush) { - m_palette.setBrush(paletteGroups[index.column()-1].group, - paletteRoles[index.row()].role, value.value()); - } - } - return QAbstractItemModel::setData(index, value, role); -} - -int PaletteModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 1 + sizeof(paletteGroups) / sizeof(paletteGroups[0]); -} - -int PaletteModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - return sizeof(paletteRoles) / sizeof(paletteRoles[0]); -} - -QVariant PaletteModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - if (section == 0) { - return tr("Role"); - } - return paletteGroups[section-1].name; - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -Qt::ItemFlags PaletteModel::flags(const QModelIndex &index) const -{ - const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); - if (m_editable && index.column() > 0) { - return baseFlags | Qt::ItemIsEditable; - } - return baseFlags; -} - -#include "palettemodel.moc" diff -Nru gammaray-1.2.2/core/palettemodel.h gammaray-2.0.1/core/palettemodel.h --- gammaray-1.2.2/core/palettemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/palettemodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -/* - palettemodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PALETTEMODEL_H -#define GAMMARAY_PALETTEMODEL_H - -#include -#include - -namespace GammaRay { - -/** - * Model showing the content of a QPalette. - */ -class PaletteModel : public QAbstractTableModel -{ - Q_OBJECT - public: - explicit PaletteModel(QObject *parent = 0); - - QPalette palette() const; - void setPalette(const QPalette &palette); - void setEditable(bool editable); - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - - private: - QPalette m_palette; - bool m_editable; -}; - -} - -#endif // GAMMARAY_PALETTEMODEL_H diff -Nru gammaray-1.2.2/core/pluginmanager.cpp gammaray-2.0.1/core/pluginmanager.cpp --- gammaray-1.2.2/core/pluginmanager.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/pluginmanager.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - pluginmanager.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "pluginmanager.h" - -#include "config-gammaray.h" -#include "proxytoolfactory.h" - -#include -#include -#include -#include -#include -#include - -#include - -#define IF_DEBUG(x) - -using namespace GammaRay; -using namespace std; - -static const QLatin1String GAMMARAY_PLUGIN_SUFFIX("gammaray"); -PluginManager *PluginManager::s_instance = 0; - -PluginManager *PluginManager::instance() -{ - if (!s_instance) { - s_instance = new PluginManager(); - s_instance->scan(); - } - return s_instance; -} - -PluginManager::PluginManager() -{ - QCoreApplication::addLibraryPath(QLatin1String(GAMMARAY_PLUGIN_INSTALL_DIR)); -} - -QStringList PluginManager::pluginPaths() const -{ - QStringList pluginPaths; - - // add plugins from gammaray's build directory - pluginPaths << QLatin1String(GAMMARAY_BUILD_DIR) + - QDir::separator() + "lib" + - QDir::separator() + "plugins" + - QDir::separator() + GAMMARAY_PLUGIN_SUFFIX; - - QStringList libraryPaths = QCoreApplication::libraryPaths(); - foreach (const QString &libraryPath, libraryPaths) { - pluginPaths << libraryPath + QDir::separator() + GAMMARAY_PLUGIN_SUFFIX; - } - - return pluginPaths; -} - -void PluginManager::scan() -{ - m_errors.clear(); - QStringList loadedPluginNames; - - foreach (const QString &pluginPath, pluginPaths()) { - const QDir dir(pluginPath); - IF_DEBUG(cout << "checking plugin path: " << qPrintable(dir.absolutePath()) << endl); - foreach (const QString &plugin, dir.entryList(QDir::Files)) { - const QString pluginFile = dir.absoluteFilePath(plugin); - const QFileInfo pluginInfo(pluginFile); - const QString pluginName = pluginInfo.baseName(); - - if (loadedPluginNames.contains(pluginName)) { - cout << "not loading plugin, already loaded: " << qPrintable(pluginFile) << endl; - continue; - } - - if (pluginInfo.suffix() == QLatin1String("desktop")) { - ProxyToolFactory *proxy = new ProxyToolFactory(pluginFile); - if (!proxy->isValid()) { - m_errors << PluginLoadError(pluginFile, QObject::tr("Failed to load plugin.")); - std::cerr << "invalid plugin " << qPrintable(pluginFile) << std::endl; - delete proxy; - } else { - IF_DEBUG(cout << "plugin looks valid " << qPrintable(pluginFile) << endl;) - m_plugins.push_back(proxy); - loadedPluginNames << pluginName; - } - } - } - } -} - -QVector PluginManager::plugins() -{ - return m_plugins; -} diff -Nru gammaray-1.2.2/core/pluginmanager.h gammaray-2.0.1/core/pluginmanager.h --- gammaray-1.2.2/core/pluginmanager.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/pluginmanager.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -/* - pluginmanager.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PLUGINMANAGER_H -#define GAMMARAY_PLUGINMANAGER_H - -#include -#include -#include - -namespace GammaRay { - -class ToolFactory; -class PluginLoadError; - -typedef QList PluginLoadErrors; - -class PluginLoadError -{ - public: - PluginLoadError(QString _pluginFile, QString _errorString) - : pluginFile(_pluginFile), errorString(_errorString) {} - - QString pluginName() const { return QFileInfo(pluginFile).baseName(); } - - public: - QString pluginFile; - QString errorString; -}; - -class PluginManager -{ - public: - static PluginManager *instance(); - - QVector plugins(); - - QList errors() { return m_errors; } - - protected: - PluginManager(); - - private: - QStringList pluginPaths() const; - void scan(); - - static PluginManager *s_instance; - QVector m_plugins; - QList m_errors; -}; - -} - -#endif // GAMMARAY_PLUGINMANAGER_H diff -Nru gammaray-1.2.2/core/probecontroller.cpp gammaray-2.0.1/core/probecontroller.cpp --- gammaray-1.2.2/core/probecontroller.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/probecontroller.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + probecontroller.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "probecontroller.h" +#include "probe.h" + +#include + +using namespace GammaRay; + +ProbeController::ProbeController(QObject* parent): QObject(parent) +{ +} + +void ProbeController::detachProbe() +{ + Probe::instance()->deleteLater(); +} + +void ProbeController::quitHost() +{ + QCoreApplication::instance()->quit(); +} + diff -Nru gammaray-1.2.2/core/probecontroller.h gammaray-2.0.1/core/probecontroller.h --- gammaray-1.2.2/core/probecontroller.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/probecontroller.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,45 @@ +/* + probecontroller.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROBECONTROLLER_H +#define GAMMARAY_PROBECONTROLLER_H + +#include + +namespace GammaRay { + +class ProbeController : public QObject, public ProbeControllerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ProbeControllerInterface) +public: + explicit ProbeController(QObject *parent = 0); + +public slots: + void detachProbe(); + void quitHost(); +}; + +} + +#endif // GAMMARAY_PROBECONTROLLER_H diff -Nru gammaray-1.2.2/core/probe.cpp gammaray-2.0.1/core/probe.cpp --- gammaray-1.2.2/core/probe.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/probe.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause Author: Stephen Kelly @@ -24,20 +24,33 @@ //krazy:excludeall=null,captruefalse,staticobjects #include "probe.h" -#include "mainwindow.h" #include "objectlistmodel.h" #include "objecttreemodel.h" +#include "metaobjecttreemodel.h" #include "connectionmodel.h" #include "toolmodel.h" #include "readorwritelocker.h" - -#include "hooking/functionoverwriterfactory.h" +#include "probesettings.h" +#include "probecontroller.h" +#include "toolpluginmodel.h" #include "tools/modelinspector/modeltest.h" +#include "remote/server.h" +#include "remote/remotemodelserver.h" +#include "remote/selectionmodelserver.h" +#include "toolpluginerrormodel.h" + +#include +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include +#endif #include -#include +#include +#include #include #include #include @@ -45,34 +58,17 @@ #include #include -#ifndef Q_OS_WIN -#include -#else -#include -#endif - -#include - -#ifdef Q_OS_MAC -#include -#include -#include -#include -#include -#endif - #define IF_DEBUG(x) using namespace GammaRay; using namespace std; -Probe *Probe::s_instance = 0; -bool functionsOverwritten = false; - -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) +QAtomicPointer Probe::s_instance = QAtomicPointer(0); namespace GammaRay { +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) + static bool probeConnectCallback(void ** args) { QObject *sender = reinterpret_cast(args[0]); @@ -94,9 +90,15 @@ return false; } -} #endif // QT_VERSION +static QItemSelectionModel* selectionModelFactory(QAbstractItemModel* model) +{ + return new SelectionModelServer(model->objectName() + ".selection", model, Probe::instance()); +} + +} + // useful for debugging, dumps the object and all it's parents // also useable from GDB! void dumpObject(QObject *obj) @@ -119,16 +121,17 @@ struct Listener { Listener() - : filterThread(0), - trackDestroyed(true) - {} + : filterThread(0), trackDestroyed(true) + { + } QThread *filterThread; bool trackDestroyed; + + QVector addedBeforeProbeInstance; }; Q_GLOBAL_STATIC(Listener, s_listener) -Q_GLOBAL_STATIC(QVector, s_addedBeforeProbeInsertion) // ensures proper information is returned by isValidObject by // locking it in objectAdded/Removed @@ -137,73 +140,46 @@ public: ObjectLock() : QReadWriteLock(QReadWriteLock::Recursive) - {} + { + } }; Q_GLOBAL_STATIC(ObjectLock, s_lock) -ProbeCreator::ProbeCreator(Type type) - : m_type(type) -{ - //push object into the main thread, as windows creates a - //different thread where this runs in - moveToThread(QApplication::instance()->thread()); - // delay to foreground thread - QMetaObject::invokeMethod(this, "createProbe", Qt::QueuedConnection); -} - -void ProbeCreator::createProbe() -{ - QWriteLocker lock(s_lock()); - // make sure we are in the ui thread - Q_ASSERT(QThread::currentThread() == qApp->thread()); - - if (!qApp || Probe::isInitialized()) { - // never create it twice - return; - } - - // Exit early instead of asserting in QWidgetPrivate::init() - const QApplication * const qGuiApplication = qApp; // qobject_cast(qApp); - if (!qGuiApplication || qGuiApplication->type() == QApplication::Tty) { - cerr << "Unable to attach to a non-GUI application.\n" - << "Your application needs to use QApplication, " - << "otherwise GammaRay can not work." << endl; - return; - } - - IF_DEBUG(cout << "setting up new probe instance" << endl;) - s_listener()->filterThread = QThread::currentThread(); - Q_ASSERT(!Probe::s_instance); - Probe::s_instance = new Probe; - s_listener()->filterThread = 0; - IF_DEBUG(cout << "done setting up new probe instance" << endl;) - - Q_ASSERT(Probe::instance()); - QMetaObject::invokeMethod(Probe::instance(), "delayedInit", Qt::QueuedConnection); - foreach (QObject *obj, *(s_addedBeforeProbeInsertion())) { - Probe::objectAdded(obj); - } - s_addedBeforeProbeInsertion()->clear(); - - if (m_type == CreateAndFindExisting) { - Probe::findExistingObjects(); - } - - deleteLater(); -} Probe::Probe(QObject *parent): QObject(parent), m_objectListModel(new ObjectListModel(this)), m_objectTreeModel(new ObjectTreeModel(this)), + m_metaObjectTreeModel(new MetaObjectTreeModel(this)), m_connectionModel(new ConnectionModel(this)), - m_toolModel(new ToolModel(this)), + m_toolModel(0), m_window(0), m_queueTimer(new QTimer(this)) { Q_ASSERT(thread() == qApp->thread()); IF_DEBUG(cout << "attaching GammaRay probe" << endl;) + ProbeSettings::receiveSettings(); + m_toolModel = new ToolModel(this); + + Server *server = new Server(this); + ProbeSettings::sendPort(server->port()); + + StreamOperators::registerOperators(); + ObjectBroker::setSelectionModelFactoryCallback(selectionModelFactory); + ObjectBroker::registerObject(new ProbeController(this)); + + registerModel(QLatin1String("com.kdab.GammaRay.ObjectTree"), m_objectTreeModel); + registerModel(QLatin1String("com.kdab.GammaRay.ObjectList"), m_objectListModel); + registerModel(QLatin1String("com.kdab.GammaRay.MetaObjectModel"), m_metaObjectTreeModel); + registerModel(QLatin1String("com.kdab.GammaRay.ToolModel"), m_toolModel); + registerModel(QLatin1String("com.kdab.GammaRay.ConnectionModel"), m_connectionModel); + + ToolPluginModel *toolPluginModel = new ToolPluginModel(m_toolModel->plugins(), this); + registerModel(QLatin1String("com.kdab.GammaRay.ToolPluginModel"), toolPluginModel); + ToolPluginErrorModel *toolPluginErrorModel = new ToolPluginErrorModel(m_toolModel->pluginErrors(), this); + registerModel(QLatin1String("com.kdab.GammaRay.ToolPluginErrorModel"), toolPluginErrorModel); + if (qgetenv("GAMMARAY_MODELTEST") == "1") { new ModelTest(m_objectListModel, m_objectListModel); new ModelTest(m_objectTreeModel, m_objectTreeModel); @@ -231,15 +207,22 @@ QInternal::unregisterCallback(QInternal::DisconnectCallback, &GammaRay::probeDisconnectCallback); #endif - s_instance = 0; + ObjectBroker::clear(); + + s_instance = QAtomicPointer(0); +} + +QThread* Probe::filteredThread() +{ + return s_listener()->filterThread; } -void Probe::setWindow(GammaRay::MainWindow *window) +void Probe::setWindow(QObject *window) { m_window = window; } -GammaRay::MainWindow *Probe::window() const +QObject* Probe::window() const { return m_window; } @@ -250,36 +233,126 @@ return NULL; } +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) return s_instance; +#else + return s_instance.load(); +#endif } bool Probe::isInitialized() { - return s_instance && qApp; + return instance() && qApp; +} + +bool Probe::canShowWidgets() +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + const QApplication * const qGuiApplication = qobject_cast(qApp); + return qGuiApplication && qGuiApplication->type() != QApplication::Tty; +#else + return QCoreApplication::instance()->inherits("QApplication"); +#endif +} + +void Probe::createProbe(bool findExisting) +{ + Q_ASSERT(!isInitialized()); + + // first create the probe and its children + // we must not hold the object lock here as otherwise we can deadlock + // with other QObject's we create and other threads are using. One + // example are QAbstractSocketEngine. + IF_DEBUG(cout << "setting up new probe instance" << endl;) + s_listener()->filterThread = QThread::currentThread(); + Probe *probe = new Probe; + s_listener()->filterThread = 0; + IF_DEBUG(cout << "done setting up new probe instance" << endl;) + + // now we can get the lock and add items which where added before this point in time + { + QWriteLocker lock(s_lock()); + // now we set the instance while holding the lock, + // all future calls to object{Added,Removed} will + // act directly on the data structures there instead + // of using addedBeforeProbeInstance + // this will only happen _after_ the object lock above is released though + Q_ASSERT(!instance()); + + s_instance = QAtomicPointer(probe); + + // add objects to the probe that were tracked before its creation + foreach (QObject *obj, s_listener()->addedBeforeProbeInstance) { + objectAdded(obj); + } + s_listener()->addedBeforeProbeInstance.clear(); + + // try to find existing objects by other means + if (findExisting) { + probe->findExistingObjects(); + } + } + + // eventually initialize the rest + QMetaObject::invokeMethod(probe, "delayedInit", Qt::QueuedConnection); +} + +void Probe::startupHookReceived() +{ + s_listener()->trackDestroyed = false; } void Probe::delayedInit() { - if (qgetenv("GAMMARAY_UNSET_PRELOAD") == "1") { - qputenv("LD_PRELOAD", ""); + QCoreApplication::instance()->installEventFilter(this); + + QString appName = qApp->applicationName(); + if (appName.isEmpty() && !qApp->arguments().isEmpty()) { + appName = qApp->arguments().first().remove(qApp->applicationDirPath()); + if (appName.startsWith('.')) { + appName = appName.right(appName.length() - 1); + } + if (appName.startsWith('/')) { + appName = appName.right(appName.length() - 1); + } } - if (qgetenv("GAMMARAY_UNSET_DYLD") == "1") { - qputenv("DYLD_INSERT_LIBRARIES", ""); - qputenv("DYLD_FORCE_FLAT_NAMESPACE", ""); + if (appName.isEmpty()) { + appName = tr("PID %1").arg(qApp->applicationPid()); } + Server::instance()->setLabel(appName); - QCoreApplication::instance()->installEventFilter(s_instance); + if (ProbeSettings::value("InProcessUi", false).toBool()) + showInProcessUi(); +} + +void Probe::showInProcessUi() +{ + if (!canShowWidgets()) { + cerr << "Unable to show in-process UI in a non-QWidget based application." << endl; + return; + } IF_DEBUG(cout << "creating GammaRay::MainWindow" << endl;) s_listener()->filterThread = QThread::currentThread(); - GammaRay::MainWindow *window = new GammaRay::MainWindow; + + QString path = Paths::currentProbePath(); + if (!path.isEmpty()) + path += QDir::separator(); + path += "gammaray_inprocessui"; + QLibrary lib; + lib.setFileName(path); + if (!lib.load()) { + std::cerr << "Failed to load in-process UI module: " << qPrintable(lib.errorString()) << std::endl; + } else { + void(*factory)() = reinterpret_cast(lib.resolve("gammaray_create_inprocess_mainwindow")); + if (!factory) + std::cerr << Q_FUNC_INFO << ' ' << qPrintable(lib.errorString()) << endl; + else + factory(); + } + s_listener()->filterThread = 0; IF_DEBUG(cout << "creation done" << endl;) - - window->setAttribute(Qt::WA_DeleteOnClose); - instance()->setWindow(window); - instance()->setParent(window); - window->show(); } bool Probe::filterObject(QObject *obj) const @@ -293,6 +366,13 @@ Util::descendantOf(window(), obj); } +void Probe::registerModel(const QString& objectName, QAbstractItemModel* model) +{ + RemoteModelServer *ms = new RemoteModelServer(objectName, model); + ms->setModel(model); + ObjectBroker::registerModelInternal(objectName, model); +} + QAbstractItemModel *Probe::objectListModel() const { return m_objectListModel; @@ -303,6 +383,11 @@ return m_objectTreeModel; } +QAbstractItemModel *Probe::metaObjectModel() const +{ + return m_metaObjectTreeModel; +} + QAbstractItemModel *Probe::connectionModel() const { return m_connectionModel; @@ -324,7 +409,7 @@ return m_validObjects.contains(obj); } -QReadWriteLock *Probe::objectLock() const +QReadWriteLock *Probe::objectLock() { return s_lock(); } @@ -339,68 +424,72 @@ << hex << obj << (fromCtor ? " (from ctor)" : "") << endl;) return; - } else if (isInitialized()) { - if (instance()->filterObject(obj)) { - IF_DEBUG(cout - << "objectAdded Filter: " - << hex << obj - << (fromCtor ? " (from ctor)" : "") << endl;) - return; - } else if (instance()->m_validObjects.contains(obj)) { - // this happens when we get a child event before the objectAdded call from the ctor - // or when we add an item from s_addedBeforeProbeInsertion who got added already - // due to the add-parent-before-child logic - IF_DEBUG(cout - << "objectAdded Known: " - << hex << obj - << (fromCtor ? " (from ctor)" : "") << endl;) - Q_ASSERT(fromCtor || s_addedBeforeProbeInsertion()->contains(obj)); - return; - } + } - // make sure we already know the parent - if (obj->parent() && !instance()->m_validObjects.contains(obj->parent())) { - objectAdded(obj->parent(), fromCtor); - } - Q_ASSERT(!obj->parent() || instance()->m_validObjects.contains(obj->parent())); - - instance()->m_validObjects << obj; - if (s_listener()->trackDestroyed) { - // when we did not use a preload variant that - // overwrites qt_removeObject we must track object - // deletion manually - connect(obj, SIGNAL(destroyed(QObject*)), - instance(), SLOT(handleObjectDestroyed(QObject*)), - Qt::DirectConnection); - } - - if (!fromCtor && obj->parent() && instance()->m_queuedObjects.contains(obj->parent())) { - // when a child event triggers a call to objectAdded while inside the ctor - // the parent is already tracked but it's call to objectFullyConstructed - // was delayed. hence we must do the same for the child for integrity - fromCtor = true; - } - - IF_DEBUG(cout << "objectAdded: " << hex << obj - << (fromCtor ? " (from ctor)" : "") - << ", p: " << obj->parent() << endl;) - - if (fromCtor) { - Q_ASSERT(!instance()->m_queuedObjects.contains(obj)); - instance()->m_queuedObjects << obj; - if (!instance()->m_queueTimer->isActive()) { - // timers must not be started from a different thread - QMetaObject::invokeMethod(instance()->m_queueTimer, "start", Qt::AutoConnection); - } - } else { - instance()->objectFullyConstructed(obj); - } - } else { + if (!isInitialized()) { IF_DEBUG(cout << "objectAdded Before: " << hex << obj << (fromCtor ? " (from ctor)" : "") << endl;) - s_addedBeforeProbeInsertion()->push_back(obj); + s_listener()->addedBeforeProbeInstance << obj; + return; + } + + if (instance()->filterObject(obj)) { + IF_DEBUG(cout + << "objectAdded Filter: " + << hex << obj + << (fromCtor ? " (from ctor)" : "") << endl;) + return; + } + + if (instance()->m_validObjects.contains(obj)) { + // this happens when we get a child event before the objectAdded call from the ctor + // or when we add an item from addedBeforeProbeInstance who got added already + // due to the add-parent-before-child logic + IF_DEBUG(cout + << "objectAdded Known: " + << hex << obj + << (fromCtor ? " (from ctor)" : "") << endl;) + return; + } + + // make sure we already know the parent + if (obj->parent() && !instance()->m_validObjects.contains(obj->parent())) { + objectAdded(obj->parent(), fromCtor); + } + Q_ASSERT(!obj->parent() || instance()->m_validObjects.contains(obj->parent())); + + instance()->m_validObjects << obj; + if (!instance()->hasReliableObjectTracking()) { + // when we did not use a preload variant that + // overwrites qt_removeObject we must track object + // deletion manually + connect(obj, SIGNAL(destroyed(QObject*)), + instance(), SLOT(handleObjectDestroyed(QObject*)), + Qt::DirectConnection); + } + + if (!fromCtor && obj->parent() && instance()->m_queuedObjects.contains(obj->parent())) { + // when a child event triggers a call to objectAdded while inside the ctor + // the parent is already tracked but it's call to objectFullyConstructed + // was delayed. hence we must do the same for the child for integrity + fromCtor = true; + } + + IF_DEBUG(cout << "objectAdded: " << hex << obj + << (fromCtor ? " (from ctor)" : "") + << ", p: " << obj->parent() << endl;) + + if (fromCtor) { + Q_ASSERT(!instance()->m_queuedObjects.contains(obj)); + instance()->m_queuedObjects << obj; + if (!instance()->m_queueTimer->isActive()) { + // timers must not be started from a different thread + QMetaObject::invokeMethod(instance()->m_queueTimer, "start", Qt::AutoConnection); + } + } else { + instance()->objectFullyConstructed(obj); } } @@ -435,7 +524,9 @@ // deleted already IF_DEBUG(cout << "stale fully constructed: " << hex << obj << endl;) return; - } else if (filterObject(obj)) { + } + + if (filterObject(obj)) { // when the call was delayed from the ctor construction, // the parent might not have been set properly yet. hence // apply the filter again @@ -456,10 +547,12 @@ // alternative way of detecting reparenting... // Without linking to the QtQuick library of course, for extra fun. if (obj->inherits("QQuickItem")) { - bool foo = connect(obj, SIGNAL(parentChanged(QQuickItem*)), this, SLOT(objectParentChanged())); + connect(obj, SIGNAL(parentChanged(QQuickItem*)), this, SLOT(objectParentChanged())); } m_objectListModel->objectAdded(obj); + m_metaObjectTreeModel->objectAdded(obj); + m_toolModel->objectAdded(obj); emit objectCreated(obj); @@ -468,33 +561,43 @@ void Probe::objectRemoved(QObject *obj) { QWriteLocker lock(s_lock()); - if (isInitialized()) { - IF_DEBUG(cout << "object removed:" << hex << obj << " " << obj->parent() << endl;) - - bool success = instance()->m_validObjects.remove(obj); - if (!success) { - // object was not tracked by the probe, probably a gammaray object - return; - } - instance()->m_queuedObjects.removeOne(obj); - - instance()->m_objectListModel->objectRemoved(obj); + if (!isInitialized()) { + IF_DEBUG(cout + << "objectRemoved Before: " + << hex << obj + << " have statics: " << s_listener() << endl;) - instance()->connectionRemoved(obj, 0, 0, 0); - instance()->connectionRemoved(0, 0, obj, 0); + if (!s_listener()) + return; - emit instance()->objectDestroyed(obj); - } else if (s_addedBeforeProbeInsertion()) { - for (QVector::iterator it = s_addedBeforeProbeInsertion()->begin(); - it != s_addedBeforeProbeInsertion()->end();) { + QVector &addedBefore = s_listener()->addedBeforeProbeInstance; + for (QVector::iterator it = addedBefore.begin(); it != addedBefore.end();) { if (*it == obj) { - it = s_addedBeforeProbeInsertion()->erase(it); + it = addedBefore.erase(it); } else { ++it; } } + return; } + + IF_DEBUG(cout << "object removed:" << hex << obj << " " << obj->parent() << endl;) + + bool success = instance()->m_validObjects.remove(obj); + if (!success) { + // object was not tracked by the probe, probably a gammaray object + return; + } + + instance()->m_queuedObjects.removeOne(obj); + + instance()->m_objectListModel->objectRemoved(obj); + + instance()->connectionRemoved(obj, 0, 0, 0); + instance()->connectionRemoved(0, 0, obj, 0); + + emit instance()->objectDestroyed(obj); } void Probe::handleObjectDestroyed(QObject *obj) @@ -505,7 +608,7 @@ void Probe::objectParentChanged() { if (sender()) { - emit objectReparanted(sender()); + emit objectReparented(sender()); } } @@ -573,222 +676,99 @@ // object is known already, just update the position in the tree // BUT: only when we did not queue this item before IF_DEBUG(cout << "update pos: " << hex << obj << endl;) - emit objectReparanted(obj); + emit objectReparented(obj); } } else if (tracked) { objectRemoved(obj); } } - if (event->type() == QEvent::MouseButtonRelease) { - QMouseEvent *mouseEv = static_cast(event); - if (mouseEv->button() == Qt::LeftButton && - mouseEv->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier)) { - QWidget *widget = QApplication::widgetAt(mouseEv->globalPos()); - if (widget) { - emit widgetSelected(widget, widget->mapFromGlobal(mouseEv->globalPos())); - } - } - } - - // make modal dialogs non-modal so that the gammaray window is still reachable - if (event->type() == QEvent::Show) { - QDialog *dlg = qobject_cast(receiver); - if (dlg) { - dlg->setWindowModality(Qt::NonModal); - } - } // we have no preloading hooks, so recover all objects we see - if (s_listener()->trackDestroyed && event->type() != QEvent::ChildAdded && - event->type() != QEvent::ChildRemoved && !filterObject(receiver)) { + if (!hasReliableObjectTracking() && event->type() != QEvent::ChildAdded && + event->type() != QEvent::ChildRemoved && // already handled above + event->type() != QEvent::Destroy && event->type() != QEvent::WinIdChange && // unsafe since emitted from dtors + !filterObject(receiver)) { QWriteLocker lock(s_lock()); const bool tracked = m_validObjects.contains(receiver); if (!tracked) { - objectAdded(receiver); + discoverObject(receiver); } } + + // filters provided by plugins + if (!filterObject(receiver)) { + foreach (QObject *filter, m_globalEventFilters) + filter->eventFilter(receiver, event); + } + return QObject::eventFilter(receiver, event); } void Probe::findExistingObjects() { - addObjectRecursive(QCoreApplication::instance()); - foreach (QObject *obj, QApplication::topLevelWidgets()) { - addObjectRecursive(obj); - } + discoverObject(QCoreApplication::instance()); } -void Probe::addObjectRecursive(QObject *obj) +void Probe::discoverObject(QObject* obj) { if (!obj) { return; } - objectRemoved(obj); // in case we find it twice - objectAdded(obj); - foreach (QObject *child, obj->children()) { - addObjectRecursive(child); - } -} -// taken from qobject.cpp -const int gammaray_flagged_locations_count = 2; -static const char *gammaray_flagged_locations[gammaray_flagged_locations_count] = {0}; - -const char *Probe::connectLocation(const char *member) -{ - for (int i = 0; i < gammaray_flagged_locations_count; ++i) { - if (member == gammaray_flagged_locations[i]) { - // signature includes location information after the first null-terminator - const char *location = member + qstrlen(member) + 1; - if (*location != '\0') { - return location; - } - return 0; - } - } - return 0; -} - -extern "C" Q_DECL_EXPORT void qt_startup_hook() -{ - s_listener()->trackDestroyed = false; + QWriteLocker lock(s_lock()); + if (m_validObjects.contains(obj)) + return; - new ProbeCreator(ProbeCreator::CreateOnly); -#if !defined Q_OS_WIN && !defined Q_OS_MAC - if (!functionsOverwritten) { - static void(*next_qt_startup_hook)() = (void (*)()) dlsym(RTLD_NEXT, "qt_startup_hook"); - next_qt_startup_hook(); + objectAdded(obj); + foreach (QObject *child, obj->children()) { + discoverObject(child); } -#endif } -extern "C" Q_DECL_EXPORT void qt_addObject(QObject *obj) +void Probe::installGlobalEventFilter(QObject* filter) { - Probe::objectAdded(obj, true); -#if !defined Q_OS_WIN && !defined Q_OS_MAC - if (!functionsOverwritten) { - static void (*next_qt_addObject)(QObject *obj) = - (void (*)(QObject *obj)) dlsym(RTLD_NEXT, "qt_addObject"); - next_qt_addObject(obj); - } -#endif + Q_ASSERT(!m_globalEventFilters.contains(filter)); + m_globalEventFilters.push_back(filter); } -extern "C" Q_DECL_EXPORT void qt_removeObject(QObject *obj) +bool Probe::hasReliableObjectTracking() const { - Probe::objectRemoved(obj); -#if !defined Q_OS_WIN && !defined Q_OS_MAC - if (!functionsOverwritten) { - static void (*next_qt_removeObject)(QObject *obj) = - (void (*)(QObject *obj)) dlsym(RTLD_NEXT, "qt_removeObject"); - next_qt_removeObject(obj); - } -#endif + return !s_listener()->trackDestroyed; } -#ifndef GAMMARAY_UNKNOWN_CXX_MANGLED_NAMES -#ifndef Q_OS_WIN -Q_DECL_EXPORT const char *qFlagLocation(const char *method) -#else -Q_DECL_EXPORT const char *myFlagLocation(const char *method) -#endif +void Probe::selectObject(QObject* object, const QPoint& pos) { - static int gammaray_idx = 0; - gammaray_flagged_locations[gammaray_idx] = method; - gammaray_idx = (gammaray_idx+1) % gammaray_flagged_locations_count; - -#ifndef Q_OS_WIN - static const char *(*next_qFlagLocation)(const char *method) = - (const char * (*)(const char *method)) dlsym(RTLD_NEXT, "_Z13qFlagLocationPKc"); - - Q_ASSERT_X(next_qFlagLocation, "", - "Recompile with GAMMARAY_UNKNOWN_CXX_MANGLED_NAMES enabled, " - "your compiler uses an unsupported C++ name mangling scheme"); - return next_qFlagLocation(method); -#else - return method; -#endif + emit objectSelected(object, pos); } -#endif -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) -void overwriteQtFunctions() -{ - functionsOverwritten = true; - AbstractFunctionOverwriter *overwriter = FunctionOverwriterFactory::createFunctionOverwriter(); +//BEGIN: SignalSlotsLocationStore - overwriter->overwriteFunction(QLatin1String("qt_startup_hook"), (void*)qt_startup_hook); - overwriter->overwriteFunction(QLatin1String("qt_addObject"), (void*)qt_addObject); - overwriter->overwriteFunction(QLatin1String("qt_removeObject"), (void*)qt_removeObject); -#if defined(Q_OS_WIN) -#ifdef ARCH_64 -#ifdef __MINGW32__ - overwriter->overwriteFunction( - QLatin1String("_Z13qFlagLocationPKc"), (void*)myFlagLocation); -#else - overwriter->overwriteFunction( - QLatin1String("?qFlagLocation@@YAPEBDPEBD@Z"), (void*)myFlagLocation); -#endif -#else -# ifdef __MINGW32__ - overwriter->overwriteFunction( - QLatin1String("_Z13qFlagLocationPKc"), (void*)myFlagLocation); -# else - overwriter->overwriteFunction( - QLatin1String("?qFlagLocation@@YAPBDPBD@Z"), (void*)myFlagLocation); -# endif -#endif -#endif -} -#endif +// taken from qobject.cpp +const int gammaray_flagged_locations_count = 2; +const char *gammaray_flagged_locations[gammaray_flagged_locations_count] = {0}; -#ifdef Q_OS_WIN -extern "C" Q_DECL_EXPORT void gammaray_probe_inject(); +static int gammaray_idx = 0; -extern "C" BOOL WINAPI DllMain(HINSTANCE/*hInstance*/, DWORD dwReason, LPVOID/*lpvReserved*/) +void SignalSlotsLocationStore::flagLocation(const char *method) { - switch(dwReason) { - case DLL_PROCESS_ATTACH: - { - overwriteQtFunctions(); - - gammaray_probe_inject(); - break; - } - case DLL_PROCESS_DETACH: - { - //Unloading does not work, because we overwrite existing code - exit(-1); - break; - } - }; - return TRUE; + gammaray_flagged_locations[gammaray_idx] = method; + gammaray_idx = (gammaray_idx+1) % gammaray_flagged_locations_count; } -#endif -extern "C" Q_DECL_EXPORT void gammaray_probe_inject() +const char *SignalSlotsLocationStore::extractLocation(const char *member) { - if (!qApp) { - return; + for (int i = 0; i < gammaray_flagged_locations_count; ++i) { + if (member == gammaray_flagged_locations[i]) { + // signature includes location information after the first null-terminator + const char *location = member + qstrlen(member) + 1; + if (*location != '\0') { + return location; + } + return 0; + } } - printf("gammaray_probe_inject()\n"); - // make it possible to re-attach - new ProbeCreator(ProbeCreator::CreateAndFindExisting); + return 0; } -#ifdef Q_OS_MAC -// we need a way to execute some code upon load, so let's abuse -// static initialization -class HitMeBabyOneMoreTime -{ - public: - HitMeBabyOneMoreTime() - { - overwriteQtFunctions(); - } - -}; -static HitMeBabyOneMoreTime britney; -#endif +//END -#include "probe.moc" diff -Nru gammaray-1.2.2/core/probe.h gammaray-2.0.1/core/probe.h --- gammaray-1.2.2/core/probe.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/probe.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,52 +24,44 @@ #ifndef GAMMARAY_PROBE_H #define GAMMARAY_PROBE_H -#include "include/gammaray_export.h" -#include "include/probeinterface.h" +#include "gammaray_core_export.h" +#include "probeinterface.h" #include #include #include #include +#include +class QThread; class QPoint; class QTimer; namespace GammaRay { +class ProbeCreator; +class MetaObjectTreeModel; class ConnectionModel; class ObjectListModel; class ObjectTreeModel; class ToolModel; class MainWindow; +class BenchSuite; -/** - * Creates Probe instance in main thread and deletes self afterwards. - */ -class ProbeCreator : public QObject -{ - Q_OBJECT - public: - enum Type { - CreateOnly, - CreateAndFindExisting - }; - ProbeCreator(Type t); - - private slots: - void createProbe(); - - private: - Type m_type; -}; - -class GAMMARAY_EXPORT Probe : public QObject, public ProbeInterface +class GAMMARAY_CORE_EXPORT Probe : public QObject, public ProbeInterface { Q_OBJECT public: virtual ~Probe(); + /** + * NOTE: You must hold the object lock when operating on the instance! + */ static Probe *instance(); + + /** + * Returns true if the probe is initialized, false otherwise. + */ static bool isInitialized(); static void objectAdded(QObject *obj, bool fromCtor = false); @@ -80,17 +72,19 @@ static void connectionRemoved(QObject *sender, const char *signal, QObject *receiver, const char *method); - static void findExistingObjects(); - QAbstractItemModel *objectListModel() const; QAbstractItemModel *objectTreeModel() const; + QAbstractItemModel *metaObjectModel() const; QAbstractItemModel *connectionModel() const; ToolModel *toolModel() const; + void registerModel(const QString& objectName, QAbstractItemModel* model); + /*override*/ void installGlobalEventFilter(QObject* filter); + /*override*/ bool hasReliableObjectTracking() const; + /*override*/ void discoverObject(QObject* object); + /*override*/ void selectObject(QObject* object, const QPoint& pos = QPoint()); - static const char *connectLocation(const char *member); - - GammaRay::MainWindow *window() const; - void setWindow(GammaRay::MainWindow *window); + QObject *window() const; + void setWindow(QObject *window); QObject *probe() const; @@ -98,7 +92,8 @@ * Lock this to check the validity of a QObject * and to access it safely afterwards. */ - QReadWriteLock *objectLock() const; + static QReadWriteLock *objectLock(); + /** * check whether @p obj is still valid * @@ -108,15 +103,21 @@ bool filterObject(QObject *obj) const; + /** Check if we are capable of showing widgets. */ + static bool canShowWidgets(); + + /// internal + static void startupHookReceived(); + signals: /** - * Emitted when the user selected @p widget at position @p pos in the probed application. + * Emitted when the user selected @p object at position @p pos in the probed application. */ - void widgetSelected(QWidget *widget, const QPoint &pos); + void objectSelected(QObject *object, const QPoint &pos); void objectCreated(QObject *obj); void objectDestroyed(QObject *obj); - void objectReparanted(QObject *obj); + void objectReparented(QObject *obj); protected: bool eventFilter(QObject *receiver, QEvent *event); @@ -128,22 +129,40 @@ void objectParentChanged(); private: + friend class ProbeCreator; + friend class BenchSuite; + + static QThread* filteredThread(); + void objectFullyConstructed(QObject *obj); + void findExistingObjects(); + void showInProcessUi(); + + static void createProbe(bool findExisting); explicit Probe(QObject *parent = 0); - static void addObjectRecursive(QObject *obj); - static Probe *s_instance; + static QAtomicPointer s_instance; ObjectListModel *m_objectListModel; ObjectTreeModel *m_objectTreeModel; + MetaObjectTreeModel *m_metaObjectTreeModel; ConnectionModel *m_connectionModel; ToolModel *m_toolModel; - GammaRay::MainWindow *m_window; + QObject *m_window; QSet m_validObjects; QQueue m_queuedObjects; QTimer *m_queueTimer; + QVector m_globalEventFilters; +}; - friend class ProbeCreator; +class GAMMARAY_CORE_EXPORT SignalSlotsLocationStore +{ +public: + /// store the location of @p method + static void flagLocation(const char *method); + + /// retrieve the location of @p member + static const char *extractLocation(const char *member); }; } diff -Nru gammaray-1.2.2/core/probeinterface.h gammaray-2.0.1/core/probeinterface.h --- gammaray-1.2.2/core/probeinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/probeinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,142 @@ +/* + probeinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares the ProbeInterface abstract base class. + + @brief + Declares the ProbeInterface abstract base class. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_PROBEINTERFACE_H +#define GAMMARAY_PROBEINTERFACE_H + +#include + +class QObject; +class QAbstractItemModel; +class QString; + +namespace GammaRay { + +/** + * @brief An abstract interface for accessing the core GammaRay probe. + * + * The ProbeInterface is an abstract interface that allows one to access + * the core GammaRay probe without linking to it. + */ +class ProbeInterface +{ + public: + virtual inline ~ProbeInterface() + { + } + + /** + * Returns the object list model. + * @return a pointer to a QAbstractItemModel instance. + */ + virtual QAbstractItemModel *objectListModel() const = 0; + + /** + * Returns the object tree model. + * @return a pointer to a QAbstractItemModel instance. + */ + virtual QAbstractItemModel *objectTreeModel() const = 0; + + /** + * Returns the connection model. + * @return a pointer to a QAbstractItemModel instance. + */ + virtual QAbstractItemModel *connectionModel() const = 0; + + /** + * Determines if the specified QObject belongs to the GammaRay Probe or Window. + * + * These objects should not be tracked or shown to the user, + * hence must be explictly filtered. + * @param object is a pointer to a QObject instance. + * + * @return true if the specified QObject belongs to the GammaRay Probe + * or Window; false otherwise. + */ + virtual bool filterObject(QObject *object) const = 0; + + /** + * Returns the probe QObject for connecting signals. + * @return a pointer to a QObject instance. + */ + virtual QObject *probe() const = 0; + + /** + * Register a model for remote usage. + * @param objectName unique identifier for the model, typically in reverse domain notation. + */ + virtual void registerModel(const QString &objectName, QAbstractItemModel* model) = 0; + + /** + * Install a global event filter. + * Use this rather than installing the filter manually on QCoreApplication, + * this will filter out GammaRay-internal events and objects already for you. + */ + virtual void installGlobalEventFilter(QObject *filter) = 0; + + /** + * Returns @c true if we have working hooks in QtCore, that is we are notified reliably + * about every QObject creation/destruction. + * If this is not the case, we try to discover QObjects by walking the hierarchy, starting + * from known singletons, and by watching out for unknown receivers of events. + * This is far from complete obviously, and plug-ins can help finding more objects, using + * specific knowledge about the types they are responsible for. + * + * Connect to the objectAdded(QObject*) signal on probe(), and call discoverObject(QObject*) + * for "your" objects. + * + * @since 2.0 + */ + virtual bool hasReliableObjectTracking() const = 0; + + /** + * Notify the probe about QObjects your plug-in can discover by using information about + * the types it can handle. + * Only use this if hasReliableObjectTracking() returns @c false. + * + * @see hasReliableObjectTracking() + * @since 2.0 + */ + virtual void discoverObject(QObject *object) = 0; + + /** + * Notify the probe about the user selecting one of "your" objects via in-app interaction. + * If you know the exact position the user interacted with, pass that in as @p pos. + * + * @since 2.0 + */ + virtual void selectObject(QObject *object, const QPoint &pos = QPoint()) = 0; +}; + +} + +#endif diff -Nru gammaray-1.2.2/core/probesettings.cpp gammaray-2.0.1/core/probesettings.cpp --- gammaray-1.2.2/core/probesettings.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/probesettings.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,147 @@ +/* + probesettings.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#include "probesettings.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +static QHash s_probeSettings; + +QVariant ProbeSettings::value(const QString& key, const QVariant& defaultValue) +{ + QByteArray v = s_probeSettings.value(key.toUtf8()); + if (v.isEmpty()) + v = qgetenv("GAMMARAY_" + key.toLocal8Bit()); + if (v.isEmpty()) + return defaultValue; + + switch (defaultValue.type()) { + case QVariant::String: + return QString::fromUtf8(v); + case QVariant::Bool: + return v == "true" || v == "1" || v == "TRUE"; + case QVariant::Int: + return v.toInt(); + default: + return v; + } +} + +void ProbeSettings::receiveSettings() +{ +#ifdef HAVE_SHM + QSharedMemory shm(QLatin1String("gammaray-") + QString::number(launcherIdentifier())); + if (!shm.attach()) { + qWarning() << "Unable to receive probe settings, cannot attach to shared memory region" << shm.key() << shm.nativeKey() << ", error is:" << shm.errorString(); + qWarning() << "Continueing anyway, with default settings."; + return; + } + SharedMemoryLocker locker(&shm); + + QByteArray ba = QByteArray::fromRawData(static_cast(shm.data()), shm.size()); + QBuffer buffer(&ba); + buffer.open(QIODevice::ReadOnly); + + while (Message::canReadMessage(&buffer)) { + const Message msg = Message::readMessage(&buffer); + switch (msg.type()) { + case Protocol::ServerVersion: + { + qint32 version; + msg.payload() >> version; + if (version != Protocol::version()) { + qWarning() << "Unable to receive probe settings, mismatching protocol versions (expected:" << Protocol::version() << "got:" << version << ")"; + qWarning() << "Continueing anyway, but this is likely going to fail."; + return; + } + break; + } + case Protocol::ProbeSettings: + { + msg.payload() >> s_probeSettings; + //qDebug() << Q_FUNC_INFO << s_probeSettings; + const QString probePath = value("ProbePath").toString(); + if (!probePath.isEmpty()) + Paths::setRootPath(probePath + QDir::separator() + GAMMARAY_INVERSE_PROBE_DIR); + } + default: + continue; + } + } +#endif +} + +qint64 ProbeSettings::launcherIdentifier() +{ + bool ok; + const qint64 id = qgetenv("GAMMARAY_LAUNCHER_ID").toLongLong(&ok); + if (ok && id > 0) + return id; + return QCoreApplication::applicationPid(); +} + +void ProbeSettings::sendPort(quint16 port) +{ +#ifdef HAVE_SHM + QSharedMemory shm(QLatin1String("gammaray-") + QString::number(launcherIdentifier())); + if (!shm.attach()) { + qWarning() << "Unable to receive probe settings, cannot attach to shared memory region" << shm.key() << shm.nativeKey() << ", error is:" << shm.errorString(); + qWarning() << "Continueing anyway, with default settings."; + return; + } + + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + { + Message msg(Protocol::LauncherAddress, Protocol::ServerPort); + msg.payload() << port; + msg.write(&buffer); + } + buffer.close(); + + if(shm.size() < ba.size()) + qFatal("SHM region too small!"); + + { + SharedMemoryLocker locker(&shm); + qMemCopy(shm.data(), ba.constData(), ba.size()); + qMemSet(static_cast(shm.data()) + ba.size(), 0xff, shm.size() - ba.size()); + } + + QSystemSemaphore sem("gammaray-semaphore-" + QString::number(launcherIdentifier()), QSystemSemaphore::Open); + sem.release(); +#endif +} diff -Nru gammaray-1.2.2/core/probesettings.h gammaray-2.0.1/core/probesettings.h --- gammaray-1.2.2/core/probesettings.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/probesettings.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + probesettings.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROBESETTINGS_H +#define GAMMARAY_PROBESETTINGS_H + +#include "gammaray_core_export.h" + +#include + +namespace GammaRay { + +/** General purpose settings of the probe provided by the launcher. */ +namespace ProbeSettings +{ + GAMMARAY_CORE_EXPORT QVariant value(const QString &key, const QVariant &defaultValue = QString()); + + /** Call if using runtime attaching to obtain settings provided via shared memory. */ + void receiveSettings(); + + /** Identifier used for finding the communication channels to the launcher. */ + qint64 launcherIdentifier(); + + /** Sends the TCP port used for communication with the client back to the launcher. */ + void sendPort(quint16 port); +} + +} + +#endif // GAMMARAY_PROBESETTINGS_H diff -Nru gammaray-1.2.2/core/propertycontroller.cpp gammaray-2.0.1/core/propertycontroller.cpp --- gammaray-1.2.2/core/propertycontroller.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/propertycontroller.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,226 @@ +/* + propertycontroller.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertycontroller.h" + +#include "connectionfilterproxymodel.h" +#include "connectionmodel.h" +#include "metapropertymodel.h" +#include "methodargumentmodel.h" +#include "multisignalmapper.h" +#include "objectclassinfomodel.h" +#include "objectdynamicpropertymodel.h" +#include "objectenummodel.h" +#include "objectmethodmodel.h" +#include "objectstaticpropertymodel.h" +#include "probe.h" +#include "varianthandler.h" + +#include "remote/remotemodelserver.h" + +#include "common/objectbroker.h" +#include "common/enums.h" + +#include +#include +#include +#include + +using namespace GammaRay; + +PropertyController::PropertyController(const QString &baseName, QObject *parent) : + PropertyControllerInterface(baseName + ".controller", parent), + m_objectBaseName(baseName), + m_staticPropertyModel(new ObjectStaticPropertyModel(this)), + m_dynamicPropertyModel(new ObjectDynamicPropertyModel(this)), + m_classInfoModel(new ObjectClassInfoModel(this)), + m_methodModel(new ObjectMethodModel(this)), + m_inboundConnectionModel(new ConnectionFilterProxyModel(this)), + m_outboundConnectionModel(new ConnectionFilterProxyModel(this)), + m_enumModel(new ObjectEnumModel(this)), + m_signalMapper(0), + m_methodLogModel(new QStandardItemModel(this)), + m_metaPropertyModel(new MetaPropertyModel(this)), + m_methodArgumentModel(new MethodArgumentModel(this)) +{ + m_inboundConnectionModel->setFilterOnReceiver(true); + m_outboundConnectionModel->setFilterOnSender(true); + + registerModel(m_staticPropertyModel, "staticProperties"); + registerModel(m_dynamicPropertyModel, "dynamicProperties"); + registerModel(m_methodModel, "methods"); + registerModel(m_methodLogModel, "methodLog"); + registerModel(m_classInfoModel, "classInfo"); + registerModel(m_inboundConnectionModel, "inboundConnections"); + registerModel(m_outboundConnectionModel, "outboundConnections"); + registerModel(m_enumModel, "enums"); + registerModel(m_metaPropertyModel, "nonQProperties"); + registerModel(m_methodArgumentModel, "methodArguments"); + + ObjectBroker::selectionModel(m_methodModel); // trigger creation + + // TODO 1.3 had an optimization using the ProxyDetacher for these models, re-add that + m_inboundConnectionModel->setSourceModel(Probe::instance()->connectionModel()); + m_outboundConnectionModel->setSourceModel(Probe::instance()->connectionModel()); +} + +PropertyController::~PropertyController() +{ +} + +void PropertyController::registerModel(QAbstractItemModel *model, const QString &nameSuffix) +{ + Probe::instance()->registerModel(m_objectBaseName + '.' + nameSuffix, model); +} + +void PropertyController::signalEmitted(QObject* sender, int signalIndex, const QVector& args) +{ + Q_ASSERT(m_object == sender); + + QStringList prettyArgs; + foreach (const QVariant &v, args) + prettyArgs.push_back(VariantHandler::displayString(v)); + + m_methodLogModel->appendRow( + new QStandardItem(tr("%1: Signal %2 emitted, arguments: %3"). + arg(QTime::currentTime().toString("HH:mm:ss.zzz")). +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + arg(sender->metaObject()->method(signalIndex).signature()) +#else + arg(QString(sender->metaObject()->method(signalIndex).methodSignature())) +#endif + .arg(prettyArgs.join(", ")))); +} + +void PropertyController::setObject(QObject *object) +{ + if (m_object) + disconnect(m_object, 0, this, 0); + if (object) + connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed())); + + m_object = object; + m_staticPropertyModel->setObject(object); + m_dynamicPropertyModel->setObject(object); + m_inboundConnectionModel->filterReceiver(object); + m_outboundConnectionModel->filterSender(object); + + const QMetaObject *metaObject = 0; + if (object) { + metaObject = object->metaObject(); + } + m_enumModel->setMetaObject(metaObject); + m_classInfoModel->setMetaObject(metaObject); + m_methodModel->setMetaObject(metaObject); + + delete m_signalMapper; + m_signalMapper = new MultiSignalMapper(this); + connect(m_signalMapper, SIGNAL(signalEmitted(QObject*,int,QVector)), SLOT(signalEmitted(QObject*,int,QVector))); + + m_methodLogModel->clear(); + + m_metaPropertyModel->setObject(object); + + emit displayStateChanged(PropertyWidgetDisplayState::QObject); +} + +void PropertyController::setObject(void *object, const QString &className) +{ + setObject(0); + m_metaPropertyModel->setObject(object, className); + + emit displayStateChanged(PropertyWidgetDisplayState::Object); +} + +void PropertyController::setMetaObject(const QMetaObject *metaObject) +{ + setObject(0); + m_enumModel->setMetaObject(metaObject); + m_classInfoModel->setMetaObject(metaObject); + m_methodModel->setMetaObject(metaObject); + + emit displayStateChanged(PropertyWidgetDisplayState::MetaObject); +} + +void PropertyController::activateMethod() +{ + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(m_methodModel); + if (selectionModel->selectedRows().size() != 1) { + return; + } + const QModelIndex index = selectionModel->selectedRows().first(); + + const QMetaMethod method = index.data(ObjectMethodModelRole::MetaMethod).value(); + if (method.methodType() == QMetaMethod::Slot) { + m_methodArgumentModel->setMethod(method); + } else if (method.methodType() == QMetaMethod::Signal) { + m_signalMapper->connectToSignal(m_object, method); + } +} + +void PropertyController::invokeMethod(Qt::ConnectionType connectionType) +{ + if (!m_object) { + m_methodLogModel->appendRow( + new QStandardItem( + tr("%1: Invocation failed: Invalid object, probably got deleted in the meantime."). + arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); + return; + } + + QMetaMethod method; + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(m_methodModel); + if (selectionModel->selectedRows().size() == 1) { + const QModelIndex index = selectionModel->selectedRows().first(); + method = index.data(ObjectMethodModelRole::MetaMethod).value(); + } + + if (method.methodType() != QMetaMethod::Slot) { + m_methodLogModel->appendRow( + new QStandardItem( + tr("%1: Invocation failed: Invalid method (not a slot?)."). + arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); + return; + } + + const QVector args = m_methodArgumentModel->arguments(); + // TODO retrieve return value and add it to the log in case of success + // TODO measure executation time and that to the log + const bool result = method.invoke(m_object.data(), connectionType, + args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); + + if (!result) { + m_methodLogModel->appendRow( + new QStandardItem( + tr("%1: Invocation failed.."). + arg(QTime::currentTime().toString("HH:mm:ss.zzz")))); + return; + } + + m_methodArgumentModel->setMethod(QMetaMethod()); +} + +void PropertyController::objectDestroyed() +{ + setObject(0); +} diff -Nru gammaray-1.2.2/core/propertycontroller.h gammaray-2.0.1/core/propertycontroller.h --- gammaray-1.2.2/core/propertycontroller.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/propertycontroller.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,92 @@ +/* + propertycontroller.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYCONTROLLER_H +#define GAMMARAY_PROPERTYCONTROLLER_H + +#include "gammaray_core_export.h" + +#include + +#include + +class QAbstractItemModel; +class QStandardItemModel; + +namespace GammaRay { + +class ConnectionFilterProxyModel; +class MultiSignalMapper; +class ObjectDynamicPropertyModel; +class ObjectStaticPropertyModel; +class ObjectClassInfoModel; +class ObjectMethodModel; +class ObjectEnumModel; +class MetaPropertyModel; +class MethodArgumentModel; + +/** @brief Non-UI part of the property widget. */ +class GAMMARAY_CORE_EXPORT PropertyController : public PropertyControllerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::PropertyControllerInterface) +public: + explicit PropertyController(const QString &baseName, QObject *parent); + ~PropertyController(); + + void setObject(QObject *object); + void setObject(void *object, const QString &className); + void setMetaObject(const QMetaObject *metaObject); + +public slots: + void activateMethod(); + void invokeMethod(Qt::ConnectionType type); + +private slots: + void signalEmitted(QObject *sender, int signalIndex, const QVector &args); + void objectDestroyed(); + +private: + void registerModel(QAbstractItemModel *model, const QString &nameSuffix); + +private: + QString m_objectBaseName; + + QPointer m_object; + ObjectStaticPropertyModel *m_staticPropertyModel; + ObjectDynamicPropertyModel *m_dynamicPropertyModel; + ObjectClassInfoModel *m_classInfoModel; + ObjectMethodModel *m_methodModel; + ConnectionFilterProxyModel *m_inboundConnectionModel; + ConnectionFilterProxyModel *m_outboundConnectionModel; + ObjectEnumModel *m_enumModel; + MultiSignalMapper *m_signalMapper; + QStandardItemModel *m_methodLogModel; + MetaPropertyModel *m_metaPropertyModel; + + MethodArgumentModel *m_methodArgumentModel; +}; + +} + +#endif // GAMMARAY_PROPERTYCONTROLLER_H diff -Nru gammaray-1.2.2/core/propertyeditor/palettedialog.cpp gammaray-2.0.1/core/propertyeditor/palettedialog.cpp --- gammaray-1.2.2/core/propertyeditor/palettedialog.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/palettedialog.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -/* - palettedialog.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "palettedialog.h" - -#include "ui_palettedialog.h" -#include "palettemodel.h" -#include "propertyeditor/propertyeditorfactory.h" - -#include -#include - -using namespace GammaRay; - -PaletteDialog::PaletteDialog(const QPalette &palette, QWidget *parent) - : QDialog(parent), - ui(new Ui::PaletteDialog), - m_model(new PaletteModel(this)) -{ - ui->setupUi(this); - m_model->setPalette(palette); - m_model->setEditable(true); - ui->paletteView->setModel(m_model); - - QStyledItemDelegate *delegate = - qobject_cast(ui->paletteView->itemDelegate()); - if (delegate) { - m_propertyEditorFactory.reset(new PropertyEditorFactory); - delegate->setItemEditorFactory(m_propertyEditorFactory.data()); - } -} - -PaletteDialog::~PaletteDialog() -{ - delete ui; -} - -QPalette PaletteDialog::editedPalette() const -{ - return m_model->palette(); -} - -#include "palettedialog.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/palettedialog.h gammaray-2.0.1/core/propertyeditor/palettedialog.h --- gammaray-1.2.2/core/propertyeditor/palettedialog.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/palettedialog.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -/* - palettedialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PALETTEDIALOG_H -#define GAMMARAY_PALETTEDIALOG_H - -#include - -namespace GammaRay { - -class PropertyEditorFactory; - -class PaletteModel; - -namespace Ui { - class PaletteDialog; -} - -class PaletteDialog : public QDialog -{ - Q_OBJECT - public: - explicit PaletteDialog(const QPalette &palette, QWidget *parent = 0); - virtual ~PaletteDialog(); - - QPalette editedPalette() const; - - private: - Ui::PaletteDialog *ui; - PaletteModel *m_model; - QScopedPointer m_propertyEditorFactory; -}; - -} - -#endif // GAMMARAY_PALETTEDIALOG_H diff -Nru gammaray-1.2.2/core/propertyeditor/palettedialog.ui gammaray-2.0.1/core/propertyeditor/palettedialog.ui --- gammaray-1.2.2/core/propertyeditor/palettedialog.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/palettedialog.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ - - - GammaRay::PaletteDialog - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - - - false - - - true - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Save - - - - - - - - - buttonBox - accepted() - GammaRay::PaletteDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - GammaRay::PaletteDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff -Nru gammaray-1.2.2/core/propertyeditor/propertycoloreditor.cpp gammaray-2.0.1/core/propertyeditor/propertycoloreditor.cpp --- gammaray-1.2.2/core/propertyeditor/propertycoloreditor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertycoloreditor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,43 +0,0 @@ -/* - propertycoloreditor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertycoloreditor.h" - -#include - -using namespace GammaRay; - -PropertyColorEditor::PropertyColorEditor(QWidget *parent) - : PropertyExtendedEditor(parent) -{ -} - -void PropertyColorEditor::edit() -{ - const QColor color = QColorDialog::getColor(value().value(), this); - if (color.isValid()) { - setValue(QVariant::fromValue(color)); - } -} - -#include "propertycoloreditor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertycoloreditor.h gammaray-2.0.1/core/propertyeditor/propertycoloreditor.h --- gammaray-1.2.2/core/propertyeditor/propertycoloreditor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertycoloreditor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -/* - propertycoloreditor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYCOLOREDITOR_H -#define GAMMARAY_PROPERTYCOLOREDITOR_H - -#include "propertyextendededitor.h" - -namespace GammaRay { - -/** Property editor for QColor. */ -class PropertyColorEditor : public PropertyExtendedEditor -{ - Q_OBJECT - public: - explicit PropertyColorEditor(QWidget *parent = 0); - - protected: - virtual void edit(); -}; - -} - -#endif // GAMMARAY_PROPERTYCOLOREDITOR_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.cpp gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.cpp --- gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - propertydoublepaireditor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertydoublepaireditor.h" - -#include "ui_propertydoublepaireditor.h" - -using namespace GammaRay; - -PropertyDoublePairEditor::PropertyDoublePairEditor(QWidget *parent) - : QWidget(parent), ui(new Ui::PropertyDoublePairEditor) -{ - ui->setupUi(this); -} - -PropertyPointFEditor::PropertyPointFEditor(QWidget *parent) - : PropertyDoublePairEditor(parent) -{ -} - -QPointF PropertyPointFEditor::pointF() const -{ - return QPointF(ui->xBox->value(), ui->yBox->value()); -} - -void PropertyPointFEditor::setPointF(const QPointF &point) -{ - ui->xBox->setValue(point.x()); - ui->yBox->setValue(point.y()); -} - -PropertySizeFEditor::PropertySizeFEditor(QWidget *parent) : PropertyDoublePairEditor(parent) -{ -} - -QSizeF PropertySizeFEditor::sizeF() const -{ - return QSizeF(ui->xBox->value(), ui->yBox->value()); -} - -void PropertySizeFEditor::setSizeF(const QSizeF &size) -{ - ui->xBox->setValue(size.width()); - ui->yBox->setValue(size.height()); -} - -#include "propertydoublepaireditor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.h gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.h --- gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -/* - propertydoublepaireditor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H -#define GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H - -#include - -namespace GammaRay { - -namespace Ui { - class PropertyDoublePairEditor; -} - -/** Property editor for pairs of doubles, such as PointF and SizeF. */ -class PropertyDoublePairEditor : public QWidget -{ - Q_OBJECT - public: - explicit PropertyDoublePairEditor(QWidget *parent = 0); - - protected: - QScopedPointer ui; -}; - -class PropertyPointFEditor : public PropertyDoublePairEditor -{ - Q_OBJECT - Q_PROPERTY(QPointF pointF READ pointF WRITE setPointF USER true) - public: - explicit PropertyPointFEditor(QWidget *parent = 0); - QPointF pointF() const; - void setPointF(const QPointF &point); -}; - -class PropertySizeFEditor : public PropertyDoublePairEditor -{ - Q_OBJECT - Q_PROPERTY(QSizeF sizeF READ sizeF WRITE setSizeF USER true) - public: - explicit PropertySizeFEditor(QWidget *parent = 0); - QSizeF sizeF() const; - void setSizeF(const QSizeF &size); -}; - -} - -#endif // GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.ui gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.ui --- gammaray-1.2.2/core/propertyeditor/propertydoublepaireditor.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertydoublepaireditor.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ - - - GammaRay::PropertyDoublePairEditor - - - - 0 - 0 - 400 - 300 - - - - - 0 - - - - - false - - - - - - - x - - - Qt::AlignCenter - - - - - - - false - - - - - - - - diff -Nru gammaray-1.2.2/core/propertyeditor/propertyeditorfactory.cpp gammaray-2.0.1/core/propertyeditor/propertyeditorfactory.cpp --- gammaray-1.2.2/core/propertyeditor/propertyeditorfactory.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyeditorfactory.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -/* - propertyeditorfactory.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertyeditorfactory.h" -#include "propertycoloreditor.h" -#include "propertyfonteditor.h" -#include "propertyintpaireditor.h" -#include "propertydoublepaireditor.h" -#include "propertypaletteeditor.h" - -#include - -using namespace GammaRay; - -PropertyEditorFactory::PropertyEditorFactory() -{ - registerEditor(QVariant::Color, new QStandardItemEditorCreator()); - registerEditor(QVariant::Font, new QStandardItemEditorCreator()); - registerEditor(QVariant::Palette, new QStandardItemEditorCreator()); - registerEditor(QVariant::Point, new QStandardItemEditorCreator()); - registerEditor(QVariant::PointF, new QStandardItemEditorCreator()); - registerEditor(QVariant::Size, new QStandardItemEditorCreator()); - registerEditor(QVariant::SizeF, new QStandardItemEditorCreator()); -} - -QWidget *PropertyEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const -{ - QWidget *w = QItemEditorFactory::createEditor(type, parent); - if (!w) { - return 0; - } - - // the read-only view is still in the background usually, so transpareny is not a good choice here - w->setAutoFillBackground(true); - return w; -} diff -Nru gammaray-1.2.2/core/propertyeditor/propertyeditorfactory.h gammaray-2.0.1/core/propertyeditor/propertyeditorfactory.h --- gammaray-1.2.2/core/propertyeditor/propertyeditorfactory.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyeditorfactory.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,41 +0,0 @@ -/* - propertyeditorfactory.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYEDITORFACTORY_H -#define GAMMARAY_PROPERTYEDITORFACTORY_H - -#include - -namespace GammaRay { - -/** Item editor factory with support for extra types while keeping support for the built-in ones. */ -class PropertyEditorFactory : public QItemEditorFactory -{ - public: - PropertyEditorFactory(); - virtual QWidget *createEditor(QVariant::Type type, QWidget *parent) const; -}; - -} - -#endif // GAMMARAY_PROPERTYEDITORFACTORY_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertyextendededitor.cpp gammaray-2.0.1/core/propertyeditor/propertyextendededitor.cpp --- gammaray-1.2.2/core/propertyeditor/propertyextendededitor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyextendededitor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -/* - propertyextendededitor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertyextendededitor.h" -#include "ui_propertyextendededitor.h" - -#include "include/util.h" - -#include -using namespace GammaRay; - -PropertyExtendedEditor::PropertyExtendedEditor(QWidget *parent) - : QWidget(parent), ui(new Ui::PropertyExtendedEditor) -{ - ui->setupUi(this); - // TODO: make button content smaller by using a tiny icon - connect(ui->editButton, SIGNAL(clicked()),SLOT(edit())); -} - -PropertyExtendedEditor::~PropertyExtendedEditor() -{ - delete ui; -} - -QVariant PropertyExtendedEditor::value() const -{ - return m_value; -} - -void PropertyExtendedEditor::setValue(const QVariant &value) -{ - m_value = value; - ui->valueLabel->setText(Util::variantToString(value)); -} - -#include "propertyextendededitor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertyextendededitor.h gammaray-2.0.1/core/propertyeditor/propertyextendededitor.h --- gammaray-1.2.2/core/propertyeditor/propertyextendededitor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyextendededitor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - propertyextendededitor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYEXTENDEDEDITOR_H -#define GAMMARAY_PROPERTYEXTENDEDEDITOR_H - -#include -#include - -namespace GammaRay { - -namespace Ui { - class PropertyExtendedEditor; -} - -/** Base class for property editors that open a separate dialog. */ -class PropertyExtendedEditor : public QWidget -{ - Q_OBJECT - Q_PROPERTY(QVariant value READ value WRITE setValue USER true) - public: - explicit PropertyExtendedEditor(QWidget *parent = 0); - virtual ~PropertyExtendedEditor(); - - QVariant value() const; - void setValue(const QVariant &value); - - protected slots: - virtual void edit() = 0; - - private: - Ui::PropertyExtendedEditor *ui; - QVariant m_value; -}; - -} - -#endif // GAMMARAY_PROPERTYEXTENDEDEDITOR_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertyextendededitor.ui gammaray-2.0.1/core/propertyeditor/propertyextendededitor.ui --- gammaray-1.2.2/core/propertyeditor/propertyextendededitor.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyextendededitor.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ - - - GammaRay::PropertyExtendedEditor - - - - 0 - 0 - 392 - 23 - - - - - 0 - - - 0 - - - - - - - - ... - - - - - - - - diff -Nru gammaray-1.2.2/core/propertyeditor/propertyfonteditor.cpp gammaray-2.0.1/core/propertyeditor/propertyfonteditor.cpp --- gammaray-1.2.2/core/propertyeditor/propertyfonteditor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyfonteditor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -/* - propertyfonteditor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertyfonteditor.h" - -#include - -using namespace GammaRay; - -PropertyFontEditor::PropertyFontEditor(QWidget *parent) - : PropertyExtendedEditor(parent) -{ -} - -void PropertyFontEditor::edit() -{ - bool ok = false; - const QFont font = QFontDialog::getFont(&ok, value().value(), this); - if (ok) { - setValue(font); - } -} - -#include "propertyfonteditor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertyfonteditor.h gammaray-2.0.1/core/propertyeditor/propertyfonteditor.h --- gammaray-1.2.2/core/propertyeditor/propertyfonteditor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyfonteditor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,43 +0,0 @@ -/* - propertyfonteditor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYFONTEDITOR_H -#define GAMMARAY_PROPERTYFONTEDITOR_H - -#include "propertyextendededitor.h" - -namespace GammaRay { - -class PropertyFontEditor : public PropertyExtendedEditor -{ - Q_OBJECT - public: - explicit PropertyFontEditor(QWidget *parent = 0); - - protected: - virtual void edit(); -}; - -} - -#endif // GAMMARAY_PROPERTYFONTEDITOR_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.cpp gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.cpp --- gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ -/* - propertyintpaireditor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertyintpaireditor.h" -#include "ui_propertyintpaireditor.h" - -#include - -#include - -using namespace GammaRay; - -PropertyIntPairEditor::PropertyIntPairEditor(QWidget *parent) - : QWidget(parent), ui(new Ui::PropertyIntPairEditor) -{ - ui->setupUi(this); - ui->xBox->setMinimum(std::numeric_limits::min()); - ui->xBox->setMaximum(std::numeric_limits::max()); - ui->yBox->setMinimum(std::numeric_limits::min()); - ui->yBox->setMaximum(std::numeric_limits::max()); -} - -PropertyPointEditor::PropertyPointEditor(QWidget *parent) - : PropertyIntPairEditor(parent) -{ -} - -QPoint PropertyPointEditor::point() const -{ - return QPoint(ui->xBox->value(), ui->yBox->value()); -} - -void PropertyPointEditor::setPoint(const QPoint &point) -{ - ui->xBox->setValue(point.x()); - ui->yBox->setValue(point.y()); -} - -PropertySizeEditor::PropertySizeEditor(QWidget *parent) - : PropertyIntPairEditor(parent) -{ -} - -QSize PropertySizeEditor::sizeValue() const -{ - return QSize(ui->xBox->value(), ui->yBox->value()); -} - -void PropertySizeEditor::setSizeValue(const QSize &size) -{ - ui->xBox->setValue(size.width()); - ui->yBox->setValue(size.height()); -} - -#include "propertyintpaireditor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.h gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.h --- gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,76 +0,0 @@ -/* - propertyintpaireditor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYINTPAIREDITOR_H -#define GAMMARAY_PROPERTYINTPAIREDITOR_H - -#include - -class QPoint; - -namespace GammaRay { - -namespace Ui { - class PropertyIntPairEditor; -} - -/** Property editor for QPoint, QSize and anything else consisting of two integer values. */ -class PropertyIntPairEditor : public QWidget -{ - Q_OBJECT - public: - explicit PropertyIntPairEditor(QWidget *parent = 0); - - protected: - QScopedPointer ui; -}; - -/** Property editor for points. Since QStyledItemDelegate ignore valuePropertyName and insists on - * USER properties we need one class per type here... - */ -class PropertyPointEditor : public PropertyIntPairEditor -{ - Q_OBJECT - Q_PROPERTY(QPoint point READ point WRITE setPoint USER true) - public: - explicit PropertyPointEditor(QWidget *parent = 0); - - QPoint point() const; - void setPoint(const QPoint &point); -}; - -/** Same again for size. */ -class PropertySizeEditor : public PropertyIntPairEditor -{ - Q_OBJECT - Q_PROPERTY(QSize sizeValue READ sizeValue WRITE setSizeValue USER true) - public: - explicit PropertySizeEditor(QWidget *parent = 0); - - QSize sizeValue() const; - void setSizeValue(const QSize &size); -}; - -} - -#endif // GAMMARAY_PROPERTYINTPAIREDITOR_H diff -Nru gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.ui gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.ui --- gammaray-1.2.2/core/propertyeditor/propertyintpaireditor.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertyintpaireditor.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ - - - GammaRay::PropertyIntPairEditor - - - - 0 - 0 - 145 - 22 - - - - - 0 - - - - - false - - - -99999 - - - 99999 - - - - - - - x - - - Qt::AlignCenter - - - - - - - false - - - - - - - - diff -Nru gammaray-1.2.2/core/propertyeditor/propertypaletteeditor.cpp gammaray-2.0.1/core/propertyeditor/propertypaletteeditor.cpp --- gammaray-1.2.2/core/propertyeditor/propertypaletteeditor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertypaletteeditor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -/* - propertypaletteeditor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertypaletteeditor.h" -#include "palettedialog.h" - -using namespace GammaRay; - -PropertyPaletteEditor::PropertyPaletteEditor(QWidget *parent) - : PropertyExtendedEditor(parent) -{ -} - -void PropertyPaletteEditor::edit() -{ - PaletteDialog dlg(value().value(), this); - if (dlg.exec() == QDialog::Accepted) { - setValue(dlg.editedPalette()); - } -} - -#include "propertypaletteeditor.moc" diff -Nru gammaray-1.2.2/core/propertyeditor/propertypaletteeditor.h gammaray-2.0.1/core/propertyeditor/propertypaletteeditor.h --- gammaray-1.2.2/core/propertyeditor/propertypaletteeditor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertyeditor/propertypaletteeditor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,43 +0,0 @@ -/* - propertypaletteeditor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYPALETTEEDITOR_H -#define GAMMARAY_PROPERTYPALETTEEDITOR_H - -#include "propertyextendededitor.h" - -namespace GammaRay { - -class PropertyPaletteEditor : public PropertyExtendedEditor -{ - Q_OBJECT - public: - explicit PropertyPaletteEditor(QWidget *parent = 0); - - protected: - virtual void edit(); -}; - -} - -#endif // GAMMARAY_PROPERTYPALETTEEDITOR_H diff -Nru gammaray-1.2.2/core/propertywidget.cpp gammaray-2.0.1/core/propertywidget.cpp --- gammaray-1.2.2/core/propertywidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertywidget.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,225 +0,0 @@ -/* - propertywidget.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "propertywidget.h" -#include "connectionfilterproxymodel.h" -#include "connectionmodel.h" -#include "metapropertymodel.h" -#include "methodinvocationdialog.h" -#include "multisignalmapper.h" -#include "objectclassinfomodel.h" -#include "objectdynamicpropertymodel.h" -#include "objectenummodel.h" -#include "objectmethodmodel.h" -#include "objectstaticpropertymodel.h" -#include "probe.h" -#include "proxydetacher.h" - -#include "propertyeditor/propertyeditorfactory.h" - -#include "kde/krecursivefilterproxymodel.h" - -#include -#include -#include -#include -#include - -using namespace GammaRay; - -PropertyWidget::PropertyWidget(QWidget *parent) - : QWidget(parent), - m_staticPropertyModel(new ObjectStaticPropertyModel(this)), - m_dynamicPropertyModel(new ObjectDynamicPropertyModel(this)), - m_classInfoModel(new ObjectClassInfoModel(this)), - m_methodModel(new ObjectMethodModel(this)), - m_inboundConnectionModel(new ConnectionFilterProxyModel(this)), - m_outboundConnectionModel(new ConnectionFilterProxyModel(this)), - m_enumModel(new ObjectEnumModel(this)), - m_signalMapper(0), - m_methodLogModel(new QStandardItemModel(this)), - m_metaPropertyModel(new MetaPropertyModel(this)), - m_editorFactory(new PropertyEditorFactory) -{ - ui.setupUi(this); - - QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); - proxy->setDynamicSortFilter(true); - proxy->setSourceModel(m_staticPropertyModel); - ui.staticPropertyView->setModel(proxy); - ui.staticPropertyView->sortByColumn(0, Qt::AscendingOrder); - ui.staticPropertyView->header()->setResizeMode(0, QHeaderView::ResizeToContents); - ui.staticPropertySearchLine->setProxy(proxy); - setEditorFactory(ui.staticPropertyView); - - proxy = new QSortFilterProxyModel(this); - proxy->setDynamicSortFilter(true); - proxy->setSourceModel(m_dynamicPropertyModel); - ui.dynamicPropertyView->setModel(proxy); - ui.dynamicPropertyView->sortByColumn(0, Qt::AscendingOrder); - ui.dynamicPropertyView->header()->setResizeMode(0, QHeaderView::ResizeToContents); - setEditorFactory(ui.dynamicPropertyView); - ui.dynamicPropertySearchLine->setProxy(proxy); - - proxy = new QSortFilterProxyModel(this); - proxy->setDynamicSortFilter(true); - proxy->setSourceModel(m_methodModel); - ui.methodView->setModel(proxy); - ui.methodView->sortByColumn(0, Qt::AscendingOrder); - ui.methodView->header()->setResizeMode(QHeaderView::ResizeToContents); - ui.methodSearchLine->setProxy(proxy); - connect(ui.methodView, SIGNAL(doubleClicked(QModelIndex)), - SLOT(methodActivated(QModelIndex))); - connect(ui.methodView, SIGNAL(customContextMenuRequested(QPoint)), - SLOT(methodConextMenu(QPoint))); - ui.methodLog->setModel(m_methodLogModel); - - proxy = new QSortFilterProxyModel(this); - proxy->setDynamicSortFilter(true); - proxy->setSourceModel(m_classInfoModel); - ui.classInfoView->setModel(proxy); - ui.classInfoView->sortByColumn(0, Qt::AscendingOrder); - ui.classInfoView->header()->setResizeMode(QHeaderView::ResizeToContents); - ui.classInfoSearchLine->setProxy(proxy); - - new ProxyDetacher(ui.inboundConnectionView, m_inboundConnectionModel, - Probe::instance()->connectionModel()); - ui.inboundConnectionView->setModel(m_inboundConnectionModel); - ui.inboundConnectionView->sortByColumn(0, Qt::AscendingOrder); - ui.inboundConnectionSearchLine->setProxy(m_inboundConnectionModel); - - new ProxyDetacher(ui.outboundConnectionView, m_outboundConnectionModel, - Probe::instance()->connectionModel()); - ui.outboundConnectionView->setModel(m_outboundConnectionModel); - ui.outboundConnectionView->sortByColumn(0, Qt::AscendingOrder); - ui.outboundConnectionSearchLine->setProxy(m_outboundConnectionModel); - - proxy = new KRecursiveFilterProxyModel(this); - proxy->setDynamicSortFilter(true); - proxy->setSourceModel(m_enumModel); - ui.enumView->setModel(proxy); - ui.enumView->sortByColumn(0, Qt::AscendingOrder); - ui.enumView->header()->setResizeMode(QHeaderView::ResizeToContents); - ui.enumSearchLine->setProxy(proxy); - - ui.metaPropertyView->setModel(m_metaPropertyModel); - setEditorFactory(ui.metaPropertyView); -} - -void GammaRay::PropertyWidget::setObject(QObject *object) -{ - m_object = object; - m_staticPropertyModel->setObject(object); - m_dynamicPropertyModel->setObject(object); - m_classInfoModel->setObject(object); - m_methodModel->setObject(object); - m_inboundConnectionModel->filterReceiver(object); - m_outboundConnectionModel->filterSender(object); - m_enumModel->setObject(object); - - delete m_signalMapper; - m_signalMapper = new MultiSignalMapper(this); - connect(m_signalMapper, SIGNAL(signalEmitted(QObject*,int)), SLOT(signalEmitted(QObject*,int))); - - m_methodLogModel->clear(); - - m_metaPropertyModel->setObject(object); - - setQObjectTabsVisible(true); -} - -void PropertyWidget::setObject(void *object, const QString &className) -{ - setObject(0); - m_metaPropertyModel->setObject(object, className); - setQObjectTabsVisible(false); -} - -void GammaRay::PropertyWidget::methodActivated(const QModelIndex &index) -{ - const QMetaMethod method = index.data(ObjectMethodModel::MetaMethodRole).value(); - if (method.methodType() == QMetaMethod::Slot) { - MethodInvocationDialog *dlg = new MethodInvocationDialog(this); - dlg->setMethod(m_object.data(), method); - dlg->show(); - // TODO: return value should go into ui->methodLog - } else if (method.methodType() == QMetaMethod::Signal) { - m_signalMapper->connectToSignal(m_object, method); - } -} - -void PropertyWidget::signalEmitted(QObject *sender, int signalIndex) -{ - Q_ASSERT(m_object == sender); - m_methodLogModel->appendRow( - new QStandardItem(tr("%1: Signal %2 emitted"). - arg(QTime::currentTime().toString("HH:mm:ss.zzz")). -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - arg(sender->metaObject()->method(signalIndex).signature()))); -#else - arg(QString(sender->metaObject()->method(signalIndex).methodSignature())))); -#endif -} - -void PropertyWidget::methodConextMenu(const QPoint &pos) -{ - const QModelIndex index = ui.methodView->indexAt(pos); - if (!index.isValid()) { - return; - } - - const QMetaMethod method = index.data(ObjectMethodModel::MetaMethodRole).value(); - QMenu contextMenu; - if (method.methodType() == QMetaMethod::Slot) { - contextMenu.addAction(tr("Invoke")); - } else if (method.methodType() == QMetaMethod::Signal) { - contextMenu.addAction(tr("Connect to")); - } - - if (contextMenu.exec(ui.methodView->viewport()->mapToGlobal(pos))) { - methodActivated(index); - } -} - -void PropertyWidget::setQObjectTabsVisible(bool visible) -{ - // TODO: this should actually hide instead of disable... - for (int i = 0; i < ui.tabWidget->count(); ++i) { - if (ui.tabWidget->widget(i) != ui.metaPropertyTab) { - ui.tabWidget->setTabEnabled(i, visible); - } - } - if (!visible) { - ui.tabWidget->setCurrentWidget(ui.metaPropertyTab); - } -} - -void PropertyWidget::setEditorFactory(QAbstractItemView *view) -{ - QStyledItemDelegate *delegate = qobject_cast(view->itemDelegate()); - if (delegate) { - delegate->setItemEditorFactory(m_editorFactory.data()); - } -} - -#include "propertywidget.moc" diff -Nru gammaray-1.2.2/core/propertywidget.h gammaray-2.0.1/core/propertywidget.h --- gammaray-1.2.2/core/propertywidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertywidget.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -/* - propertywidget.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROPERTYWIDGET_H -#define GAMMARAY_PROPERTYWIDGET_H - -#include "ui_propertywidget.h" -#include - -class QStandardItemModel; - -namespace GammaRay { - -class ConnectionFilterProxyModel; -class MultiSignalMapper; -class ObjectDynamicPropertyModel; -class ObjectStaticPropertyModel; -class ObjectClassInfoModel; -class ObjectMethodModel; -class ObjectEnumModel; -class MetaPropertyModel; -class PropertyEditorFactory; - -class PropertyWidget : public QWidget -{ - Q_OBJECT - public: - explicit PropertyWidget(QWidget *parent = 0); - - void setObject(QObject *object); - void setObject(void *object, const QString &className); - - private: - void setQObjectTabsVisible(bool visible); - void setEditorFactory(QAbstractItemView *view); - - private slots: - void methodActivated(const QModelIndex &index); - void signalEmitted(QObject *sender, int signalIndex); - void methodConextMenu(const QPoint &pos); - - private: - Ui::PropertyWidget ui; - QPointer m_object; - ObjectStaticPropertyModel *m_staticPropertyModel; - ObjectDynamicPropertyModel *m_dynamicPropertyModel; - ObjectClassInfoModel *m_classInfoModel; - ObjectMethodModel *m_methodModel; - ConnectionFilterProxyModel *m_inboundConnectionModel; - ConnectionFilterProxyModel *m_outboundConnectionModel; - ObjectEnumModel *m_enumModel; - MultiSignalMapper *m_signalMapper; - QStandardItemModel *m_methodLogModel; - MetaPropertyModel *m_metaPropertyModel; - QScopedPointer m_editorFactory; -}; - -} - -#endif // GAMMARAY_PROPERTYWIDGET_H diff -Nru gammaray-1.2.2/core/propertywidget.ui gammaray-2.0.1/core/propertywidget.ui --- gammaray-1.2.2/core/propertywidget.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/propertywidget.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,226 +0,0 @@ - - - GammaRay::PropertyWidget - - - - 0 - 0 - 816 - 605 - - - - - 0 - - - - - 0 - - - - Static Properties - - - - - - - - - false - - - true - - - true - - - - - - - - Dynamic Properties - - - - - - - - - false - - - true - - - true - - - - - - - - Methods - - - - - - - - - Qt::CustomContextMenu - - - false - - - true - - - true - - - - - - - false - - - true - - - false - - - - - - - - Inbound Connections - - - - - - - - - false - - - true - - - true - - - - - - - - Outbound Connections - - - - - - - - - false - - - true - - - true - - - - - - - - Enums - - - - - - - - - true - - - - - - - - Class Info - - - - - - - - - false - - - true - - - true - - - - - - - - Non-QObject Properties - - - - - - false - - - true - - - true - - - - - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
-
- - -
diff -Nru gammaray-1.2.2/core/proxydetacher.cpp gammaray-2.0.1/core/proxydetacher.cpp --- gammaray-1.2.2/core/proxydetacher.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/proxydetacher.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -56,4 +56,3 @@ return QObject::eventFilter(obj, e); } -#include "proxydetacher.moc" diff -Nru gammaray-1.2.2/core/proxydetacher.h gammaray-2.0.1/core/proxydetacher.h --- gammaray-1.2.2/core/proxydetacher.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/proxydetacher.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/proxytoolfactory.cpp gammaray-2.0.1/core/proxytoolfactory.cpp --- gammaray-1.2.2/core/proxytoolfactory.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/proxytoolfactory.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,62 +23,25 @@ #include "proxytoolfactory.h" -#include -#include -#include -#include -#include - -#include - using namespace GammaRay; +using namespace std; ProxyToolFactory::ProxyToolFactory(const QString &path, QObject *parent) - : QObject(parent), m_factory(0) + : ProxyFactory(path, parent) { - const QFileInfo pluginInfo(path); - m_id = pluginInfo.baseName(); - - QSettings desktopFile(path, QSettings::IniFormat); - desktopFile.beginGroup(QLatin1String("Desktop Entry")); - m_name = desktopFile.value(QLatin1String("Name")).toString(); - m_supportedTypes = - desktopFile.value( - QLatin1String("X-GammaRay-Types")).toString().split(QLatin1Char(';'), - QString::SkipEmptyParts); - m_pluginPath = - pluginInfo.dir().absoluteFilePath(desktopFile.value(QLatin1String("Exec")).toString()); - - const QString dllBaseName = desktopFile.value(QLatin1String("Exec")).toString(); - if (dllBaseName.isEmpty()) { - m_errorString = tr("Invalid 'Exec' line in plugin spec file"); - return; - } - - foreach (const QString &entry, - pluginInfo.dir().entryList(QStringList(dllBaseName + QLatin1Char('*')), QDir::Files)) { - const QString path = pluginInfo.dir().absoluteFilePath(entry); - if (QLibrary::isLibrary(path)) { - m_pluginPath = path; - break; - } - } + m_name = value(QLatin1String("Name")).toString(); + m_supportedTypes = value(QLatin1String("X-GammaRay-Types")).toString().split(QLatin1Char(';'), QString::SkipEmptyParts); } bool ProxyToolFactory::isValid() const { return - !m_id.isEmpty() && + !id().isEmpty() && !m_name.isEmpty() && !m_pluginPath.isEmpty() && !m_supportedTypes.isEmpty(); } -QString ProxyToolFactory::id() const -{ - return m_id; -} - QString ProxyToolFactory::name() const { return m_name; @@ -91,24 +54,11 @@ void ProxyToolFactory::init(ProbeInterface *probe) { - QPluginLoader loader(m_pluginPath, this); - m_factory = qobject_cast(loader.instance()); - if (!m_factory) { - std::cerr << "error loading plugin " << qPrintable(m_pluginPath) - << ": " << qPrintable(loader.errorString()) << std::endl; + loadPlugin(); + ToolFactory *fac = factory(); + if (!fac) { return; } - Q_ASSERT(m_factory); - m_factory->init(probe); + Q_ASSERT(fac); + fac->init(probe); } - -QWidget *ProxyToolFactory::createWidget(ProbeInterface *probe, QWidget *parentWidget) -{ - if (!m_factory) { - return new QLabel(tr("Plugin '%1' could not be loaded.").arg(m_pluginPath), parentWidget); - } - Q_ASSERT(m_factory); - return m_factory->createWidget(probe, parentWidget); -} - -#include "proxytoolfactory.moc" diff -Nru gammaray-1.2.2/core/proxytoolfactory.h gammaray-2.0.1/core/proxytoolfactory.h --- gammaray-1.2.2/core/proxytoolfactory.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/proxytoolfactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,7 +24,8 @@ #ifndef GAMMARAY_PROXYTOOLFACTORY_H #define GAMMARAY_PROXYTOOLFACTORY_H -#include "include/toolfactory.h" +#include +#include "toolfactory.h" namespace GammaRay { @@ -35,9 +36,8 @@ * * TODO: Improve error reporting */ -class ProxyToolFactory : public QObject, public ToolFactory +class ProxyToolFactory : public ProxyFactory { - Q_OBJECT public: /** * @param path Path to the plugin spec file @@ -47,23 +47,14 @@ /** Returns @c true if the plugin seems valid from all the information we have so far. */ bool isValid() const; - /** Returns a human-readable error string if loading failed */ - QString errorString() const { return m_errorString; } - - virtual QString id() const; virtual QString name() const; virtual QStringList supportedTypes() const; virtual void init(ProbeInterface *probe); - virtual QWidget *createWidget(ProbeInterface *probe, QWidget *parentWidget); private: - QString m_id; - QString m_pluginPath; QString m_name; - QString m_errorString; QStringList m_supportedTypes; - ToolFactory *m_factory; }; } diff -Nru gammaray-1.2.2/core/readorwritelocker.h gammaray-2.0.1/core/readorwritelocker.h --- gammaray-1.2.2/core/readorwritelocker.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/readorwritelocker.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -38,7 +38,7 @@ class ReadOrWriteLocker { public: - ReadOrWriteLocker(QReadWriteLock *lock) + explicit ReadOrWriteLocker(QReadWriteLock *lock) : m_lock(lock), m_locked(false) { diff -Nru gammaray-1.2.2/core/remote/remotemodelserver.cpp gammaray-2.0.1/core/remote/remotemodelserver.cpp --- gammaray-1.2.2/core/remote/remotemodelserver.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/remotemodelserver.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,306 @@ +/* + remotemodelserver.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "remotemodelserver.h" +#include "server.h" +#include +#include + +#include +#include +#include +#include + +#include + +using namespace GammaRay; +using namespace std; + +RemoteModelServer::RemoteModelServer(const QString &objectName, QObject *parent) : + QObject(parent), + m_model(0), + m_dummyBuffer(new QBuffer(&m_dummyData, this)), + m_monitored(false) +{ + setObjectName(objectName); + m_myAddress = Server::instance()->registerObject(objectName, this, "newRequest"); + Server::instance()->registerMonitorNotifier(m_myAddress, this, "modelMonitored"); + m_dummyBuffer->open(QIODevice::WriteOnly); + connect(Server::instance(), SIGNAL(disconnected()), this, SLOT(modelMonitored())); +} + +RemoteModelServer::~RemoteModelServer() +{ +} + +void RemoteModelServer::setModel(QAbstractItemModel *model) +{ + if (m_model) { + disconnectModel(); + if (m_monitored) + modelReset(); + } + + m_model = model; + if (m_model && m_monitored) + connectModel(); +} + +void RemoteModelServer::connectModel() +{ + Q_ASSERT(m_model); + connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(dataChanged(QModelIndex,QModelIndex))); + connect(m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), SLOT(headerDataChanged(Qt::Orientation,int,int))); + connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(rowsInserted(QModelIndex,int,int))); + connect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(rowsMoved(QModelIndex,int,int,QModelIndex,int))); + connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(rowsRemoved(QModelIndex,int,int))); + connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), SLOT(columnsInserted(QModelIndex,int,int))); + connect(m_model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(columnsMoved(QModelIndex,int,int,QModelIndex,int))); + connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), SLOT(columnsRemoved(QModelIndex,int,int))); + connect(m_model, SIGNAL(layoutChanged()), SLOT(layoutChanged())); + connect(m_model, SIGNAL(modelReset()), SLOT(modelReset())); + connect(m_model, SIGNAL(destroyed(QObject*)), SLOT(modelDeleted())); +} + +void RemoteModelServer::disconnectModel() +{ + Q_ASSERT(m_model); + disconnect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); + disconnect(m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this, SLOT(headerDataChanged(Qt::Orientation,int,int))); + disconnect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int))); + disconnect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsMoved(QModelIndex,int,int,QModelIndex,int))); + disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); + disconnect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(columnsInserted(QModelIndex,int,int))); + disconnect(m_model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(columnsMoved(QModelIndex,int,int,QModelIndex,int))); + disconnect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(columnsRemoved(QModelIndex,int,int))); + disconnect(m_model, SIGNAL(layoutChanged()), this, SLOT(layoutChanged())); + disconnect(m_model, SIGNAL(modelReset()), this, SLOT(modelReset())); + disconnect(m_model, SIGNAL(destroyed(QObject*)), this, SLOT(modelDeleted())); +} + +void RemoteModelServer::newRequest(const GammaRay::Message &msg) +{ + if (!m_model && msg.type() != Protocol::ModelSyncBarrier) + return; + + switch (msg.type()) { + case Protocol::ModelRowColumnCountRequest: + { + Protocol::ModelIndex index; + msg.payload() >> index; + const QModelIndex qmIndex = Protocol::toQModelIndex(m_model, index); + + Message msg(m_myAddress, Protocol::ModelRowColumnCountReply); + msg.payload() << index << m_model->rowCount(qmIndex) << m_model->columnCount(qmIndex); + Server::send(msg); + break; + } + + case Protocol::ModelContentRequest: + { + Protocol::ModelIndex index; + msg.payload() >> index; + const QModelIndex qmIndex = Protocol::toQModelIndex(m_model, index); + if (!qmIndex.isValid()) + break; + + Message msg(m_myAddress, Protocol::ModelContentReply); + msg.payload() << index << filterItemData(m_model->itemData(qmIndex)) << qint32(m_model->flags(qmIndex)); + Server::send(msg); + break; + } + + case Protocol::ModelHeaderRequest: + { + qint8 orientation; + qint32 section; + msg.payload() >> orientation >> section; + Q_ASSERT(orientation == Qt::Horizontal || orientation == Qt::Vertical); + Q_ASSERT(section >= 0); + + QHash data; + // TODO: add all roles + data.insert(Qt::DisplayRole, m_model->headerData(section, static_cast(orientation), Qt::DisplayRole)); + data.insert(Qt::ToolTipRole, m_model->headerData(section, static_cast(orientation), Qt::ToolTipRole)); + + Message msg(m_myAddress, Protocol::ModelHeaderReply); + msg.payload() << orientation << section << data; + Server::send(msg); + break; + } + + case Protocol::ModelSetDataRequest: + { + Protocol::ModelIndex index; + int role; + QVariant value; + msg.payload() >> index >> role >> value; + + m_model->setData(Protocol::toQModelIndex(m_model, index), value, role); + break; + } + + case Protocol::ModelSyncBarrier: + { + qint32 barrierId; + msg.payload() >> barrierId; + Message reply(m_myAddress, Protocol::ModelSyncBarrier); + reply.payload() << barrierId; + Server::send(reply); + break; + } + } +} + +QMap RemoteModelServer::filterItemData(const QMap< int, QVariant >& data) const +{ + QMap itemData(data); + for (QMap::iterator it = itemData.begin(); it != itemData.end();) { + if (it.value().userType() == qMetaTypeId()) { + // see also: https://bugreports.qt-project.org/browse/QTBUG-33321 + const QIcon icon = it.value().value(); + ///TODO: what size to use? icon.availableSizes is empty... + if (!icon.isNull()) + it.value() = icon.pixmap(QSize(16, 16)); + ++it; + } else if (canSerialize(it.value())) { + ++it; + } else { + it = itemData.erase(it); + } + } + return itemData; +} + +bool RemoteModelServer::canSerialize(const QVariant& value) const +{ + // ugly, but there doesn't seem to be a better way atm to find out without trying + m_dummyBuffer->seek(0); + QDataStream stream(m_dummyBuffer); + return QMetaType::save(stream, value.userType(), value.constData()); +} + +void RemoteModelServer::modelMonitored(bool monitored) +{ + if (m_monitored == monitored) + return; + m_monitored = monitored; + if (m_model) { + if (m_monitored) + connectModel(); + else + disconnectModel(); + } +} + +void RemoteModelServer::dataChanged(const QModelIndex& begin, const QModelIndex& end) +{ + // TODO check if somebody is listening (here or in Server?) + if (!Server::isConnected()) + return; + Message msg(m_myAddress, Protocol::ModelContentChanged); + msg.payload() << Protocol::fromQModelIndex(begin) << Protocol::fromQModelIndex(end); + Server::send(msg); +} + +void RemoteModelServer::headerDataChanged(Qt::Orientation orientation, int first, int last) +{ + if (!Server::isConnected()) + return; + Message msg(m_myAddress, Protocol::ModelHeaderChanged); + msg.payload() << qint8(orientation) << first << last; + Server::send(msg); +} + +void RemoteModelServer::rowsInserted(const QModelIndex& parent, int start, int end) +{ + sendAddRemoveMessage(Protocol::ModelRowsAdded, parent, start, end); +} + +void RemoteModelServer::rowsMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow) +{ + sendMoveMessage(Protocol::ModelRowsMoved, sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); +} + +void RemoteModelServer::rowsRemoved(const QModelIndex& parent, int start, int end) +{ + sendAddRemoveMessage(Protocol::ModelRowsRemoved, parent, start, end); +} + +void RemoteModelServer::columnsInserted(const QModelIndex& parent, int start, int end) +{ + sendAddRemoveMessage(Protocol::ModelColumnsAdded, parent, start, end); +} + +void RemoteModelServer::columnsMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationColumn) +{ + sendMoveMessage(Protocol::ModelColumnsMoved, sourceParent, sourceStart, sourceEnd, destinationParent, destinationColumn); +} + +void RemoteModelServer::columnsRemoved(const QModelIndex& parent, int start, int end) +{ + sendAddRemoveMessage(Protocol::ModelColumnsRemoved, parent, start, end); +} + +void RemoteModelServer::layoutChanged() +{ + if (!Server::isConnected()) + return; + Server::send(Message(m_myAddress, Protocol::ModelLayoutChanged)); +} + +void RemoteModelServer::modelReset() +{ + if (!Server::isConnected()) + return; + Server::send(Message(m_myAddress, Protocol::ModelReset)); +} + +void RemoteModelServer::sendAddRemoveMessage(Protocol::MessageType type, const QModelIndex& parent, int start, int end) +{ + if (!Server::isConnected()) + return; + Message msg(m_myAddress, type); + msg.payload() << Protocol::fromQModelIndex(parent) << start << end; + Server::send(msg); + +} + +void RemoteModelServer::sendMoveMessage(Protocol::MessageType type, const QModelIndex& sourceParent, int sourceStart, int sourceEnd, + const QModelIndex& destinationParent, int destinationIndex) +{ + if (!Server::isConnected()) + return; + Message msg(m_myAddress, type); + msg.payload() << Protocol::fromQModelIndex(sourceParent) << qint32(sourceStart) << qint32(sourceEnd) + << Protocol::fromQModelIndex(destinationParent) << qint32(destinationIndex); + Server::send(msg); +} + +void RemoteModelServer::modelDeleted() +{ + m_model = 0; + if (m_monitored) + modelReset(); +} + diff -Nru gammaray-1.2.2/core/remote/remotemodelserver.h gammaray-2.0.1/core/remote/remotemodelserver.h --- gammaray-1.2.2/core/remote/remotemodelserver.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/remotemodelserver.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,92 @@ +/* + remotemodelserver.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_REMOTEMODELSERVER_H +#define GAMMARAY_REMOTEMODELSERVER_H + +#include + +#include +#include + +class QBuffer; +class QAbstractItemModel; + +namespace GammaRay { + +class Message; + +/** Provides the server-side interface for a QAbstractItemModel to be used from a separate process. */ +class RemoteModelServer : public QObject +{ + Q_OBJECT + public: + /** Registers a new model server object with name @p objectName (must be unique). */ + explicit RemoteModelServer(const QString &objectName, QObject *parent = 0); + ~RemoteModelServer(); + + /** Set the source model for this model server instance. */ + void setModel(QAbstractItemModel *model); + + public slots: + void newRequest(const GammaRay::Message &msg); + /** Notifications about an object on the client side (un)monitoring this object. + * If no one is watching, we don't send out any change notification to reduce network traffice. + */ + void modelMonitored(bool monitored = false); + + private: + void connectModel(); + void disconnectModel(); + void sendAddRemoveMessage(Protocol::MessageType type, const QModelIndex &parent, int start, int end); + void sendMoveMessage(Protocol::MessageType type, const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationIndex); + QMap< int, QVariant > filterItemData(const QMap< int, QVariant >& data) const; + bool canSerialize(const QVariant &value) const; + + private slots: + void dataChanged(const QModelIndex &begin, const QModelIndex &end); + void headerDataChanged(Qt::Orientation orientation, int first, int last); + void rowsInserted(const QModelIndex &parent, int start, int end); + void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow); + void rowsRemoved(const QModelIndex &parent, int start, int end); + void columnsInserted(const QModelIndex &parent, int start, int end); + void columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn); + void columnsRemoved(const QModelIndex &parent, int start, int end); + void layoutChanged(); + void modelReset(); + + void modelDeleted(); + + private: + QPointer m_model; + // those two are used for canSerialize, since recreating the QBuffer is somewhat expensive, + // especially since being a QObject triggers all kind of GammaRay internals + QByteArray m_dummyData; + QBuffer *m_dummyBuffer; + Protocol::ObjectAddress m_myAddress; + bool m_monitored; +}; + +} + +#endif diff -Nru gammaray-1.2.2/core/remote/selectionmodelserver.cpp gammaray-2.0.1/core/remote/selectionmodelserver.cpp --- gammaray-1.2.2/core/remote/selectionmodelserver.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/selectionmodelserver.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ +/* + selectionmodelserver.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "selectionmodelserver.h" +#include "server.h" + +using namespace GammaRay; + +SelectionModelServer::SelectionModelServer(const QString& objectName, QAbstractItemModel* model, QObject* parent): + NetworkSelectionModel(objectName, model, parent) +{ + m_myAddress = Server::instance()->registerObject(objectName, this, "newMessage"); +} + +SelectionModelServer::~SelectionModelServer() +{ +} + diff -Nru gammaray-1.2.2/core/remote/selectionmodelserver.h gammaray-2.0.1/core/remote/selectionmodelserver.h --- gammaray-1.2.2/core/remote/selectionmodelserver.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/selectionmodelserver.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + selectionmodelserver.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SELECTIONMODELSERVER_H +#define GAMMARAY_SELECTIONMODELSERVER_H + +#include + +namespace GammaRay { + +/** Server-side of the network transparent QItemSelection model. */ +class SelectionModelServer : public NetworkSelectionModel +{ + Q_OBJECT +public: + explicit SelectionModelServer(const QString& objectName, QAbstractItemModel* model, QObject* parent); + ~SelectionModelServer(); +}; + +} + +#endif // GAMMARAY_SELECTIONMODELSERVER_H diff -Nru gammaray-1.2.2/core/remote/server.cpp gammaray-2.0.1/core/remote/server.cpp --- gammaray-1.2.2/core/remote/server.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/server.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,282 @@ +/* + server.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "server.h" +#include "probe.h" +#include "probesettings.h" +#include "multisignalmapper.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace GammaRay; +using namespace std; + +Server::Server(QObject *parent) : + Endpoint(parent), + m_tcpServer(new QTcpServer(this)), + m_nextAddress(endpointAddress()), + m_broadcastTimer(new QTimer(this)), + m_broadcastSocket(new QUdpSocket(this)), + m_signalMapper(new MultiSignalMapper(this)) +{ + if (!ProbeSettings::value("RemoteAccessEnabled", true).toBool()) + return; + + const QHostAddress address(ProbeSettings::value("TCPServer", QLatin1String("0.0.0.0")).toString()); + + connect(m_tcpServer, SIGNAL(newConnection()), SLOT(newConnection())); + + // try the default port first, and fall back to a random port otherwise + if (!m_tcpServer->listen(address, defaultPort())) + m_tcpServer->listen(address, 0); + + // broadcast announcement only if we are actually listinging to remote connections +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + if (address.toString() != "127.0.0.1" && address.toString() != "::1") { +#else + if (!address.isLoopback()) { +#endif + m_broadcastTimer->setInterval(5 * 1000); + m_broadcastTimer->setSingleShot(false); + m_broadcastTimer->start(); + connect(m_broadcastTimer, SIGNAL(timeout()), SLOT(broadcast())); + connect(this, SIGNAL(disconnected()), m_broadcastTimer, SLOT(start())); + } + + connect(m_signalMapper, SIGNAL(signalEmitted(QObject*,int,QVector)), + this, SLOT(forwardSignal(QObject*,int,QVector))); +} + +Server::~Server() +{ +} + +Server* Server::instance() +{ + Q_ASSERT(s_instance); + return static_cast(s_instance); +} + +bool Server::isRemoteClient() const +{ + return false; +} + +QString Server::serverAddress() const +{ + return QHostAddress(QHostAddress::LocalHost).toString(); +} + +void Server::newConnection() +{ + if (isConnected()) { + cerr << Q_FUNC_INFO << " connected already, refusing incoming connection." << endl; + m_tcpServer->nextPendingConnection()->close(); + return; + } + + m_broadcastTimer->stop(); + setDevice(m_tcpServer->nextPendingConnection()); + + // send greeting message for protocol version check + { + Message msg(endpointAddress(), Protocol::ServerVersion); + msg.payload() << Protocol::version(); + send(msg); + } + + { + Message msg(endpointAddress(), Protocol::ServerInfo); + msg.payload() << label(); // TODO: expand with anything else needed here: Qt/GammaRay version, hostname, that kind of stuff + send(msg); + } + + { + Message msg(endpointAddress(), Protocol::ObjectMapReply); + msg.payload() << objectAddresses(); + send(msg); + } +} + +void Server::messageReceived(const Message& msg) +{ + if (msg.address() == endpointAddress()) { + switch (msg.type()) { + case Protocol::ObjectMonitored: + case Protocol::ObjectUnmonitored: + { + Protocol::ObjectAddress addr; + msg.payload() >> addr; + Q_ASSERT(addr > Protocol::InvalidObjectAddress); + const QHash >::const_iterator it = m_monitorNotifiers.constFind(addr); + if (it == m_monitorNotifiers.constEnd()) + break; + //cout << Q_FUNC_INFO << " un/monitor " << (int)addr << endl; + QMetaObject::invokeMethod(it.value().first, it.value().second, Q_ARG(bool, msg.type() == Protocol::ObjectMonitored)); + break; + } + } + } else { + dispatchMessage(msg); + } +} + +void Server::invokeObject(const QString &objectName, const char *method, const QVariantList &args) const +{ + Endpoint::invokeObject(objectName, method, args); + + QObject* object = ObjectBroker::objectInternal(objectName); + Q_ASSERT(object); + // also invoke locally for in-process mode + invokeObjectLocal(object, method, args); +} + +Protocol::ObjectAddress Server::registerObject(const QString &name, QObject *object) +{ + registerObjectInternal(name, ++m_nextAddress); + Protocol::ObjectAddress address = Endpoint::registerObject(name, object); + Q_ASSERT(m_nextAddress); + + if (isConnected()) { + Message msg(endpointAddress(), Protocol::ObjectAdded); + msg.payload() << name << m_nextAddress; + send(msg); + } + + const QMetaObject *meta = object->metaObject(); + for(int i = 0; i < meta->methodCount(); ++i) { + const QMetaMethod method = meta->method(i); + if (method.methodType() == QMetaMethod::Signal) { + m_signalMapper->connectToSignal(object, method); + } + } + + return address; +} + +void Server::forwardSignal(QObject* sender, int signalIndex, const QVector< QVariant >& args) +{ + if (!isConnected()) + return; + + Q_ASSERT(sender); + Q_ASSERT(signalIndex >= 0); + const QMetaMethod signal = sender->metaObject()->method(signalIndex); + Q_ASSERT(signal.methodType() == QMetaMethod::Signal); + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + QByteArray name = signal.signature(); +#else + QByteArray name = signal.methodSignature(); +#endif + // get the name of the function to invoke, excluding the parens and function arguments. + name = name.mid(0, name.indexOf('(')); + + QVariantList v; + foreach(const QVariant &arg, args) + v.push_back(arg); + Endpoint::invokeObject(sender->objectName(), name, v); +} + +Protocol::ObjectAddress Server::registerObject(const QString& objectName, QObject* receiver, const char* messageHandlerName) +{ + registerObjectInternal(objectName, ++m_nextAddress); + Q_ASSERT(m_nextAddress); + registerMessageHandlerInternal(m_nextAddress, receiver, messageHandlerName); + + if (isConnected()) { + Message msg(endpointAddress(), Protocol::ObjectAdded); + msg.payload() << objectName << m_nextAddress; + send(msg); + } + + return m_nextAddress; +} + +void Server::registerMonitorNotifier(Protocol::ObjectAddress address, QObject* receiver, const char* monitorNotifier) +{ + Q_ASSERT(address != Protocol::InvalidObjectAddress); + Q_ASSERT(receiver); + Q_ASSERT(monitorNotifier); + + m_monitorNotifiers.insert(address, qMakePair(receiver, monitorNotifier)); +} + +void Server::handlerDestroyed(Protocol::ObjectAddress objectAddress, const QString& objectName) +{ + unregisterObjectInternal(objectName); + m_monitorNotifiers.remove(objectAddress); + + if (isConnected()) { + Message msg(endpointAddress(), Protocol::ObjectRemoved); + msg.payload() << objectName; + send(msg); + } +} + +void Server::objectDestroyed(Protocol::ObjectAddress /*objectAddress*/, const QString &objectName, QObject *object) +{ + Q_UNUSED(object); + unregisterObjectInternal(objectName); + + if (isConnected()) { + Message msg(endpointAddress(), Protocol::ObjectRemoved); + msg.payload() << objectName; + send(msg); + } +} + +void Server::broadcast() +{ + QString myAddress; + foreach (const QHostAddress &addr, QNetworkInterface::allAddresses()) { + if (addr == QHostAddress::LocalHost || addr == QHostAddress::LocalHostIPv6 || !addr.scopeId().isEmpty()) + continue; + myAddress = addr.toString(); + break; + } + + QByteArray datagram; + QDataStream stream(&datagram, QIODevice::WriteOnly); + stream << Protocol::broadcastFormatVersion(); + stream << Protocol::version(); + stream << myAddress; + stream << port(); + stream << label(); // TODO integrate hostname + m_broadcastSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, broadcastPort()); +} + +quint16 Server::port() const +{ + return m_tcpServer->serverPort(); +} diff -Nru gammaray-1.2.2/core/remote/server.h gammaray-2.0.1/core/remote/server.h --- gammaray-1.2.2/core/remote/server.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/remote/server.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,106 @@ +/* + server.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SERVER_H +#define GAMMARAY_SERVER_H + +#include "../gammaray_core_export.h" + +#include +#include + +class QTcpServer; +class QUdpSocket; +class QTimer; + +namespace GammaRay { + +class MultiSignalMapper; + +/** Server side connection endpoint. */ +class GAMMARAY_CORE_EXPORT Server : public Endpoint +{ + Q_OBJECT + public: + explicit Server(QObject *parent = 0); + ~Server(); + + /** + * Register a server-side QObject to send/receive messages to/from the client side. + */ + virtual Protocol::ObjectAddress registerObject(const QString &name, QObject *object); + + /** Register a new object with name @p objectName as a destination for messages. + * New messages to that object are passed to the slot @p messageHandlerName on @p receiver. + */ + Protocol::ObjectAddress registerObject(const QString &objectName, QObject* receiver, const char* messageHandlerName); + + /** + * Register a callback slot @p monitorNotifier on object @p receiver that is called if the usage + * of an object with address @p address changes on the client side. + * + * This is useful for example to disable expensive operations like sending large amounts of + * data if nobody is interested anyway. + */ + void registerMonitorNotifier(Protocol::ObjectAddress address, QObject *receiver, const char* monitorNotifier); + + /** Singleton accessor. */ + static Server* instance(); + + /** + * Call @p method on the remote client and also directly on the local object identified by @p objectName. + */ + virtual void invokeObject(const QString &objectName, const char *method, const QVariantList &args = QVariantList()) const; + + bool isRemoteClient() const; + QString serverAddress() const; + quint16 port() const; + protected: + void messageReceived(const Message& msg); + void handlerDestroyed(Protocol::ObjectAddress objectAddress, const QString& objectName); + void objectDestroyed(Protocol::ObjectAddress objectAddress, const QString &objectName, QObject *object); + + private slots: + void newConnection(); + void broadcast(); + + /** + * Forward the signal that triggered the call to this slot to the remote client if connected. + */ + void forwardSignal(QObject* sender, int signalIndex, const QVector &args); + + private: + QTcpServer *m_tcpServer; + QHash > m_monitorNotifiers; + Protocol::ObjectAddress m_nextAddress; + + QString m_label; + QTimer* m_broadcastTimer; + QUdpSocket* m_broadcastSocket; + + MultiSignalMapper* m_signalMapper; +}; + +} + +#endif diff -Nru gammaray-1.2.2/core/sidepane.cpp gammaray-2.0.1/core/sidepane.cpp --- gammaray-1.2.2/core/sidepane.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/sidepane.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,82 +0,0 @@ -/* - sidepane.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "sidepane.h" - -#include -#include - -using namespace GammaRay; - -class Delegate : public QStyledItemDelegate -{ - public: - explicit Delegate(QObject *parent = 0) - : QStyledItemDelegate(parent) - { - } - - virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const - { - static const int heightMargin = 10; - - QSize size = QStyledItemDelegate::sizeHint(option, index); - size.setHeight(size.height() + heightMargin); - return size; - } -}; - -SidePane::SidePane(QWidget *parent) - : QListView(parent) -{ - viewport()->setAutoFillBackground(false); - - setItemDelegate(new Delegate(this)); -} - -SidePane::~SidePane() -{ -} - -QSize SidePane::sizeHint() const -{ - static const int widthMargin = 10; - - if (!model()) { - return QSize(0, 0); - } - - const int width = sizeHintForColumn(0) + widthMargin; - const int height = QListView::sizeHint().height(); - - return QSize(width, height); -} - -void SidePane::resizeEvent(QResizeEvent *e) -{ - setMinimumWidth(sizeHint().width()); - - QListView::resizeEvent(e); -} - -#include "sidepane.moc" diff -Nru gammaray-1.2.2/core/sidepane.h gammaray-2.0.1/core/sidepane.h --- gammaray-1.2.2/core/sidepane.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/sidepane.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ -/* - sidepane.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SIDEPANE_H -#define GAMMARAY_SIDEPANE_H - -#include - -namespace GammaRay { - -class SidePane : public QListView -{ - Q_OBJECT - public: - explicit SidePane(QWidget *parent = 0); - virtual ~SidePane(); - - virtual QSize sizeHint() const; - - protected: - virtual void resizeEvent(QResizeEvent *e); -}; - -} - -#endif // GAMMARAY_SIDEPANE_H diff -Nru gammaray-1.2.2/core/singlecolumnobjectproxymodel.h gammaray-2.0.1/core/singlecolumnobjectproxymodel.h --- gammaray-1.2.2/core/singlecolumnobjectproxymodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/singlecolumnobjectproxymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,86 @@ +/* + singlecolumnobjectproxymodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares the SingleColumnObjectProxyModel class. + + @brief + Declares the SingleColumnObjectProxyModel class. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H +#define GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H + +#include +#include "util.h" + +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) +#include +typedef QSortFilterProxyModel QIdentityProxyModel; +#else +#include +#endif + +namespace GammaRay { + +/** + * @brief A QIdentityProxyModel for generic Objects. + */ +class SingleColumnObjectProxyModel : public QIdentityProxyModel +{ + public: + /** + * Constructor. + * @param parent is the parent object for this instance. + */ + explicit SingleColumnObjectProxyModel(QObject *parent = 0) + : QIdentityProxyModel(parent) + { + } + + /** + * Returns the data for the specified model. + * @param proxyIndex is a QModelIndex. + * @param role is a Qt role. + * + * @return on success, a QVariant containing the data; + * QVariant() if some anamoly occurs. + */ + QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const + { + if (proxyIndex.isValid() && role == Qt::DisplayRole && proxyIndex.column() == 0) { + const QObject *obj = proxyIndex.data(ObjectModel::ObjectRole).value(); + if (obj) { + return Util::displayString(obj); + } + } + + return QIdentityProxyModel::data(proxyIndex, role); + } +}; + +} + +#endif // GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H diff -Nru gammaray-1.2.2/core/toolfactory.h gammaray-2.0.1/core/toolfactory.h --- gammaray-1.2.2/core/toolfactory.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/toolfactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,155 @@ +/* + toolfactory.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares the ToolFactory abstract base class. + + @brief + Declares the ToolFactory abstract base class. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_TOOLFACTORY_H +#define GAMMARAY_TOOLFACTORY_H + +#include "probeinterface.h" +#include + +#include +#include +#include + +namespace GammaRay { + +class ProbeInterface; + +/** + * @brief An abstract interface for probe tools. + * + * The ToolFactory class is an abstract base class for creating probe tools + * for GammaRay. Each tool must have a unique identifier. + */ +class ToolFactory +{ + public: + virtual inline ~ToolFactory() + { + } + + /** + * Unique id of this tool + * @return a QString containing the tool id. + */ + virtual QString id() const = 0; + + /** + * Human readable name of this tool. + * @return a QString containing the tool name. + */ + virtual QString name() const = 0; + + /** + * Class names of types this tool can handle. + * The tool will only be activated if an object of one of these types + * is seen in the probed application. + * @return a QStringList of class names of types this tool supports. + */ + virtual QStringList supportedTypes() const = 0; + + /** + * Initialize the tool. + * Implement this method to do non-GUI initialization, such as creating + * object tracking models etc. + * @param probe The probe interface allowing access to the object models. + */ + virtual void init(ProbeInterface *probe) = 0; +}; + +/** + * @brief A templated generic ToolFactory for some data type and tool. + */ +template +class StandardToolFactory : public ToolFactory +{ +public: + virtual inline QStringList supportedTypes() const + { + return QStringList(Type::staticMetaObject.className()); + } + + virtual inline QString id() const + { + return Tool::staticMetaObject.className(); + } + + virtual inline void init(ProbeInterface *probe) + { + new Tool(probe, probe->probe()); + } +}; + +/** + * @brief A templated generic ToolFactory for some data type and Tool. + */ +// TODO: split this completely, this is just a migration aid +template +class StandardToolFactory2 : public ToolFactory, public ToolUiFactory +{ + public: + virtual inline QStringList supportedTypes() const + { + return QStringList(Type::staticMetaObject.className()); + } + + virtual inline QString id() const + { + return Tool::staticMetaObject.className(); + } + + virtual inline void init(ProbeInterface *probe) + { + new Tool(probe, probe->probe()); + } + + virtual inline QWidget *createWidget(QWidget *parentWidget) + { + return new ToolUi(parentWidget); + } + + virtual bool remotingSupported() const + { + return true; + } +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::ToolFactory, "com.kdab.GammaRay.ToolFactory/1.0") +Q_DECLARE_METATYPE(GammaRay::ToolFactory *) + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#define Q_PLUGIN_METADATA(x) +#endif + +#endif diff -Nru gammaray-1.2.2/core/toolmodel.cpp gammaray-2.0.1/core/toolmodel.cpp --- gammaray-1.2.2/core/toolmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/toolmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,29 +21,29 @@ along with this program. If not, see . */ -#include "config-gammaray.h" #include "toolmodel.h" -#include "include/toolfactory.h" +#include "toolfactory.h" +#include "proxytoolfactory.h" +#include "probe.h" +#include "readorwritelocker.h" +#include "probesettings.h" -#include "tools/codecbrowser/codecbrowser.h" #include "tools/connectioninspector/connectioninspector.h" -#include "tools/fontbrowser/fontbrowser.h" #include "tools/localeinspector/localeinspector.h" #include "tools/metatypebrowser/metatypebrowser.h" #include "tools/modelinspector/modelinspector.h" #include "tools/objectinspector/objectinspector.h" #include "tools/resourcebrowser/resourcebrowser.h" -#include "tools/sceneinspector/sceneinspector.h" -#include "tools/selectionmodelinspector/selectionmodelinspector.h" #include "tools/textdocumentinspector/textdocumentinspector.h" -#include "tools/widgetinspector/widgetinspector.h" #include "tools/messagehandler/messagehandler.h" -#include "tools/styleinspector/styleinspector.h" +#include "tools/metaobjectbrowser/metaobjectbrowser.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include "tools/standardpaths/standardpaths.h" +#include "tools/mimetypes/mimetypes.h" +#endif -#include "pluginmanager.h" -#include "probe.h" -#include "readorwritelocker.h" +#include #include #include @@ -57,31 +57,37 @@ { // built-in tools m_tools.push_back(new ObjectInspectorFactory(this)); - m_tools.push_back(new WidgetInspectorFactory(this)); - m_tools.push_back(new ModelInspector(this)); - m_tools.push_back(new SceneInspectorFactory(this)); + m_tools.push_back(new ModelInspectorFactory(this)); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) m_tools.push_back(new ConnectionInspectorFactory(this)); +#endif m_tools.push_back(new ResourceBrowserFactory(this)); + m_tools.push_back(new MetaObjectBrowserFactory(this)); m_tools.push_back(new MetaTypeBrowserFactory(this)); - m_tools.push_back(new SelectionModelInspectorFactory(this)); - m_tools.push_back(new FontBrowserFactory(this)); - m_tools.push_back(new CodecBrowserFactory(this)); m_tools.push_back(new TextDocumentInspectorFactory(this)); m_tools.push_back(new MessageHandlerFactory(this)); m_tools.push_back(new LocaleInspectorFactory(this)); - m_tools.push_back(new StyleInspectorFactory(this)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + m_tools.push_back(new StandardPathsFactory(this)); + m_tools.push_back(new MimeTypesFactory(this)); +#endif - Q_FOREACH (ToolFactory *factory, PluginManager::instance()->plugins()) { + m_pluginManager.reset(new ToolPluginManager(this)); + Q_FOREACH (ToolFactory *factory, m_pluginManager->plugins()) { m_tools.push_back(factory); } // everything but the object inspector is inactive initially const int numberOfTools(m_tools.size()); - for (int i = 1; i < numberOfTools; ++i) { + for (int i = 0; i < numberOfTools; ++i) { m_inactiveTools.insert(m_tools.at(i)); } } +ToolModel::~ToolModel() +{ +} + QVariant ToolModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { @@ -104,26 +110,14 @@ ToolFactory *toolIface = m_tools.at(index.row()); if (role == Qt::DisplayRole) { return toolIface->name(); - } else if (role == ToolFactoryRole) { + } else if (role == ToolModelRole::ToolFactory) { return QVariant::fromValue(toolIface); - } else if (role == ToolWidgetRole) { - return QVariant::fromValue(m_toolWidgets.value(toolIface)); - } else if (role == ToolIdRole) { + } else if (role == ToolModelRole::ToolId) { return toolIface->id(); } return QVariant(); } -bool ToolModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (index.isValid() && role == Qt::EditRole) { - ToolFactory *toolIface = m_tools.at(index.row()); - m_toolWidgets.insert(toolIface, value.value()); - return true; - } - return QAbstractItemModel::setData(index, value, role); -} - int ToolModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { @@ -144,11 +138,19 @@ return flags; } +QMap ToolModel::itemData(const QModelIndex& index) const +{ + QMap map = QAbstractListModel::itemData(index); + map.insert(ToolModelRole::ToolId, data(index, ToolModelRole::ToolId)); + // the other custom roles are useless on the client anyway, since they contain raw pointers + return map; +} + void ToolModel::objectAdded(QObject *obj) { // delay to main thread if required QMetaObject::invokeMethod(this, "objectAddedMainThread", - Qt::AutoConnection, Q_ARG(QObject *, obj)); + Qt::AutoConnection, Q_ARG(QObject*, obj)); } void ToolModel::objectAddedMainThread(QObject *obj) @@ -175,4 +177,13 @@ } } -#include "toolmodel.moc" +QVector< ToolFactory* > ToolModel::plugins() const +{ + return m_pluginManager->plugins(); +} + +PluginLoadErrors ToolModel::pluginErrors() const +{ + return m_pluginManager->errors(); +} + diff -Nru gammaray-1.2.2/core/toolmodel.h gammaray-2.0.1/core/toolmodel.h --- gammaray-1.2.2/core/toolmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/toolmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,13 +24,20 @@ #ifndef GAMMARAY_TOOLMODEL_H #define GAMMARAY_TOOLMODEL_H +#include +#include + #include #include #include +#include namespace GammaRay { class ToolFactory; +class ProxyToolFactory; + +typedef PluginManager ToolPluginManager; /** * Manages the list of available probing tools. @@ -39,18 +46,19 @@ { Q_OBJECT public: - enum Role { - ToolFactoryRole = Qt::UserRole + 1, - ToolWidgetRole, - ToolIdRole - }; explicit ToolModel(QObject *parent = 0); + ~ToolModel(); virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual QMap itemData(const QModelIndex& index) const; + + /** returns all tools provided by plugins for the ToolPluginModel. */ + QVector plugins() const; + /** returns all plugin load errors. */ + PluginLoadErrors pluginErrors() const; public slots: /** Check if we have to activate tools for this type */ @@ -67,8 +75,9 @@ private: QVector m_tools; - QHash m_toolWidgets; QSet m_inactiveTools; + QPointer m_parentWidget; + QScopedPointer m_pluginManager; }; } diff -Nru gammaray-1.2.2/core/toolpluginerrormodel.cpp gammaray-2.0.1/core/toolpluginerrormodel.cpp --- gammaray-1.2.2/core/toolpluginerrormodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/toolpluginerrormodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "toolpluginerrormodel.h" + +using namespace GammaRay; + +ToolPluginErrorModel::ToolPluginErrorModel(const PluginLoadErrors& errors, QObject* parent) + : QAbstractTableModel(parent), m_errors(errors) +{ +} + +ToolPluginErrorModel::~ToolPluginErrorModel() +{ +} + +int ToolPluginErrorModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return 3; +} + +int ToolPluginErrorModel::rowCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return m_errors.size(); +} + +QVariant ToolPluginErrorModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const int row = index.row(); + const int column = index.column(); + if (role == Qt::DisplayRole) { + switch (column) { + case 0: + return m_errors[row].pluginName(); + case 1: + return m_errors[row].pluginFile; + case 2: + return m_errors[row].errorString; + } + } + return QVariant(); +} + +QVariant ToolPluginErrorModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return tr("Plugin Name"); + case 1: + return tr("Plugin File"); + case 2: + return tr("Error Message"); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + diff -Nru gammaray-1.2.2/core/toolpluginerrormodel.h gammaray-2.0.1/core/toolpluginerrormodel.h --- gammaray-1.2.2/core/toolpluginerrormodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/toolpluginerrormodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_TOOLPLUGINERRORMODEL_H +#define GAMMARAY_TOOLPLUGINERRORMODEL_H + +#include + +#include + +namespace GammaRay { + +/** List of plugin loading errors on the target. */ +class ToolPluginErrorModel : public QAbstractTableModel +{ + Q_OBJECT +public: + explicit ToolPluginErrorModel(const PluginLoadErrors &errors, QObject *parent = 0); + ~ToolPluginErrorModel(); + + QVariant data(const QModelIndex& index, int role) const; + int columnCount(const QModelIndex& parent) const; + int rowCount(const QModelIndex& parent) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + +private: + PluginLoadErrors m_errors; +}; +} + +#endif // GAMMARAY_TOOLPLUGINERRORMODEL_H diff -Nru gammaray-1.2.2/core/toolpluginmodel.cpp gammaray-2.0.1/core/toolpluginmodel.cpp --- gammaray-1.2.2/core/toolpluginmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/toolpluginmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,85 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "toolpluginmodel.h" +#include "toolfactory.h" + +using namespace GammaRay; + +ToolPluginModel::ToolPluginModel(const QVector &plugins, QObject* parent): + QAbstractTableModel(parent), + m_tools(plugins) +{ +} + +ToolPluginModel::~ToolPluginModel() +{ +} + +int ToolPluginModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return 3; +} + +int ToolPluginModel::rowCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return m_tools.size(); +} + +QVariant ToolPluginModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const int row = index.row(); + const int column = index.column(); + if (role == Qt::DisplayRole) { + ToolFactory *factory = m_tools[row]; + switch (column) { + case 0: + return factory->id(); + case 1: + return factory->name(); + case 2: + return factory->supportedTypes().join(", "); + } + } + return QVariant(); +} + +QVariant ToolPluginModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return tr("Id"); + case 1: + return tr("Name"); + case 2: + return tr("Supported types"); + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + diff -Nru gammaray-1.2.2/core/toolpluginmodel.h gammaray-2.0.1/core/toolpluginmodel.h --- gammaray-1.2.2/core/toolpluginmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/toolpluginmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_TOOLPLUGINMODEL_H +#define GAMMARAY_TOOLPLUGINMODEL_H + +#include +#include + +namespace GammaRay { + +class ToolFactory; + +/** Information about loaded plugins, for display in the about dialog. */ +class ToolPluginModel : public QAbstractTableModel +{ + Q_OBJECT +public: + explicit ToolPluginModel(const QVector &plugins, QObject *parent = 0); + ~ToolPluginModel(); + + QVariant data(const QModelIndex& index, int role) const; + int columnCount(const QModelIndex& parent) const; + int rowCount(const QModelIndex& parent) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + +private: + QVector m_tools; +}; +} + +#endif // GAMMARAY_TOOLPLUGINMODEL_H diff -Nru gammaray-1.2.2/core/tools/CMakeLists.txt gammaray-2.0.1/core/tools/CMakeLists.txt --- gammaray-1.2.2/core/tools/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} -) - -# Disabled in Qt5 - QFormBuilder include is not installed -if(NOT Qt5Core_FOUND) - add_subdirectory(widgetinspector) -endif() diff -Nru gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.cpp gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.cpp --- gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -/* - codecbrowser.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "codecbrowser.h" -#include "ui_codecbrowser.h" - -#include "codecmodel.h" - -using namespace GammaRay; - -CodecBrowser::CodecBrowser(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::CodecBrowser) -{ - Q_UNUSED(probe); - ui->setupUi(this); - - ui->codecList->setRootIsDecorated(false); - ui->codecList->setModel(new AllCodecsModel(this)); - ui->codecList->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_selectedCodecsModel = new SelectedCodecsModel(this); - ui->selectedCodecs->setRootIsDecorated(false); - ui->selectedCodecs->setModel(m_selectedCodecsModel); - - ui->codecList->header()->setResizeMode(0, QHeaderView::ResizeToContents); - ui->selectedCodecs->header()->setResizeMode(0, QHeaderView::ResizeToContents); - - connect(ui->codecList->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(updateCodecs(QItemSelection,QItemSelection))); - connect(ui->codecText, SIGNAL(textChanged(QString)), - m_selectedCodecsModel, SLOT(updateText(QString))); -} - -void CodecBrowser::updateCodecs(const QItemSelection &selected, - const QItemSelection &deselected) -{ - Q_UNUSED(selected); - Q_UNUSED(deselected); - - QStringList currentCodecNames; - foreach (const QModelIndex &index, ui->codecList->selectionModel()->selectedRows()) { - const QString codecName = index.data().toString(); - currentCodecNames.append(codecName); - } - - m_selectedCodecsModel->setCodecs(currentCodecNames); -} - -#include "codecbrowser.moc" diff -Nru gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.h gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.h --- gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -/* - codecbrowser.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_CODECBROWSER_CODECBROWSER_H -#define GAMMARAY_CODECBROWSER_CODECBROWSER_H - -#include "include/toolfactory.h" - -#include - -class QItemSelection; - -namespace GammaRay { - -class SelectedCodecsModel; - -namespace Ui { - class CodecBrowser; -} - -class CodecBrowser : public QWidget -{ - Q_OBJECT - public: - explicit CodecBrowser(ProbeInterface *probe, QWidget *parent = 0); - - private slots: - void updateCodecs(const QItemSelection &selected, const QItemSelection &deselected); - - private: - QScopedPointer ui; - SelectedCodecsModel *m_selectedCodecsModel; -}; - -class CodecBrowserFactory : public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - public: - explicit CodecBrowserFactory(QObject *parent) : QObject(parent) - { - } - - virtual inline QString name() const - { - return tr("Text Codecs"); - } -}; - -} - -#endif // GAMMARAY_CODECBROWSER_H diff -Nru gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.ui gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.ui --- gammaray-1.2.2/core/tools/codecbrowser/codecbrowser.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/codecbrowser/codecbrowser.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,40 +0,0 @@ - - - GammaRay::CodecBrowser - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - - - - codec preview text - - - - - - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/codecbrowser/codecmodel.cpp gammaray-2.0.1/core/tools/codecbrowser/codecmodel.cpp --- gammaray-1.2.2/core/tools/codecbrowser/codecmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/codecbrowser/codecmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,192 +0,0 @@ -/* - codecmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "codecmodel.h" - -#include - -using namespace GammaRay; - -AllCodecsModel::AllCodecsModel(QObject *parent) - : QAbstractItemModel(parent) -{ -} - -int AllCodecsModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 2; -} - -QVariant AllCodecsModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::DisplayRole) { - if (index.column() == 0) { - return QTextCodec::availableCodecs().at(index.row()); - } - if (index.column() == 1) { - QList aliases = - QTextCodec::codecForName(QTextCodec::availableCodecs().at(index.row()))->aliases(); - - QString result; - int size = aliases.size(); - int i = 0; - foreach (const QByteArray &ba, aliases) { - result.append(ba); - - ++i; - if (i != size) { - result.append(", "); - } - } - return result; - } - } - return QVariant(); -} - -QVariant AllCodecsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - if (section == 0) { - return "Codec"; - } else if (section == 1) { - return "Aliases"; - } - } - return QVariant(); -} - -QModelIndex AllCodecsModel::index(int row, int column, const QModelIndex &parent) const -{ - if (parent.isValid()) { - return QModelIndex(); - } - if (!hasIndex(row, column, parent)) { - return QModelIndex(); - } - return createIndex(row, column); -} - -QModelIndex AllCodecsModel::parent(const QModelIndex &child) const -{ - Q_UNUSED(child); - return QModelIndex(); -} - -int AllCodecsModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - return QTextCodec::availableCodecs().size(); -} - -SelectedCodecsModel::SelectedCodecsModel(QObject *parent) - : QAbstractItemModel(parent) -{ -} - -void SelectedCodecsModel::setCodecs(const QStringList &codecs) -{ - beginResetModel(); - m_codecs = codecs; - endResetModel(); -} - -QStringList SelectedCodecsModel::currentCodecs() const -{ - return m_codecs; -} - -void SelectedCodecsModel::updateText(const QString &text) -{ - beginResetModel(); - m_text = text; - endResetModel(); -} - -QVariant SelectedCodecsModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - if (section == 0) { - return "Codec"; - } - if (section == 1) { - return "Data"; - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -int SelectedCodecsModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - return m_codecs.size(); -} - -QModelIndex SelectedCodecsModel::index(int row, int column, const QModelIndex &parent) const -{ - if (parent.isValid()) { - return QModelIndex(); - } - if (!hasIndex(row, column, parent)) { - return QModelIndex(); - } - return createIndex(row, column); -} - -QModelIndex SelectedCodecsModel::parent(const QModelIndex &child) const -{ - Q_UNUSED(child); - return QModelIndex(); -} - -int SelectedCodecsModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 2; -} - -QVariant SelectedCodecsModel::data(const QModelIndex &index, int role) const -{ - if (index.column() == 0) { - if (role == Qt::DisplayRole) { - return m_codecs.at(index.row()); - } - } else if (index.column() == 1) { - if (role == Qt::DisplayRole) { - const QByteArray ba = - QTextCodec::codecForName(m_codecs.at(index.row()).toLatin1())->fromUnicode(m_text); -// QString result; -// foreach () - return ba.toHex(); - } - } - - return QVariant(); -} - -#include "codecmodel.moc" diff -Nru gammaray-1.2.2/core/tools/codecbrowser/codecmodel.h gammaray-2.0.1/core/tools/codecbrowser/codecmodel.h --- gammaray-1.2.2/core/tools/codecbrowser/codecmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/codecbrowser/codecmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,89 +0,0 @@ -/* - codecmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_CODECBROWSER_CODECMODEL_H -#define GAMMARAY_CODECBROWSER_CODECMODEL_H - -#include -#include -#include - -namespace GammaRay { - -class AllCodecsModel : public QAbstractItemModel -{ - Q_OBJECT - public: - AllCodecsModel(QObject *parent); - - virtual QVariant headerData(int section, - Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const; - - virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - - virtual QModelIndex parent(const QModelIndex &child) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; -}; - -class SelectedCodecsModel : public QAbstractItemModel -{ - Q_OBJECT - public: - SelectedCodecsModel(QObject *parent); - - void setCodecs(const QStringList &codecs); - QStringList currentCodecs() const; - - virtual QVariant headerData(int section, - Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const; - - virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - - virtual QModelIndex parent(const QModelIndex &child) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - public slots: - void updateText(const QString &text); - - private: - QStringList m_codecs; - QString m_text; -}; - -} - -#endif diff -Nru gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.cpp gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.cpp --- gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,32 +22,12 @@ */ #include "connectioninspector.h" -#include "connectionfilterproxymodel.h" -#include "proxydetacher.h" -#include "ui_connectioninspector.h" - -#include "include/probeinterface.h" - -#include using namespace GammaRay; -ConnectionInspector::ConnectionInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::ConnectionInspector) +ConnectionInspector::ConnectionInspector(ProbeInterface *probe, QObject *parent) + : QObject(parent) { - ui->setupUi(this); - - ConnectionFilterProxyModel *proxy = new ConnectionFilterProxyModel(this); - new ProxyDetacher(ui->connectionView, proxy, probe->connectionModel()); - ui->connectionSearchLine->setProxy(proxy); - ui->connectionView->setModel(proxy); - - if (qgetenv("GAMMARAY_TEST_FILTER") == "1") { - QMetaObject::invokeMethod(ui->connectionSearchLine->lineEdit(), "setText", - Qt::QueuedConnection, - Q_ARG(QString, QLatin1String("destroyed"))); - } + Q_UNUSED(probe); } -#include "connectioninspector.moc" diff -Nru gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.h gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.h --- gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,24 +24,15 @@ #ifndef GAMMARAY_CONNECTIONINSPECTOR_CONNECTIONINSPECTOR_H #define GAMMARAY_CONNECTIONINSPECTOR_CONNECTIONINSPECTOR_H -#include "include/toolfactory.h" - -#include +#include "toolfactory.h" namespace GammaRay { -namespace Ui { - class ConnectionInspector; -} - -class ConnectionInspector : public QWidget +class ConnectionInspector : public QObject { Q_OBJECT public: - explicit ConnectionInspector(ProbeInterface *probe, QWidget *parent = 0); - - private: - QScopedPointer ui; + explicit ConnectionInspector(ProbeInterface *probe, QObject *parent = 0); }; class ConnectionInspectorFactory : public QObject, diff -Nru gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.ui gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.ui --- gammaray-1.2.2/core/tools/connectioninspector/connectioninspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/connectioninspector/connectioninspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ - - - GammaRay::ConnectionInspector - - - - 0 - 0 - 400 - 300 - - - - - - - - - - true - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
-
- - -
diff -Nru gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.cpp gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.cpp --- gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,122 +0,0 @@ -/* - fontbrowser.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "fontbrowser.h" -#include "ui_fontbrowser.h" - -#include "fontmodel.h" - -using namespace GammaRay; - -FontBrowser::FontBrowser(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::FontBrowser) -{ - Q_UNUSED(probe); - ui->setupUi(this); - - QFontDatabase database; - - m_selectedFontModel = new FontModel(this); - ui->selectedFontsView->setModel(m_selectedFontModel); - ui->selectedFontsView->setRootIsDecorated(false); - - ui->fontTree->setSelectionMode(QAbstractItemView::ExtendedSelection); - foreach (const QString &family, database.families()) { - QTreeWidgetItem *familyItem = new QTreeWidgetItem(ui->fontTree); - familyItem->setText(0, family); - - foreach (const QString &style, database.styles(family)) { - QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); - styleItem->setText(0, style); - - QString sizes; - foreach (int points, database.smoothSizes(family, style)) { - sizes += QString::number(points) + ' '; - } - - styleItem->setText(1, sizes.trimmed()); - } - } - ui->fontTree->header()->setResizeMode(0, QHeaderView::ResizeToContents); - ui->selectedFontsView->header()->setResizeMode(0, QHeaderView::ResizeToContents); - connect(ui->fontTree->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(updateFonts(QItemSelection,QItemSelection))); - connect(ui->fontText, SIGNAL(textChanged(QString)), - m_selectedFontModel, SLOT(updateText(QString))); - - ui->pointSize->setValue(font().pointSize()); - - connect(ui->boldBox, SIGNAL(toggled(bool)), - m_selectedFontModel, SLOT(toggleBoldFont(bool))); - connect(ui->italicBox, SIGNAL(toggled(bool)), - m_selectedFontModel, SLOT(toggleItalicFont(bool))); - connect(ui->underlineBox, SIGNAL(toggled(bool)), - m_selectedFontModel, SLOT(toggleUnderlineFont(bool))); - connect(ui->pointSize, SIGNAL(valueChanged(int)), - m_selectedFontModel, SLOT(setPointSize(int))); -} - -void FontBrowser::updateFonts(const QItemSelection &selected, const QItemSelection &deselected) -{ - Q_UNUSED(selected); - Q_UNUSED(deselected); - QList previousFonts = m_selectedFontModel->currentFonts(); - QStringList previousFontNames; - foreach (const QFont &f, previousFonts) { - previousFontNames.append(f.family()); - } - QList currentFonts; - QStringList currentFontNames; - foreach (const QModelIndex &index, ui->fontTree->selectionModel()->selectedRows()) { - if (index.parent().isValid()) { - continue; - } - QFont font(index.data().toString()); - font.setBold(ui->boldBox->isChecked()); - font.setUnderline(ui->underlineBox->isChecked()); - font.setItalic(ui->italicBox->isChecked()); - font.setPointSize(ui->pointSize->value()); - currentFontNames.append(font.family()); - if (previousFontNames.contains(font.family())) { - continue; - } - currentFonts.append(font); - } - { - QList::iterator it = previousFonts.begin(); - while (it != previousFonts.end()) { - if (!currentFontNames.contains(it->family())) { - it = previousFonts.erase(it); - } else { - ++it; - } - } - } - - currentFonts << previousFonts; - m_selectedFontModel->updateFonts(currentFonts); -} - -#include "fontbrowser.moc" diff -Nru gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.h gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.h --- gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,73 +0,0 @@ -/* - fontbrowser.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_FONTBROWSER_FONTBROWSER_H -#define GAMMARAY_FONTBROWSER_FONTBROWSER_H - -#include "include/toolfactory.h" - -#include -#include - -class QItemSelection; - -namespace GammaRay { - -class FontModel; - -namespace Ui { - class FontBrowser; -} - -class FontBrowser : public QWidget -{ - Q_OBJECT - public: - explicit FontBrowser(ProbeInterface *probe, QWidget *parent = 0); - - private slots: - void updateFonts(const QItemSelection &selected, const QItemSelection &deselected); - - private: - QScopedPointer ui; - FontModel *m_selectedFontModel; -}; - -class FontBrowserFactory : public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - public: - explicit FontBrowserFactory(QObject *parent) : QObject(parent) - { - } - - virtual inline QString name() const - { - return tr("Fonts"); - } -}; - -} - -#endif // GAMMARAY_FONTBROWSER_H diff -Nru gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.ui gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.ui --- gammaray-1.2.2/core/tools/fontbrowser/fontbrowser.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/fontbrowser/fontbrowser.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,107 +0,0 @@ - - - GammaRay::FontBrowser - - - - 0 - 0 - 742 - 300 - - - - - - - Qt::Horizontal - - - - 2 - - - - Fonts - - - - - Smooth sizes - - - - - - - - - preview text - - - - - - - - 0 - - - - - Point Size: - - - - - - - - - - Bold - - - - - - - Italic - - - - - - - Underline - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/fontbrowser/fontmodel.cpp gammaray-2.0.1/core/tools/fontbrowser/fontmodel.cpp --- gammaray-1.2.2/core/tools/fontbrowser/fontmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/fontbrowser/fontmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,166 +0,0 @@ -/* - fontmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "fontmodel.h" - -using namespace GammaRay; - -FontModel::FontModel(QObject *parent) - : QAbstractItemModel(parent) -{ -} - -QList FontModel::currentFonts() const -{ - return m_fonts; -} - -void FontModel::updateFonts(const QList &fonts) -{ - beginResetModel(); - m_fonts = fonts; - endResetModel(); -} - -void FontModel::updateText(const QString &text) -{ - beginResetModel(); - m_text = text; - endResetModel(); -} - -QVariant FontModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - if (section == 0) { - return "Font"; - } - if (section == 1) { - return "Text Preview"; - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -int FontModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - return m_fonts.size(); -} - -QModelIndex FontModel::index(int row, int column, const QModelIndex &parent) const -{ - if (parent.isValid()) { - return QModelIndex(); - } - if (!hasIndex(row, column, parent)) { - return QModelIndex(); - } - return createIndex(row, column); -} - -QModelIndex FontModel::parent(const QModelIndex &child) const -{ - Q_UNUSED(child); - return QModelIndex(); -} - -int FontModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 2; -} - -QVariant FontModel::data(const QModelIndex &index, int role) const -{ - if (index.column() == 0) { - if (role == Qt::DisplayRole) { - return m_fonts.at(index.row()).family(); - } - } else if (index.column() == 1) { - if (role == Qt::DisplayRole) { - return m_text.isEmpty() ? "" : m_text; - } - if (role == Qt::FontRole) { - return m_fonts.at(index.row()); - } - } - - return QVariant(); -} - -void FontModel::setPointSize(int size) -{ - if (m_fonts.isEmpty()) { - return; - } - - for (int i = 0; i < m_fonts.size(); ++i) { - m_fonts[i].setPointSize(size); - } - - emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); -} - -void FontModel::toggleItalicFont(bool italic) -{ - if (m_fonts.isEmpty()) { - return; - } - - for (int i = 0; i < m_fonts.size(); ++i) { - m_fonts[i].setItalic(italic); - } - - emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); -} - -void FontModel::toggleUnderlineFont(bool underline) -{ - if (m_fonts.isEmpty()) { - return; - } - - for (int i = 0; i < m_fonts.size(); ++i) { - m_fonts[i].setUnderline(underline); - } - - emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); -} - -void FontModel::toggleBoldFont(bool bold) -{ - if (m_fonts.isEmpty()) { - return; - } - - for (int i = 0; i < m_fonts.size(); ++i) { - m_fonts[i].setBold(bold); - } - - emit dataChanged(index(0, 1), index(rowCount() - 1, 1)); -} - -#include "fontmodel.moc" diff -Nru gammaray-1.2.2/core/tools/fontbrowser/fontmodel.h gammaray-2.0.1/core/tools/fontbrowser/fontmodel.h --- gammaray-1.2.2/core/tools/fontbrowser/fontmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/fontbrowser/fontmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -/* - fontmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_FONTBROWSER_FONTMODEL_H -#define GAMMARAY_FONTBROWSER_FONTMODEL_H - -#include -#include - -namespace GammaRay { - -class FontModel : public QAbstractItemModel -{ - Q_OBJECT - public: - FontModel(QObject *parent); - - void updateFonts(const QList &fonts); - QList currentFonts() const; - - virtual QVariant headerData(int section, - Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const; - - virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - - virtual QModelIndex parent(const QModelIndex &child) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - public slots: - void updateText(const QString &text); - void toggleBoldFont(bool bold); - void toggleItalicFont(bool italic); - void toggleUnderlineFont(bool underline); - void setPointSize(int size); - - private: - QList m_fonts; - QString m_text; -}; - -} - -#endif diff -Nru gammaray-1.2.2/core/tools/localeinspector/localeaccessormodel.cpp gammaray-2.0.1/core/tools/localeinspector/localeaccessormodel.cpp --- gammaray-1.2.2/core/tools/localeinspector/localeaccessormodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localeaccessormodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -28,8 +28,8 @@ using namespace GammaRay; -LocaleAccessorModel::LocaleAccessorModel(QObject *parent) - : QAbstractTableModel(parent) +LocaleAccessorModel::LocaleAccessorModel(LocaleDataAccessorRegistry *registry, QObject *parent) + : QAbstractTableModel(parent), m_registry(registry) { } @@ -38,7 +38,7 @@ if (parent.isValid()) { return 0; } - int area = LocaleDataAccessorRegistry::accessors().size(); + int area = m_registry->accessors().size(); return qSqrt(area); } @@ -47,7 +47,7 @@ if (parent.isValid()) { return 0; } - int area = LocaleDataAccessorRegistry::accessors().size(); + int area = m_registry->accessors().size(); return qCeil((float)area / (int)qSqrt(area)); } @@ -58,7 +58,7 @@ QVariant LocaleAccessorModel::data(const QModelIndex &index, int role) const { - QVector acc = LocaleDataAccessorRegistry::accessors(); + QVector acc = m_registry->accessors(); int offset = (index.row() * columnCount()) + index.column(); if (offset >= acc.size()) { return QVariant(); @@ -70,7 +70,7 @@ return accessor->accessorName(); case Qt::CheckStateRole: return - LocaleDataAccessorRegistry::enabledAccessors().contains(accessor) ? + m_registry->enabledAccessors().contains(accessor) ? Qt::Checked : Qt::Unchecked; case AccessorRole: @@ -87,8 +87,8 @@ } bool enabled = value.toInt() == Qt::Checked; LocaleDataAccessor *accessor = index.data(AccessorRole).value(); - LocaleDataAccessorRegistry::setAccessorEnabled(accessor, enabled); - return false; + m_registry->setAccessorEnabled(accessor, enabled); + emit dataChanged(index, index); + return true; } -#include "localeaccessormodel.moc" diff -Nru gammaray-1.2.2/core/tools/localeinspector/localeaccessormodel.h gammaray-2.0.1/core/tools/localeinspector/localeaccessormodel.h --- gammaray-1.2.2/core/tools/localeinspector/localeaccessormodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localeaccessormodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -24,9 +24,11 @@ #include #include +#include namespace GammaRay { +class LocaleDataAccessorRegistry; struct LocaleDataAccessor; class LocaleAccessorModel : public QAbstractTableModel @@ -35,10 +37,10 @@ Q_ENUMS(CustomRoles) public: enum CustomRoles { - AccessorRole = Qt::UserRole + 1 + AccessorRole = UserRole + 1 }; - explicit LocaleAccessorModel(QObject *parent = 0); + explicit LocaleAccessorModel(LocaleDataAccessorRegistry *registry, QObject *parent = 0); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -48,6 +50,7 @@ private: QVector enabledAccessors; + LocaleDataAccessorRegistry *m_registry; }; } diff -Nru gammaray-1.2.2/core/tools/localeinspector/localedataaccessor.cpp gammaray-2.0.1/core/tools/localeinspector/localedataaccessor.cpp --- gammaray-1.2.2/core/tools/localeinspector/localedataaccessor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localedataaccessor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -25,35 +25,35 @@ using namespace GammaRay; -Q_GLOBAL_STATIC(LocaleDataAccessorRegistry, instance) - -LocaleDataAccessorRegistry::LocaleDataAccessorRegistry() +LocaleDataAccessorRegistry::LocaleDataAccessorRegistry(QObject *parent) + : QObject(parent) { + init(); } -LocaleDataAccessorRegistry *LocaleDataAccessorRegistry::instance() +LocaleDataAccessorRegistry::~LocaleDataAccessorRegistry() { - return ::instance(); + qDeleteAll(m_accessors); } QVector< LocaleDataAccessor * > LocaleDataAccessorRegistry::accessors() { - return ::instance()->m_accessors; + return m_accessors; } QVector< LocaleDataAccessor * > LocaleDataAccessorRegistry::enabledAccessors() { - return ::instance()->m_enabledAccessors; + return m_enabledAccessors; } void LocaleDataAccessorRegistry::registerAccessor(LocaleDataAccessor *accessor) { - ::instance()->m_accessors.push_back(accessor); + m_accessors.push_back(accessor); } void LocaleDataAccessorRegistry::setAccessorEnabled(LocaleDataAccessor *accessor, bool enabled) { - QVector< LocaleDataAccessor * > &accessors = ::instance()->m_enabledAccessors; + QVector< LocaleDataAccessor * > &accessors = m_enabledAccessors; if (enabled && !accessors.contains(accessor)) { accessors.push_back(accessor); } else { @@ -62,9 +62,12 @@ accessors.remove(idx); } } - emit ::instance()->accessorsChanged(); + emit accessorsChanged(); } +void LocaleDataAccessorRegistry::init() +{ + LOCALE_SIMPLE_DEFAULT_ACCESSOR(Name, return locale.name(); ) @@ -167,6 +170,35 @@ } return QLocale().createSeparatedList(resultList); ) + +LOCALE_SIMPLE_ACCESSOR(BCP47, + return locale.bcp47Name(); +) #endif -#include "localedataaccessor.moc" +LOCALE_SIMPLE_ACCESSOR(DecimalPoint, + return locale.decimalPoint(); +) + +LOCALE_SIMPLE_ACCESSOR(GroupSeparator, + return locale.groupSeparator(); +) + +LOCALE_SIMPLE_ACCESSOR(Exponential, + return locale.exponential(); +) + +LOCALE_SIMPLE_ACCESSOR(Percent, + return locale.percent(); +) + +LOCALE_SIMPLE_ACCESSOR(PositiveSign, + return locale.positiveSign(); +) + +LOCALE_SIMPLE_ACCESSOR(NegativeSign, + return locale.negativeSign(); +) + +} + diff -Nru gammaray-1.2.2/core/tools/localeinspector/localedataaccessor.h gammaray-2.0.1/core/tools/localeinspector/localedataaccessor.h --- gammaray-1.2.2/core/tools/localeinspector/localedataaccessor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localedataaccessor.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation toolocale. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -23,9 +23,10 @@ #define GAMMARAY_LOCALEINSPECTOR_LOCALEDATAACCESSOR_H #include -#include #include #include +#include +#include namespace GammaRay { @@ -35,41 +36,44 @@ { Q_OBJECT public: - LocaleDataAccessorRegistry(); - - static LocaleDataAccessorRegistry *instance(); + explicit LocaleDataAccessorRegistry(QObject *parent = 0); + ~LocaleDataAccessorRegistry(); - static void registerAccessor(LocaleDataAccessor *accessor); - static void setAccessorEnabled(LocaleDataAccessor *accessor, bool enabled); - static QVector accessors(); - static QVector enabledAccessors(); + void registerAccessor(LocaleDataAccessor *accessor); + void setAccessorEnabled(LocaleDataAccessor *accessor, bool enabled); + QVector accessors(); + QVector enabledAccessors(); Q_SIGNALS: void accessorsChanged(); private: + void init(); + + private: QVector m_accessors; QVector m_enabledAccessors; }; struct LocaleDataAccessor { - LocaleDataAccessor(bool defaultAccessor = false) + LocaleDataAccessor(LocaleDataAccessorRegistry *registry, bool defaultAccessor = false) { - LocaleDataAccessorRegistry::registerAccessor(this); + registry->registerAccessor(this); if (defaultAccessor) { - LocaleDataAccessorRegistry::setAccessorEnabled(this, true); + registry->setAccessorEnabled(this, true); } } + virtual ~LocaleDataAccessor() {} virtual QString accessorName() = 0; - QString data(const QLocale &locale, int role) + QVariant data(const QLocale &locale, int role) { if (role == Qt::DisplayRole) { return display(locale); } - return QString(); + return QVariant(); } virtual QString display(const QLocale &) { @@ -80,6 +84,7 @@ #define LOCALE_DISPLAY_ACCESSOR(NAME) \ struct Locale##NAME##Accessor : LocaleDataAccessor \ { \ + Locale##NAME##Accessor(LocaleDataAccessorRegistry *registry) : LocaleDataAccessor(registry) {} \ QString accessorName() { return #NAME; } \ QString display(const QLocale &locale) \ { \ @@ -87,7 +92,7 @@ #define LOCALE_DEFAULT_DISPLAY_ACCESSOR(NAME) \ struct Locale##NAME##Accessor : LocaleDataAccessor \ { \ - Locale##NAME##Accessor() : LocaleDataAccessor(true) {} \ + Locale##NAME##Accessor(LocaleDataAccessorRegistry *registry) : LocaleDataAccessor(registry, true) {} \ \ QString accessorName() \ { \ @@ -99,7 +104,7 @@ #define LOCALE_DISPLAY_ACCESSOR_END(NAME) \ return QString(); \ } \ -} locale##NAME##Accessor; +}; new Locale##NAME##Accessor(this); #define LOCALE_SIMPLE_ACCESSOR(NAME, IMPLEMENTATION) \ LOCALE_DISPLAY_ACCESSOR(NAME) \ diff -Nru gammaray-1.2.2/core/tools/localeinspector/localeinspector.cpp gammaray-2.0.1/core/tools/localeinspector/localeinspector.cpp --- gammaray-1.2.2/core/tools/localeinspector/localeinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localeinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -20,32 +20,21 @@ */ #include "localeinspector.h" -#include "ui_localeinspector.h" #include "localemodel.h" #include "localeaccessormodel.h" - -#include +#include "localedataaccessor.h" using namespace GammaRay; -LocaleInspector::LocaleInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::LocaleInspector) +LocaleInspector::LocaleInspector(ProbeInterface *probe, QObject *parent) +: QObject(parent) { - Q_UNUSED(probe); - - LocaleModel *model = new LocaleModel(this); - LocaleAccessorModel *accessorModel = new LocaleAccessorModel(this); - - ui->setupUi(this); - - ui->localeTable->setModel(model); - ui->accessorTable->setModel(accessorModel); + LocaleDataAccessorRegistry *registry = new LocaleDataAccessorRegistry(this); - ui->accessorTable->resizeColumnsToContents(); - ui->localeTable->resizeColumnsToContents(); - connect(model, SIGNAL(modelReset()), ui->localeTable, SLOT(resizeColumnsToContents())); + LocaleModel *model = new LocaleModel(registry, this); + probe->registerModel("com.kdab.GammaRay.LocaleModel", model); + LocaleAccessorModel *accessorModel = new LocaleAccessorModel(registry, this); + probe->registerModel("com.kdab.GammaRay.LocaleAccessorModel", accessorModel); } -#include "localeinspector.moc" diff -Nru gammaray-1.2.2/core/tools/localeinspector/localeinspector.h gammaray-2.0.1/core/tools/localeinspector/localeinspector.h --- gammaray-1.2.2/core/tools/localeinspector/localeinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localeinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -22,30 +22,15 @@ #ifndef GAMMARAY_LOCALEINSPECTOR_LOCALEINSPECTOR_H #define GAMMARAY_LOCALEINSPECTOR_LOCALEINSPECTOR_H -#include "include/toolfactory.h" - -#include - -namespace Ui { - class LocaleInspector; -} +#include "toolfactory.h" namespace GammaRay { -class LocaleModel; - -class LocaleInspector : public QWidget +class LocaleInspector : public QObject { Q_OBJECT public: - explicit LocaleInspector(ProbeInterface *probe, QWidget *parent = 0); - -// private slots: -// void updateFonts(const QItemSelection &selected, const QItemSelection &deselected); - - private: - QScopedPointer< ::Ui::LocaleInspector> ui; - LocaleModel *m_localeModel; + explicit LocaleInspector(ProbeInterface *probe, QObject *parent = 0); }; class LocaleInspectorFactory : public QObject, public StandardToolFactory diff -Nru gammaray-1.2.2/core/tools/localeinspector/localeinspector.ui gammaray-2.0.1/core/tools/localeinspector/localeinspector.ui --- gammaray-1.2.2/core/tools/localeinspector/localeinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localeinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ - - - LocaleInspector - - - - 0 - 0 - 654 - 506 - - - - - - - Qt::Vertical - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/localeinspector/localemodel.cpp gammaray-2.0.1/core/tools/localeinspector/localemodel.cpp --- gammaray-1.2.2/core/tools/localeinspector/localemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -27,11 +27,11 @@ using namespace GammaRay; -LocaleModel::LocaleModel(QObject *parent) - : QAbstractTableModel(parent) +LocaleModel::LocaleModel(LocaleDataAccessorRegistry *registry, QObject *parent) + : QAbstractTableModel(parent), m_registry(registry) { init(); - connect(LocaleDataAccessorRegistry::instance(), SIGNAL(accessorsChanged()), SLOT(reinit())); + connect(registry, SIGNAL(accessorsChanged()), SLOT(reinit())); } int LocaleModel::columnCount(const QModelIndex &parent) const @@ -68,7 +68,7 @@ void LocaleModel::init() { - m_localeData = LocaleDataAccessorRegistry::enabledAccessors(); + m_localeData = m_registry->enabledAccessors(); #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) m_locales = @@ -103,4 +103,3 @@ return m_locales.size(); } -#include "localemodel.moc" diff -Nru gammaray-1.2.2/core/tools/localeinspector/localemodel.h gammaray-2.0.1/core/tools/localeinspector/localemodel.h --- gammaray-1.2.2/core/tools/localeinspector/localemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/localeinspector/localemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -28,13 +28,14 @@ namespace GammaRay { +class LocaleDataAccessorRegistry; struct LocaleDataAccessor; class LocaleModel : public QAbstractTableModel { Q_OBJECT public: - explicit LocaleModel(QObject *parent = 0); + explicit LocaleModel(LocaleDataAccessorRegistry *registry, QObject *parent = 0); virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -52,6 +53,7 @@ private: QVector m_locales; QVector m_localeData; + LocaleDataAccessorRegistry *m_registry; }; } diff -Nru gammaray-1.2.2/core/tools/messagehandler/backtrace_dummy.cpp gammaray-2.0.1/core/tools/messagehandler/backtrace_dummy.cpp --- gammaray-1.2.2/core/tools/messagehandler/backtrace_dummy.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/backtrace_dummy.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,21 +4,21 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "backtrace.h" diff -Nru gammaray-1.2.2/core/tools/messagehandler/backtrace.h gammaray-2.0.1/core/tools/messagehandler/backtrace.h --- gammaray-1.2.2/core/tools/messagehandler/backtrace.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/backtrace.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,21 +4,22 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef GAMMARAY_MESSAGEHANDLER_BACKTRACE_H diff -Nru gammaray-1.2.2/core/tools/messagehandler/backtrace_unix.cpp gammaray-2.0.1/core/tools/messagehandler/backtrace_unix.cpp --- gammaray-1.2.2/core/tools/messagehandler/backtrace_unix.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/backtrace_unix.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,21 +4,22 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA NOTE: This file is heavily inspired/copied from kdebug.cpp in kdelibs/kdecore/io @@ -52,7 +53,7 @@ #endif //NOTE: we don't have check_function_exists, so lets just hardcode some OS'es -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #define HAVE_BACKTRACE (1) #endif ///TODO: what else is supported? what about mac? @@ -135,6 +136,8 @@ if (strings) { free (strings); } +#else + Q_UNUSED(levels); #endif return s; } @@ -163,6 +166,8 @@ if (strings) { free(strings); } +#else + Q_UNUSED(levels); #endif return s; } diff -Nru gammaray-1.2.2/core/tools/messagehandler/backtrace_win.cpp gammaray-2.0.1/core/tools/messagehandler/backtrace_win.cpp --- gammaray-1.2.2/core/tools/messagehandler/backtrace_win.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/backtrace_win.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,21 +4,22 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "backtrace.h" diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagehandler.cpp gammaray-2.0.1/core/tools/messagehandler/messagehandler.cpp --- gammaray-1.2.2/core/tools/messagehandler/messagehandler.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagehandler.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -23,15 +23,15 @@ #include "messagehandler.h" #include "messagemodel.h" -#include "ui_messagehandler.h" +#include "backtrace.h" + +#include +#include + +#include #include -#include -#include -#include -#include #include -#include #include static QTextStream cerr(stdout); @@ -48,7 +48,7 @@ ///WARNING: do not trigger *any* kind of debug output here /// this would trigger an infinite loop and hence crash! - MessageModel::Message message; + DebugMessage message; message.type = type; message.message = QString::fromLocal8Bit(msg); message.time = QTime::currentTime(); @@ -70,47 +70,10 @@ } } - if (type == QtFatalMsg && qgetenv("GAMMARAY_GDB") != "1" && qgetenv("GAMMARAY_UNITTEST") != "1" && - QThread::currentThread() == QApplication::instance()->thread()) { - foreach (QWidget *w, qApp->topLevelWidgets()) { - w->setEnabled(false); + if (!message.backtrace.isEmpty() && (qgetenv("GAMMARAY_UNITTEST") == "1" || type == QtFatalMsg)) { + if (type == QtFatalMsg) { + cerr << "QFatal in " << qPrintable(qApp->applicationName()) << " (" << qPrintable(qApp->applicationFilePath()) << ')' << endl; } - QDialog dlg; - dlg.setWindowTitle(QObject::tr("QFatal in %1"). - arg(qApp->applicationName().isEmpty() ? - qApp->applicationFilePath() : - qApp->applicationName())); - QGridLayout *layout = new QGridLayout; - QLabel *iconLabel = new QLabel; - QIcon icon = dlg.style()->standardIcon(QStyle::SP_MessageBoxCritical, 0, &dlg); - int iconSize = dlg.style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, &dlg); - iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); - iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - layout->addWidget(iconLabel, 0, 0); - QLabel *errorLabel = new QLabel; - errorLabel->setTextFormat(Qt::PlainText); - errorLabel->setWordWrap(true); - errorLabel->setText(message.message); - layout->addWidget(errorLabel, 0, 1); - if (!message.backtrace.isEmpty()) { - QListWidget *backtrace = new QListWidget; - foreach (const QString &frame, message.backtrace) { - backtrace->addItem(frame); - } - layout->addWidget(backtrace, 1, 0, 1, 2); - } - QDialogButtonBox *buttons = new QDialogButtonBox; - buttons->addButton(QDialogButtonBox::Close); - QObject::connect(buttons, SIGNAL(accepted()), - &dlg, SLOT(accept())); - QObject::connect(buttons, SIGNAL(rejected()), - &dlg, SLOT(reject())); - layout->addWidget(buttons, 2, 0, 1, 2); - dlg.setLayout(layout); - dlg.adjustSize(); - dlg.exec(); - } else if (!message.backtrace.isEmpty() && - (qgetenv("GAMMARAY_UNITTEST") == "1" || type == QtFatalMsg)) { cerr << "START BACKTRACE:" << endl; int i = 0; foreach (const QString &frame, message.backtrace) { @@ -119,6 +82,13 @@ cerr << "END BACKTRACE" << endl; } + if (type == QtFatalMsg && qgetenv("GAMMARAY_GDB") != "1" && qgetenv("GAMMARAY_UNITTEST") != "1") { + // Enforce handling on the GUI thread and block until we are done. + QMetaObject::invokeMethod(static_cast(s_model)->parent(), "handleFatalMessage", + qApp->thread() == QThread::currentThread() ? Qt::DirectConnection : Qt::BlockingQueuedConnection, + Q_ARG(GammaRay::DebugMessage, message)); + } + // reset msg handler so the app still works as usual // but make sure we don't let other threads bypass our // handler during that time @@ -126,7 +96,8 @@ s_handlerDisabled = true; qInstallMsgHandler(s_handler); #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) - qt_message_output(type, QMessageLogContext(), msg); + static QMessageLogContext context; + qt_message_output(type, context, msg); #else qt_message_output(type, msg); #endif @@ -137,40 +108,20 @@ if (s_model) { // add directly from foreground thread, delay from background thread QMetaObject::invokeMethod(s_model, "addMessage", Qt::AutoConnection, - Q_ARG(MessageModel::Message, message)); + Q_ARG(GammaRay::DebugMessage, message)); } } -MessageHandler::MessageHandler(ProbeInterface * /*probe*/, QWidget *parent) - : QWidget(parent), - ui(new Ui::MessageHandler), - m_messageModel(0), - m_messageProxy(new QSortFilterProxyModel(this)) -{ - ui->setupUi(this); - - ui->messageSearchLine->setProxy(m_messageProxy); - ui->messageView->setModel(m_messageProxy); - ui->messageView->setIndentation(0); - ui->messageView->setSortingEnabled(true); - - ///FIXME: implement this - ui->backtraceView->hide(); -} - -void MessageHandler::setModel(MessageModel *model) +MessageHandler::MessageHandler(ProbeInterface *probe, QObject *parent) + : MessageHandlerInterface(parent), + m_messageModel(new MessageModel(this)) { - m_messageModel = model; - m_messageProxy->setSourceModel(m_messageModel); -} -MessageHandlerFactory::MessageHandlerFactory(QObject *parent) - : QObject(parent), - m_messageModel(new MessageModel(this)) -{ Q_ASSERT(s_model == 0); s_model = m_messageModel; + probe->registerModel("com.kdab.GammaRay.MessageModel", m_messageModel); + // install handler directly, catches most cases, // i.e. user has no special handler or the handler // is created before the QApplication @@ -180,7 +131,20 @@ QMetaObject::invokeMethod(this, "ensureHandlerInstalled", Qt::QueuedConnection); } -void MessageHandlerFactory::ensureHandlerInstalled() +MessageHandler::~MessageHandler() +{ + QMutexLocker lock(&s_mutex); + + s_model = 0; + QtMsgHandler oldHandler = qInstallMsgHandler(s_handler); + if (oldHandler != handleMessage) { + // ups, the app installed it's own handler after ours... + qInstallMsgHandler(oldHandler); + } + s_handler = 0; +} + +void MessageHandler::ensureHandlerInstalled() { QMutexLocker lock(&s_mutex); @@ -195,28 +159,18 @@ } } -MessageHandlerFactory::~MessageHandlerFactory() +void MessageHandler::handleFatalMessage(const DebugMessage &message) { - QMutexLocker lock(&s_mutex); - - s_model = 0; - QtMsgHandler oldHandler = qInstallMsgHandler(s_handler); - if (oldHandler != handleMessage) { - // ups, the app installed it's own handler after ours... - qInstallMsgHandler(oldHandler); + const QString app = qApp->applicationName().isEmpty() + ? qApp->applicationFilePath() + : qApp->applicationName(); + emit fatalMessageReceived(app, message.message, message.time, message.backtrace); + if (Endpoint::isConnected()) { + Endpoint::instance()->waitForMessagesWritten(); } - s_handler = 0; } -QWidget *MessageHandlerFactory::createWidget(ProbeInterface *probe, QWidget *parentWidget) +MessageHandlerFactory::MessageHandlerFactory(QObject* parent): QObject(parent) { - QWidget *widget = - StandardToolFactory::createWidget(probe, parentWidget); - - MessageHandler *handler = qobject_cast(widget); - Q_ASSERT(handler); - handler->setModel(m_messageModel); - return widget; } -#include "messagehandler.moc" diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagehandler.h gammaray-2.0.1/core/tools/messagehandler/messagehandler.h --- gammaray-1.2.2/core/tools/messagehandler/messagehandler.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagehandler.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -23,30 +23,32 @@ #ifndef GAMMARAY_MESSAGEHANDLER_MESSAGEHANDLER_H #define GAMMARAY_MESSAGEHANDLER_MESSAGEHANDLER_H -#include "include/toolfactory.h" +#include "toolfactory.h" -#include - -class QSortFilterProxyModel; +#include "messagehandlerinterface.h" namespace GammaRay { +struct DebugMessage; class MessageModel; namespace Ui { class MessageHandler; } -class MessageHandler : public QWidget +class MessageHandler : public MessageHandlerInterface { Q_OBJECT + Q_INTERFACES(GammaRay::MessageHandlerInterface) public: - explicit MessageHandler(ProbeInterface *probe, QWidget *parent = 0); - void setModel(MessageModel *model); + explicit MessageHandler(ProbeInterface *probe, QObject *parent = 0); + ~MessageHandler(); + + private slots: + void ensureHandlerInstalled(); + void handleFatalMessage(const GammaRay::DebugMessage &message); private: - QScopedPointer ui; - QSortFilterProxyModel *m_messageProxy; MessageModel *m_messageModel; }; @@ -56,20 +58,11 @@ Q_INTERFACES(GammaRay::ToolFactory) public: explicit MessageHandlerFactory(QObject *parent); - virtual ~MessageHandlerFactory(); virtual inline QString name() const { return tr("Messages"); } - - virtual QWidget *createWidget(ProbeInterface *probe, QWidget *parentWidget); - - private slots: - void ensureHandlerInstalled(); - - private: - MessageModel *m_messageModel; }; } diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagehandlerinterface.cpp gammaray-2.0.1/core/tools/messagehandler/messagehandlerinterface.cpp --- gammaray-1.2.2/core/tools/messagehandler/messagehandlerinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagehandlerinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +/* + messagehandlerinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "messagehandlerinterface.h" + +#include + +using namespace GammaRay; + +MessageHandlerInterface::MessageHandlerInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +MessageHandlerInterface::~MessageHandlerInterface() +{ + +} + diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagehandlerinterface.h gammaray-2.0.1/core/tools/messagehandler/messagehandlerinterface.h --- gammaray-1.2.2/core/tools/messagehandler/messagehandlerinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagehandlerinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + messagehandlerinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MESSAGEHANDLERINTERFACE_H +#define GAMMARAY_MESSAGEHANDLERINTERFACE_H + +#include + +class QTime; + +namespace GammaRay { + +class MessageHandlerInterface : public QObject +{ + Q_OBJECT + public: + explicit MessageHandlerInterface(QObject *parent = 0); + virtual ~MessageHandlerInterface(); + + signals: + void fatalMessageReceived(const QString &app, const QString &message, const QTime &time, const QStringList &backtrace); +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::MessageHandlerInterface, "com.kdab.GammaRay.MessageHandler") + +#endif // GAMMARAY_MESSAGEHANDLERINTERFACE_H diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagehandler.ui gammaray-2.0.1/core/tools/messagehandler/messagehandler.ui --- gammaray-1.2.2/core/tools/messagehandler/messagehandler.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagehandler.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ - - - GammaRay::MessageHandler - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - - - - - - - - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
- 1 -
-
- - -
diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagemodel.cpp gammaray-2.0.1/core/tools/messagehandler/messagemodel.cpp --- gammaray-1.2.2/core/tools/messagehandler/messagemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -46,7 +46,7 @@ MessageModel::MessageModel(QObject *parent) : QAbstractTableModel(parent) { - qRegisterMetaType("MessageModel::Message"); + qRegisterMetaType(); } MessageModel::~MessageModel() @@ -54,7 +54,7 @@ } -void MessageModel::addMessage(const MessageModel::Message &message) +void MessageModel::addMessage(const DebugMessage &message) { ///WARNING: do not trigger *any* kind of debug output here /// this would trigger an infinite loop and hence crash! @@ -85,7 +85,7 @@ return QVariant(); } - const Message &msg = m_messages.at(index.row()); + const DebugMessage &msg = m_messages.at(index.row()); if (role == Qt::DisplayRole) { if (index.column() == TypeColumn) { @@ -137,4 +137,3 @@ return QVariant(); } -#include "messagemodel.moc" diff -Nru gammaray-1.2.2/core/tools/messagehandler/messagemodel.h gammaray-2.0.1/core/tools/messagehandler/messagemodel.h --- gammaray-1.2.2/core/tools/messagehandler/messagemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/messagehandler/messagemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -27,6 +27,21 @@ #include #include +#include + +namespace GammaRay { + +struct DebugMessage { + QtMsgType type; + QString message; + QTime time; + Backtrace backtrace; +}; + +} + +Q_DECLARE_METATYPE(GammaRay::DebugMessage) +Q_DECLARE_TYPEINFO(GammaRay::DebugMessage, Q_MOVABLE_TYPE); namespace GammaRay { @@ -50,18 +65,11 @@ COLUMN_COUNT }; - struct Message { - QtMsgType type; - QString message; - QTime time; - Backtrace backtrace; - }; - public slots: - void addMessage(const MessageModel::Message &message); + void addMessage(const GammaRay::DebugMessage &message); private: - QList m_messages; + QVector m_messages; }; } diff -Nru gammaray-1.2.2/core/tools/metaobjectbrowser/metaobjectbrowser.cpp gammaray-2.0.1/core/tools/metaobjectbrowser/metaobjectbrowser.cpp --- gammaray-1.2.2/core/tools/metaobjectbrowser/metaobjectbrowser.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/metaobjectbrowser/metaobjectbrowser.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + metaobjectbrowser.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "metaobjectbrowser.h" +#include "metaobjecttreemodel.h" +#include "probe.h" +#include "propertycontroller.h" + +#include + +#include +#include + +using namespace GammaRay; + +MetaObjectBrowser::MetaObjectBrowser(ProbeInterface *probe, QObject *parent) + : QObject(parent), m_propertyController(new PropertyController("com.kdab.GammaRay.MetaObjectBrowser", this)) +{ + Q_UNUSED(probe); + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(Probe::instance()->metaObjectModel()); + + connect(selectionModel,SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(objectSelected(QItemSelection))); + + m_propertyController->setMetaObject(0); // init +} + +void MetaObjectBrowser::objectSelected(const QItemSelection &selection) +{ + QModelIndex index; + if (selection.size() == 1) + index = selection.first().topLeft(); + + if (index.isValid()) { + const QMetaObject *metaObject = + index.data(MetaObjectTreeModel::MetaObjectRole).value(); + m_propertyController->setMetaObject(metaObject); + } else { + m_propertyController->setMetaObject(0); + } +} + diff -Nru gammaray-1.2.2/core/tools/metaobjectbrowser/metaobjectbrowser.h gammaray-2.0.1/core/tools/metaobjectbrowser/metaobjectbrowser.h --- gammaray-1.2.2/core/tools/metaobjectbrowser/metaobjectbrowser.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/metaobjectbrowser/metaobjectbrowser.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ +/* + metaobjectbrowser.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METAOBJECTBROWSER_METATYPEBROWSER_H +#define GAMMARAY_METAOBJECTBROWSER_METATYPEBROWSER_H + +#include "toolfactory.h" + +class QItemSelection; + +namespace GammaRay { + +class PropertyController; + +class MetaObjectBrowser : public QObject +{ + Q_OBJECT + + public: + explicit MetaObjectBrowser(ProbeInterface *probe, QObject *parent = 0); + + private Q_SLOTS: + void objectSelected(const QItemSelection &selection); + + private: + PropertyController *m_propertyController; +}; + +class MetaObjectBrowserFactory : public QObject, + public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + + public: + explicit MetaObjectBrowserFactory(QObject *parent) : QObject(parent) + { + } + + inline QString name() const + { + return tr("Meta Objects"); + } +}; + +} + +#endif // GAMMARAY_METAOBJECTBROWSER_METATYPEBROWSER_H diff -Nru gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.cpp gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.cpp --- gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,22 +22,17 @@ */ #include "metatypebrowser.h" -#include "ui_metatypebrowser.h" #include "metatypesmodel.h" +#include + using namespace GammaRay; -MetaTypeBrowser::MetaTypeBrowser(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::MetaTypeBrowser) +MetaTypeBrowser::MetaTypeBrowser(ProbeInterface *probe, QObject *parent) + : QObject(parent) { - Q_UNUSED(probe); - ui->setupUi(this); - MetaTypesModel *mtm = new MetaTypesModel(this); - ui->metaTypeView->setModel(mtm); - ui->metaTypeView->header()->setResizeMode(0, QHeaderView::ResizeToContents); + probe->registerModel("com.kdab.GammaRay.MetaTypeModel", mtm); } -#include "metatypebrowser.moc" diff -Nru gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.h gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.h --- gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,27 +21,18 @@ along with this program. If not, see . */ -#ifndef GAMMARAY_METATYPEBROWSER_METATYPEBROWSER_H -#define GAMMARAY_METATYPEBROWSER_METATYPEBROWSER_H +#ifndef GAMMARAY_METATYPEBROWSER_H +#define GAMMARAY_METATYPEBROWSER_H -#include "include/toolfactory.h" - -#include +#include "toolfactory.h" namespace GammaRay { -namespace Ui { - class MetaTypeBrowser; -} - -class MetaTypeBrowser : public QWidget +class MetaTypeBrowser : public QObject { Q_OBJECT public: - explicit MetaTypeBrowser(ProbeInterface *probe, QWidget *parent = 0); - - private: - QScopedPointer ui; + explicit MetaTypeBrowser(ProbeInterface *probe, QObject *parent = 0); }; class MetaTypeBrowserFactory : public QObject, public StandardToolFactory diff -Nru gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.ui gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.ui --- gammaray-1.2.2/core/tools/metatypebrowser/metatypebrowser.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/metatypebrowser/metatypebrowser.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - GammaRay::MetaTypeBrowser - - - - 0 - 0 - 400 - 300 - - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/metatypebrowser/metatypesmodel.cpp gammaray-2.0.1/core/tools/metatypebrowser/metatypesmodel.cpp --- gammaray-1.2.2/core/tools/metatypebrowser/metatypesmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/metatypebrowser/metatypesmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -25,31 +25,56 @@ #include #include +#include MetaTypesModel::MetaTypesModel(QObject *parent) - : QAbstractItemModel(parent), m_lastMetaType(0) + : QAbstractTableModel(parent) { - for (m_lastMetaType = 0; ; ++m_lastMetaType) { - if (!QMetaType::isRegistered(m_lastMetaType)) { - break; - } - } + scanMetaTypes(); // TODO do we need to re-run this when new types are registered at runtime? } QVariant MetaTypesModel::data(const QModelIndex &index, int role) const { - if (role != Qt::DisplayRole) { + if (role != Qt::DisplayRole || !index.isValid()) { return QVariant(); } - if (index.column() == 0) { - QString name(QMetaType::typeName(index.row())); + int metaTypeId = m_metaTypes.at(index.row()); + switch (index.column()) { + case 0: + { + QString name(QMetaType::typeName(metaTypeId)); if (name.isEmpty()) { return tr("N/A"); } return name; - } else if (index.column() == 1) { - return index.row(); + } + case 1: + return metaTypeId; +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + case 2: + return QMetaType::sizeOf(metaTypeId); + case 3: + return (QMetaType::metaObjectForType(metaTypeId) != 0); + case 4: + { + const QMetaType::TypeFlags flags = QMetaType::typeFlags(metaTypeId); + QStringList l; + #define F(x) if (flags & QMetaType:: x) l.push_back(#x) + F(NeedsConstruction); + F(NeedsDestruction); + F(MovableType); + F(PointerToQObject); + F(IsEnumeration); + F(SharedPointerToQObject); + F(WeakPointerToQObject); + F(TrackingPointerToQObject); + F(WasDeclaredAsMetaType); + #undef F + + return l.join(", "); + } +#endif } return QVariant(); } @@ -60,7 +85,7 @@ return 0; } - return m_lastMetaType; + return m_metaTypes.size(); } int MetaTypesModel::columnCount(const QModelIndex &parent) const @@ -68,34 +93,49 @@ if (parent.isValid()) { return 0; } +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) return 2; -} - -QModelIndex MetaTypesModel::index(int row, int column, const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return createIndex(row, column); -} - -QModelIndex MetaTypesModel::parent(const QModelIndex &child) const -{ - Q_UNUSED(child); - return QModelIndex(); +#else + return 5; +#endif } QVariant MetaTypesModel::headerData(int section, Qt::Orientation orientation, int role) const { - Q_UNUSED(orientation); - - if (role != Qt::DisplayRole) { + if (role != Qt::DisplayRole || orientation != Qt::Horizontal) { return QVariant(); } - if (section == 0) { + switch (section) { + case 0: return tr("Type Name"); + case 1: + return tr("Meta Type Id"); + case 2: + return tr("Size"); + case 3: + return tr("QObject-derived"); + case 4: + return tr("Type Flags"); } + return QVariant(); +} - return tr("Meta Type Id"); +void MetaTypesModel::scanMetaTypes() +{ + beginResetModel(); + m_metaTypes.clear(); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + for (int mtId = 0; QMetaType::isRegistered(mtId); ++mtId) { + m_metaTypes.push_back(mtId); + } +#else + for (int mtId = 0; mtId <= QMetaType::User || QMetaType::isRegistered(mtId); ++mtId) { + if (QMetaType::isRegistered(mtId)) { + m_metaTypes.push_back(mtId); + } + } +#endif + endResetModel(); } -#include "metatypesmodel.moc" diff -Nru gammaray-1.2.2/core/tools/metatypebrowser/metatypesmodel.h gammaray-2.0.1/core/tools/metatypebrowser/metatypesmodel.h --- gammaray-1.2.2/core/tools/metatypebrowser/metatypesmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/metatypebrowser/metatypesmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -25,29 +25,27 @@ #define GAMMARAY_METATYPEBROWSER_METATYPESMODEL_H #include +#include -class MetaTypesModel : public QAbstractItemModel +class MetaTypesModel : public QAbstractTableModel { Q_OBJECT public: - MetaTypesModel(QObject *parent = 0); + explicit MetaTypesModel(QObject *parent = 0); virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - - virtual QModelIndex parent(const QModelIndex &child) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; private: - int m_lastMetaType; + void scanMetaTypes(); + + QVector m_metaTypes; }; #endif diff -Nru gammaray-1.2.2/core/tools/mimetypes/mimetypes.cpp gammaray-2.0.1/core/tools/mimetypes/mimetypes.cpp --- gammaray-1.2.2/core/tools/mimetypes/mimetypes.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/mimetypes/mimetypes.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + mimetypes.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "mimetypes.h" +#include "mimetypesmodel.h" + +using namespace GammaRay; + +MimeTypes::MimeTypes(ProbeInterface *probe, QObject *parent) + : QObject(parent) +{ + m_model = new MimeTypesModel(this); + probe->registerModel("com.kdab.GammaRay.MimeTypeModel", m_model); +} + +MimeTypes::~MimeTypes() +{ +} + diff -Nru gammaray-1.2.2/core/tools/mimetypes/mimetypes.h gammaray-2.0.1/core/tools/mimetypes/mimetypes.h --- gammaray-1.2.2/core/tools/mimetypes/mimetypes.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/mimetypes/mimetypes.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,65 @@ +/* + mimetypes.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MIMETYPES_H +#define GAMMARAY_MIMETYPES_H + +#include + +#include +#include + +class QStandardItemModel; +class QStandardItem; + +namespace GammaRay { + +class MimeTypes : public QObject +{ + Q_OBJECT + public: + explicit MimeTypes(ProbeInterface *probe, QObject *parent = 0); + ~MimeTypes(); + + private: + QStandardItemModel *m_model; +}; + +class MimeTypesFactory : public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + public: + explicit MimeTypesFactory(QObject *parent) : QObject(parent) + { + } + + virtual inline QString name() const + { + return tr("Mime Types"); + } +}; + +} + +#endif // GAMMARAY_MIMETYPES_H diff -Nru gammaray-1.2.2/core/tools/mimetypes/mimetypesmodel.cpp gammaray-2.0.1/core/tools/mimetypes/mimetypesmodel.cpp --- gammaray-1.2.2/core/tools/mimetypes/mimetypesmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/mimetypes/mimetypesmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,173 @@ +/* + mimetypesmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "mimetypesmodel.h" + +#include +#include + +using namespace GammaRay; + +MimeTypesModel::MimeTypesModel(QObject* parent): + QStandardItemModel(parent) +{ + fillModel(); +} + +MimeTypesModel::~MimeTypesModel() +{ +} + +QVariant MimeTypesModel::data(const QModelIndex& index, int role) const +{ + if (index.isValid() && role == Qt::DecorationRole && index.column() == 3) { + QStandardItem *item = itemFromIndex(index); + if (!item) + return QVariant(); + + // on-demand lookup of icons, too slow to do that all in one go + const QVariant v = item->data(Qt::DecorationRole); + if (v.isNull()) { + const QString iconName = item->data(IconNameRole).toString(); + const QString genericIconName = item->data(GenericIconNameRole).toString(); + if (iconName.isEmpty() && genericIconName.isEmpty()) + return QVariant(); + + QIcon icon = QIcon::fromTheme(item->data(IconNameRole).toString()); + if (icon.isNull()) + icon = QIcon::fromTheme(item->data(GenericIconNameRole).toString()); + const_cast(this)->blockSignals(true); + item->setIcon(icon); + item->setData(QVariant(), IconNameRole); // reset to avoid trying to look up an icon multiple times + item->setData(QVariant(), GenericIconNameRole); + const_cast(this)->blockSignals(false); + return icon; + } else { + return v; + } + } + return QStandardItemModel::data(index, role); +} + +Qt::ItemFlags MimeTypesModel::flags(const QModelIndex& index) const +{ + return QStandardItemModel::flags(index) & ~Qt::ItemIsEditable; +} + +QVector MimeTypesModel::itemsForType(const QString &mimeTypeName) +{ + if (m_mimeTypeNodes.contains(mimeTypeName)) { + return m_mimeTypeNodes.value(mimeTypeName); + } + + makeItemsForType(mimeTypeName); + return m_mimeTypeNodes.value(mimeTypeName); +} + +void MimeTypesModel::makeItemsForType(const QString &mimeTypeName) +{ + const QMimeType mt = m_db.mimeTypeForName(mimeTypeName); + + if (mt.parentMimeTypes().isEmpty()) { + const QList row = makeRowForType(mt); + appendRow(row); + m_mimeTypeNodes[mt.name()].push_back(row.first()); + } else { + // parentMimeTypes contains duplicates and aliases + const QSet parentMimeTypeNames = normalizedMimeTypeNames(mt.parentMimeTypes()); + foreach (const QString &parentTypeName, parentMimeTypeNames) { + foreach (QStandardItem *parentItem, itemsForType(parentTypeName)) { + const QList row = makeRowForType(mt); + parentItem->appendRow(row); + m_mimeTypeNodes[mt.name()].push_back(row.first()); + } + } + } +} + +QSet< QString > MimeTypesModel::normalizedMimeTypeNames(const QStringList &typeNames) const +{ + QSet res; + foreach (const QString &typeName, typeNames) { + const QMimeType mt = m_db.mimeTypeForName(typeName); + res.insert(mt.name()); + } + + return res; +} + +QList MimeTypesModel::makeRowForType(const QMimeType &mt) +{ + QList row; + QStandardItem *item = new QStandardItem; + item->setText(mt.name()); + row.push_back(item); + + item = new QStandardItem; + item->setText(mt.comment()); + row.push_back(item); + + item = new QStandardItem; + item->setText(mt.globPatterns().join(QLatin1String(", "))); + row.push_back(item); + + item = new QStandardItem; + item->setText(mt.iconName() + QLatin1String(" / ") + mt.genericIconName()); + item->setData(mt.iconName(), IconNameRole); + item->setData(mt.genericIconName(), GenericIconNameRole); + row.push_back(item); + + item = new QStandardItem; + QString s = mt.suffixes().join(QLatin1String(", ")); + if (!mt.preferredSuffix().isEmpty() && mt.suffixes().size() > 1) { + s += QLatin1String(" (") + mt.preferredSuffix() + QLatin1Char(')'); + } + item->setText(s); + row.push_back(item); + + item = new QStandardItem; + item->setText(mt.aliases().join(QLatin1String(", "))); + row.push_back(item); + + return row; +} + +void MimeTypesModel::fillModel() +{ + clear(); + setHorizontalHeaderLabels(QStringList() << tr("Name") + << tr("Comment") + << tr("Glob Patterns") + << tr("Icons") + << tr("Suffixes") + << tr("Aliases")); + + foreach (const QMimeType &mt, m_db.allMimeTypes()) { + if (!m_mimeTypeNodes.contains(mt.name())) { + makeItemsForType(mt.name()); + } + } + + m_mimeTypeNodes.clear(); +} + diff -Nru gammaray-1.2.2/core/tools/mimetypes/mimetypesmodel.h gammaray-2.0.1/core/tools/mimetypes/mimetypesmodel.h --- gammaray-1.2.2/core/tools/mimetypes/mimetypesmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/mimetypes/mimetypesmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + mimetypesmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MIMETYPESMODEL_H +#define GAMMARAY_MIMETYPESMODEL_H + +#include +#include +#include + +namespace GammaRay { + +class MimeTypesModel : public QStandardItemModel +{ + Q_OBJECT +public: + enum Roles { + IconNameRole = UserRole + 1, + GenericIconNameRole + }; + + explicit MimeTypesModel(QObject* parent = 0); + ~MimeTypesModel(); + + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + Qt::ItemFlags flags(const QModelIndex& index) const; + +private: + void fillModel(); + QVector itemsForType(const QString& mimeTypeName); + void makeItemsForType(const QString &mimeTypeName); + static QList makeRowForType(const QMimeType &mt); + QSet normalizedMimeTypeNames(const QStringList &typeNames) const; + + QHash > m_mimeTypeNodes; + QMimeDatabase m_db; +}; + +} + +#endif // GAMMARAY_MIMETYPESMODEL_H diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelcellmodel.cpp gammaray-2.0.1/core/tools/modelinspector/modelcellmodel.cpp --- gammaray-1.2.2/core/tools/modelinspector/modelcellmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelcellmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,9 +23,9 @@ #include "modelcellmodel.h" -#include "include/util.h" +#include -#include +#include using namespace GammaRay; @@ -37,6 +37,50 @@ { beginResetModel(); m_index = index; + + m_roles.clear(); + if (index.isValid()) { + + // add built-in roles + #define R(x) qMakePair(x, QLatin1String(#x)) + m_roles << R(Qt::DisplayRole) + << R(Qt::DecorationRole) + << R(Qt::EditRole) + << R(Qt::ToolTipRole) + << R(Qt::StatusTipRole) + << R(Qt::WhatsThisRole) + << R(Qt::FontRole) + << R(Qt::TextAlignmentRole) + << R(Qt::BackgroundRole) + << R(Qt::ForegroundRole) + << R(Qt::CheckStateRole) + << R(Qt::AccessibleTextRole) + << R(Qt::AccessibleDescriptionRole) + << R(Qt::SizeHintRole) +#if QT_VERSION >= QT_VERSION_CHECK(4,8,0) + << R(Qt::InitialSortOrderRole) +#endif + ; + #undef R + + // add custom roles + QHash roleNames = index.model()->roleNames(); + for (QHash::const_iterator it = roleNames.constBegin(); + it != roleNames.constEnd(); ++it) { + bool roleFound = false; + for (int i = 0; i < m_roles.size(); ++i) { + if (m_roles.at(i).first == it.key()) { + roleFound = true; + break; + } + } + if (!roleFound) { + m_roles.push_back(qMakePair(it.key(), QString::fromLatin1(it.value()))); + } + } + + } + endResetModel(); } @@ -46,32 +90,14 @@ return QVariant(); } - const QVariant value = m_index.data(static_cast(index.row())); + Q_ASSERT(index.row() < m_roles.size()); + const QVariant value = m_index.data(m_roles.at(index.row()).first); if (role == Qt::DisplayRole) { switch(index.column()) { case 0: - { - static QVector itemDataRoleNames = QVector() - << "Qt::DisplayRole" - << "Qt::DecorationRole" - << "Qt::EditRole" - << "Qt::ToolTipRole" - << "Qt::StatusTipRole" - << "Qt::WhatsThisRole" - << "Qt::FontRole" - << "Qt::TextAlignmentRole" - << "Qt::BackgroundRole" - << "Qt::ForegroundRole" - << "Qt::CheckStateRole" - << "Qt::AccessibleTextRole" - << "Qt::AccessibleDescriptionRole" - << "Qt::SizeHintRole"; - - Q_ASSERT(index.row() < itemDataRoleNames.size()); - return itemDataRoleNames.at(index.row()); - } + return m_roles.at(index.row()).second; case 1: - return Util::variantToString(value); + return VariantHandler::displayString(value); case 2: return value.typeName(); } @@ -89,7 +115,8 @@ if (index.isValid() && m_index.isValid() && (m_index.flags() & Qt::ItemIsEditable) && role == Qt::EditRole && index.column() == 1) { - Qt::ItemDataRole sourceRole = static_cast(index.row()); + const Qt::ItemDataRole sourceRole = + static_cast(m_roles.at(index.row()).first); QAbstractItemModel *sourceModel = const_cast(m_index.model()); return sourceModel->setData(m_index, value, sourceRole); } @@ -120,7 +147,7 @@ if (parent.isValid() || !m_index.isValid()) { return 0; } - return 14; + return m_roles.size(); } QVariant ModelCellModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -138,4 +165,3 @@ return QAbstractItemModel::headerData(section, orientation, role); } -#include "modelcellmodel.moc" diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelcellmodel.h gammaray-2.0.1/core/tools/modelinspector/modelcellmodel.h --- gammaray-1.2.2/core/tools/modelinspector/modelcellmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelcellmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -25,6 +25,7 @@ #define GAMMARAY_MODELINSPECTOR_MODELCELLMODEL_H #include +#include namespace GammaRay { @@ -44,6 +45,7 @@ private: QPersistentModelIndex m_index; + QVector > m_roles; }; } diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelinspector.cpp gammaray-2.0.1/core/tools/modelinspector/modelinspector.cpp --- gammaray-1.2.2/core/tools/modelinspector/modelinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,57 +23,110 @@ #include "modelinspector.h" -#include "modelinspectorwidget.h" #include "modelmodel.h" +#include "modelcellmodel.h" #include "modeltester.h" -#include "include/probeinterface.h" +#include "probeinterface.h" + +#include +#include +#include + +#include using namespace GammaRay; -ModelInspector::ModelInspector(QObject *parent) : - QObject(parent), +ModelInspector::ModelInspector(ProbeInterface* probe, QObject *parent) : + ModelInspectorInterface(parent), m_modelModel(0), + m_modelContentServer(0), + m_modelContentSelectionModel(0), m_modelTester(0) { -} - -QString ModelInspector::id() const -{ - return metaObject()->className(); -} - -QString ModelInspector::name() const -{ - return tr("Models"); -} - -QStringList ModelInspector::supportedTypes() const -{ - return QStringList(QAbstractItemModel::staticMetaObject.className()); -} - -void ModelInspector::init(ProbeInterface *probe) -{ m_modelModel = new ModelModel(this); connect(probe->probe(), SIGNAL(objectCreated(QObject*)), m_modelModel, SLOT(objectAdded(QObject*))); connect(probe->probe(), SIGNAL(objectDestroyed(QObject*)), m_modelModel, SLOT(objectRemoved(QObject*))); + probe->registerModel("com.kdab.GammaRay.ModelModel", m_modelModel); + + m_modelSelectionModel = ObjectBroker::selectionModel(m_modelModel); + connect(m_modelSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(modelSelected(QItemSelection))); + connect(probe->probe(), SIGNAL(objectSelected(QObject*,QPoint)), SLOT(objectSelected(QObject*)) ); + + m_modelContentServer = new RemoteModelServer("com.kdab.GammaRay.ModelContent", this); + + m_cellModel = new ModelCellModel(this); + probe->registerModel("com.kdab.GammaRay.ModelCellModel", m_cellModel); + selectionChanged(QItemSelection()); m_modelTester = new ModelTester(this); connect(probe->probe(), SIGNAL(objectCreated(QObject*)), m_modelTester, SLOT(objectAdded(QObject*))); } -QWidget *ModelInspector::createWidget(ProbeInterface *probe, QWidget *parentWidget) +QString ModelInspectorFactory::name() const { - return new ModelInspectorWidget(this, probe, parentWidget); + return tr("Models"); } -ModelModel *ModelInspector::modelModel() const +void ModelInspector::modelSelected(const QItemSelection& selected) { - return m_modelModel; + if (m_modelContentSelectionModel && m_modelContentSelectionModel->model()) + ObjectBroker::unregisterSelectionModel(m_modelContentSelectionModel); + delete m_modelContentSelectionModel; + m_modelContentSelectionModel = 0; + + QModelIndex index; + if (selected.size() >= 1) + index = selected.first().topLeft(); + + if (index.isValid()) { + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + QAbstractItemModel *model = qobject_cast(obj); + m_modelContentServer->setModel(model); + + m_modelContentSelectionModel = new SelectionModelServer("com.kdab.GammaRay.ModelContent.selection", model, this); + ObjectBroker::registerSelectionModel(m_modelContentSelectionModel); + connect(m_modelContentSelectionModel, + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(selectionChanged(QItemSelection))); + } else { + m_modelContentServer->setModel(0); + } + + // clear the cell info box + selectionChanged(QItemSelection()); +} + +void ModelInspector::objectSelected(QObject* object) +{ + QAbstractItemModel *selectedModel = qobject_cast(object); + if (selectedModel) { + const QModelIndexList indexList = + m_modelModel->match(m_modelModel->index(0, 0), + ObjectModel::ObjectRole, + QVariant::fromValue(selectedModel), 1, + Qt::MatchExactly | Qt::MatchRecursive); + if (indexList.isEmpty()) { + return; + } + + const QModelIndex index = indexList.first(); + m_modelSelectionModel->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + } +} + +void ModelInspector::selectionChanged(const QItemSelection& selected) +{ + QModelIndex index; + if (selected.size() >= 1) + index = selected.first().topLeft(); + + m_cellModel->setModelIndex(index); + + emit cellSelected(index.row(), index.column(), QString::number(index.internalId()), Util::addressToString(index.internalPointer())); } -#include "modelinspector.moc" diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelinspector.h gammaray-2.0.1/core/tools/modelinspector/modelinspector.h --- gammaray-1.2.2/core/tools/modelinspector/modelinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,34 +24,57 @@ #ifndef GAMMARAY_MODELINSPECTOR_MODELINSPECTOR_H #define GAMMARAY_MODELINSPECTOR_MODELINSPECTOR_H -#include "include/toolfactory.h" +#include "toolfactory.h" -#include +#include + +class QItemSelection; +class QItemSelectionModel; namespace GammaRay { class ModelModel; +class ModelCellModel; class ModelTester; +class RemoteModelServer; -class ModelInspector : public QObject, public ToolFactory +class ModelInspector : public ModelInspectorInterface { Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) + Q_INTERFACES(GammaRay::ModelInspectorInterface) public: - explicit ModelInspector(QObject *parent = 0); - virtual QString id() const; - virtual QString name() const; - virtual QStringList supportedTypes() const; - virtual void init(ProbeInterface *probe); - virtual QWidget *createWidget(ProbeInterface *probe, QWidget *parentWidget); + explicit ModelInspector(ProbeInterface *probe, QObject *parent = 0); - ModelModel *modelModel() const; + private slots: + void modelSelected(const QItemSelection &selected); + void selectionChanged(const QItemSelection &selected); + + void objectSelected(QObject* object); private: ModelModel *m_modelModel; + QItemSelectionModel *m_modelSelectionModel; + + RemoteModelServer *m_modelContentServer; + QItemSelectionModel *m_modelContentSelectionModel; + + ModelCellModel *m_cellModel; + ModelTester *m_modelTester; }; +class ModelInspectorFactory : public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + public: + explicit ModelInspectorFactory(QObject *parent) : QObject(parent) + { + } + + QString name() const; +}; + } #endif // GAMMARAY_MODELINSPECTOR_H diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.cpp gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.cpp --- gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,104 +0,0 @@ -/* - modelinspectorwidget.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "modelinspectorwidget.h" - -#include "modelcellmodel.h" -#include "modelinspector.h" -#include "modelmodel.h" -#include "ui_modelinspectorwidget.h" - -#include "include/objectmodel.h" -#include "include/probeinterface.h" - -#include - -using namespace GammaRay; - -ModelInspectorWidget::ModelInspectorWidget(ModelInspector *modelInspector, - ProbeInterface *probe, - QWidget *parent) - : QWidget(parent), - ui(new Ui::ModelInspectorWidget) -{ - Q_UNUSED(probe); - ui->setupUi(this); - - KRecursiveFilterProxyModel *modelFilterProxy = new KRecursiveFilterProxyModel(this); - modelFilterProxy->setSourceModel(modelInspector->modelModel()); - ui->modelView->setModel(modelFilterProxy); - ui->modelSearchLine->setProxy(modelFilterProxy); - connect(ui->modelView->selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(modelSelected(QModelIndex))); - m_cellModel = new ModelCellModel(this); - ui->modelCellView->setModel(m_cellModel); - - connect(probe->probe(), SIGNAL(widgetSelected(QWidget*,QPoint)), SLOT(widgetSelected(QWidget*)) ); -} - -void ModelInspectorWidget::modelSelected(const QModelIndex &index) -{ - if (index.isValid()) { - QObject *obj = index.data(ObjectModel::ObjectRole).value(); - QAbstractItemModel *model = qobject_cast(obj); - ui->modelContentView->setModel(model); - connect(ui->modelContentView->selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(modelCellSelected(QModelIndex))); - } else { - ui->modelContentView->setModel(0); - } - m_cellModel->setModelIndex(QModelIndex()); -} - -void ModelInspectorWidget::modelCellSelected(const QModelIndex &index) -{ - m_cellModel->setModelIndex(index); -} - -void ModelInspectorWidget::widgetSelected(QWidget *widget) -{ - QAbstractItemView *view = Util::findParentOfType(widget); - if (view && view->model()) { - QAbstractItemModel *model = ui->modelView->model(); - const QModelIndexList indexList = - model->match(model->index(0, 0), - ObjectModel::ObjectRole, - QVariant::fromValue(view->model()), 1, - Qt::MatchExactly | Qt::MatchRecursive); - if (indexList.isEmpty()) { - return; - } - - const QModelIndex index = indexList.first(); - ui->modelView->selectionModel()->select( - index, - QItemSelectionModel::Select | QItemSelectionModel::Clear | - QItemSelectionModel::Rows | QItemSelectionModel::Current); - ui->modelView->scrollTo(index); - modelSelected(index); - } -} - -#include "modelinspectorwidget.moc" diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.h gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.h --- gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/* - modelinspectorwidget.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_MODELINSPECTOR_MODELINSPECTORWIDGET_H -#define GAMMARAY_MODELINSPECTOR_MODELINSPECTORWIDGET_H - -#include - -class QModelIndex; - -namespace GammaRay { - -class ModelCellModel; -class ModelInspector; -class ProbeInterface; - -namespace Ui { - class ModelInspectorWidget; -} - -class ModelInspectorWidget : public QWidget -{ - Q_OBJECT - public: - ModelInspectorWidget(ModelInspector *modelInspector, ProbeInterface *probe, - QWidget *parent = 0); - - private slots: - void modelSelected(const QModelIndex &index); - void modelCellSelected(const QModelIndex &index); - void widgetSelected(QWidget *widget); - - private: - QScopedPointer ui; - ModelCellModel *m_cellModel; -}; - -} - -#endif // GAMMARAY_MODELINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.ui gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.ui --- gammaray-1.2.2/core/tools/modelinspector/modelinspectorwidget.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ - - - GammaRay::ModelInspectorWidget - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - - - - - - true - - - true - - - - - - - - - - - Model Content: - - - - - - - - - - - - - - Cell Content: - - - - - - - false - - - true - - - true - - - - - - - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
-
-
diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelmodel.cpp gammaray-2.0.1/core/tools/modelinspector/modelmodel.cpp --- gammaray-1.2.2/core/tools/modelinspector/modelmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -153,4 +153,3 @@ return proxies; } -#include "modelmodel.moc" diff -Nru gammaray-1.2.2/core/tools/modelinspector/modelmodel.h gammaray-2.0.1/core/tools/modelinspector/modelmodel.h --- gammaray-1.2.2/core/tools/modelinspector/modelmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modelmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #ifndef GAMMARAY_MODELINSPECTOR_MODELMODEL_H #define GAMMARAY_MODELINSPECTOR_MODELMODEL_H -#include "include/objectmodelbase.h" +#include "objectmodelbase.h" #include #include diff -Nru gammaray-1.2.2/core/tools/modelinspector/modeltester.cpp gammaray-2.0.1/core/tools/modelinspector/modeltester.cpp --- gammaray-1.2.2/core/tools/modelinspector/modeltester.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modeltester.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #include "modeltester.h" #include "modeltest.h" -#include "include/util.h" +#include "util.h" #include #include @@ -35,8 +35,15 @@ namespace GammaRay { struct ModelTester::ModelTestResult { - ModelTestResult() : modelTest(0) {} - ~ModelTestResult() { delete modelTest; } + ModelTestResult() : modelTest(0) + { + } + + ~ModelTestResult() + { + delete modelTest; + } + ModelTest *modelTest; QHash failures; }; @@ -86,14 +93,11 @@ } } -#include "modeltester.moc" - // inplace build of modeltest, with some slight modificatins: // - change Q_ASSERT to non-fatal reporting // - suppress qDebug etc, since those trigger qobject creating and thus // infinite loops when model-testing the object model #include // avoid interference with any include used by modeltest -#include "modeltest.moc" #undef Q_ASSERT #define Q_ASSERT(x) (!(x) ? static_cast(static_cast(this)->parent())->failure(this->model, __FILE__, __LINE__, #x) : qt_noop()) #undef qDebug diff -Nru gammaray-1.2.2/core/tools/modelinspector/modeltester.h gammaray-2.0.1/core/tools/modelinspector/modeltester.h --- gammaray-1.2.2/core/tools/modelinspector/modeltester.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/modelinspector/modeltester.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/tools/objectinspector/objectinspector.cpp gammaray-2.0.1/core/tools/objectinspector/objectinspector.cpp --- gammaray-1.2.2/core/tools/objectinspector/objectinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/objectinspector/objectinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,72 +22,83 @@ */ #include "objectinspector.h" -#include "ui_objectinspector.h" +#include "propertycontroller.h" +#include "probeinterface.h" -#include "include/objectmodel.h" -#include "include/probeinterface.h" +#include +#include -#include - -#include +#include +#include using namespace GammaRay; -ObjectInspector::ObjectInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::ObjectInspector) +ObjectInspector::ObjectInspector(ProbeInterface *probe, QObject *parent) + : QObject(parent), + m_propertyController(new PropertyController("com.kdab.GammaRay.ObjectInspector", this)) { - ui->setupUi(this); + m_selectionModel = ObjectBroker::selectionModel(ObjectBroker::model("com.kdab.GammaRay.ObjectTree")); + + connect(m_selectionModel, + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(objectSelectionChanged(QItemSelection))); + + connect(probe->probe(), SIGNAL(objectSelected(QObject*,QPoint)), SLOT(objectSelected(QObject*))); + + // when we end up here the object model isn't populated yet + QMetaObject::invokeMethod(this, "selectDefaultItem", Qt::QueuedConnection); +} - QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this); - objectFilter->setSourceModel(probe->objectTreeModel()); - objectFilter->setDynamicSortFilter(true); - ui->objectTreeView->setModel(objectFilter); - ui->objectTreeView->header()->setResizeMode(0, QHeaderView::Stretch); - ui->objectTreeView->header()->setResizeMode(1, QHeaderView::Interactive); - ui->objectSearchLine->setProxy(objectFilter); - connect(ui->objectTreeView->selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(objectSelected(QModelIndex))); - - if (qgetenv("GAMMARAY_TEST_FILTER") == "1") { - QMetaObject::invokeMethod(ui->objectSearchLine->lineEdit(), "setText", - Qt::QueuedConnection, - Q_ARG(QString, QLatin1String("Object"))); +void ObjectInspector::selectDefaultItem() +{ + // select the qApp object (if any) in the object treeView + const QAbstractItemModel *viewModel = m_selectionModel->model(); + const QModelIndexList matches = viewModel->match(viewModel->index(0, 0), + ObjectModel::ObjectRole, QVariant::fromValue(qApp), 1, + Qt::MatchFlags(Qt::MatchExactly|Qt::MatchRecursive)); + + if (!matches.isEmpty()) { + m_selectionModel->setCurrentIndex(matches.first(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } +} - connect(probe->probe(), SIGNAL(widgetSelected(QWidget*,QPoint)), SLOT(widgetSelected(QWidget*))); +void ObjectInspector::objectSelectionChanged(const QItemSelection& selection) +{ + if (selection.isEmpty()) + objectSelected(QModelIndex()); + else + objectSelected(selection.first().topLeft()); } void ObjectInspector::objectSelected(const QModelIndex &index) { if (index.isValid()) { QObject *obj = index.data(ObjectModel::ObjectRole).value(); - ui->objectPropertyWidget->setObject(obj); + m_propertyController->setObject(obj); } else { - ui->objectPropertyWidget->setObject(0); + m_propertyController->setObject(0); } } -void ObjectInspector::widgetSelected(QWidget *widget) +void ObjectInspector::objectSelected(QObject *object) { - QAbstractItemModel *model = ui->objectTreeView->model(); + const QAbstractItemModel *model = m_selectionModel->model(); const QModelIndexList indexList = model->match(model->index(0, 0), ObjectModel::ObjectRole, - QVariant::fromValue(widget), 1, + QVariant::fromValue(object), 1, Qt::MatchExactly | Qt::MatchRecursive); if (indexList.isEmpty()) { return; } const QModelIndex index = indexList.first(); - ui->objectTreeView->selectionModel()->select( + m_selectionModel->select( index, QItemSelectionModel::Select | QItemSelectionModel::Clear | QItemSelectionModel::Rows | QItemSelectionModel::Current); - ui->objectTreeView->scrollTo(index); + // TODO: move this to the client side! + //ui->objectTreeView->scrollTo(index); objectSelected(index); } -#include "objectinspector.moc" diff -Nru gammaray-1.2.2/core/tools/objectinspector/objectinspector.h gammaray-2.0.1/core/tools/objectinspector/objectinspector.h --- gammaray-1.2.2/core/tools/objectinspector/objectinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/objectinspector/objectinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,30 +24,33 @@ #ifndef GAMMARAY_OBJECTINSPECTOR_OBJECTINSPECTOR_H #define GAMMARAY_OBJECTINSPECTOR_OBJECTINSPECTOR_H -#include "include/toolfactory.h" +#include "toolfactory.h" -#include +#include +class QItemSelection; +class QItemSelectionModel; class QModelIndex; namespace GammaRay { -namespace Ui { - class ObjectInspector; -} +class PropertyController; -class ObjectInspector : public QWidget +class ObjectInspector : public QObject { Q_OBJECT public: - explicit ObjectInspector(ProbeInterface *probe, QWidget *parent = 0); + explicit ObjectInspector(ProbeInterface *probe, QObject *parent = 0); private slots: + void selectDefaultItem(); void objectSelected(const QModelIndex &index); - void widgetSelected(QWidget *widget); + void objectSelectionChanged(const QItemSelection &selection); + void objectSelected(QObject *object); private: - QScopedPointer ui; + PropertyController *m_propertyController; + QItemSelectionModel *m_selectionModel; }; class ObjectInspectorFactory : public QObject, public StandardToolFactory diff -Nru gammaray-1.2.2/core/tools/objectinspector/objectinspector.ui gammaray-2.0.1/core/tools/objectinspector/objectinspector.ui --- gammaray-1.2.2/core/tools/objectinspector/objectinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/objectinspector/objectinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ - - - GammaRay::ObjectInspector - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - - - - - - true - - - true - - - - - - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
- - GammaRay::PropertyWidget - QWidget -
propertywidget.h
- 1 -
-
- - -
diff -Nru gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.cpp gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.cpp --- gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -23,82 +23,43 @@ #include "resourcebrowser.h" #include "resourcefiltermodel.h" -#include "ui_resourcebrowser.h" #include "qt/resourcemodel.h" +#include #include +#include +#include using namespace GammaRay; -ResourceBrowser::ResourceBrowser(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::ResourceBrowser) +ResourceBrowser::ResourceBrowser(ProbeInterface *probe, QObject *parent) + : ResourceBrowserInterface(parent) { - Q_UNUSED(probe); - ui->setupUi(this); - ResourceModel *resourceModel = new ResourceModel(this); ResourceFilterModel *proxy = new ResourceFilterModel(this); proxy->setSourceModel(resourceModel); - ui->treeView->setModel(proxy); - ui->treeView->expandAll(); - - // date modifier - not really useful and mostly empty anyways - hide it - ui->treeView->hideColumn(3); - - ui->treeView->header()->setResizeMode(QHeaderView::ResizeToContents); - - QMetaObject::invokeMethod(this, "setupLayout", Qt::QueuedConnection); - - connect(ui->treeView->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(resourceSelected(QItemSelection,QItemSelection))); - - ui->resourceLabel->setText(tr("Select a Resource to Preview")); - ui->stackedWidget->setCurrentWidget(ui->page_4); + probe->registerModel("com.kdab.GammaRay.ResourceModel", proxy); + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(proxy); + connect(selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(currentChanged(QModelIndex))); } -void ResourceBrowser::resourceSelected(const QItemSelection &selected, - const QItemSelection &deselected) +void ResourceBrowser::currentChanged(const QModelIndex ¤t) { - Q_UNUSED(deselected) - const QModelIndex selectedRow = selected.first().topLeft(); - const QFileInfo fi(selectedRow.data(ResourceModel::FilePathRole).toString()); + const QFileInfo fi(current.data(ResourceModel::FilePathRole).toString()); if (fi.isFile()) { - const QStringList l = QStringList() << "jpg" << "png" << "jpeg"; + static const QStringList l = QStringList() << "jpg" << "png" << "jpeg"; if (l.contains(fi.suffix())) { - ui->resourceLabel->setPixmap(fi.absoluteFilePath()); - ui->stackedWidget->setCurrentWidget(ui->page_4); + emit resourceSelected(QPixmap(fi.absoluteFilePath())); } else { QFile f(fi.absoluteFilePath()); f.open(QFile::ReadOnly | QFile::Text); - ui->textBrowser->setText(f.readAll()); - ui->stackedWidget->setCurrentWidget(ui->page_3); + emit resourceSelected(f.readAll()); } } else { - ui->resourceLabel->setText(tr("Select a Resource to Preview")); - ui->stackedWidget->setCurrentWidget(ui->page_4); - } -} - -void ResourceBrowser::setupLayout() -{ - // now the view was setup properly and we can mess with the splitter to resize - // the widgets for nicer display - - int viewWidth = ui->treeView->columnWidth(0) + - ui->treeView->columnWidth(1) + - ui->treeView->columnWidth(2) + - ui->treeView->contentsMargins().left() + - ui->treeView->contentsMargins().right() + 25; - const int totalWidth = ui->splitter_7->width(); - const int minPreviewWidth = 150; - if (totalWidth > viewWidth + minPreviewWidth) { - ui->splitter_7->setSizes(QList() << viewWidth << (totalWidth - viewWidth)); - ui->splitter_7->setStretchFactor(1, 3); + emit resourceDeselected(); } } -#include "resourcebrowser.moc" diff -Nru gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.h gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.h --- gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -24,30 +24,22 @@ #ifndef GAMMARAY_RESOURCEBROWSER_RESOURCEBROWSER_H #define GAMMARAY_RESOURCEBROWSER_RESOURCEBROWSER_H -#include "include/toolfactory.h" +#include "toolfactory.h" +#include -#include - -class QItemSelection; +class QModelIndex; namespace GammaRay { -namespace Ui { - class ResourceBrowser; -} - -class ResourceBrowser : public QWidget +class ResourceBrowser : public ResourceBrowserInterface { Q_OBJECT + Q_INTERFACES(GammaRay::ResourceBrowserInterface) public: - explicit ResourceBrowser(ProbeInterface *probe, QWidget *parent = 0); + explicit ResourceBrowser(ProbeInterface *probe, QObject *parent = 0); private slots: - void resourceSelected(const QItemSelection &selected, const QItemSelection &deselected); - void setupLayout(); - - private: - QScopedPointer ui; + void currentChanged(const QModelIndex ¤t); }; class ResourceBrowserFactory : public QObject, public StandardToolFactory diff -Nru gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.ui gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.ui --- gammaray-1.2.2/core/tools/resourcebrowser/resourcebrowser.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/resourcebrowser/resourcebrowser.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ - - - GammaRay::ResourceBrowser - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - 1 - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/resourcebrowser/resourcefiltermodel.cpp gammaray-2.0.1/core/tools/resourcebrowser/resourcefiltermodel.cpp --- gammaray-1.2.2/core/tools/resourcebrowser/resourcefiltermodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/resourcebrowser/resourcefiltermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -44,4 +44,3 @@ return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } -#include "resourcefiltermodel.moc" diff -Nru gammaray-1.2.2/core/tools/resourcebrowser/resourcefiltermodel.h gammaray-2.0.1/core/tools/resourcebrowser/resourcefiltermodel.h --- gammaray-1.2.2/core/tools/resourcebrowser/resourcefiltermodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/resourcebrowser/resourcefiltermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.cpp gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.cpp --- gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -/* - graphicssceneview.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "graphicssceneview.h" -#include "ui_graphicssceneview.h" - -using namespace GammaRay; - -GraphicsSceneView::GraphicsSceneView(QWidget *parent) - : QWidget(parent), - ui(new Ui::GraphicsSceneView) -{ - ui->setupUi(this); - - QFontMetrics fm(ui->sceneCoordLabel->font()); - ui->sceneCoordLabel->setFixedWidth(fm.width("00000.00 x 00000.00")); - ui->itemCoordLabel->setFixedWidth(fm.width("00000.00 x 00000.00")); - - connect(ui->graphicsView, SIGNAL(sceneCoordinatesChanged(QPointF)), - SLOT(sceneCoordinatesChanged(QPointF))); - connect(ui->graphicsView, SIGNAL(itemCoordinatesChanged(QPointF)), - SLOT(itemCoordinatesChanged(QPointF))); -} - -GraphicsSceneView::~GraphicsSceneView() -{ - delete ui; -} - -void GraphicsSceneView::showGraphicsItem(QGraphicsItem *item) -{ - ui->graphicsView->showItem(item); -} - -void GraphicsSceneView::setGraphicsScene(QGraphicsScene *scene) -{ - ui->graphicsView->setScene(scene); -} - -void GraphicsSceneView::sceneCoordinatesChanged(const QPointF &coord) -{ - ui->sceneCoordLabel->setText(QString::fromLatin1("%1 x %2"). - arg(coord.x(), 0, 'f', 2). - arg(coord.y(), 0, 'f', 2)); -} - -void GraphicsSceneView::itemCoordinatesChanged(const QPointF &coord) -{ - ui->itemCoordLabel->setText(QString::fromLatin1("%1 x %2"). - arg(coord.x(), 0, 'f', 2). - arg(coord.y(), 0, 'f', 2)); -} - -#include "graphicssceneview.moc" diff -Nru gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.h gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.h --- gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - graphicssceneview.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SCENEINSPECTOR_GRAPHICSSCENEVIEW_H -#define GAMMARAY_SCENEINSPECTOR_GRAPHICSSCENEVIEW_H - -#include - -class QGraphicsScene; -class QGraphicsItem; - -namespace GammaRay { - -namespace Ui { - class GraphicsSceneView; -} - -class GraphicsSceneView : public QWidget -{ - Q_OBJECT - public: - explicit GraphicsSceneView(QWidget *parent = 0); - ~GraphicsSceneView(); - - void showGraphicsItem(QGraphicsItem *item); - void setGraphicsScene(QGraphicsScene *scene); - - private slots: - void sceneCoordinatesChanged(const QPointF &coord); - void itemCoordinatesChanged(const QPointF &coord); - - private: - Ui::GraphicsSceneView *ui; -}; - -} - -#endif // GAMMARAY_GRAPHICSSCENEVIEW_H diff -Nru gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.ui gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.ui --- gammaray-1.2.2/core/tools/sceneinspector/graphicssceneview.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/graphicssceneview.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ - - - GammaRay::GraphicsSceneView - - - - 0 - 0 - 400 - 300 - - - - - 0 - - - - - - - Scene Coordinates: - - - - - - - 0x0 - - - - - - - Item Coordinates: - - - - - - - 0x0 - - - - - - - - - false - - - QGraphicsView::ScrollHandDrag - - - - - - - - GammaRay::GraphicsView - QGraphicsView -
tools/sceneinspector/graphicsview.h
-
-
- - -
diff -Nru gammaray-1.2.2/core/tools/sceneinspector/graphicsview.cpp gammaray-2.0.1/core/tools/sceneinspector/graphicsview.cpp --- gammaray-1.2.2/core/tools/sceneinspector/graphicsview.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/graphicsview.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,109 +0,0 @@ -/* - graphicsview.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "graphicsview.h" - -#include -#include - -using namespace GammaRay; - -GraphicsView::GraphicsView(QWidget *parent) - : QGraphicsView(parent), - m_currentItem(0) -{ - setMouseTracking(true); -} - -void GraphicsView::showItem(QGraphicsItem *item) -{ - m_currentItem = item; - fitInView(item, Qt::KeepAspectRatio); - scale(0.8f, 0.8f); -} - -void GraphicsView::keyPressEvent(QKeyEvent *event) -{ - if (event->modifiers() == Qt::CTRL) { - switch (event->key()) { - case Qt::Key_Plus: - scale(1.2, 1.2); - event->accept(); - return; - case Qt::Key_Minus: - scale(0.8, 0.8); - event->accept(); - return; - case Qt::Key_Left: - rotate(-5); - event->accept(); - break; - case Qt::Key_Right: - rotate(5); - event->accept(); - break; - } - } - QGraphicsView::keyPressEvent(event); -} - -void GraphicsView::mouseMoveEvent(QMouseEvent *event) -{ - emit sceneCoordinatesChanged(mapToScene(event->pos())); - if (m_currentItem) { - emit itemCoordinatesChanged(m_currentItem->mapFromScene(mapToScene(event->pos()))); - } - QGraphicsView::mouseMoveEvent(event); -} - -void GraphicsView::drawForeground(QPainter *painter, const QRectF &rect) -{ - QGraphicsView::drawForeground(painter, rect); - if (m_currentItem) { - const QRectF itemBoundingRect = m_currentItem->boundingRect(); - // coord system, TODO: nicer axis with arrows, tics, markers for current mouse position etc. - painter->setPen(Qt::black); - const qreal maxX = qMax(qAbs(itemBoundingRect.left()), qAbs(itemBoundingRect.right())); - const qreal maxY = qMax(qAbs(itemBoundingRect.top()), qAbs(itemBoundingRect.bottom())); - const qreal maxXY = qMax(maxX, maxY) * 1.5f; - painter->drawLine(m_currentItem->mapToScene(-maxXY, 0), m_currentItem->mapToScene(maxXY, 0)); - painter->drawLine(m_currentItem->mapToScene(0, -maxXY), m_currentItem->mapToScene(0, maxXY)); - - painter->setPen(Qt::blue); - const QPolygonF boundingBox = m_currentItem->mapToScene(itemBoundingRect); - painter->drawPolygon(boundingBox); - - painter->setPen(Qt::green); - const QPainterPath shape = m_currentItem->mapToScene(m_currentItem->shape()); - painter->drawPath(shape); - - painter->setPen(Qt::red); - const QPointF transformOrigin = - m_currentItem->mapToScene(m_currentItem->transformOriginPoint()); - painter->drawEllipse(transformOrigin, - 5.0 / transform().m11(), - 5.0 / transform().m22()); - } -} - -#include "graphicsview.moc" diff -Nru gammaray-1.2.2/core/tools/sceneinspector/graphicsview.h gammaray-2.0.1/core/tools/sceneinspector/graphicsview.h --- gammaray-1.2.2/core/tools/sceneinspector/graphicsview.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/graphicsview.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - graphicsview.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SCENEINSPECTOR_GRAPHICSVIEW_H -#define GAMMARAY_SCENEINSPECTOR_GRAPHICSVIEW_H - -#include - -namespace GammaRay { - -class GraphicsView : public QGraphicsView -{ - Q_OBJECT - public: - explicit GraphicsView(QWidget *parent = 0); - - void showItem(QGraphicsItem *item); - - signals: - void sceneCoordinatesChanged(const QPointF &sceneCoord); - void itemCoordinatesChanged(const QPointF &itemCoord); - - protected: - void keyPressEvent(QKeyEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void drawForeground(QPainter *painter, const QRectF &rect); - - private: - QGraphicsItem *m_currentItem; -}; - -} - -#endif // GAMMARAY_GRAPHICSVIEW_H diff -Nru gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.cpp gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.cpp --- gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,152 +0,0 @@ -/* - sceneinspector.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "sceneinspector.h" - -#include "metaobjectrepository.h" -#include "scenemodel.h" -#include "ui_sceneinspector.h" - -#include "include/objectmodel.h" -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" -#include "include/singlecolumnobjectproxymodel.h" - -#include - -#include -#include -#include - -using namespace GammaRay; - -SceneInspector::SceneInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::SceneInspector) -{ - ui->setupUi(this); - - connect(probe->probe(), SIGNAL(widgetSelected(QWidget*,QPoint)), - SLOT(widgetSelected(QWidget*,QPoint))); - - ObjectTypeFilterProxyModel *sceneFilterProxy = - new ObjectTypeFilterProxyModel(this); - sceneFilterProxy->setSourceModel(probe->objectListModel()); - SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); - singleColumnProxy->setSourceModel(sceneFilterProxy); - ui->sceneComboBox->setModel(singleColumnProxy); - connect(ui->sceneComboBox, SIGNAL(activated(int)), SLOT(sceneSelected(int))); - m_sceneModel = new SceneModel(this); - QSortFilterProxyModel *sceneFilter = new KRecursiveFilterProxyModel(this); - sceneFilter->setSourceModel(m_sceneModel); - ui->sceneTreeView->setModel(sceneFilter); - ui->screneTreeSearchLine->setProxy(sceneFilter); - connect(ui->sceneTreeView->selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(sceneItemSelected(QModelIndex))); - - if (ui->sceneComboBox->count()) { - sceneSelected(0); - } -} - -void SceneInspector::sceneSelected(int index) -{ - QObject *obj = ui->sceneComboBox->itemData(index, ObjectModel::ObjectRole).value(); - QGraphicsScene *scene = qobject_cast(obj); -// qDebug() << Q_FUNC_INFO << scene << obj; - - m_sceneModel->setScene(scene); - ui->graphicsSceneView->setGraphicsScene(scene); -} - -void SceneInspector::sceneItemSelected(const QModelIndex &index) -{ - if (index.isValid()) { - QGraphicsItem *item = index.data(SceneModel::SceneItemRole).value(); - QGraphicsObject *obj = item->toGraphicsObject(); - if (obj) { - ui->scenePropertyWidget->setObject(obj); - } else { - ui->scenePropertyWidget->setObject(item, findBestType(item)); - } - ui->graphicsSceneView->showGraphicsItem(item); - } else { - ui->scenePropertyWidget->setObject(0); - } -} - -void SceneInspector::widgetSelected(QWidget *widget, const QPoint &pos) -{ - QGraphicsView *qgv = Util::findParentOfType(widget); - if (qgv) { - // TODO: select qgv->scene() first, right now this only works for a single scene - QGraphicsItem *item = qgv->itemAt(widget->mapTo(qgv, pos)); - if (item) { - sceneItemSelected(item); - } - } -} - -void SceneInspector::sceneItemSelected(QGraphicsItem *item) -{ - QAbstractItemModel *model = ui->sceneTreeView->model(); - const QModelIndexList indexList = - model->match(model->index(0, 0), - SceneModel::SceneItemRole, - QVariant::fromValue(item), 1, - Qt::MatchExactly | Qt::MatchRecursive); - if (indexList.isEmpty()) { - return; - } - const QModelIndex index = indexList.first(); - ui->sceneTreeView->selectionModel()->select( - index, - QItemSelectionModel::Select | QItemSelectionModel::Clear | - QItemSelectionModel::Rows | QItemSelectionModel::Current); - ui->sceneTreeView->scrollTo(index); - sceneItemSelected(index); -} - -#define QGV_CHECK_TYPE(Class) \ - if (dynamic_cast(item) && MetaObjectRepository::instance()->hasMetaObject(#Class)) \ - return QLatin1String(#Class) - -QString SceneInspector::findBestType(QGraphicsItem *item) -{ - // keep this in reverse topological order of the class hierarchy! - // QObject-based types are covered elsewhere, so we don't need those here - QGV_CHECK_TYPE(QGraphicsEllipseItem); - QGV_CHECK_TYPE(QGraphicsPathItem); - QGV_CHECK_TYPE(QGraphicsPolygonItem); - QGV_CHECK_TYPE(QGraphicsSimpleTextItem); - QGV_CHECK_TYPE(QGraphicsRectItem); - QGV_CHECK_TYPE(QAbstractGraphicsShapeItem); - QGV_CHECK_TYPE(QGraphicsLineItem); - QGV_CHECK_TYPE(QGraphicsItemGroup); - QGV_CHECK_TYPE(QGraphicsPixmapItem); - - return QLatin1String("QGraphicsItem"); -} - -#include "sceneinspector.moc" diff -Nru gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.h gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.h --- gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -/* - sceneinspector.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SCENEINSPECTOR_SCENEINSPECTOR_H -#define GAMMARAY_SCENEINSPECTOR_SCENEINSPECTOR_H - -#include "include/toolfactory.h" - -#include -#include - -class QModelIndex; - -namespace GammaRay { - -class SceneModel; - -namespace Ui { - class SceneInspector; -} - -class SceneInspector : public QWidget -{ - Q_OBJECT - public: - explicit SceneInspector(ProbeInterface *probe, QWidget *parent = 0); - - private slots: - void sceneSelected(int index); - void sceneItemSelected(const QModelIndex &index); - void sceneItemSelected(QGraphicsItem *item); - void widgetSelected(QWidget *item, const QPoint &pos); - - private: - QString findBestType(QGraphicsItem *item); - - private: - QScopedPointer ui; - SceneModel *m_sceneModel; -}; - -class SceneInspectorFactory : public QObject, - public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - public: - explicit SceneInspectorFactory(QObject *parent) : QObject(parent) - { - } - - inline QString name() const - { - return tr("Graphics Scenes"); - } -}; - -} - -#endif // GAMMARAY_SCENEINSPECTOR_H diff -Nru gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.ui gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.ui --- gammaray-1.2.2/core/tools/sceneinspector/sceneinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/sceneinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ - - - GammaRay::SceneInspector - - - - 0 - 0 - 400 - 300 - - - - - - - - - - Qt::Horizontal - - - - Qt::Vertical - - - - - - - - - - true - - - - - - - - - - - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
- - GammaRay::PropertyWidget - QWidget -
propertywidget.h
- 1 -
- - GammaRay::GraphicsSceneView - QWidget -
tools/sceneinspector/graphicssceneview.h
- 1 -
-
-
diff -Nru gammaray-1.2.2/core/tools/sceneinspector/scenemodel.cpp gammaray-2.0.1/core/tools/sceneinspector/scenemodel.cpp --- gammaray-1.2.2/core/tools/sceneinspector/scenemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/scenemodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,184 +0,0 @@ -/* - scenemodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "scenemodel.h" - -#include -#include -#include -#include -#include - -using namespace GammaRay; - -#define QGV_ITEMTYPE(Type) \ -{ \ - Type t; \ - m_typeNames.insert(t.type(), QLatin1String(#Type)); \ -} - -SceneModel::SceneModel(QObject *parent) - : QAbstractItemModel(parent), - m_scene(0) -{ - QGV_ITEMTYPE(QGraphicsLineItem) - QGV_ITEMTYPE(QGraphicsPixmapItem) - QGV_ITEMTYPE(QGraphicsRectItem) - QGV_ITEMTYPE(QGraphicsEllipseItem) - QGV_ITEMTYPE(QGraphicsPathItem) - QGV_ITEMTYPE(QGraphicsPolygonItem) - QGV_ITEMTYPE(QGraphicsSimpleTextItem) - QGV_ITEMTYPE(QGraphicsItemGroup) -} - -void SceneModel::setScene(QGraphicsScene *scene) -{ - m_scene = scene; -// qDebug() << "total amount of graphics items:" << m_scene->items().size(); - reset(); -} - -QVariant SceneModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - QGraphicsItem *item = static_cast(index.internalPointer()); - - if (item && role == Qt::DisplayRole) { - QGraphicsObject *obj = item->toGraphicsObject(); - if (index.column() == 0) { - if (obj && !obj->objectName().isEmpty()) { - return obj->objectName(); - } - return - QString::fromLatin1("0x%1"). - arg(QString::number(reinterpret_cast(item), 16)); - } else if (index.column() == 1) { - if (obj) { - return obj->metaObject()->className(); - } - return typeName(item->type()); - } - } else if (role == SceneItemRole) { - return QVariant::fromValue(item); - } else if (item && role == Qt::ForegroundRole) { - if (!item->isVisible()) { - return qApp->palette().color(QPalette::Disabled, QPalette::Text); - } - } - return QVariant(); -} - -int SceneModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 2; -} - -int SceneModel::rowCount(const QModelIndex &parent) const -{ - if (!m_scene) { - return 0; - } - if (parent.isValid()) { - QGraphicsItem* item = static_cast(parent.internalPointer()); - if (item) { - return item->childItems().size(); - } else { - return 0; - } - } - return topLevelItems().size(); -} - -QModelIndex SceneModel::parent(const QModelIndex &child) const -{ - if (!child.isValid()) { - return QModelIndex(); - } - QGraphicsItem *item = static_cast(child.internalPointer()); - if (!item->parentItem()) { - return QModelIndex(); - } - int row = item->parentItem()->childItems().indexOf(item); - return createIndex(row, 0, item->parentItem()); -} - -QModelIndex SceneModel::index(int row, int column, const QModelIndex &parent) const -{ - if (!parent.isValid() && row >= 0 && row < topLevelItems().size()) { - return createIndex(row, column, topLevelItems().at(row)); - } - QGraphicsItem *parentItem = static_cast(parent.internalPointer()); - if (!parentItem || row < 0 || row >= parentItem->childItems().size()) { - return QModelIndex(); - } - return createIndex(row, column, parentItem->childItems().at(row)); -} - -QList SceneModel::topLevelItems() const -{ - QList topLevel; - if (!m_scene) { - return topLevel; - } - Q_FOREACH (QGraphicsItem *item, m_scene->items()) { - if (!item->parentItem()) { - topLevel.push_back(item); - } - } - return topLevel; -} - -QVariant SceneModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - switch (section) { - case 0: - return tr("Item"); - case 1: - return tr("Type"); - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -QString SceneModel::typeName(int itemType) const -{ - const QHash::const_iterator it = m_typeNames.find(itemType); - if (it != m_typeNames.end()) { - return it.value(); - } - if (itemType == QGraphicsItem::UserType) { - return QLatin1String("UserType"); - } - if (itemType > QGraphicsItem::UserType) { - return - QString::fromLatin1("UserType + %1"). - arg(itemType - static_cast(QGraphicsItem::UserType)); - } - return QString::number(itemType); -} - -#include "scenemodel.moc" diff -Nru gammaray-1.2.2/core/tools/sceneinspector/scenemodel.h gammaray-2.0.1/core/tools/sceneinspector/scenemodel.h --- gammaray-1.2.2/core/tools/sceneinspector/scenemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/sceneinspector/scenemodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -/* - scenemodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SCENEINSPECTOR_SCENEMODEL_H -#define GAMMARAY_SCENEINSPECTOR_SCENEMODEL_H - -#include - -class QGraphicsScene; -class QGraphicsItem; - -namespace GammaRay { - -class SceneModel : public QAbstractItemModel -{ - Q_OBJECT - public: - enum Role { - SceneItemRole = Qt::UserRole + 1 - }; - explicit SceneModel(QObject *parent = 0); - void setScene(QGraphicsScene *scene); - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - - private: - QList topLevelItems() const; - /// Returns a string type name for the given QGV item type id - QString typeName(int itemType) const; - - QGraphicsScene *m_scene; - QHash m_typeNames; -}; - -} - -#endif // GAMMARAY_SCENEMODEL_H diff -Nru gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.cpp gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.cpp --- gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -/* - selectionmodelinspector.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "selectionmodelinspector.h" -#include "ui_selectionmodelinspector.h" - -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" - -using namespace GammaRay; - -SelectionModelInspector::SelectionModelInspector(ProbeInterface *probe, QWidget *widget) - : QWidget(widget), ui(new Ui::SelectionModelInspector) -{ - ui->setupUi(this); - - ObjectTypeFilterProxyModel *selectionModelProxy = - new ObjectTypeFilterProxyModel(this); - selectionModelProxy->setSourceModel(probe->objectListModel()); - ui->selectionModelView->setModel(selectionModelProxy); - ui->selectionModelView->setRootIsDecorated(false); - ui->selectionModelVisualizer->setRootIsDecorated(false); - connect(ui->selectionModelView->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - SLOT(selectionModelSelected(QItemSelection,QItemSelection))); -} - -void SelectionModelInspector::selectionModelSelected(const QItemSelection &selected, - const QItemSelection &deselected) -{ - Q_UNUSED(deselected); - const QModelIndex selectedRow = selected.first().topLeft(); - QObject *selectionModelObject = selectedRow.data(ObjectModel::ObjectRole).value(); - QItemSelectionModel *selectionModel = qobject_cast(selectionModelObject); - if (selectionModel && selectionModel->model()) { - ui->selectionModelVisualizer->setModel( - const_cast(selectionModel->model())); - ui->selectionModelVisualizer->setSelectionModel(selectionModel); - } -} - -#include "selectionmodelinspector.moc" diff -Nru gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.h gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.h --- gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,69 +0,0 @@ -/* - selectionmodelinspector.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Stephen Kelly - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTOR_H -#define GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTOR_H - -#include "include/toolfactory.h" - -#include -#include - -namespace GammaRay { - -namespace Ui { - class SelectionModelInspector; -} - -class SelectionModelInspector : public QWidget -{ - Q_OBJECT - public: - explicit SelectionModelInspector(ProbeInterface *probe, QWidget *widget = 0); - - private slots: - void selectionModelSelected(const QItemSelection &selected, const QItemSelection &deselected); - - private: - QScopedPointer ui; -}; - -class SelectionModelInspectorFactory : - public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - public: - explicit SelectionModelInspectorFactory(QObject *parent) : QObject(parent) - { - } - - virtual inline QString name() const - { - return tr("Selection Models"); - } -}; - -} - -#endif // GAMMARAY_SELECTIONMODELINSPECTOR_H diff -Nru gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.ui gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.ui --- gammaray-1.2.2/core/tools/selectionmodelinspector/selectionmodelinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/selectionmodelinspector/selectionmodelinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ - - - GammaRay::SelectionModelInspector - - - - 0 - 0 - 400 - 300 - - - - - - - Qt::Horizontal - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/standardpaths/standardpaths.cpp gammaray-2.0.1/core/tools/standardpaths/standardpaths.cpp --- gammaray-1.2.2/core/tools/standardpaths/standardpaths.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/standardpaths/standardpaths.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + standardpaths.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "standardpaths.h" +#include "standardpathsmodel.h" + +using namespace GammaRay; + +StandardPaths::StandardPaths(ProbeInterface *probe, QObject *parent) + : QObject(parent) +{ + StandardPathsModel *model = new StandardPathsModel(this); + probe->registerModel("com.kdab.GammaRay.StandardPathsModel", model); +} + +StandardPaths::~StandardPaths() +{ +} + diff -Nru gammaray-1.2.2/core/tools/standardpaths/standardpaths.h gammaray-2.0.1/core/tools/standardpaths/standardpaths.h --- gammaray-1.2.2/core/tools/standardpaths/standardpaths.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/standardpaths/standardpaths.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + standardpaths.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STANDARDPATHS_H +#define GAMMARAY_STANDARDPATHS_H + +#include + +namespace GammaRay { + +class StandardPaths : public QObject +{ + Q_OBJECT + public: + explicit StandardPaths(ProbeInterface *probe, QObject *parent = 0); + ~StandardPaths(); +}; + +class StandardPathsFactory : public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + public: + explicit StandardPathsFactory(QObject *parent) : QObject(parent) + { + } + + virtual inline QString name() const + { + return tr("Standard Paths"); + } +}; + +} + +#endif // GAMMARAY_STANDARDPATHS_H diff -Nru gammaray-1.2.2/core/tools/standardpaths/standardpathsmodel.cpp gammaray-2.0.1/core/tools/standardpaths/standardpathsmodel.cpp --- gammaray-1.2.2/core/tools/standardpaths/standardpathsmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/standardpaths/standardpathsmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,128 @@ +/* + standardpathsmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "standardpathsmodel.h" + +#include + +using namespace GammaRay; + +struct standard_path_t { + QStandardPaths::StandardLocation location; + const char *locationName; +}; + +#define P(x) { QStandardPaths:: x, #x } + +static standard_path_t standard_paths[] = { + P(DesktopLocation), + P(DocumentsLocation), + P(FontsLocation), + P(ApplicationsLocation), + P(MusicLocation), + P(MoviesLocation), + P(PicturesLocation), + P(TempLocation), + P(HomeLocation), + P(DataLocation), + P(CacheLocation), + P(GenericDataLocation), + P(RuntimeLocation), + P(ConfigLocation), + P(DownloadLocation), + P(GenericCacheLocation) +}; + +#undef P + +static int standard_path_count = sizeof(standard_paths) / sizeof(standard_path_t); + +StandardPathsModel::StandardPathsModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +StandardPathsModel::~StandardPathsModel() +{ +} + +QVariant StandardPathsModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + if (role == Qt::TextAlignmentRole) { + return static_cast(Qt::AlignLeft | Qt::AlignTop); + } + + if (role == Qt::DisplayRole) { + const QStandardPaths::StandardLocation loc = standard_paths[index.row()].location; + switch (index.column()) { + case 0: + return QString::fromLatin1(standard_paths[index.row()].locationName); + case 1: + return QStandardPaths::displayName(loc); + case 2: + return QStandardPaths::standardLocations(loc).join(QLatin1String("\n")); + case 3: + return QStandardPaths::writableLocation(loc); + } + } + + return QVariant(); +} + +int StandardPathsModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 4; +} + +int StandardPathsModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return standard_path_count; +} + +QVariant StandardPathsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical || role != Qt::DisplayRole) { + return QVariant(); + } + + switch (section) { + case 0: + return tr("Type"); + case 1: + return tr("Display Name"); + case 2: + return tr("Standard Locations"); + case 3: + return tr("Writable Location"); + } + return QVariant(); +} + diff -Nru gammaray-1.2.2/core/tools/standardpaths/standardpathsmodel.h gammaray-2.0.1/core/tools/standardpaths/standardpathsmodel.h --- gammaray-1.2.2/core/tools/standardpaths/standardpathsmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/tools/standardpaths/standardpathsmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + standardpathsmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STANDARDPATHSMODEL_H +#define GAMMARAY_STANDARDPATHSMODEL_H + +#include + +namespace GammaRay { + +class StandardPathsModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit StandardPathsModel(QObject *parent = 0); + ~StandardPathsModel(); + + QVariant data(const QModelIndex &index, int role) const; + + int columnCount(const QModelIndex &parent) const; + + int rowCount(const QModelIndex &parent) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + +}; + +} + +#endif // GAMMARAY_STANDARDPATHSMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementmodel.cpp gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementmodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,81 +0,0 @@ -/* - abstractstyleelementmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "abstractstyleelementmodel.h" - -#include -#include -#include - -using namespace GammaRay; - -AbstractStyleElementModel::AbstractStyleElementModel(QObject *parent) - : QAbstractTableModel(parent) -{ -} - -void AbstractStyleElementModel::setStyle(QStyle *style) -{ - beginResetModel(); - m_style = QPointer(style); - endResetModel(); -} - -QVariant AbstractStyleElementModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || !m_style) { - return QVariant(); - } - return doData(index.row(), index.column(), role); -} - -int AbstractStyleElementModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return doColumnCount(); -} - -int AbstractStyleElementModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid() || !m_style) { - return 0; - } - return doRowCount(); -} - -bool AbstractStyleElementModel::isMainStyle() const -{ - QStyle *style = qApp->style(); - forever { - if (style == m_style) { - return true; - } - QProxyStyle *proxy = qobject_cast(style); - if (!proxy) { - return false; - } - style = proxy->baseStyle(); - } -} - -#include "abstractstyleelementmodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementmodel.h gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementmodel.h --- gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - abstractstyleelementmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTMODEL_H -#define GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTMODEL_H - -#include -#include - -class QStyle; - -namespace GammaRay { - -/** - * Base class for all models showing style elements. - */ -class AbstractStyleElementModel : public QAbstractTableModel -{ - Q_OBJECT - public: - explicit AbstractStyleElementModel(QObject *parent = 0); - - void setStyle(QStyle *style); - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - protected: - virtual QVariant doData(int row, int column, int role) const = 0; - virtual int doColumnCount() const = 0; - virtual int doRowCount() const = 0; - - /** Returns @c true if we are looking at the primary style of the application - * ie. the one set in QApplication. This takes proxy styles into account. - */ - bool isMainStyle() const; - - protected: - QPointer m_style; -}; - -} - -#endif // GAMMARAY_ABSTRACTSTYLEELEMENTMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementstatetable.cpp gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementstatetable.cpp --- gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementstatetable.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementstatetable.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,131 +0,0 @@ -/* - abstractstyleelementstatetable.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "abstractstyleelementstatetable.h" -#include "styleoption.h" - -#include -#include - -using namespace GammaRay; - -AbstractStyleElementStateTable::AbstractStyleElementStateTable(QObject *parent) - : AbstractStyleElementModel(parent), - m_cellWidth(64), - m_cellHeight(64), - m_zoomFactor(1) -{ -} - -int AbstractStyleElementStateTable::doColumnCount() const -{ - return StyleOption::stateCount(); -} - -QVariant AbstractStyleElementStateTable::doData(int row, int column, int role) const -{ - Q_UNUSED(column); - Q_UNUSED(row); - if (role == Qt::SizeHintRole) { - return QSize(cellWidth() * zoomFactor() + 4, cellHeight() * zoomFactor() + 4); - } - return QVariant(); -} - -QVariant AbstractStyleElementStateTable::headerData(int section, - Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - return StyleOption::stateDisplayName(section); - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -void AbstractStyleElementStateTable::drawTransparencyBackground(QPainter *painter, - const QRect &rect) const -{ - QPixmap bgPattern(16, 16); - bgPattern.fill(Qt::lightGray); - QPainter bgPainter(&bgPattern); - bgPainter.fillRect(8, 0, 8, 8, Qt::gray); - bgPainter.fillRect(0, 8, 8, 8, Qt::gray); - - QBrush bgBrush; - bgBrush.setTexture(bgPattern); - painter->fillRect(rect, bgBrush); -} - -int AbstractStyleElementStateTable::cellWidth() const -{ - return m_cellWidth; -} - -int AbstractStyleElementStateTable::cellHeight() const -{ - return m_cellHeight; -} - -int AbstractStyleElementStateTable::zoomFactor() const -{ - return m_zoomFactor; -} - -void AbstractStyleElementStateTable::setCellWidth(int width) -{ - m_cellWidth = width; - if (rowCount() > 0) { - emit dataChanged(index(0, 0), index(doRowCount() - 1, doColumnCount() - 1)); - } -} - -void AbstractStyleElementStateTable::setCellHeight(int height) -{ - m_cellHeight = height; - if (rowCount() > 0) { - emit dataChanged(index(0, 0), index(doRowCount() - 1, doColumnCount() - 1)); - } -} - -void AbstractStyleElementStateTable::setZoomFactor(int zoom) -{ - Q_ASSERT(zoom > 0); - m_zoomFactor = zoom; - if (rowCount() > 0) { - emit dataChanged(index(0, 0), index(doRowCount() - 1, doColumnCount() - 1)); - } -} - -QSize AbstractStyleElementStateTable::effectiveCellSize() const -{ - return QSize(cellWidth() * zoomFactor(), cellHeight() * zoomFactor()); -} - -void AbstractStyleElementStateTable::fillStyleOption(QStyleOption *option, int column) const -{ - option->rect = QRect(0, 0, cellWidth(), cellHeight()); - option->palette = m_style->standardPalette(); - option->state = StyleOption::prettyState(column); -} - -#include "abstractstyleelementstatetable.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementstatetable.h gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementstatetable.h --- gammaray-1.2.2/core/tools/styleinspector/abstractstyleelementstatetable.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/abstractstyleelementstatetable.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ -/* - abstractstyleelementstatetable.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTSTATETABLE_H -#define GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTSTATETABLE_H - -#include "abstractstyleelementmodel.h" - -class QStyleOption; -class QRect; -class QPainter; - -namespace GammaRay { - -/** - * Base class for style element x style option state tables. - * Covers the state part, sub-classes need to fill in the corresponding rows. - */ -class AbstractStyleElementStateTable : public GammaRay::AbstractStyleElementModel -{ - Q_OBJECT - public: - explicit AbstractStyleElementStateTable(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - int cellWidth() const; - int cellHeight() const; - int zoomFactor() const; - - public slots: - void setCellWidth(int width); - void setCellHeight(int height); - void setZoomFactor(int zoom); - - protected: - virtual int doColumnCount() const; - virtual QVariant doData(int row, int column, int role) const; - - void drawTransparencyBackground(QPainter *painter, const QRect &rect) const; - /// actual size of the cell on screen - QSize effectiveCellSize() const; - /// standard setup for the style option used in a cell in column @p column - void fillStyleOption(QStyleOption *option, int column) const; - - private: - int m_cellWidth; - int m_cellHeight; - int m_zoomFactor; -}; - -} - -#endif // GAMMARAY_ABSTRACTSTYLEELEMENTSTATETABLE_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/complexcontrolmodel.cpp gammaray-2.0.1/core/tools/styleinspector/complexcontrolmodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/complexcontrolmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/complexcontrolmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,116 +0,0 @@ -/* - complexcontrolmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "complexcontrolmodel.h" -#include "styleoption.h" - -#include -#include -#include - -#include -#ifdef _MSC_VER // only MSVC doesn't have log2()... -static double log2(double n) -{ - return log(n) / log(2.0f); -} -#endif - -using namespace GammaRay; - -struct complex_control_element_t { - const char *name; - QStyle::ComplexControl control; - QStyleOption * (*styleOptionFactory)(); - QStyle::SubControls subControls; -}; - -#define MAKE_CC2( control, factory ) { #control, QStyle:: control, &StyleOption:: factory, 0 } -#define MAKE_CC3( control, factory, subControls ) { #control, QStyle:: control, &StyleOption:: factory, subControls } - -static complex_control_element_t complexControlElements[] = { - MAKE_CC3(CC_SpinBox, makeSpinBoxStyleOption, QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown | QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField), - MAKE_CC3(CC_ComboBox, makeComboBoxStyleOption, QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxArrow | QStyle::SC_ComboBoxEditField | QStyle::SC_ComboBoxListBoxPopup), - MAKE_CC3(CC_ScrollBar, makeSliderStyleOption, QStyle::SC_ScrollBarAddLine | QStyle::SC_ScrollBarSubLine | QStyle::SC_ScrollBarAddPage | QStyle::SC_ScrollBarSubPage | QStyle::SC_ScrollBarFirst | QStyle::SC_ScrollBarLast | QStyle::SC_ScrollBarSlider | QStyle::SC_ScrollBarGroove), - MAKE_CC3(CC_Slider, makeSliderStyleOption, QStyle::SC_SliderGroove | QStyle::SC_SliderHandle | QStyle::SC_SliderTickmarks), - MAKE_CC3(CC_ToolButton, makeToolButtonStyleOption, QStyle::SC_ToolButton | QStyle::SC_ToolButtonMenu), - MAKE_CC3(CC_TitleBar, makeTitleBarStyleOption, QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarMinButton | QStyle::SC_TitleBarMaxButton | QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarNormalButton | QStyle::SC_TitleBarShadeButton | QStyle::SC_TitleBarUnshadeButton | QStyle::SC_TitleBarContextHelpButton), -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - MAKE_CC2(CC_Q3ListView, makeStyleOptionComplex), -#endif - MAKE_CC3(CC_Dial, makeSliderStyleOption, QStyle::SC_DialHandle | QStyle::SC_DialGroove | QStyle::SC_DialTickmarks), - MAKE_CC2(CC_GroupBox, makeStyleOptionComplex), -// MAKE_CC2(CC_GroupBox, makeGroupBoxStyleOption), // TODO: oxygen crashes with that due to widget access - MAKE_CC3(CC_MdiControls, makeStyleOptionComplex, QStyle::SC_MdiNormalButton | QStyle::SC_MdiMinButton | QStyle::SC_MdiCloseButton) -}; - -ComplexControlModel::ComplexControlModel(QObject *parent) : AbstractStyleElementStateTable(parent) -{ -} - -QVariant ComplexControlModel::doData(int row, int column, int role) const -{ - if (role == Qt::DecorationRole) { - QPixmap pixmap(effectiveCellSize()); - QPainter painter(&pixmap); - drawTransparencyBackground(&painter, pixmap.rect()); - painter.scale(zoomFactor(), zoomFactor()); - - QScopedPointer opt(qstyleoption_cast(complexControlElements[row].styleOptionFactory())); - Q_ASSERT(opt); - fillStyleOption(opt.data(), column); - m_style->drawComplexControl(complexControlElements[row].control, opt.data(), &painter); - - int colorIndex = 7; - for (int i = 0; i < log2(QStyle::SC_All); ++i) { - QStyle::SubControl sc = static_cast(1 << i); - if (sc & complexControlElements[row].subControls) { - QRectF scRect = m_style->subControlRect(complexControlElements[row].control, opt.data(), sc); - scRect.adjust(0, 0, -1.0 / zoomFactor(), -1.0 / zoomFactor()); - if (scRect.isValid() && !scRect.isEmpty()) { - painter.setPen(static_cast(colorIndex++)); // HACK: add some real color mapping - painter.drawRect(scRect); - } - } - } - - return pixmap; - } - - return AbstractStyleElementStateTable::doData(row, column, role); -} - -int ComplexControlModel::doRowCount() const -{ - return sizeof(complexControlElements) / sizeof(complexControlElements[0]); -} - -QVariant ComplexControlModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Vertical && role == Qt::DisplayRole) { - return complexControlElements[section].name; - } - return AbstractStyleElementStateTable::headerData(section, orientation, role); -} - -#include "complexcontrolmodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/complexcontrolmodel.h gammaray-2.0.1/core/tools/styleinspector/complexcontrolmodel.h --- gammaray-1.2.2/core/tools/styleinspector/complexcontrolmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/complexcontrolmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - complexcontrolmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_COMPLEXCONTROLMODEL_H -#define GAMMARAY_STYLEINSPECTOR_COMPLEXCONTROLMODEL_H - -#include "abstractstyleelementstatetable.h" - -namespace GammaRay { - -class ComplexControlModel : public AbstractStyleElementStateTable -{ - Q_OBJECT - public: - explicit ComplexControlModel(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - protected: - virtual QVariant doData(int row, int column, int role) const; - virtual int doRowCount() const; -}; - -} - -#endif // GAMMARAY_COMPLEXCONTROLMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/controlmodel.cpp gammaray-2.0.1/core/tools/styleinspector/controlmodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/controlmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/controlmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,130 +0,0 @@ -/* - controlmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "controlmodel.h" -#include "styleoption.h" - -#include -#include -#include - -using namespace GammaRay; - -struct control_element_t { - const char *name; - QStyle::ControlElement control; - QStyleOption * (*styleOptionFactory)(); -}; - -#define MAKE_CE( control ) { #control , QStyle:: control, &StyleOption::makeStyleOption } -#define MAKE_CE_X( control, factory ) { #control, QStyle:: control, &StyleOption:: factory } - -static control_element_t controlElements[] = { - MAKE_CE_X(CE_PushButton, makeButtonStyleOption), - MAKE_CE_X(CE_PushButtonBevel, makeButtonStyleOption), - MAKE_CE_X(CE_PushButtonLabel, makeButtonStyleOption), - MAKE_CE_X(CE_CheckBox, makeButtonStyleOption), - MAKE_CE_X(CE_CheckBoxLabel, makeButtonStyleOption), - MAKE_CE_X(CE_RadioButton, makeButtonStyleOption), - MAKE_CE_X(CE_RadioButtonLabel, makeButtonStyleOption), - MAKE_CE_X(CE_TabBarTab, makeTabStyleOption), - MAKE_CE_X(CE_TabBarTabShape, makeTabStyleOption), - MAKE_CE_X(CE_TabBarTabLabel, makeTabStyleOption), - MAKE_CE_X(CE_ProgressBar, makeProgressBarStyleOption), - MAKE_CE_X(CE_ProgressBarGroove, makeProgressBarStyleOption), - MAKE_CE_X(CE_ProgressBarContents, makeProgressBarStyleOption), - MAKE_CE_X(CE_ProgressBarLabel, makeProgressBarStyleOption), - MAKE_CE_X(CE_MenuItem, makeMenuStyleOption), - MAKE_CE(CE_MenuScroller), - MAKE_CE(CE_MenuVMargin), - MAKE_CE(CE_MenuHMargin), - MAKE_CE(CE_MenuTearoff), - MAKE_CE(CE_MenuEmptyArea), - MAKE_CE_X(CE_MenuBarItem, makeMenuStyleOption), - MAKE_CE(CE_MenuBarEmptyArea), - MAKE_CE_X(CE_ToolButtonLabel, makeToolButtonStyleOption), - MAKE_CE_X(CE_Header, makeHeaderStyleOption), - MAKE_CE_X(CE_HeaderSection, makeHeaderStyleOption), - MAKE_CE_X(CE_HeaderLabel, makeHeaderStyleOption), -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - MAKE_CE(CE_Q3DockWindowEmptyArea), -#endif - MAKE_CE_X(CE_ToolBoxTab, makeToolBoxStyleOption), - MAKE_CE(CE_SizeGrip), - MAKE_CE(CE_Splitter), - MAKE_CE(CE_RubberBand), - MAKE_CE(CE_DockWidgetTitle), - MAKE_CE_X(CE_ScrollBarAddLine, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarSubLine, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarAddPage, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarSubPage, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarSlider, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarFirst, makeSliderStyleOption), - MAKE_CE_X(CE_ScrollBarLast, makeSliderStyleOption), - MAKE_CE(CE_FocusFrame), - MAKE_CE_X(CE_ComboBoxLabel, makeComboBoxStyleOption), - MAKE_CE(CE_ToolBar), - MAKE_CE_X(CE_ToolBoxTabShape, makeToolBoxStyleOption), - MAKE_CE_X(CE_ToolBoxTabLabel, makeToolBoxStyleOption), - MAKE_CE_X(CE_HeaderEmptyArea, makeHeaderStyleOption), - MAKE_CE(CE_ColumnViewGrip), - MAKE_CE_X(CE_ItemViewItem, makeItemViewStyleOption), - MAKE_CE_X(CE_ShapedFrame, makeFrameStyleOption) -}; - -ControlModel::ControlModel(QObject *parent) - : AbstractStyleElementStateTable(parent) -{ -} - -QVariant ControlModel::doData(int row, int column, int role) const -{ - if (role == Qt::DecorationRole) { - QPixmap pixmap(effectiveCellSize()); - QPainter painter(&pixmap); - drawTransparencyBackground(&painter, pixmap.rect()); - painter.scale(zoomFactor(), zoomFactor()); - - QScopedPointer opt(controlElements[row].styleOptionFactory()); - fillStyleOption(opt.data(), column); - m_style->drawControl(controlElements[row].control, opt.data(), &painter); - return pixmap; - } - - return AbstractStyleElementStateTable::doData(row, column, role); -} - -int ControlModel::doRowCount() const -{ - return sizeof(controlElements) / sizeof(controlElements[0]); -} - -QVariant ControlModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Vertical && role == Qt::DisplayRole) { - return controlElements[section].name; - } - return AbstractStyleElementStateTable::headerData(section, orientation, role); -} - -#include "controlmodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/controlmodel.h gammaray-2.0.1/core/tools/styleinspector/controlmodel.h --- gammaray-1.2.2/core/tools/styleinspector/controlmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/controlmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - controlmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_CONTROLMODEL_H -#define GAMMARAY_STYLEINSPECTOR_CONTROLMODEL_H - -#include "abstractstyleelementstatetable.h" - -namespace GammaRay { - -/** - * Model for listing all controls provided by a QStyle. - */ -class ControlModel : public AbstractStyleElementStateTable -{ - Q_OBJECT - public: - explicit ControlModel(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - protected: - virtual QVariant doData(int row, int column, int role) const; - virtual int doRowCount() const; -}; - -} - -#endif // GAMMARAY_CONTROLMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/dynamicproxystyle.cpp gammaray-2.0.1/core/tools/styleinspector/dynamicproxystyle.cpp --- gammaray-1.2.2/core/tools/styleinspector/dynamicproxystyle.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/dynamicproxystyle.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -/* - dynamicproxystyle.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "dynamicproxystyle.h" - -#include - -using namespace GammaRay; - -QWeakPointer DynamicProxyStyle::s_instance; - -DynamicProxyStyle::DynamicProxyStyle(QStyle *baseStyle) - : QProxyStyle(baseStyle) -{ - s_instance = QWeakPointer(this); -} - -DynamicProxyStyle *DynamicProxyStyle::instance() -{ - if (!s_instance) { - insertProxyStyle(); - } - return s_instance.data(); -} - -bool DynamicProxyStyle::exists() -{ - return s_instance; -} - -void DynamicProxyStyle::insertProxyStyle() -{ - // TODO: if the current style is a CSS proxy, add us underneath - // to avoid Qt adding yet another CSS proxy on top - qApp->setStyle(new DynamicProxyStyle(qApp->style())); -} - -void DynamicProxyStyle::setPixelMetric(QStyle::PixelMetric metric, int value) -{ - m_pixelMetrics.insert(metric, value); -} - -int DynamicProxyStyle::pixelMetric(QStyle::PixelMetric metric, - const QStyleOption *option, - const QWidget *widget) const -{ - QHash::const_iterator it = m_pixelMetrics.find(metric); - if (it != m_pixelMetrics.end()) { - return it.value(); - } - return QProxyStyle::pixelMetric(metric, option, widget); -} - -#include "dynamicproxystyle.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/dynamicproxystyle.h gammaray-2.0.1/core/tools/styleinspector/dynamicproxystyle.h --- gammaray-1.2.2/core/tools/styleinspector/dynamicproxystyle.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/dynamicproxystyle.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -/* - dynamicproxystyle.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_DYNAMICPROXYSTYLE_H -#define GAMMARAY_STYLEINSPECTOR_DYNAMICPROXYSTYLE_H - -#include -#include - -namespace GammaRay { - -/** - * A proxy style that allows runtime-editing of various parameters. - */ -class DynamicProxyStyle : public QProxyStyle -{ - Q_OBJECT - public: - explicit DynamicProxyStyle(QStyle *baseStyle); - - static DynamicProxyStyle *instance(); - static bool exists(); - static void insertProxyStyle(); - - void setPixelMetric(PixelMetric metric, int value); - - virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, - const QWidget *widget = 0) const; - - private: - QHash m_pixelMetrics; - static QWeakPointer s_instance; -}; - -} - -#endif // GAMMARAY_DYNAMICPROXYSTYLE_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/pixelmetricmodel.cpp gammaray-2.0.1/core/tools/styleinspector/pixelmetricmodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/pixelmetricmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/pixelmetricmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,205 +0,0 @@ -/* - pixelmetricmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "pixelmetricmodel.h" -#include "dynamicproxystyle.h" - -#include - -using namespace GammaRay; - -struct pixel_metric_t { - const char *name; - QStyle::PixelMetric pixelMetric; -}; - -#define MAKE_PM(metric) { #metric, QStyle:: metric } - -static pixel_metric_t pixelMetrics[] = { - MAKE_PM(PM_ButtonMargin), - MAKE_PM(PM_ButtonDefaultIndicator), - MAKE_PM(PM_MenuButtonIndicator), - MAKE_PM(PM_ButtonShiftHorizontal), - MAKE_PM(PM_ButtonShiftVertical), - MAKE_PM(PM_DefaultFrameWidth), - MAKE_PM(PM_SpinBoxFrameWidth), - MAKE_PM(PM_ComboBoxFrameWidth), - MAKE_PM(PM_MaximumDragDistance), - MAKE_PM(PM_ScrollBarExtent), - MAKE_PM(PM_ScrollBarSliderMin), - MAKE_PM(PM_SliderThickness), - MAKE_PM(PM_SliderControlThickness), - MAKE_PM(PM_SliderLength), - MAKE_PM(PM_SliderTickmarkOffset), - MAKE_PM(PM_SliderSpaceAvailable), - MAKE_PM(PM_DockWidgetSeparatorExtent), - MAKE_PM(PM_DockWidgetHandleExtent), - MAKE_PM(PM_DockWidgetFrameWidth), - MAKE_PM(PM_TabBarTabOverlap), - MAKE_PM(PM_TabBarTabHSpace), - MAKE_PM(PM_TabBarTabVSpace), - MAKE_PM(PM_TabBarBaseHeight), - MAKE_PM(PM_TabBarBaseOverlap), - MAKE_PM(PM_ProgressBarChunkWidth), - MAKE_PM(PM_SplitterWidth), - MAKE_PM(PM_TitleBarHeight), - MAKE_PM(PM_MenuScrollerHeight), - MAKE_PM(PM_MenuHMargin), - MAKE_PM(PM_MenuVMargin), - MAKE_PM(PM_MenuPanelWidth), - MAKE_PM(PM_MenuTearoffHeight), - MAKE_PM(PM_MenuDesktopFrameWidth), - MAKE_PM(PM_MenuBarPanelWidth), - MAKE_PM(PM_MenuBarItemSpacing), - MAKE_PM(PM_MenuBarVMargin), - MAKE_PM(PM_MenuBarHMargin), - MAKE_PM(PM_IndicatorWidth), - MAKE_PM(PM_IndicatorHeight), - MAKE_PM(PM_ExclusiveIndicatorWidth), - MAKE_PM(PM_ExclusiveIndicatorHeight), -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - MAKE_PM(PM_CheckListButtonSize), - MAKE_PM(PM_CheckListControllerSize), -#endif - MAKE_PM(PM_DialogButtonsSeparator), - MAKE_PM(PM_DialogButtonsButtonWidth), - MAKE_PM(PM_DialogButtonsButtonHeight), - MAKE_PM(PM_MdiSubWindowFrameWidth), - MAKE_PM(PM_MdiSubWindowMinimizedWidth), - MAKE_PM(PM_HeaderMargin), - MAKE_PM(PM_HeaderMarkSize), - MAKE_PM(PM_HeaderGripMargin), - MAKE_PM(PM_TabBarTabShiftHorizontal), - MAKE_PM(PM_TabBarTabShiftVertical), - MAKE_PM(PM_TabBarScrollButtonWidth), - MAKE_PM(PM_ToolBarFrameWidth), - MAKE_PM(PM_ToolBarHandleExtent), - MAKE_PM(PM_ToolBarItemSpacing), - MAKE_PM(PM_ToolBarItemMargin), - MAKE_PM(PM_ToolBarSeparatorExtent), - MAKE_PM(PM_ToolBarExtensionExtent), - MAKE_PM(PM_SpinBoxSliderHeight), - MAKE_PM(PM_DefaultTopLevelMargin), - MAKE_PM(PM_DefaultChildMargin), - MAKE_PM(PM_DefaultLayoutSpacing), - MAKE_PM(PM_ToolBarIconSize), - MAKE_PM(PM_ListViewIconSize), - MAKE_PM(PM_IconViewIconSize), - MAKE_PM(PM_SmallIconSize), - MAKE_PM(PM_LargeIconSize), - MAKE_PM(PM_FocusFrameVMargin), - MAKE_PM(PM_FocusFrameHMargin), - MAKE_PM(PM_ToolTipLabelFrameWidth), - MAKE_PM(PM_CheckBoxLabelSpacing), - MAKE_PM(PM_TabBarIconSize), - MAKE_PM(PM_SizeGripSize), - MAKE_PM(PM_DockWidgetTitleMargin), - MAKE_PM(PM_MessageBoxIconSize), - MAKE_PM(PM_ButtonIconSize), - MAKE_PM(PM_DockWidgetTitleBarButtonMargin), - MAKE_PM(PM_RadioButtonLabelSpacing), - MAKE_PM(PM_LayoutLeftMargin), - MAKE_PM(PM_LayoutTopMargin), - MAKE_PM(PM_LayoutRightMargin), - MAKE_PM(PM_LayoutBottomMargin), - MAKE_PM(PM_LayoutHorizontalSpacing), - MAKE_PM(PM_LayoutVerticalSpacing), - MAKE_PM(PM_TabBar_ScrollButtonOverlap), - MAKE_PM(PM_TextCursorWidth), - MAKE_PM(PM_TabCloseIndicatorWidth), - MAKE_PM(PM_TabCloseIndicatorHeight), - MAKE_PM(PM_ScrollView_ScrollBarSpacing), - MAKE_PM(PM_SubMenuOverlap) -}; - -PixelMetricModel::PixelMetricModel(QObject *parent) - : AbstractStyleElementModel(parent) -{ -} - -QVariant PixelMetricModel::doData(int row, int column, int role) const -{ - if (role == Qt::DisplayRole || role == Qt::EditRole) { - switch (column) { - case 0: - return pixelMetrics[row].name; - case 1: - return - (isMainStyle() && DynamicProxyStyle::exists()) ? - DynamicProxyStyle::instance()->pixelMetric(pixelMetrics[row].pixelMetric) : - m_style->pixelMetric(pixelMetrics[row].pixelMetric); - } - } - - return QVariant(); -} - -int PixelMetricModel::doColumnCount() const -{ - return 2; -} - -int PixelMetricModel::doRowCount() const -{ - return QStyle::PM_SubMenuOverlap + 1; -} - -QVariant PixelMetricModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Metric"); - case 1: - return tr("Default Value"); - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -Qt::ItemFlags PixelMetricModel::flags(const QModelIndex &index) const -{ - const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); - if (index.isValid() && index.column() == 1 && isMainStyle()) { - return baseFlags | Qt::ItemIsEditable; - } - return baseFlags; -} - -bool PixelMetricModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (!index.isValid() || - index.column() != 1 || - !value.isValid() || - !value.canConvert(QVariant::Int) || - role != Qt::EditRole) { - return false; - } - - DynamicProxyStyle::instance()->setPixelMetric( - pixelMetrics[index.row()].pixelMetric, value.toInt()); - - return true; -} - -#include "pixelmetricmodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/pixelmetricmodel.h gammaray-2.0.1/core/tools/styleinspector/pixelmetricmodel.h --- gammaray-1.2.2/core/tools/styleinspector/pixelmetricmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/pixelmetricmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -/* - pixelmetricmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_PIXELMETRICMODEL_H -#define GAMMARAY_STYLEINSPECTOR_PIXELMETRICMODEL_H - -#include "abstractstyleelementmodel.h" - -namespace GammaRay { - -/** - * Lists all pixel metric values of a given QStyle. - */ -class PixelMetricModel : public AbstractStyleElementModel -{ - Q_OBJECT - public: - explicit PixelMetricModel(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - - protected: - virtual QVariant doData(int row, int column, int role) const; - virtual int doColumnCount() const; - virtual int doRowCount() const; -}; - -} - -#endif // GAMMARAY_PIXELMETRICMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/primitivemodel.cpp gammaray-2.0.1/core/tools/styleinspector/primitivemodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/primitivemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/primitivemodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,136 +0,0 @@ -/* - primitivemodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "primitivemodel.h" -#include "styleoption.h" - -#include -#include -#include - -using namespace GammaRay; - -struct primitive_element_t { - const char *name; - QStyle::PrimitiveElement primitive; - QStyleOption * (*styleOptionFactory)(); -}; - -#define MAKE_PE( primitive ) { #primitive , QStyle:: primitive, &StyleOption::makeStyleOption } -#define MAKE_PE_X( primitive, factory ) { #primitive, QStyle:: primitive, &StyleOption:: factory } - -static primitive_element_t primititveElements[] = { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - MAKE_PE(PE_Q3CheckListController), - MAKE_PE(PE_Q3CheckListExclusiveIndicator), - MAKE_PE(PE_Q3CheckListIndicator), - MAKE_PE(PE_Q3DockWindowSeparator), - MAKE_PE(PE_Q3Separator), -#endif - MAKE_PE_X(PE_Frame, makeFrameStyleOption), - MAKE_PE(PE_FrameDefaultButton), - MAKE_PE_X(PE_FrameDockWidget, makeFrameStyleOption), - MAKE_PE(PE_FrameFocusRect), - MAKE_PE_X(PE_FrameGroupBox, makeFrameStyleOption), - MAKE_PE_X(PE_FrameLineEdit, makeFrameStyleOption), - MAKE_PE_X(PE_FrameMenu, makeFrameStyleOption), - MAKE_PE(PE_FrameStatusBarItem), - MAKE_PE_X(PE_FrameTabWidget, makeTabWidgetFrameStyleOption), - MAKE_PE_X(PE_FrameWindow, makeFrameStyleOption), - MAKE_PE(PE_FrameButtonBevel), - MAKE_PE(PE_FrameButtonTool), - MAKE_PE_X(PE_FrameTabBarBase, makeTabBarBaseStyleOption), - MAKE_PE_X(PE_PanelButtonCommand, makeButtonStyleOption), - MAKE_PE(PE_PanelButtonBevel), - MAKE_PE(PE_PanelButtonTool), - MAKE_PE(PE_PanelMenuBar), - MAKE_PE(PE_PanelToolBar), - MAKE_PE_X(PE_PanelLineEdit, makeFrameStyleOption), - MAKE_PE(PE_IndicatorArrowDown), - MAKE_PE(PE_IndicatorArrowLeft), - MAKE_PE(PE_IndicatorArrowRight), - MAKE_PE(PE_IndicatorArrowUp), - MAKE_PE(PE_IndicatorBranch), - MAKE_PE(PE_IndicatorButtonDropDown), - MAKE_PE(PE_IndicatorViewItemCheck), - MAKE_PE_X(PE_IndicatorCheckBox, makeButtonStyleOption), - MAKE_PE(PE_IndicatorDockWidgetResizeHandle), - MAKE_PE_X(PE_IndicatorHeaderArrow, makeHeaderStyleOption), - MAKE_PE(PE_IndicatorMenuCheckMark), - MAKE_PE(PE_IndicatorProgressChunk), - MAKE_PE_X(PE_IndicatorRadioButton, makeButtonStyleOption), - MAKE_PE_X(PE_IndicatorSpinDown, makeSpinBoxStyleOption), - MAKE_PE_X(PE_IndicatorSpinMinus, makeSpinBoxStyleOption), - MAKE_PE_X(PE_IndicatorSpinPlus, makeSpinBoxStyleOption), - MAKE_PE_X(PE_IndicatorSpinUp, makeSpinBoxStyleOption), - MAKE_PE(PE_IndicatorToolBarHandle), - MAKE_PE(PE_IndicatorToolBarSeparator), - MAKE_PE(PE_PanelTipLabel), - MAKE_PE_X(PE_IndicatorTabTear, makeTabStyleOption), - MAKE_PE(PE_PanelScrollAreaCorner), - MAKE_PE(PE_Widget), - MAKE_PE(PE_IndicatorColumnViewArrow), - MAKE_PE(PE_IndicatorItemViewItemDrop), - MAKE_PE_X(PE_PanelItemViewItem, makeItemViewStyleOption), - MAKE_PE(PE_PanelItemViewRow), - MAKE_PE(PE_PanelStatusBar), - MAKE_PE(PE_IndicatorTabClose), - MAKE_PE(PE_PanelMenu) -}; - -PrimitiveModel::PrimitiveModel(QObject *parent) - : AbstractStyleElementStateTable(parent) -{ -} - -QVariant PrimitiveModel::doData(int row, int column, int role) const -{ - if (role == Qt::DecorationRole) { - QPixmap pixmap(effectiveCellSize()); - QPainter painter(&pixmap); - drawTransparencyBackground(&painter, pixmap.rect()); - painter.scale(zoomFactor(), zoomFactor()); - - QScopedPointer opt((primititveElements[row].styleOptionFactory)()); - fillStyleOption(opt.data(), column); - m_style->drawPrimitive(primititveElements[row].primitive, opt.data(), &painter); - return pixmap; - } - - return AbstractStyleElementStateTable::doData(row, column, role); -} - -int PrimitiveModel::doRowCount() const -{ - return sizeof(primititveElements) / sizeof(primititveElements[0]) ; -} - -QVariant PrimitiveModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Vertical && role == Qt::DisplayRole) { - return primititveElements[section].name; - } - return AbstractStyleElementStateTable::headerData(section, orientation, role); -} - -#include "primitivemodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/primitivemodel.h gammaray-2.0.1/core/tools/styleinspector/primitivemodel.h --- gammaray-1.2.2/core/tools/styleinspector/primitivemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/primitivemodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - primitivemodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_PRIMITIVEMODEL_H -#define GAMMARAY_STYLEINSPECTOR_PRIMITIVEMODEL_H - -#include "abstractstyleelementstatetable.h" - -namespace GammaRay { - -/** - * Model for primitive style elements. - */ -class PrimitiveModel : public AbstractStyleElementStateTable -{ - Q_OBJECT - public: - explicit PrimitiveModel(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - protected: - virtual QVariant doData(int row, int column, int role) const; - virtual int doRowCount() const; -}; - -} - -#endif // GAMMARAY_PRIMITIVEMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/standardiconmodel.cpp gammaray-2.0.1/core/tools/styleinspector/standardiconmodel.cpp --- gammaray-1.2.2/core/tools/styleinspector/standardiconmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/standardiconmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,154 +0,0 @@ -/* - standardiconmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "standardiconmodel.h" - -#include "include/util.h" - -using namespace GammaRay; - -StandardIconModel::StandardIconModel(QObject *parent) : AbstractStyleElementModel(parent) -{ -} - -QVariant StandardIconModel::dataForStandardIcon(QStyle::StandardPixmap stdPix, - const QString &name, - int column, int role) const -{ - if (column == 0) { - if (role == Qt::DisplayRole) { - return name; - } - } else if (column == 1) { - if (role == Qt::DecorationRole) { - return m_style->standardIcon(stdPix); - } else if (role == Qt::DisplayRole) { - return Util::variantToString(m_style->standardIcon(stdPix)); - } - } - return QVariant(); -} - -#define MAKE_SP(stdPix) \ -if (row == QStyle:: stdPix) \ - return dataForStandardIcon(QStyle:: stdPix, QLatin1String(#stdPix), column, role) - -QVariant StandardIconModel::doData(int row, int column, int role) const -{ - MAKE_SP(SP_TitleBarMenuButton); - MAKE_SP(SP_TitleBarMinButton); - MAKE_SP(SP_TitleBarMaxButton); - MAKE_SP(SP_TitleBarCloseButton); - MAKE_SP(SP_TitleBarNormalButton); - MAKE_SP(SP_TitleBarShadeButton); - MAKE_SP(SP_TitleBarUnshadeButton); - MAKE_SP(SP_TitleBarContextHelpButton); - MAKE_SP(SP_DockWidgetCloseButton); - MAKE_SP(SP_MessageBoxInformation); - MAKE_SP(SP_MessageBoxWarning); - MAKE_SP(SP_MessageBoxCritical); - MAKE_SP(SP_MessageBoxQuestion); - MAKE_SP(SP_DesktopIcon); - MAKE_SP(SP_TrashIcon); - MAKE_SP(SP_ComputerIcon); - MAKE_SP(SP_DriveFDIcon); - MAKE_SP(SP_DriveHDIcon); - MAKE_SP(SP_DriveCDIcon); - MAKE_SP(SP_DriveDVDIcon); - MAKE_SP(SP_DriveNetIcon); - MAKE_SP(SP_DirOpenIcon); - MAKE_SP(SP_DirClosedIcon); - MAKE_SP(SP_DirLinkIcon); - MAKE_SP(SP_FileIcon); - MAKE_SP(SP_FileLinkIcon); - MAKE_SP(SP_ToolBarHorizontalExtensionButton); - MAKE_SP(SP_ToolBarVerticalExtensionButton); - MAKE_SP(SP_FileDialogStart); - MAKE_SP(SP_FileDialogEnd); - MAKE_SP(SP_FileDialogToParent); - MAKE_SP(SP_FileDialogNewFolder); - MAKE_SP(SP_FileDialogDetailedView); - MAKE_SP(SP_FileDialogInfoView); - MAKE_SP(SP_FileDialogContentsView); - MAKE_SP(SP_FileDialogListView); - MAKE_SP(SP_FileDialogBack); - MAKE_SP(SP_DirIcon); - MAKE_SP(SP_DialogOkButton); - MAKE_SP(SP_DialogCancelButton); - MAKE_SP(SP_DialogHelpButton); - MAKE_SP(SP_DialogOpenButton); - MAKE_SP(SP_DialogSaveButton); - MAKE_SP(SP_DialogCloseButton); - MAKE_SP(SP_DialogApplyButton); - MAKE_SP(SP_DialogResetButton); - MAKE_SP(SP_DialogDiscardButton); - MAKE_SP(SP_DialogYesButton); - MAKE_SP(SP_DialogNoButton); - MAKE_SP(SP_ArrowUp); - MAKE_SP(SP_ArrowDown); - MAKE_SP(SP_ArrowLeft); - MAKE_SP(SP_ArrowRight); - MAKE_SP(SP_ArrowBack); - MAKE_SP(SP_ArrowForward); - MAKE_SP(SP_DirHomeIcon); - MAKE_SP(SP_CommandLink); - MAKE_SP(SP_VistaShield); - MAKE_SP(SP_BrowserReload); - MAKE_SP(SP_BrowserStop); - MAKE_SP(SP_MediaPlay); - MAKE_SP(SP_MediaStop); - MAKE_SP(SP_MediaPause); - MAKE_SP(SP_MediaSkipForward); - MAKE_SP(SP_MediaSkipBackward); - MAKE_SP(SP_MediaSeekForward); - MAKE_SP(SP_MediaSeekBackward); - MAKE_SP(SP_MediaVolume); - MAKE_SP(SP_MediaVolumeMuted); - - return QVariant(); -} - -int StandardIconModel::doColumnCount() const -{ - return 2; -} - -int StandardIconModel::doRowCount() const -{ - return QStyle::SP_MediaVolumeMuted + 1; -} - -QVariant StandardIconModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Name"); - case 1: - return tr("Icon"); - } - } - return QAbstractItemModel::headerData(section, orientation, role); -} - -#include "standardiconmodel.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/standardiconmodel.h gammaray-2.0.1/core/tools/styleinspector/standardiconmodel.h --- gammaray-1.2.2/core/tools/styleinspector/standardiconmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/standardiconmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - standardiconmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_STANDARDICONMODEL_H -#define GAMMARAY_STYLEINSPECTOR_STANDARDICONMODEL_H - -#include "abstractstyleelementmodel.h" - -#include - -namespace GammaRay { - -/** - * Lists all standard icons of a style. - */ -class StandardIconModel : public AbstractStyleElementModel -{ - Q_OBJECT - public: - explicit StandardIconModel(QObject *parent = 0); - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - protected: - virtual QVariant doData(int row, int column, int role) const; - virtual int doColumnCount() const; - virtual int doRowCount() const; - - private: - QVariant dataForStandardIcon(QStyle::StandardPixmap stdPix, - const QString &name, - int column, int role) const; -}; - -} - -#endif // GAMMARAY_STANDARDICONMODEL_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.cpp gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.cpp --- gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ -/* - styleelementstatetablepage.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "styleelementstatetablepage.h" -#include "ui_styleelementstatetablepage.h" -#include "abstractstyleelementstatetable.h" - -using namespace GammaRay; - -StyleElementStateTablePage::StyleElementStateTablePage(QWidget *parent) - : QWidget(parent), ui(new Ui::StyleElementStateTablePage) -{ - ui->setupUi(this); - ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); - ui->tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); -} - -StyleElementStateTablePage::~StyleElementStateTablePage() -{ - delete ui; -} - -void StyleElementStateTablePage::setModel(AbstractStyleElementStateTable *model) -{ - ui->tableView->setModel(model); - ui->widthBox->setValue(model->cellWidth()); - ui->heightBox->setValue(model->cellHeight()); - - connect(ui->widthBox, SIGNAL(valueChanged(int)), - model, SLOT(setCellWidth(int))); - - connect(ui->heightBox, SIGNAL(valueChanged(int)), - model, SLOT(setCellHeight(int))); - - connect(ui->zoomSlider, SIGNAL(valueChanged(int)), - model, SLOT(setZoomFactor(int))); -} - -#include "styleelementstatetablepage.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.h gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.h --- gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - styleelementstatetablepage.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_STYLEELEMENTSTATETABLEPAGE_H -#define GAMMARAY_STYLEINSPECTOR_STYLEELEMENTSTATETABLEPAGE_H - -#include - -namespace GammaRay { - -class AbstractStyleElementStateTable; - -namespace Ui { - class StyleElementStateTablePage; -} - -/** - * Tab page for showing a style element x state table and corresponding config UI. - */ -class StyleElementStateTablePage : public QWidget -{ - Q_OBJECT - public: - explicit StyleElementStateTablePage(QWidget *parent = 0); - ~StyleElementStateTablePage(); - void setModel(AbstractStyleElementStateTable *model); - - private: - Ui::StyleElementStateTablePage *ui; -}; - -} - -#endif // GAMMARAY_STYLEELEMENTSTATETABLEPAGE_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.ui gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.ui --- gammaray-1.2.2/core/tools/styleinspector/styleelementstatetablepage.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleelementstatetablepage.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,114 +0,0 @@ - - - GammaRay::StyleElementStateTablePage - - - - 0 - 0 - 400 - 300 - - - - - 0 - - - - - QAbstractItemView::NoSelection - - - false - - - - - - - - - Cell &Width: - - - widthBox - - - - - - - px - - - 999 - - - - - - - Cell &Height: - - - heightBox - - - - - - - px - - - 999 - - - - - - - &Zoom: - - - zoomSlider - - - - - - - 1 - - - 8 - - - 1 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleinspector.cpp gammaray-2.0.1/core/tools/styleinspector/styleinspector.cpp --- gammaray-1.2.2/core/tools/styleinspector/styleinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleinspector.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,95 +0,0 @@ -/* - styleinspector.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "styleinspector.h" -#include "complexcontrolmodel.h" -#include "controlmodel.h" -#include "palettemodel.h" -#include "pixelmetricmodel.h" -#include "primitivemodel.h" -#include "standardiconmodel.h" -#include "ui_styleinspector.h" - -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" -#include "include/singlecolumnobjectproxymodel.h" - -#include - -using namespace GammaRay; - -StyleInspector::StyleInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::StyleInspector), - m_primitiveModel(new PrimitiveModel(this)), - m_controlModel(new ControlModel(this)), - m_complexControlModel(new ComplexControlModel(this)), - m_pixelMetricModel(new PixelMetricModel(this)), - m_standardIconModel(new StandardIconModel(this)), - m_standardPaletteModel(new PaletteModel(this)) -{ - ui->setupUi(this); - - ObjectTypeFilterProxyModel *styleFilter = new ObjectTypeFilterProxyModel(this); - styleFilter->setSourceModel(probe->objectListModel()); - SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); - singleColumnProxy->setSourceModel(styleFilter); - ui->styleSelector->setModel(singleColumnProxy); - connect(ui->styleSelector, SIGNAL(activated(int)), SLOT(styleSelected(int))); - - ui->primitivePage->setModel(m_primitiveModel); - ui->controlPage->setModel(m_controlModel); - ui->complexControlPage->setModel(m_complexControlModel); - - ui->pixelMetricView->setModel(m_pixelMetricModel); - ui->pixelMetricView->header()->setResizeMode(QHeaderView::ResizeToContents); - - ui->standardIconView->setModel(m_standardIconModel); - ui->standardIconView->header()->setResizeMode(QHeaderView::ResizeToContents); - - ui->standardPaletteView->setModel(m_standardPaletteModel); - ui->standardIconView->header()->setResizeMode(QHeaderView::ResizeToContents); - - if (ui->styleSelector->count()) { - styleSelected(0); - } -} - -StyleInspector::~StyleInspector() -{ - delete ui; -} - -void StyleInspector::styleSelected(int index) -{ - QObject *obj = ui->styleSelector->itemData(index, ObjectModel::ObjectRole).value(); - QStyle *style = qobject_cast(obj); - m_primitiveModel->setStyle(style); - m_controlModel->setStyle(style); - m_complexControlModel->setStyle(style); - m_pixelMetricModel->setStyle(style); - m_standardIconModel->setStyle(style); - m_standardPaletteModel->setPalette(style ? style->standardPalette() : qApp->palette()); -} - -#include "styleinspector.moc" diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleinspector.h gammaray-2.0.1/core/tools/styleinspector/styleinspector.h --- gammaray-1.2.2/core/tools/styleinspector/styleinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleinspector.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ -/* - styleinspector.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_STYLEINSPECTOR_H -#define GAMMARAY_STYLEINSPECTOR_STYLEINSPECTOR_H - -#include "include/toolfactory.h" - -#include -#include - -namespace GammaRay { - -class ComplexControlModel; -class ControlModel; -class PaletteModel; -class PixelMetricModel; -class PrimitiveModel; -class StandardIconModel; - -namespace Ui { - class StyleInspector; -} - -class StyleInspector : public QWidget -{ - Q_OBJECT - public: - explicit StyleInspector(ProbeInterface *probe, QWidget *parent = 0); - virtual ~StyleInspector(); - - private slots: - void styleSelected(int index); - - private: - Ui::StyleInspector *ui; - PrimitiveModel *m_primitiveModel; - ControlModel *m_controlModel; - ComplexControlModel *m_complexControlModel; - PixelMetricModel *m_pixelMetricModel; - StandardIconModel *m_standardIconModel; - PaletteModel *m_standardPaletteModel; -}; - -class StyleInspectorFactory : public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - - public: - explicit StyleInspectorFactory(QObject *parent = 0) : QObject(parent) - { - } - - virtual QString name() const - { - return tr("Style"); - } -}; - -} - -#endif // GAMMARAY_STYLEINSPECTOR_H diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleinspector.ui gammaray-2.0.1/core/tools/styleinspector/styleinspector.ui --- gammaray-1.2.2/core/tools/styleinspector/styleinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,137 +0,0 @@ - - - GammaRay::StyleInspector - - - - 0 - 0 - 400 - 300 - - - - - - - - - - 0 - 0 - - - - &Style: - - - styleSelector - - - - - - - - - - - - 0 - - - - Primitives - - - - - - - - - - Controls - - - - - - - - - - Complex Controls - - - - - - - - - - Pixel Metric - - - - - - false - - - true - - - - - - - - Standard Icons - - - - - - false - - - true - - - - - - - - Standard Palette - - - - - - false - - - true - - - - - - - - - - - - GammaRay::StyleElementStateTablePage - QWidget -
tools/styleinspector/styleelementstatetablepage.h
- 1 -
-
- - -
diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleoption.cpp gammaray-2.0.1/core/tools/styleinspector/styleoption.cpp --- gammaray-1.2.2/core/tools/styleinspector/styleoption.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleoption.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,223 +0,0 @@ -/* - styleoption.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "styleoption.h" - -#include - -using namespace GammaRay; - -struct style_state_t { - const char *name; - QStyle::State state; -}; - -#define MAKE_STATE( state ) { #state, QStyle:: state } - -static style_state_t styleStates[] = { - MAKE_STATE(State_None), - MAKE_STATE(State_Enabled), - MAKE_STATE(State_Raised), - MAKE_STATE(State_Sunken), - MAKE_STATE(State_Off), - MAKE_STATE(State_NoChange), - MAKE_STATE(State_On), - MAKE_STATE(State_DownArrow), - MAKE_STATE(State_Horizontal), - MAKE_STATE(State_HasFocus), - MAKE_STATE(State_Top), - MAKE_STATE(State_Bottom), - MAKE_STATE(State_FocusAtBorder), - MAKE_STATE(State_AutoRaise), - MAKE_STATE(State_MouseOver), - MAKE_STATE(State_UpArrow), - MAKE_STATE(State_Selected), - MAKE_STATE(State_Active), - MAKE_STATE(State_Window), - MAKE_STATE(State_Open), - MAKE_STATE(State_Children), - MAKE_STATE(State_Item), - MAKE_STATE(State_Sibling), - MAKE_STATE(State_Editing), - MAKE_STATE(State_KeyboardFocusChange), - MAKE_STATE(State_ReadOnly), - MAKE_STATE(State_Small), - MAKE_STATE(State_Mini) -}; - -int StyleOption::stateCount() -{ - return sizeof(styleStates) / sizeof(style_state_t); -} - -QString StyleOption::stateDisplayName(int index) -{ - return QString::fromLatin1(styleStates[index].name).mid(6); // remove the State_ prefix -} - -QStyle::State StyleOption::prettyState(int index) -{ - QStyle::State s = styleStates[index].state; - if (s == QStyle::State_None) { - return s; - } - return s | QStyle::State_Enabled; // enable by default, else we usually see disabled stuff only -} - -QStyleOption *StyleOption::makeStyleOption() -{ - return new QStyleOption; -} - -QStyleOption *StyleOption::makeStyleOptionComplex() -{ - return new QStyleOptionComplex; -} - -QStyleOption *StyleOption::makeButtonStyleOption() -{ - QStyleOptionButton *opt = new QStyleOptionButton; - opt->features = QStyleOptionButton::None; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption *StyleOption::makeComboBoxStyleOption() -{ - QStyleOptionComboBox *opt = new QStyleOptionComboBox; - opt->frame = true; - opt->currentText = QLatin1String("Current Text"); - return opt; -} - -QStyleOption *StyleOption::makeFrameStyleOption() -{ - QStyleOptionFrameV3 *opt = new QStyleOptionFrameV3; - opt->lineWidth = 1; - opt->midLineWidth = 0; - opt->frameShape = QFrame::StyledPanel; - return opt; -} - -QStyleOption *StyleOption::makeGroupBoxStyleOption() -{ - QStyleOptionGroupBox *opt = new QStyleOptionGroupBox; - opt->lineWidth = 1; - opt->midLineWidth = 0; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption *StyleOption::makeHeaderStyleOption() -{ - QStyleOptionHeader *opt = new QStyleOptionHeader; - opt->orientation = Qt::Horizontal; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption *StyleOption::makeItemViewStyleOption() -{ - QStyleOptionViewItemV4 *opt = new QStyleOptionViewItemV4; - opt->text = QLatin1String("Text"); - opt->features = QStyleOptionViewItemV2::HasDisplay; - return opt; -} - -QStyleOption *StyleOption::makeMenuStyleOption() -{ - QStyleOptionMenuItem *opt = new QStyleOptionMenuItem; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption *StyleOption::makeProgressBarStyleOption() -{ - QStyleOptionProgressBarV2 *opt = new QStyleOptionProgressBarV2; - opt->minimum = 0; - opt->maximum = 100; - opt->progress = 42; - return opt; -} - -QStyleOption *StyleOption::makeSliderStyleOption() -{ - QStyleOptionSlider *opt = new QStyleOptionSlider; - opt->minimum = 0; - opt->maximum = 100; - opt->sliderValue = 42; - opt->tickInterval = 5; - return opt; -} - -QStyleOption *StyleOption::makeSpinBoxStyleOption() -{ - QStyleOptionSpinBox *opt = new QStyleOptionSpinBox; - opt->frame = true; - return opt; -} - -QStyleOption *StyleOption::makeTabStyleOption() -{ - QStyleOptionTabV3 *opt = new QStyleOptionTabV3; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption *StyleOption::makeTabBarBaseStyleOption() -{ - return new QStyleOptionTabBarBaseV2; -} - -QStyleOption *StyleOption::makeTabWidgetFrameStyleOption() -{ - QStyleOptionTabWidgetFrameV2 *opt = new QStyleOptionTabWidgetFrameV2; - opt->lineWidth = 1; - return opt; -} - -QStyleOption *StyleOption::makeTitleBarStyleOption() -{ - QStyleOptionTitleBar *opt = new QStyleOptionTitleBar; - opt->text = QLatin1String("Title"); - opt->titleBarFlags = Qt::WindowMinMaxButtonsHint | - Qt::WindowTitleHint | - Qt::WindowSystemMenuHint | - Qt::WindowCloseButtonHint; - return opt; -} - -QStyleOption *StyleOption::makeToolBoxStyleOption() -{ - QStyleOptionToolBoxV2 *opt = new QStyleOptionToolBoxV2; - opt->text = QLatin1String("Label"); - return opt; -} - -QStyleOption * StyleOption::makeToolButtonStyleOption() -{ - QStyleOptionToolButton *opt = new QStyleOptionToolButton; - opt->text = QLatin1String("Label"); - opt->toolButtonStyle = Qt::ToolButtonFollowStyle; - return opt; -} diff -Nru gammaray-1.2.2/core/tools/styleinspector/styleoption.h gammaray-2.0.1/core/tools/styleinspector/styleoption.h --- gammaray-1.2.2/core/tools/styleinspector/styleoption.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/styleinspector/styleoption.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -/* - styleoption.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STYLEINSPECTOR_STYLEOPTION_H -#define GAMMARAY_STYLEINSPECTOR_STYLEOPTION_H - -#include - -class QStyleOption; -class QString; - -namespace GammaRay { - -/** - * Various helper methods for dealing with QStyleOption. - */ -namespace StyleOption { - - int stateCount(); - QString stateDisplayName(int index); - QStyle::State prettyState(int index); - - QStyleOption *makeStyleOption(); - QStyleOption *makeStyleOptionComplex(); - - QStyleOption *makeButtonStyleOption(); - QStyleOption *makeComboBoxStyleOption(); - QStyleOption *makeFrameStyleOption(); - QStyleOption *makeGroupBoxStyleOption(); - QStyleOption *makeHeaderStyleOption(); - QStyleOption *makeItemViewStyleOption(); - QStyleOption *makeMenuStyleOption(); - QStyleOption *makeProgressBarStyleOption(); - QStyleOption *makeSliderStyleOption(); - QStyleOption *makeSpinBoxStyleOption(); - QStyleOption *makeTabStyleOption(); - QStyleOption *makeTabBarBaseStyleOption(); - QStyleOption *makeTabWidgetFrameStyleOption(); - QStyleOption *makeTitleBarStyleOption(); - QStyleOption *makeToolBoxStyleOption(); - QStyleOption *makeToolButtonStyleOption(); -} - -} - -#endif // GAMMARAY_STYLEOPTION_H diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentcontentview.cpp gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentcontentview.cpp --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentcontentview.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentcontentview.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - textdocumentcontentview.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "textdocumentcontentview.h" - -#include - -using namespace GammaRay; - -TextDocumentContentView::TextDocumentContentView(QWidget *parent): QTextEdit(parent) -{ -} - -void TextDocumentContentView::setShowBoundingBox(const QRectF &boundingBox) -{ - m_boundingBox = boundingBox; - viewport()->update(); -} - -void TextDocumentContentView::paintEvent(QPaintEvent *e) -{ - QTextEdit::paintEvent(e); - if (!m_boundingBox.isEmpty()) { - QPainter painter(viewport()); - painter.setPen(Qt::red); - painter.drawRect(m_boundingBox); - } -} - -#include "textdocumentcontentview.moc" diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentcontentview.h gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentcontentview.h --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentcontentview.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentcontentview.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -/* - textdocumentcontentview.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTCONTENTVIEW_H -#define GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTCONTENTVIEW_H - -#include - -namespace GammaRay { - -class TextDocumentContentView : public QTextEdit -{ - Q_OBJECT - public: - explicit TextDocumentContentView(QWidget *parent = 0); - - void setShowBoundingBox(const QRectF &boundingBox); - - protected: - virtual void paintEvent(QPaintEvent *e); - - private: - QRectF m_boundingBox; -}; - -} - -#endif // GAMMARAY_TEXTDOCUMENTCONTENTVIEW_H diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentformatmodel.cpp gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentformatmodel.cpp --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentformatmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentformatmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ #include "textdocumentformatmodel.h" -#include "include/util.h" +#include #include #include @@ -71,7 +71,7 @@ case 0: return QString::fromLatin1(propertyEnum().key(index.row())); case 1: - return Util::variantToString(m_format.property(enumValue)); + return VariantHandler::displayString(m_format.property(enumValue)); case 2: return QString::fromLatin1(m_format.property(enumValue).typeName()); } @@ -96,4 +96,3 @@ return QAbstractItemModel::headerData(section, orientation, role); } -#include "textdocumentformatmodel.moc" diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentformatmodel.h gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentformatmodel.h --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentformatmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentformatmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.cpp gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.cpp --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -25,35 +25,38 @@ #include "textdocumentformatmodel.h" #include "textdocumentmodel.h" -#include "ui_textdocumentinspector.h" -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" +#include "objecttypefilterproxymodel.h" +#include "probeinterface.h" +#include + +#include #include using namespace GammaRay; -TextDocumentInspector::TextDocumentInspector(ProbeInterface *probe, QWidget *parent): - QWidget(parent), - ui(new Ui::TextDocumentInspector) +TextDocumentInspector::TextDocumentInspector(ProbeInterface *probe, QObject *parent): + QObject(parent) { - ui->setupUi(this); - ObjectTypeFilterProxyModel *documentFilter = new ObjectTypeFilterProxyModel(this); documentFilter->setSourceModel(probe->objectListModel()); - ui->documentList->setModel(documentFilter); - connect(ui->documentList->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + probe->registerModel("com.kdab.GammaRay.TextDocumentsModel", documentFilter); + + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(documentFilter); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(documentSelected(QItemSelection,QItemSelection))); + m_textDocumentModel = new TextDocumentModel(this); - ui->documentTree->setModel(m_textDocumentModel); - connect(ui->documentTree->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + probe->registerModel("com.kdab.GammaRay.TextDocumentModel", m_textDocumentModel); + + selectionModel = ObjectBroker::selectionModel(m_textDocumentModel); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(documentElementSelected(QItemSelection,QItemSelection))); + m_textDocumentFormatModel = new TextDocumentFormatModel(this); - ui->documentFormatView->setModel(m_textDocumentFormatModel); + probe->registerModel("com.kdab.GammaRay.TextDocumentFormatModel", m_textDocumentFormatModel); } void TextDocumentInspector::documentSelected(const QItemSelection &selected, @@ -64,17 +67,6 @@ QObject *selectedObj = selectedRow.data(ObjectModel::ObjectRole).value(); QTextDocument *doc = qobject_cast(selectedObj); - if (m_currentDocument) { - disconnect(m_currentDocument, SIGNAL(contentsChanged()), - this, SLOT(documentContentChanged())); - } - m_currentDocument = QPointer(doc); - - if (doc) { - ui->documentView->setDocument(doc); - connect(doc, SIGNAL(contentsChanged()), SLOT(documentContentChanged())); - documentContentChanged(); - } m_textDocumentModel->setDocument(doc); } @@ -82,17 +74,11 @@ const QItemSelection &deselected) { Q_UNUSED(deselected); + if (selected.isEmpty()) { + return; + } const QModelIndex selectedRow = selected.first().topLeft(); const QTextFormat f = selectedRow.data(TextDocumentModel::FormatRole).value(); m_textDocumentFormatModel->setFormat(f); - - const QRectF boundingBox = selectedRow.data(TextDocumentModel::BoundingBoxRole).toRectF(); - ui->documentView->setShowBoundingBox(boundingBox); -} - -void TextDocumentInspector::documentContentChanged() -{ - ui->htmlView->setPlainText(m_currentDocument->toHtml()); } -#include "textdocumentinspector.moc" diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.h gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.h --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,11 +24,10 @@ #ifndef GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTINSPECTOR_H #define GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTINSPECTOR_H -#include "include/toolfactory.h" +#include "toolfactory.h" #include #include -#include class QItemSelection; @@ -37,26 +36,19 @@ class TextDocumentModel; class TextDocumentFormatModel; -namespace Ui { - class TextDocumentInspector; -} - -class TextDocumentInspector : public QWidget +class TextDocumentInspector : public QObject { Q_OBJECT public: - explicit TextDocumentInspector(ProbeInterface *probe, QWidget *parent = 0); + explicit TextDocumentInspector(ProbeInterface *probe, QObject *parent = 0); private slots: void documentSelected(const QItemSelection &selected, const QItemSelection &deselected); void documentElementSelected(const QItemSelection &selected, const QItemSelection &deselected); - void documentContentChanged(); private: - QScopedPointer ui; TextDocumentModel *m_textDocumentModel; TextDocumentFormatModel *m_textDocumentFormatModel; - QPointer m_currentDocument; }; class TextDocumentInspectorFactory diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.ui gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.ui --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,131 +0,0 @@ - - - GammaRay::TextDocumentInspector - - - - 0 - 0 - 762 - 631 - - - - - - - Qt::Horizontal - - - - - - - All documents: - - - - - - - false - - - true - - - true - - - - - - - - Qt::Vertical - - - - - - - Document structure: - - - - - - - true - - - true - - - - - - - - - - - Element format: - - - - - - - false - - - true - - - true - - - - - - - - - 0 - - - - Content - - - - - - - - - - HTML - - - - - - - - - - - - - - - GammaRay::TextDocumentContentView - QTextEdit -
tools/textdocumentinspector/textdocumentcontentview.h
-
-
- - -
diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentmodel.cpp gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentmodel.cpp --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -148,4 +148,3 @@ parent->appendRow(QList() << item << formatItem(format)); } -#include "textdocumentmodel.moc" diff -Nru gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentmodel.h gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentmodel.h --- gammaray-1.2.2/core/tools/textdocumentinspector/textdocumentmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/textdocumentinspector/textdocumentmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include #include +#include class QTextTable; class QTextBlock; @@ -41,7 +42,7 @@ explicit TextDocumentModel(QObject *parent = 0); enum Roles { - FormatRole = Qt::UserRole, + FormatRole = UserRole, BoundingBoxRole }; diff -Nru gammaray-1.2.2/core/tools/widgetinspector/CMakeLists.txt gammaray-2.0.1/core/tools/widgetinspector/CMakeLists.txt --- gammaray-1.2.2/core/tools/widgetinspector/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,13 +0,0 @@ -add_library(gammaray_widget_export_actions SHARED - widgetinspector_export_actions.cpp - uiextractor.cpp -) - -target_link_libraries(gammaray_widget_export_actions - ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} - ${QT_QTSVG_LIBRARIES} - ${QT_QTDESIGNER_LIBRARIES} -) - -install(TARGETS gammaray_widget_export_actions ${INSTALL_TARGETS_DEFAULT_ARGS}) diff -Nru gammaray-1.2.2/core/tools/widgetinspector/overlaywidget.cpp gammaray-2.0.1/core/tools/widgetinspector/overlaywidget.cpp --- gammaray-1.2.2/core/tools/widgetinspector/overlaywidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/overlaywidget.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,198 +0,0 @@ -/* - overlaywidget.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Tobias Koenig - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "overlaywidget.h" - -#include -#include -#include -#include -#include - -using namespace GammaRay; - -static QWidget *toplevelWidget(QWidget *widget) -{ - QWidget *parent = widget; - while (parent->parentWidget() && - (qobject_cast(parent->parentWidget()) == 0) && - (qobject_cast(parent) == 0)) { - parent = parent->parentWidget(); - } - - return parent; -} - -OverlayWidget::OverlayWidget() - : m_currentToplevelWidget(0), - m_currentWidget(0) -{ - setAttribute(Qt::WA_TransparentForMouseEvents); - setFocusPolicy(Qt::NoFocus); -} - -void OverlayWidget::placeOn(QWidget *widget) -{ - if (widget == 0) { - if (m_currentWidget) { - m_currentWidget->removeEventFilter(this); - } - - if (m_currentToplevelWidget) { - m_currentToplevelWidget->removeEventFilter(this); - } - - m_currentToplevelWidget = 0; - m_currentWidget = 0; - m_widgetRect = QRect(); - m_layoutPath = QPainterPath(); - - update(); - return; - } - - QWidget *toplevel = toplevelWidget(widget); - Q_ASSERT(toplevel); - - if (m_currentWidget) { - m_currentWidget->removeEventFilter(this); - } - - m_currentWidget = widget; - - if (toplevel != m_currentToplevelWidget) { - if (m_currentToplevelWidget) { - m_currentToplevelWidget->removeEventFilter(this); - } - - m_currentToplevelWidget = toplevel; - - setParent(toplevel); - move(0, 0); - resize(toplevel->size()); - - m_currentToplevelWidget->installEventFilter(this); - - show(); - } - - m_currentWidget->installEventFilter(this); - - updatePositions(); -} - -bool OverlayWidget::eventFilter(QObject *receiver, QEvent *event) -{ - if (receiver == m_currentToplevelWidget) { - if (event->type() == QEvent::Resize) { - resizeOverlay(); - updatePositions(); - } - } else if (receiver == m_currentWidget) { - if (event->type() == QEvent::Resize || event->type() == QEvent::Move) { - resizeOverlay(); - updatePositions(); - } - } - - return false; -} - -void OverlayWidget::updatePositions() -{ - if (!m_currentWidget || !m_currentToplevelWidget) { - return; - } - - if (!m_currentWidget->isVisible() || m_currentWidget->isHidden()) { - m_widgetColor = Qt::green; - } else { - m_widgetColor = Qt::red; - } - - const QPoint parentPos = m_currentWidget->mapTo(m_currentToplevelWidget, QPoint(0, 0)); - m_widgetRect = QRect(parentPos.x(), parentPos.y(), - m_currentWidget->width(), - m_currentWidget->height()).adjusted(0, 0, -1, -1); - - m_layoutPath = QPainterPath(); - - if (m_currentWidget->layout() && - qstrcmp(m_currentWidget->layout()->metaObject()->className(), "QMainWindowLayout") != 0) { - const QRect layoutGeometry = m_currentWidget->layout()->geometry(); - - const QRect mappedOuterRect = - QRect(m_currentWidget->mapTo(m_currentToplevelWidget, - layoutGeometry.topLeft()), layoutGeometry.size()); - - QPainterPath outerPath; - outerPath.addRect(mappedOuterRect.adjusted(1, 1, -2, -2)); - - QPainterPath innerPath; - for (int i = 0; i < m_currentWidget->layout()->count(); ++i) { - QLayoutItem *item = m_currentWidget->layout()->itemAt(i); - const QRect mappedInnerRect = - QRect(m_currentWidget->mapTo(m_currentToplevelWidget, - item->geometry().topLeft()), item->geometry().size()); - innerPath.addRect(mappedInnerRect); - } - - m_layoutPath.setFillRule(Qt::OddEvenFill); - m_layoutPath = outerPath.subtracted(innerPath); - - if (m_layoutPath.isEmpty()) { - m_layoutPath = outerPath; - m_layoutPath.addPath(innerPath); - m_drawLayoutOutlineOnly = true; - } else { - m_drawLayoutOutlineOnly = false; - } - } - - update(); -} - -void OverlayWidget::resizeOverlay() -{ - if (m_currentToplevelWidget) { - move(0, 0); - resize(m_currentToplevelWidget->size()); - } -} - -void OverlayWidget::paintEvent(QPaintEvent *) -{ - QPainter p(this); - p.setPen(m_widgetColor); - p.drawRect(m_widgetRect); - - QBrush brush(Qt::BDiagPattern); - brush.setColor(Qt::blue); - - if (!m_drawLayoutOutlineOnly) { - p.fillPath(m_layoutPath, brush); - } - - p.setPen(Qt::blue); - p.drawPath(m_layoutPath); -} diff -Nru gammaray-1.2.2/core/tools/widgetinspector/overlaywidget.h gammaray-2.0.1/core/tools/widgetinspector/overlaywidget.h --- gammaray-1.2.2/core/tools/widgetinspector/overlaywidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/overlaywidget.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - overlaywidget.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Tobias Koenig - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WIDGETINSPECTOR_OVERLAYWIDGET_H -#define GAMMARAY_WIDGETINSPECTOR_OVERLAYWIDGET_H - -#include - -namespace GammaRay { - -class OverlayWidget : public QWidget -{ - public: - OverlayWidget(); - - void placeOn(QWidget *widget); - - virtual bool eventFilter(QObject *receiver, QEvent *event); - - protected: - virtual void paintEvent(QPaintEvent *event); - - private: - void resizeOverlay(); - void updatePositions(); - - QWidget *m_currentToplevelWidget; - QWidget *m_currentWidget; - QRect m_widgetRect; - QColor m_widgetColor; - - QPainterPath m_layoutPath; - bool m_drawLayoutOutlineOnly; -}; - -} - -#endif diff -Nru gammaray-1.2.2/core/tools/widgetinspector/uiextractor.cpp gammaray-2.0.1/core/tools/widgetinspector/uiextractor.cpp --- gammaray-1.2.2/core/tools/widgetinspector/uiextractor.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/uiextractor.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,67 +0,0 @@ -/* - uiextractor.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "uiextractor.h" - -#include -#include -#include -#include - -using namespace GammaRay; - -bool UiExtractor::checkProperty(QObject *obj, const QString &prop) const -{ - const QMetaObject *mo = obj->metaObject(); - const QMetaProperty mp = mo->property(mo->indexOfProperty(prop.toLatin1())); - - // TODO come up with some more aggressive filtering - if (mp.isValid() && mp.isDesignable(obj) && mp.isStored(obj) && mp.isWritable()) { - const QVariant value = mp.read(obj); - - // try to figure out the default by resetting to it - if (mp.isResettable()) { - mp.reset(obj); - if (mp.read(obj) == value) { - return false; - } - mp.write(obj, value); - return true; - } - - // some guessing for non-resettable properties - if (value.isNull() || !value.isValid()) { - return false; - } - - if (value.type() == QVariant::String) { - return !value.toString().isEmpty(); - } else if (value.type() == QVariant::Locale) { - return value.value() != QLocale::system(); - } - - return true; - } - - return false; -} diff -Nru gammaray-1.2.2/core/tools/widgetinspector/uiextractor.h gammaray-2.0.1/core/tools/widgetinspector/uiextractor.h --- gammaray-1.2.2/core/tools/widgetinspector/uiextractor.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/uiextractor.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -/* - uiextractor.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WIDGETINSPECTOR_UIEXTRACTOR_H -#define GAMMARAY_WIDGETINSPECTOR_UIEXTRACTOR_H - -#include - -namespace GammaRay { - -class UiExtractor : public QFormBuilder -{ - protected: - virtual bool checkProperty(QObject *obj, const QString &prop) const; -}; - -} - -#endif // GAMMARAY_UIEXTRACTOR_H diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.cpp gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.cpp --- gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,297 +0,0 @@ -/* - widgetinspector.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "widgetinspector.h" -#include "config-gammaray.h" -#include "overlaywidget.h" -#include "paintbufferviewer.h" -#include "widgettreemodel.h" -#include "ui_widgetinspector.h" - -#include "include/objectmodel.h" -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_PRIVATE_QT_HEADERS -#include //krazy:exclude=camelcase -#endif - -using namespace GammaRay; - -WidgetInspector::WidgetInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), ui(new Ui::WidgetInspector), m_overlayWidget(new OverlayWidget) -{ - ui->setupUi(this); - - m_overlayWidget->hide(); - connect(m_overlayWidget, SIGNAL(destroyed(QObject*)), SLOT(handleOverlayWidgetDestroyed(QObject*))); - - connect(probe->probe(), SIGNAL(widgetSelected(QWidget*,QPoint)), SLOT(widgetSelected(QWidget*))); - - WidgetTreeModel *widgetFilterProxy = new WidgetTreeModel(this); - widgetFilterProxy->setSourceModel(probe->objectTreeModel()); - KRecursiveFilterProxyModel *widgetSearchProxy = new KRecursiveFilterProxyModel(this); - widgetSearchProxy->setSourceModel(widgetFilterProxy); - ui->widgetTreeView->setModel(widgetSearchProxy); - ui->widgetTreeView->header()->setResizeMode(0, QHeaderView::Stretch); - ui->widgetTreeView->header()->setResizeMode(1, QHeaderView::Interactive); - ui->widgetSearchLine->setProxy(widgetSearchProxy); - connect(ui->widgetTreeView->selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - SLOT(widgetSelected(QModelIndex))); - - connect(ui->actionSaveAsImage, SIGNAL(triggered()), SLOT(saveAsImage())); - connect(ui->actionSaveAsSvg, SIGNAL(triggered()), SLOT(saveAsSvg())); - connect(ui->actionSaveAsPdf, SIGNAL(triggered()), SLOT(saveAsPdf())); - connect(ui->actionSaveAsUiFile, SIGNAL(triggered()), SLOT(saveAsUiFile())); - connect(ui->actionAnalyzePainting, SIGNAL(triggered()), SLOT(analyzePainting())); - - addAction(ui->actionSaveAsImage); - addAction(ui->actionSaveAsSvg); - addAction(ui->actionSaveAsPdf); - addAction(ui->actionSaveAsUiFile); -#ifdef HAVE_PRIVATE_QT_HEADERS - addAction(ui->actionAnalyzePainting); -#endif - - setActionsEnabled(false); -} - -void WidgetInspector::widgetSelected(const QModelIndex &index) -{ - if (index.isValid()) { - QObject *obj = index.data(ObjectModel::ObjectRole).value(); - QWidget *widget = qobject_cast(obj); - QLayout* layout = qobject_cast(obj); - if (!widget && layout) { - widget = layout->parentWidget(); - } - - ui->widgetPropertyWidget->setObject(obj); - ui->widgetPreviewWidget->setWidget(widget); - setActionsEnabled(widget != 0); - - if (widget && qobject_cast(widget) == 0) { - m_overlayWidget->placeOn(widget); - } else { - m_overlayWidget->placeOn(0); - } - } else { - ui->widgetPropertyWidget->setObject(0); - ui->widgetPreviewWidget->setWidget(0); - m_overlayWidget->placeOn(0); - setActionsEnabled(false); - } -} - -void WidgetInspector::handleOverlayWidgetDestroyed(QObject* ) -{ - // the target application might have destroyed the overlay widget (e.g. because the parent of the overlay got destroyed) - // just recreate a new one in this case - m_overlayWidget = new OverlayWidget; - m_overlayWidget->hide(); -} - -void WidgetInspector::widgetSelected(QWidget *widget) -{ - QAbstractItemModel *model = ui->widgetTreeView->model(); - const QModelIndexList indexList = - model->match(model->index(0, 0), - ObjectModel::ObjectRole, - QVariant::fromValue(widget), 1, - Qt::MatchExactly | Qt::MatchRecursive); - if (indexList.isEmpty()) { - return; - } - const QModelIndex index = indexList.first(); - ui->widgetTreeView->selectionModel()->select( - index, - QItemSelectionModel::Select | QItemSelectionModel::Clear | - QItemSelectionModel::Rows | QItemSelectionModel::Current); - ui->widgetTreeView->scrollTo(index); - widgetSelected(index); -} - -void WidgetInspector::setActionsEnabled(bool enabled) -{ - foreach (QAction *action, actions()) { - action->setEnabled(enabled); - } -} - -QWidget *WidgetInspector::selectedWidget() const -{ - const QModelIndexList indexes = ui->widgetTreeView->selectionModel()->selectedRows(); - if (indexes.isEmpty()) { - return 0; - } - const QModelIndex index = indexes.first(); - if (index.isValid()) { - QObject *obj = index.data(ObjectModel::ObjectRole).value(); - QWidget *widget = qobject_cast(obj); - QLayout* layout = qobject_cast(obj); - if (!widget && layout) { - widget = layout->parentWidget(); - } - return widget; - } - return 0; -} - -void WidgetInspector::saveAsImage() -{ - const QString fileName = - QFileDialog::getSaveFileName( - this, - tr("Save As Image"), - QString(), - tr("Image Files (*.png *.jpg)")); - - QWidget *widget = selectedWidget(); - if (fileName.isEmpty() || !widget) { - return; - } - - QPixmap pixmap(widget->size()); - m_overlayWidget->hide(); - widget->render(&pixmap); - m_overlayWidget->show(); - pixmap.save(fileName); -} - -void WidgetInspector::saveAsSvg() -{ - const QString fileName = - QFileDialog::getSaveFileName( - this, - tr("Save As SVG"), - QString(), - tr("Scalable Vector Graphics (*.svg)")); - - QWidget *widget = selectedWidget(); - if (fileName.isEmpty() || !widget) { - return; - } - - m_overlayWidget->hide(); - callExternalExportAction("gammaray_save_widget_to_svg", widget, fileName); - m_overlayWidget->show(); -} - -void WidgetInspector::saveAsPdf() -{ - const QString fileName = - QFileDialog::getSaveFileName( - this, - tr("Save As PDF"), - QString(), - tr("PDF (*.pdf)")); - - QWidget *widget = selectedWidget(); - if (fileName.isEmpty() || !widget) { - return; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel); - printer.setPaperSize(widget->size(), QPrinter::DevicePixel); - - m_overlayWidget->hide(); - widget->render(&printer); - m_overlayWidget->show(); -} - -void WidgetInspector::saveAsUiFile() -{ - const QString fileName = - QFileDialog::getSaveFileName( - this, - tr("Save As Qt Designer UI File"), - QString(), - tr("Qt Designer UI File (*.ui)")); - - QWidget *widget = selectedWidget(); - if (fileName.isEmpty() || !widget) { - return; - } - - callExternalExportAction("gammaray_save_widget_to_ui", widget, fileName); -} - -void WidgetInspector::callExternalExportAction(const char *name, - QWidget *widget, - const QString &fileName) -{ - if (!m_externalExportActions.isLoaded()) { - const QString probePath = - QString::fromLocal8Bit(qgetenv("GAMMARAY_PROBE_PATH")); - - m_externalExportActions.setFileName( - probePath + QLatin1String("/libgammaray_widget_export_actions")); - - m_externalExportActions.load(); - } - - void(*function)(QWidget *, const QString &) = - reinterpret_cast(m_externalExportActions.resolve(name)); - - if (!function) { - qWarning() << m_externalExportActions.errorString(); - return; - } - function(widget, fileName); -} - -void WidgetInspector::analyzePainting() -{ - QWidget *widget = selectedWidget(); - if (!widget) { - return; - } -#ifdef HAVE_PRIVATE_QT_HEADERS - QPaintBuffer buffer; - m_overlayWidget->hide(); - buffer.setBoundingRect(widget->rect()); - widget->render(&buffer); - m_overlayWidget->show(); - - PaintBufferViewer *viewer = new PaintBufferViewer(0); - viewer->setWindowTitle(tr("Analyze Painting")); - viewer->setAttribute(Qt::WA_DeleteOnClose); - viewer->setPaintBuffer(buffer); - viewer->show(); -#endif -} - -#include "widgetinspector.moc" diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetinspector_export_actions.cpp gammaray-2.0.1/core/tools/widgetinspector/widgetinspector_export_actions.cpp --- gammaray-1.2.2/core/tools/widgetinspector/widgetinspector_export_actions.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetinspector_export_actions.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - widgetinspector_export_actions.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file widgetinspector_export_actions.cpp - * dlopen hack to avoid dependencies on QtSvg and QtDesigner in the main probe. - */ - -#include "uiextractor.h" - -#include -#include -#include -#include - -extern "C" { - -Q_DECL_EXPORT void gammaray_save_widget_to_svg(QWidget *widget, const QString &fileName) -{ - QSvgGenerator svg; - svg.setFileName(fileName); - svg.setSize(widget->size()); - svg.setViewBox(QRect(QPoint(0, 0), widget->size())); - QPainter painter(&svg); - widget->render(&painter); - painter.end(); -} - -Q_DECL_EXPORT void gammaray_save_widget_to_ui(QWidget *widget, const QString &fileName) -{ - QFile file(fileName); - if (file.open(QFile::WriteOnly)) { - GammaRay::UiExtractor formBuilder; - formBuilder.save(&file, widget); - } -} - -} diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.h gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.h --- gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,90 +0,0 @@ -/* - widgetinspector.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTOR_H -#define GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTOR_H - -#include "include/toolfactory.h" - -#include -#include - -class QModelIndex; - -namespace GammaRay { - -class OverlayWidget; - -namespace Ui { - class WidgetInspector; -} - -class WidgetInspector : public QWidget -{ - Q_OBJECT - public: - explicit WidgetInspector(ProbeInterface *probe, QWidget *parent = 0); - - private: - void setActionsEnabled(bool enabled); - QWidget *selectedWidget() const; - void callExternalExportAction(const char *name, QWidget *widget, const QString &fileName); - - private slots: - void widgetSelected(const QModelIndex &index); - void widgetSelected(QWidget *widget); - - void handleOverlayWidgetDestroyed(QObject*); - - void saveAsImage(); - void saveAsSvg(); - void saveAsPdf(); - void saveAsUiFile(); - - void analyzePainting(); - - private: - OverlayWidget *m_overlayWidget; - QScopedPointer ui; - QLibrary m_externalExportActions; -}; - -class WidgetInspectorFactory - : public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - public: - explicit WidgetInspectorFactory(QObject *parent) : QObject(parent) - { - } - - inline QString name() const - { - return tr("Widgets"); - } -}; - -} - -#endif // GAMMARAY_WIDGETINSPECTOR_H diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.ui gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.ui --- gammaray-1.2.2/core/tools/widgetinspector/widgetinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,107 +0,0 @@ - - - GammaRay::WidgetInspector - - - - 0 - 0 - 732 - 528 - - - - - - - Qt::Horizontal - - - - Qt::Vertical - - - - - - - - - - - - - - Preview - - - - - - - - - - - - - - - Save as &Image... - - - Save currently selected widget as image. - - - - - Save as &SVG... - - - Renders the currently selected image as SVG vector graphic. - - - - - Save as &PDF... - - - Renders the currently selected widget in to a PDF file. - - - - - Save as &UI file... - - - Saves the currently selected widget as a Qt designer UI file. - - - - - &Analyze Painting... - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
-
- - GammaRay::PropertyWidget - QWidget -
propertywidget.h
- 1 -
- - GammaRay::WidgetPreviewWidget - QWidget -
tools/widgetinspector/widgetpreviewwidget.h
- 1 -
-
- - -
diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetpreviewwidget.cpp gammaray-2.0.1/core/tools/widgetinspector/widgetpreviewwidget.cpp --- gammaray-1.2.2/core/tools/widgetinspector/widgetpreviewwidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetpreviewwidget.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,79 +0,0 @@ -/* - widgetpreviewwidget.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "widgetpreviewwidget.h" - -#include -#include - -using namespace GammaRay; - -WidgetPreviewWidget::WidgetPreviewWidget(QWidget *parent) - : QWidget(parent), m_grabbingWidget(false) -{ -} - -void WidgetPreviewWidget::setWidget(QWidget *widget) -{ - if (m_widget) { - m_widget.data()->removeEventFilter(this); - } - if (widget != this) { - m_widget = widget; - } else { - m_widget = 0; - } - if (widget) { - widget->installEventFilter(this); - } - update(); -} - -void WidgetPreviewWidget::paintEvent(QPaintEvent *event) -{ - if (m_widget && !m_grabbingWidget) { - m_grabbingWidget = true; - const QPixmap pixmap = QPixmap::grabWidget(m_widget.data()); - m_grabbingWidget = false; - QPainter painter(this); - const qreal scale = qMin(1.0, qMin((qreal)width() / (qreal)pixmap.width(), - (qreal)height() / (qreal)pixmap.height())); - const qreal targetWidth = pixmap.width() * scale; - const qreal targetHeight = pixmap.height() * scale; - painter.drawPixmap((width() - targetWidth) / 2, - (height() - targetHeight) / 2, - targetWidth, targetHeight, - pixmap); - } - QWidget::paintEvent(event); -} - -bool WidgetPreviewWidget::eventFilter(QObject *receiver, QEvent *event) -{ - if (!m_grabbingWidget && receiver == m_widget.data() && event->type() == QEvent::Paint) { - update(); - } - return QWidget::eventFilter(receiver, event); -} - -#include "widgetpreviewwidget.moc" diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgetpreviewwidget.h gammaray-2.0.1/core/tools/widgetinspector/widgetpreviewwidget.h --- gammaray-1.2.2/core/tools/widgetinspector/widgetpreviewwidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgetpreviewwidget.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - widgetpreviewwidget.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETPREVIEWWIDGET_H -#define GAMMARAY_WIDGETINSPECTOR_WIDGETPREVIEWWIDGET_H - -#include -#include - -namespace GammaRay { - -class WidgetPreviewWidget : public QWidget -{ - Q_OBJECT - public: - explicit WidgetPreviewWidget(QWidget *parent = 0); - void setWidget(QWidget *widget); - - protected: - virtual void paintEvent(QPaintEvent *event); - virtual bool eventFilter(QObject *receiver, QEvent *event); - - private: - QPointer m_widget; - bool m_grabbingWidget; -}; - -} - -#endif // GAMMARAY_WIDGETPREVIEWWIDGET_H diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgettreemodel.cpp gammaray-2.0.1/core/tools/widgetinspector/widgettreemodel.cpp --- gammaray-1.2.2/core/tools/widgetinspector/widgettreemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgettreemodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/* - widgettreemodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "widgettreemodel.h" - -#include -#include -#include -#include - -using namespace GammaRay; - -WidgetTreeModel::WidgetTreeModel(QObject *parent) - : ObjectFilterProxyModelBase(parent) -{ -} - -QVariant WidgetTreeModel::data(const QModelIndex &index, int role) const -{ - if (index.isValid() && role == Qt::ForegroundRole) { - QObject *obj = index.data(ObjectModel::ObjectRole).value(); - QWidget *widget = qobject_cast(obj); - if (!widget) { - QLayout *layout = qobject_cast(obj); - if (layout) - widget = layout->parentWidget(); - } - if (widget && !widget->isVisible()) { - return qApp->palette().color(QPalette::Disabled, QPalette::Text); - } - } - return QSortFilterProxyModel::data(index, role); -} - -bool WidgetTreeModel::filterAcceptsObject(QObject *object) const -{ - return object->isWidgetType() || qobject_cast(object); -} - -#include "widgettreemodel.moc" diff -Nru gammaray-1.2.2/core/tools/widgetinspector/widgettreemodel.h gammaray-2.0.1/core/tools/widgetinspector/widgettreemodel.h --- gammaray-1.2.2/core/tools/widgetinspector/widgettreemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/tools/widgetinspector/widgettreemodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - widgettreemodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETTREEMODEL_H -#define GAMMARAY_WIDGETINSPECTOR_WIDGETTREEMODEL_H - -#include "include/objecttypefilterproxymodel.h" - -namespace GammaRay { - -/** Widget tree model. - * @todo Show layout hierarchy instead of object hierarchy. - */ -class WidgetTreeModel : public ObjectFilterProxyModelBase -{ - Q_OBJECT - public: - explicit WidgetTreeModel(QObject *parent = 0); - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - protected: - virtual bool filterAcceptsObject(QObject *object) const; -}; - -} - -#endif // GAMMARAY_WIDGETTREEMODEL_H diff -Nru gammaray-1.2.2/core/util.cpp gammaray-2.0.1/core/util.cpp --- gammaray-1.2.2/core/util.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/core/util.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,28 +21,22 @@ along with this program. If not, see . */ -#include "include/util.h" -#include "include/metatypedeclarations.h" +#include "util.h" +#include +#include "varianthandler.h" -#include #include #include -#include -#include #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include + +#include using namespace GammaRay; +using namespace std; namespace GammaRay { @@ -67,257 +61,6 @@ return object->objectName(); } -QString Util::addressToUid(const void *p) -{ - return QString::number(reinterpret_cast(p), 16); -} - -static QString sizePolicyToString(QSizePolicy::Policy policy) -{ - const int index = QSizePolicy::staticMetaObject.indexOfEnumerator("Policy"); - const QMetaEnum metaEnum = QSizePolicy::staticMetaObject.enumerator(index); - return QString::fromLatin1(metaEnum.valueToKey(policy)); -} - -QString GammaRay::Util::variantToString(const QVariant &value) -{ - switch (value.type()) { - case QVariant::Icon: - { - const QIcon icon = value.value(); - if (icon.isNull()) { - return QObject::tr(""); - } - QStringList l; - foreach (const QSize &size, icon.availableSizes()) { - l.push_back(variantToString(size)); - } - return l.join(QLatin1String(", ")); - } - case QVariant::Line: - return - QString::fromUtf8("%1 x %2 → %3 x %4"). - arg(value.toLine().x1()).arg(value.toLine().y1()). - arg(value.toLine().x2()).arg(value.toLine().y2()); - - case QVariant::LineF: - return - QString::fromUtf8("%1 x %2 → %3 x %4"). - arg(value.toLineF().x1()).arg(value.toLineF().y1()). - arg(value.toLineF().x2()).arg(value.toLineF().y2()); - - case QVariant::Point: - return - QString::fromLatin1("%1x%2"). - arg(value.toPoint().x()). - arg(value.toPoint().y()); - - case QVariant::PointF: - return - QString::fromLatin1("%1x%2"). - arg(value.toPointF().x()). - arg(value.toPointF().y()); - - case QVariant::Rect: - return - QString::fromLatin1("%1x%2 %3x%4"). - arg(value.toRect().x()). - arg(value.toRect().y()). - arg(value.toRect().width()). - arg(value.toRect().height()); - - case QVariant::RectF: - return - QString::fromLatin1("%1x%2 %3x%4"). - arg(value.toRectF().x()). - arg(value.toRectF().y()). - arg(value.toRectF().width()). - arg(value.toRectF().height()); - - case QVariant::Region: - { - const QRegion region = value.value(); - if (region.isEmpty()) { - return QLatin1String(""); - } - if (region.rectCount() == 1) { - return variantToString(region.rects().first()); - } else { - return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); - } - } - - case QVariant::Palette: - { - const QPalette pal = value.value(); - if (pal == qApp->palette()) { - return QLatin1String(""); - } - return QLatin1String(""); - } - - case QVariant::Size: - return - QString::fromLatin1("%1x%2"). - arg(value.toSize().width()). - arg(value.toSize().height()); - - case QVariant::SizeF: - return - QString::fromLatin1("%1x%2"). - arg(value.toSizeF().width()). - arg(value.toSizeF().height()); - - case QVariant::SizePolicy: - return - QString::fromLatin1("%1 x %2"). - arg(sizePolicyToString(value.value().horizontalPolicy())). - arg(sizePolicyToString(value.value().verticalPolicy())); - - case QVariant::StringList: - return value.toStringList().join(", "); - - case QVariant::Transform: - { - const QTransform t = value.value(); - return - QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). - arg(t.m11()).arg(t.m12()).arg(t.m13()). - arg(t.m21()).arg(t.m22()).arg(t.m23()). - arg(t.m31()).arg(t.m32()).arg(t.m33()); - } - default: - break; - } - - // types with dynamic type ids - if (value.type() == (QVariant::Type)qMetaTypeId()) { - const QTextLength l = value.value(); - QString typeStr; - switch (l.type()) { - case QTextLength::VariableLength: - typeStr = QObject::tr("variable"); - break; - case QTextLength::FixedLength: - typeStr = QObject::tr("fixed"); - break; - case QTextLength::PercentageLength: - typeStr = QObject::tr("percentage"); - break; - } - return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); - } - - if (value.userType() == qMetaTypeId()) { - const QPainterPath path = value.value(); - if (path.isEmpty()) { - return QObject::tr(""); - } - return QObject::tr("<%1 elements>").arg(path.elementCount()); - } - -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) - if (value.type() == (QVariant::Type)qMetaTypeId()) { - return displayString(value.value()); - } - - if (value.userType() == qMetaTypeId()) { - return addressToString(value.value()); - } - if (value.userType() == qMetaTypeId()) { - return addressToString(value.value()); - } - if (value.userType() == qMetaTypeId()) { - return addressToString(value.value()); - } - if (value.userType() == qMetaTypeId()) { - return displayString(value.value()); - } - if (value.userType() == qMetaTypeId()) { - return displayString(value.value()); - } - if (value.userType() == qMetaTypeId()) { - return displayString(value.value()); - } -#else - // HACK workaround for a Qt bug which makes canConvert() crash on a variant holding a null pointer - if (value.value() && value.canConvert()) { - return displayString(value.value()); - } -#endif - - // enums - const QString enumStr = enumToString(value); - if (!enumStr.isEmpty()) { - return enumStr; - } - - return value.toString(); -} - -QVariant Util::decorationForVariant(const QVariant &value) -{ - switch (value.type()) { - case QVariant::Brush: - { - const QBrush b = value.value(); - if (b.style() != Qt::NoBrush) { - QPixmap p(16, 16); - p.fill(QColor(0, 0, 0, 0)); - QPainter painter(&p); - painter.setBrush(b); - painter.drawRect(0, 0, p.width() - 1, p.height() - 1); - return p; - } - } - case QVariant::Color: - { - const QColor c = value.value(); - if (c.isValid()) { - QPixmap p(16, 16); - QPainter painter(&p); - painter.setBrush(QBrush(c)); - painter.drawRect(0, 0, p.width() - 1, p.height() - 1); - return p; - } - } - case QVariant::Cursor: - { - const QCursor c = value.value(); - if (!c.pixmap().isNull()) { - return c.pixmap().scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation); - } - } - case QVariant::Icon: - { - return value; - } - case QVariant::Pen: - { - const QPen pen = value.value(); - if (pen.style() != Qt::NoPen) { - QPixmap p(16, 16); - p.fill(QColor(0, 0, 0, 0)); - QPainter painter(&p); - painter.setPen(pen); - painter.translate(0, 8 - pen.width() / 2); - painter.drawLine(0, 0, p.width(), 0); - return p; - } - } - case QVariant::Pixmap: - { - const QPixmap p = value.value(); - if(!p.isNull()) { - return QVariant::fromValue(p.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation)); - } - } - default: break; - } - - return QVariant(); -} - QString Util::addressToString(const void *p) { return (QLatin1String("0x") + QString::number(reinterpret_cast(p), 16)); @@ -378,47 +121,99 @@ return enumStr; } } - return Util::variantToString(value); + return VariantHandler::displayString(value); } -static QVariant iconForObject(const QMetaObject *mo, QObject *obj) +struct IconCacheEntry +{ + QVariant defaultIcon; + + // pair of property name and expected string value + typedef QPair PropertyPair; + // a list of property pairs + typedef QVector PropertyMap; + // pair of icon and property map, for which this icon is valid + typedef QPair PropertyIcon; + typedef QVector PropertyIcons; + PropertyIcons propertyIcons; +}; +/// maps latin1 class name to list of icons valid for a given property map +typedef QHash IconDatabase; + +static IconDatabase readIconData() { - const QString basePath = QString::fromLatin1(":/gammaray/classes/%1/").arg(mo->className()); - const QDir dir(basePath); - if (dir.exists()) { - // see if we find one with exactly matching properties - const QStringList filterList = QStringList() << QLatin1String("*.png"); - foreach (const QString &entry, dir.entryList(filterList, QDir::Files)) { - if (entry == QLatin1String("default.png")) { + IconDatabase data; + + const QString basePath = QLatin1String(":/gammaray/classes/"); + QDir dir(basePath); + + const QStringList filterList = QStringList() << QLatin1String("*.png"); + + foreach (const QFileInfo &classEntry, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { + IconCacheEntry perClassData; + dir.cd(classEntry.fileName()); + const QStringList classIcons = dir.entryList(filterList, QDir::Files); + dir.cdUp(); + if (classIcons.isEmpty()) { + cerr << "invalid class icon resource file: " << qPrintable(classEntry.absoluteFilePath()) << endl; + continue; + } + foreach (const QString &iconName, classIcons) { + const QIcon icon(classEntry.absoluteFilePath() + '/' + iconName); + if (iconName == QLatin1String("default.png")) { + perClassData.defaultIcon = icon; continue; } - QString propString(entry); + // special property-specific icons with file name format prop1=val;prop2=val.png + QString propString(iconName); propString.chop(4); const QStringList props = propString.split(QLatin1String(";")); - if (props.isEmpty()) { - continue; - } - bool allMatch = true; + IconCacheEntry::PropertyMap propertyMap; foreach (const QString &prop, props) { const QStringList keyValue = prop.split(QLatin1Char('=')); if (keyValue.size() != 2) { continue; } - if (stringifyProperty(obj, keyValue.first()) != keyValue.last()) { + propertyMap << qMakePair(keyValue.at(0), keyValue.at(1)); + } + Q_ASSERT(!propertyMap.isEmpty()); + perClassData.propertyIcons << qMakePair(QVariant::fromValue(icon), propertyMap); + } + data[classEntry.fileName().toLatin1()] = perClassData; + } + return data; +} + +static QVariant iconForObject(const QMetaObject *mo, QObject *obj) +{ + static const IconDatabase iconDataBase = readIconData(); + // stupid Qt convention to use int for sizes... the static cast shuts down warnings about conversion from size_t to int. + const QByteArray className = QByteArray::fromRawData(mo->className(), static_cast(strlen(mo->className()))); + IconDatabase::const_iterator it = iconDataBase.constFind(className); + if (it != iconDataBase.constEnd()) { + foreach (const IconCacheEntry::PropertyIcon &propertyIcon, it->propertyIcons) { + bool allMatch = true; + Q_ASSERT(!propertyIcon.second.isEmpty()); + foreach (const IconCacheEntry::PropertyPair &keyValue, propertyIcon.second) { + if (stringifyProperty(obj, keyValue.first) != keyValue.second) { allMatch = false; break; } } if (allMatch) { - return QIcon(basePath + entry); + return propertyIcon.first; } } - return QIcon(basePath + QLatin1String("default.png")); - } else if (mo->superClass()) { + return it->defaultIcon; + } + + if (mo->superClass()) { return iconForObject(mo->superClass(), obj); } + return QVariant(); } + } QVariant Util::iconForObject(QObject *obj) @@ -428,3 +223,16 @@ } return QVariant(); } + +void Util::drawTransparencyPattern(QPainter *painter, const QRect &rect, int squareSize) +{ + QPixmap bgPattern(2 * squareSize, 2 * squareSize); + bgPattern.fill(Qt::lightGray); + QPainter bgPainter(&bgPattern); + bgPainter.fillRect(squareSize, 0, squareSize, squareSize, Qt::gray); + bgPainter.fillRect(0, squareSize, squareSize, squareSize, Qt::gray); + + QBrush bgBrush; + bgBrush.setTexture(bgPattern); + painter->fillRect(rect, bgBrush); +} diff -Nru gammaray-1.2.2/core/util.h gammaray-2.0.1/core/util.h --- gammaray-1.2.2/core/util.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/util.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,131 @@ +/* + util.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + @file + This file is part of the GammaRay Plugin API and declares various utility + methods needed when writing a plugin. + + @brief + Declares various utility methods needed when writing a GammaRay plugin. + + @author Volker Krause \ +*/ + +#ifndef GAMMARAY_UTIL_H +#define GAMMARAY_UTIL_H + +#include "gammaray_core_export.h" + +#include +#include + +class QRect; +class QPainter; +class QObject; + +namespace GammaRay { + +/** + * @brief GammaRay utilities. + */ +namespace Util { + + /** + * Returns a human readable string name of the specified QObject. + * @param object is a pointer to a valid QObject. + * + * @return a QString containing the human readable display string. + */ + GAMMARAY_CORE_EXPORT QString displayString(const QObject *object); + + /** + * Returns a string version (as a hex number starting with "0x") of the + * memory address @p p. + * @param p is a pointer to an address in memory. + * + * @return a QString containing the human readable address string. + */ + GAMMARAY_CORE_EXPORT QString addressToString(const void *p); + + /** + * Translates an enum or flag value into a human readable text. + * @param value The numerical value. Type information from the QVariant + * are used to find the corresponding QMetaEnum. + * @param typeName Use this if the @p value has type int + * (e.g. the case for QMetaProperty::read). + * @param object Additional QObject to search for QMetaEnums. + * + * @return a QString containing the string version of the specified @p value. + */ + GAMMARAY_CORE_EXPORT QString enumToString(const QVariant &value, + const char *typeName = 0, + QObject *object = 0); + + /** + * Determines if the QObject @p obj is a descendant of the QObject @p ascendant. + * @param ascendant is a pointer to a QObject. + * @param object is a pointer to a QObject. + * + * @return true if @p obj is a descendant of @p ascendant; false otherwise. + */ + GAMMARAY_CORE_EXPORT bool descendantOf(const QObject *ascendant, const QObject *object); + + /** + * Finds the parent QObject of the specified type T, if such exists. + * @param object is a pointer to a QObject. + * + * @return zero on failure; else a pointer to a data type T. + * + */ + template + T *findParentOfType(QObject *object) { + if (!object) { + return 0; + } + if (qobject_cast(object)) { + return qobject_cast(object); + } + return findParentOfType(object->parent()); + } + + /** + * Returns an icon for the given object. In normal operation a QIcon is + * returned containing the icon most closely associated with the data type + * pointed to by @p object + * @param object is a pointer to a QObject. + * + * @return on failure QVariant() is returned; else a QIcon + */ + GAMMARAY_CORE_EXPORT QVariant iconForObject(QObject *object); + + /** + * Draws a transparency pattern, i.e. the common checkerboard pattern into @p rect. + * + * @p size The size of the individual checkerboard squares. + */ + GAMMARAY_CORE_EXPORT void drawTransparencyPattern(QPainter *painter, const QRect &rect, int squareSize = 8); +} + +} + +#endif // GAMMARAY_UTIL_H diff -Nru gammaray-1.2.2/core/varianthandler.cpp gammaray-2.0.1/core/varianthandler.cpp --- gammaray-1.2.2/core/varianthandler.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/varianthandler.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,392 @@ +/* + varianthandler.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "varianthandler.h" +#include "util.h" +#include "common/metatypedeclarations.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 0 , 0) +#include +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +namespace GammaRay +{ + +struct VariantHandlerRepository +{ + QHash*> stringConverters; +}; + +} + +Q_GLOBAL_STATIC(VariantHandlerRepository, s_variantHandlerRepository) + +QString VariantHandler::displayString(const QVariant &value) +{ + switch (value.type()) { +#ifndef QT_NO_CURSOR + case QVariant::Cursor: + { + const QCursor cursor = value.value(); + return Util::enumToString(QVariant::fromValue(cursor.shape()), "Qt::CursorShape"); + } +#endif + case QVariant::Icon: + { + const QIcon icon = value.value(); + if (icon.isNull()) { + return QObject::tr(""); + } + QStringList l; + foreach (const QSize &size, icon.availableSizes()) { + l.push_back(displayString(size)); + } + return l.join(QLatin1String(", ")); + } + case QVariant::Line: + return + QString::fromUtf8("%1 x %2 → %3 x %4"). + arg(value.toLine().x1()).arg(value.toLine().y1()). + arg(value.toLine().x2()).arg(value.toLine().y2()); + + case QVariant::LineF: + return + QString::fromUtf8("%1 x %2 → %3 x %4"). + arg(value.toLineF().x1()).arg(value.toLineF().y1()). + arg(value.toLineF().x2()).arg(value.toLineF().y2()); + + case QVariant::Locale: + return value.value().name(); + + case QVariant::Point: + return + QString::fromLatin1("%1x%2"). + arg(value.toPoint().x()). + arg(value.toPoint().y()); + + case QVariant::PointF: + return + QString::fromLatin1("%1x%2"). + arg(value.toPointF().x()). + arg(value.toPointF().y()); + + case QVariant::Rect: + return + QString::fromLatin1("%1x%2 %3x%4"). + arg(value.toRect().x()). + arg(value.toRect().y()). + arg(value.toRect().width()). + arg(value.toRect().height()); + + case QVariant::RectF: + return + QString::fromLatin1("%1x%2 %3x%4"). + arg(value.toRectF().x()). + arg(value.toRectF().y()). + arg(value.toRectF().width()). + arg(value.toRectF().height()); + + case QVariant::Region: + { + const QRegion region = value.value(); + if (region.isEmpty()) { + return QLatin1String(""); + } + if (region.rectCount() == 1) { + return displayString(region.rects().first()); + } else { + return QString::fromLatin1("<%1 rects>").arg(region.rectCount()); + } + } + + case QVariant::Palette: + { + const QPalette pal = value.value(); + if (pal == qApp->palette()) { + return QLatin1String(""); + } + return QLatin1String(""); + } + + case QVariant::Size: + return + QString::fromLatin1("%1x%2"). + arg(value.toSize().width()). + arg(value.toSize().height()); + + case QVariant::SizeF: + return + QString::fromLatin1("%1x%2"). + arg(value.toSizeF().width()). + arg(value.toSizeF().height()); + + case QVariant::StringList: + return value.toStringList().join(", "); + + case QVariant::Transform: + { + const QTransform t = value.value(); + return + QString::fromLatin1("[%1 %2 %3, %4 %5 %6, %7 %8 %9]"). + arg(t.m11()).arg(t.m12()).arg(t.m13()). + arg(t.m21()).arg(t.m22()).arg(t.m23()). + arg(t.m31()).arg(t.m32()).arg(t.m33()); + } + default: + break; + } + + // types with dynamic type ids + if (value.type() == (QVariant::Type)qMetaTypeId()) { + const QTextLength l = value.value(); + QString typeStr; + switch (l.type()) { + case QTextLength::VariableLength: + typeStr = QObject::tr("variable"); + break; + case QTextLength::FixedLength: + typeStr = QObject::tr("fixed"); + break; + case QTextLength::PercentageLength: + typeStr = QObject::tr("percentage"); + break; + } + return QString::fromLatin1("%1 (%2)").arg(l.rawValue()).arg(typeStr); + } + + if (value.userType() == qMetaTypeId()) { + const QPainterPath path = value.value(); + if (path.isEmpty()) { + return QObject::tr(""); + } + return QObject::tr("<%1 elements>").arg(path.elementCount()); + } + + if (value.userType() == qMetaTypeId()) { + const QMargins margins = value.value(); + return QObject::tr("left: %1, top: %2, right: %3, bottom: %4") + .arg(margins.left()).arg(margins.top()) + .arg(margins.right()).arg(margins.bottom()); + } + + if (value.canConvert()) { + return Util::displayString(value.value()); + } + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + if (value.userType() == qMetaTypeId >()) { + const QSet set = value.value >(); + QStringList l; + foreach (const QByteArray &b, set) { + l.push_back(QString::fromUtf8(b)); + } + return l.join(", "); + } + + if (value.userType() == qMetaTypeId()) { + const QSurfaceFormat format = value.value(); + QString s; + switch (format.renderableType()) { + case QSurfaceFormat::DefaultRenderableType: + s += "Default"; + break; + case QSurfaceFormat::OpenGL: + s += "OpenGL"; + break; + case QSurfaceFormat::OpenGLES: + s += "OpenGL ES"; + break; + case QSurfaceFormat::OpenVG: + s += "OpenVG"; + break; + } + + s += " (" + QString::number(format.majorVersion()) + + '.' + QString::number(format.minorVersion()); + switch (format.profile()) { + case QSurfaceFormat::CoreProfile: + s += " core"; + break; + case QSurfaceFormat::CompatibilityProfile: + s += " compat"; + break; + case QSurfaceFormat::NoProfile: + break; + } + s += ')'; + + s += " RGBA: " + QString::number(format.redBufferSize()) + + '/' + QString::number(format.greenBufferSize()) + + '/' + QString::number(format.blueBufferSize()) + + '/' + QString::number(format.alphaBufferSize()); + + s += " Depth: " + QString::number(format.depthBufferSize()); + s += " Stencil: " + QString::number(format.stencilBufferSize()); + + s += " Buffer: "; + switch (format.swapBehavior()) { + case QSurfaceFormat::DefaultSwapBehavior: + s += "default"; + break; + case QSurfaceFormat::SingleBuffer: + s += "single"; + break; + case QSurfaceFormat::DoubleBuffer: + s += "double"; + break; + case QSurfaceFormat::TripleBuffer: + s += "triple"; + break; + default: + s += "unknown"; + } + + return s; + } + + if (value.userType() == qMetaTypeId()) { + const QSurface::SurfaceClass sc = value.value(); + switch (sc) { + case QSurface::Window: return QObject::tr("Window"); +#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0) + case QSurface::Offscreen: return QObject::tr("Offscreen"); +#endif + default: return QObject::tr("Unknown Surface Class"); + } + } + + if (value.userType() == qMetaTypeId()) { + const QSurface::SurfaceType type = value.value(); + switch (type) { + case QSurface::RasterSurface: return QObject::tr("Raster"); + case QSurface::OpenGLSurface: return QObject::tr("OpenGL"); + default: return QObject::tr("Unknown Surface Type"); + } + } + +#endif + + // enums + const QString enumStr = Util::enumToString(value); + if (!enumStr.isEmpty()) { + return enumStr; + } + + // custom converters + const QHash*>::const_iterator it = + s_variantHandlerRepository()->stringConverters.constFind(value.userType()); + if (it != s_variantHandlerRepository()->stringConverters.constEnd()) { + return (*it.value())(value); + } + + return value.toString(); +} + +QVariant VariantHandler::decoration(const QVariant &value) +{ + switch (value.type()) { + case QVariant::Brush: + { + const QBrush b = value.value(); + if (b.style() != Qt::NoBrush) { + QPixmap p(16, 16); + p.fill(QColor(0, 0, 0, 0)); + QPainter painter(&p); + painter.setBrush(b); + painter.drawRect(0, 0, p.width() - 1, p.height() - 1); + return p; + } + } + case QVariant::Color: + { + const QColor c = value.value(); + if (c.isValid()) { + QPixmap p(16, 16); + QPainter painter(&p); + painter.setBrush(QBrush(c)); + painter.drawRect(0, 0, p.width() - 1, p.height() - 1); + return p; + } + } +#ifndef QT_NO_CURSOR + case QVariant::Cursor: + { + const QCursor c = value.value(); + if (!c.pixmap().isNull()) { + return c.pixmap().scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation); + } + } +#endif + case QVariant::Icon: + { + return value; + } + case QVariant::Pen: + { + const QPen pen = value.value(); + if (pen.style() != Qt::NoPen) { + QPixmap p(16, 16); + p.fill(QColor(0, 0, 0, 0)); + QPainter painter(&p); + painter.setPen(pen); + painter.translate(0, 8 - pen.width() / 2); + painter.drawLine(0, 0, p.width(), 0); + return p; + } + } + case QVariant::Pixmap: + { + const QPixmap p = value.value(); + if(!p.isNull()) { + return QVariant::fromValue(p.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation)); + } + } + default: break; + } + + return QVariant(); +} + +void VariantHandler::registerStringConverter(int type, Converter *converter) +{ + s_variantHandlerRepository()->stringConverters.insert(type, converter); +} diff -Nru gammaray-1.2.2/core/varianthandler.h gammaray-2.0.1/core/varianthandler.h --- gammaray-1.2.2/core/varianthandler.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/core/varianthandler.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,87 @@ +/* + varianthandler.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_VARIANTHANDLER_H +#define GAMMARAY_VARIANTHANDLER_H + +#include "gammaray_core_export.h" + +#include + +namespace GammaRay { + +/** @brief Variant conversion functions, extendable by plugins. */ +namespace VariantHandler +{ + ///@cond internal + template struct Converter + { + virtual RetT operator() (const QVariant &v) = 0; + }; + + template struct ConverterImpl : public Converter + { + explicit inline ConverterImpl(FuncT converter) : f(converter) {} + /*override*/ inline RetT operator() (const QVariant &v) { return f(v.value()); } + FuncT f; + }; + ///@endcond + + /** + * Returns a human readable string version of the QVariant value. + * Converts to the variant type and prints the string value accordingly. + * @param value is a QVariant. + * + * @return a QString containing the human readable string. + */ + GAMMARAY_CORE_EXPORT QString displayString(const QVariant &value); + + /** + * Returns a value representing @p value in a itemview decoration role. + * @param value is a QVariant. + * + * @return a QVariant itemview decoration role. + */ + GAMMARAY_CORE_EXPORT QVariant decoration(const QVariant &value); + + /** + * Register a string conversion functions for a variant type. + * @internal + */ + GAMMARAY_CORE_EXPORT void registerStringConverter(int type, Converter *converter); + + /** + * Register a string conversion function for a variant type. + * @tparam T The type for which to use this converter function. + */ + template + inline void registerStringConverter(FuncT f) + { + Converter *converter = new ConverterImpl(f); + registerStringConverter(qMetaTypeId(), converter); + } +} + +} + +#endif // GAMMARAY_VARIANTHANDLER_H diff -Nru gammaray-1.2.2/debian/changelog gammaray-2.0.1/debian/changelog --- gammaray-1.2.2/debian/changelog 2013-10-23 22:42:50.000000000 +0000 +++ gammaray-2.0.1/debian/changelog 2014-03-18 16:16:50.000000000 +0000 @@ -1,8 +1,44 @@ -gammaray (1.2.2-1build1) trusty; urgency=low +gammaray (2.0.1-1ubuntu1) trusty; urgency=medium - * Rebuild for graphviz 2.34. + * Fix build failure with GraphViz >= 2.36.0. + - Add graphviz-2.36.0.patch, cherry-picked from upstream. - -- Colin Watson Wed, 23 Oct 2013 23:42:50 +0100 + -- Felix Geyer Tue, 18 Mar 2014 17:16:13 +0100 + +gammaray (2.0.1-1) unstable; urgency=medium + + * New upstream release. + * Refreshed d/patches/use-empty-rpath.patch. + + -- Jakub Adam Wed, 05 Mar 2014 19:28:40 +0100 + +gammaray (2.0.0-1) unstable; urgency=low + + * New upstream release. + * Refreshed d/patches/use-empty-rpath.patch. + * Removed no longer needed patches: + - widget-export-actions-location.patch + - harfbuzz-search-path.patch + - find-widget-export-actions-when-attaching.patch + - gammaray-probe-versioned-soname.patch. + * Use xz for orig tarball compression. + * Bump Standards-Version to 3.9.5. + * Enable build of Qt5 GUI and Qt5 + Qt4 probe libraries. + + -- Jakub Adam Tue, 21 Jan 2014 22:03:14 +0100 + +gammaray (1.3.0-1) experimental; urgency=low + + * New upstream release. + * Add dependency on VTK 5.10 and enable object visualizer plugin. + * Don't set RPATH in binaries; prevents binary-or-shlib-defines-rpath + lintian error. + * Refreshed d/patches/widget-export-actions-location.patch and + d/patches/gammaray-probe-versioned-soname.patch. + * Enable KJob tracker plugin. + * Updated d/copyright. + + -- Jakub Adam Mon, 04 Feb 2013 22:54:36 +0100 gammaray (1.2.2-1) unstable; urgency=low diff -Nru gammaray-1.2.2/debian/control gammaray-2.0.1/debian/control --- gammaray-1.2.2/debian/control 2012-12-22 17:15:45.000000000 +0000 +++ gammaray-2.0.1/debian/control 2014-03-18 16:16:55.000000000 +0000 @@ -1,10 +1,18 @@ Source: gammaray Priority: optional Section: devel -Maintainer: Debian KDE Extras Team +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Debian KDE Extras Team Uploaders: Jakub Adam Build-Depends: debhelper (>= 9), cmake, + kdelibs5-dev, + qtbase5-private-dev, + qtscript5-dev, + qttools5-dev, + libqt5svg5-dev, + libqt5webkit5-dev, + qtdeclarative5-dev, libqt4-dev, libqt4-private-dev, libqtwebkit-dev, @@ -12,7 +20,7 @@ gdb, xauth, xvfb -Standards-Version: 3.9.4 +Standards-Version: 3.9.5 Vcs-Git: git://anonscm.debian.org/pkg-kde/kde-extras/gammaray.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-kde/kde-extras/gammaray.git Homepage: http://www.kdab.com/gammaray @@ -22,7 +30,8 @@ Pre-Depends: ${misc:Pre-Depends} Depends: ${shlibs:Depends}, ${misc:Depends} -Recommends: gdb +Recommends: gammaray-probe-qt4, + gdb Description: Tool for examining the internals of Qt application GammaRay is a tool for examining the internals of a Qt application and to some extent also manipulate it. GammaRay uses injection methods to @@ -31,6 +40,41 @@ the complex internal structures you find in some Qt frameworks, such as QGraphicsView, model/view, QTextDocument, state machines and more. +Package: gammaray-probe-qt4 +Architecture: any +Pre-Depends: ${misc:Pre-Depends} +Depends: gammaray (= ${binary:Version}), + ${shlibs:Depends}, + ${misc:Depends} +Description: GammaRay support for inspecting Qt4 applications + This package contains GammaRay probe libraries that have to be loaded + into the application being inspected in order to allow GammaRay to + examine its internals. The gammaray package already includes the probe + binaries compiled for Qt5. Install this package if you want to use + GammaRay with Qt4 applications. + +#Package: gammaray-plugin-objectvisualizer +#Architecture: any +#Depends: gammaray (= ${binary:Version}), +# ${shlibs:Depends}, +# ${misc:Depends} +#Description: QObject hierarchy visualization plugin for GammaRay +# This plugin can visualize parent-child relationships of QObjects in a +# form of planar or 3D acyclic graph. Multiple graph layout algorihtms +# are available. +# . +# Also, for use with 3D glasses, various types of stereoscopic rendering +# are supported. + +Package: gammaray-plugin-kjobtracker +Architecture: any +Depends: gammaray (= ${binary:Version}), + ${shlibs:Depends}, + ${misc:Depends} +Description: KJob tracker plugin for GammaRay + This plugin can be used to monitor KJob instances within a KDE-based + application. + Package: gammaray-dev Architecture: any Section: libdevel diff -Nru gammaray-1.2.2/debian/copyright gammaray-2.0.1/debian/copyright --- gammaray-1.2.2/debian/copyright 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/copyright 2014-01-21 19:11:56.000000000 +0000 @@ -3,7 +3,7 @@ Files: * Copyright: 2006, Bradley T. Hughes - 2010-2011, Klarälvdalens Datakonsult AB, a KDAB Group company + 2010-2013, Klarälvdalens Datakonsult AB, a KDAB Group company License: GPL-2+ Files: 3rdparty/kde/* @@ -14,18 +14,14 @@ License: LGPL-2+ Files: 3rdparty/qt/* - launcher/processlist.h - launcher/processlist_win.cpp - launcher/processlist_unix.cpp + launcher/ui/processlist.h + launcher/ui/processlist_win.cpp + launcher/ui/processlist_unix.cpp Copyright: 2011, Nokia Corporation and/or its subsidiary(-ies) License: LGPL-2.1 -Files: cmake/FindQt5Transitional.cmake -Copyright: 2012, Klarälvdalens Datakonsult AB, a KDAB Group company -License: BSD-3-clause - Files: cmake/GammaRayMacros.cmake -Copyright: 2011, Volker Krause +Copyright: 2011-2013 Klarälvdalens Datakonsult AB, a KDAB Group company License: BSD-3-clause Files: cmake/ECMQt4To5Porting.cmake @@ -34,6 +30,8 @@ Files: cmake/FindGraphviz.cmake Copyright: 2009, Adrien Bustany + 2013, Kevin Funk + 2012-2013, Klarälvdalens Datakonsult AB, a KDAB Group company License: GPL-3+ Files: cmake/MacroLogFeature.cmake @@ -42,9 +40,9 @@ 2009, Sebastian Trueg License: BSD-3-clause -Files: core/palettemodel.cpp +Files: core/ui/palettemodel.cpp Copyright: 2010, Ariya Hidayat - 2012, Klarälvdalens Datakonsult AB, a KDAB Group company + 2012-2013, Klarälvdalens Datakonsult AB, a KDAB Group company License: GPL-2+ Files: core/tools/messagehandler/StackWalker.cpp @@ -54,14 +52,24 @@ Files: core/tools/modelinspector/modeltest.cpp core/tools/modelinspector/modeltest.h + tests/modeltest.cpp + tests/modeltest.h Copyright: 2007 Trolltech ASA License: GPL-2 Files: core/tools/messagehandler/backtrace_unix.cpp Copyright: 2002 Holger Freyther (freyther@kde.org) - 2010-2011, Klarälvdalens Datakonsult AB, a KDAB Group company + 2010-2013, Klarälvdalens Datakonsult AB, a KDAB Group company 1997, Matthias Kalle Dalheimer (kalle@kde.org) -License: GPL-2+ or LGPL-2+ +License: LGPL-2+ + +Files: debian/* +Copyright: 2012-2014, Debian KDE Extras Team +License: GPL-2+ + +Files: launcher/injector/interactiveprocess.* +Copyright: 2006, Bradley T. Hughes +License: GPL-2+ License: GPL-2 For full text of GNU General Public License v2 see diff -Nru gammaray-1.2.2/debian/gammaray-dev.install gammaray-2.0.1/debian/gammaray-dev.install --- gammaray-1.2.2/debian/gammaray-dev.install 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray-dev.install 2014-01-21 19:11:56.000000000 +0000 @@ -1,2 +1,2 @@ usr/include -usr/lib/libgammaray_probe.so +usr/lib/libgammaray*.so diff -Nru gammaray-1.2.2/debian/gammaray.install gammaray-2.0.1/debian/gammaray.install --- gammaray-1.2.2/debian/gammaray.install 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray.install 2014-01-21 19:11:56.000000000 +0000 @@ -1,5 +1,19 @@ usr/bin -usr/lib/gammaray -usr/lib/libgammaray_probe.so.* -usr/lib/qt4 +usr/lib/libgammaray*qt5*.so.* +usr/lib/gammaray/libexec +usr/lib/gammaray/*/qt5*/gammaray_actioninspector* +usr/lib/gammaray/*/qt5*/gammaray_codecbrowser* +usr/lib/gammaray/*/qt5*/gammaray_fontbrowser* +usr/lib/gammaray/*/qt5*/gammaray_inprocessui.so +usr/lib/gammaray/*/qt5*/gammaray_probe.so +usr/lib/gammaray/*/qt5*/gammaray_sceneinspector* +usr/lib/gammaray/*/qt5*/gammaray_scriptenginedebugger* +usr/lib/gammaray/*/qt5*/gammaray_selectionmodelinspector* +usr/lib/gammaray/*/qt5*/gammaray_statemachineviewer* +usr/lib/gammaray/*/qt5*/gammaray_styleinspector* +usr/lib/gammaray/*/qt5*/gammaray_timertop* +usr/lib/gammaray/*/qt5*/gammaray_webinspector* +usr/lib/gammaray/*/qt5*/gammaray_widgetinspector* +usr/lib/gammaray/*/qt5*/libgammaray_widget_export_actions.so +usr/lib/gammaray/*/qt5*/styles/* usr/share diff -Nru gammaray-1.2.2/debian/gammaray.lintian-overrides gammaray-2.0.1/debian/gammaray.lintian-overrides --- gammaray-1.2.2/debian/gammaray.lintian-overrides 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray.lintian-overrides 2014-01-21 19:11:56.000000000 +0000 @@ -1,2 +1 @@ -gammaray: hardening-no-fortify-functions usr/lib/libgammaray_probe.so.* gammaray: package-name-doesnt-match-sonames diff -Nru gammaray-1.2.2/debian/gammaray-plugin-kjobtracker.install gammaray-2.0.1/debian/gammaray-plugin-kjobtracker.install --- gammaray-1.2.2/debian/gammaray-plugin-kjobtracker.install 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray-plugin-kjobtracker.install 2014-01-21 19:11:56.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/gammaray/*/qt*/gammaray_kjobtracker* diff -Nru gammaray-1.2.2/debian/gammaray-plugin-objectvisualizer.install gammaray-2.0.1/debian/gammaray-plugin-objectvisualizer.install --- gammaray-1.2.2/debian/gammaray-plugin-objectvisualizer.install 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray-plugin-objectvisualizer.install 2014-01-21 19:11:56.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/gammaray/*/qt*/gammaray_objectvisualizer* diff -Nru gammaray-1.2.2/debian/gammaray-probe-qt4.install gammaray-2.0.1/debian/gammaray-probe-qt4.install --- gammaray-1.2.2/debian/gammaray-probe-qt4.install 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray-probe-qt4.install 2014-01-21 19:11:56.000000000 +0000 @@ -0,0 +1,27 @@ +usr/lib/libgammaray*qt4*.so.* +usr/lib/gammaray/*/qt4*/gammaray_actioninspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_actioninspector_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_codecbrowser.desktop +usr/lib/gammaray/*/qt4*/gammaray_codecbrowser_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_fontbrowser.desktop +usr/lib/gammaray/*/qt4*/gammaray_fontbrowser_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_inprocessui.so +usr/lib/gammaray/*/qt4*/gammaray_probe.so +usr/lib/gammaray/*/qt4*/gammaray_sceneinspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_sceneinspector_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_scriptenginedebugger.desktop +usr/lib/gammaray/*/qt4*/gammaray_scriptenginedebugger_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_selectionmodelinspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_selectionmodelinspector_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_statemachineviewer.desktop +usr/lib/gammaray/*/qt4*/gammaray_statemachineviewer_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_styleinspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_styleinspector_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_timertop.desktop +usr/lib/gammaray/*/qt4*/gammaray_timertop_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_webinspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_webinspector_plugin.so +usr/lib/gammaray/*/qt4*/gammaray_widgetinspector.desktop +usr/lib/gammaray/*/qt4*/gammaray_widgetinspector_plugin.so +usr/lib/gammaray/*/qt4*/libgammaray_widget_export_actions.so + diff -Nru gammaray-1.2.2/debian/gammaray-probe-qt4.lintian-overrides gammaray-2.0.1/debian/gammaray-probe-qt4.lintian-overrides --- gammaray-1.2.2/debian/gammaray-probe-qt4.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/gammaray-probe-qt4.lintian-overrides 2014-01-21 19:11:56.000000000 +0000 @@ -0,0 +1 @@ +gammaray-probe-qt4: package-name-doesnt-match-sonames diff -Nru gammaray-1.2.2/debian/gbp.conf gammaray-2.0.1/debian/gbp.conf --- gammaray-1.2.2/debian/gbp.conf 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/gbp.conf 2014-01-21 19:11:56.000000000 +0000 @@ -1,2 +1,2 @@ [DEFAULT] -compression=bzip2 +compression=xz diff -Nru gammaray-1.2.2/debian/patches/find-widget-export-actions-when-attaching.patch gammaray-2.0.1/debian/patches/find-widget-export-actions-when-attaching.patch --- gammaray-1.2.2/debian/patches/find-widget-export-actions-when-attaching.patch 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/patches/find-widget-export-actions-when-attaching.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -From: Jakub Adam -Date: Sun, 8 Jul 2012 15:36:59 +0200 -Subject: find-widget-export-actions-when-attaching - -The library search path is hand over to the forked process by setting -GAMMARAY_PROBE_PATH environment variable. This doesn't work when Gammaray -attaches to a running Qt application. As we know the exact location on -a Debian system, we don't have to rely on env variables and use -hardcoded GAMMARAY_LIB_INSTALL_DIR instead, which works in all cases. ---- - core/tools/widgetinspector/widgetinspector.cpp | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/core/tools/widgetinspector/widgetinspector.cpp b/core/tools/widgetinspector/widgetinspector.cpp -index 1fafc92..234933c 100644 ---- a/core/tools/widgetinspector/widgetinspector.cpp -+++ b/core/tools/widgetinspector/widgetinspector.cpp -@@ -246,7 +246,7 @@ void WidgetInspector::callExternalExportAction(const char *name, - { - if (!m_externalExportActions.isLoaded()) { - const QString probePath = -- QString::fromLocal8Bit(qgetenv("GAMMARAY_PROBE_PATH") + "/gammaray"); -+ QString::fromLocal8Bit(GAMMARAY_LIB_INSTALL_DIR "/gammaray"); - - m_externalExportActions.setFileName( - probePath + QLatin1String("/libgammaray_widget_export_actions")); diff -Nru gammaray-1.2.2/debian/patches/gammaray-probe-versioned-soname.patch gammaray-2.0.1/debian/patches/gammaray-probe-versioned-soname.patch --- gammaray-1.2.2/debian/patches/gammaray-probe-versioned-soname.patch 2012-12-22 17:15:45.000000000 +0000 +++ gammaray-2.0.1/debian/patches/gammaray-probe-versioned-soname.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ -From: Jakub Adam -Date: Sun, 8 Jul 2012 17:36:36 +0200 -Subject: gammaray-probe-versioned-soname - ---- - CMakeLists.txt | 1 + - config-gammaray.h.cmake | 1 + - core/CMakeLists.txt | 2 +- - launcher/probefinder.cpp | 2 +- - 4 files changed, 4 insertions(+), 2 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index f2055bb..4bbee30 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -28,6 +28,7 @@ set(GAMMARAY_VERSION_MINOR "2") - set(GAMMARAY_VERSION_PATCH "2") - set(GAMMARAY_VERSION "${GAMMARAY_VERSION_MAJOR}.${GAMMARAY_VERSION_MINOR}.${GAMMARAY_VERSION_PATCH}") - set(GAMMARAY_VERSION_STRING "${GAMMARAY_VERSION}") -+set(GAMMARAY_PROBE_SOVERSION "${GAMMARAY_VERSION_STRING}") - - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - -diff --git a/config-gammaray.h.cmake b/config-gammaray.h.cmake -index 0236a7c..2bda83c 100644 ---- a/config-gammaray.h.cmake -+++ b/config-gammaray.h.cmake -@@ -1,5 +1,6 @@ - #define GAMMARAY_LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" - #define GAMMARAY_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_DIR}" -+#define GAMMARAY_PROBE_SOVERSION "${GAMMARAY_PROBE_SOVERSION}" - // for finding the probe during automatic tests - #define GAMMARAY_BUILD_DIR "${CMAKE_BINARY_DIR}" - -diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt -index b49d795..10d81e3 100644 ---- a/core/CMakeLists.txt -+++ b/core/CMakeLists.txt -@@ -172,6 +172,6 @@ target_link_libraries(gammaray_probe - if(NOT WIN32) - target_link_libraries(gammaray_probe dl) - endif() --set_target_properties(gammaray_probe PROPERTIES PREFIX "") -+set_target_properties(gammaray_probe PROPERTIES SOVERSION ${GAMMARAY_PROBE_SOVERSION}) - - install(TARGETS gammaray_probe ${INSTALL_TARGETS_DEFAULT_ARGS}) -diff --git a/launcher/probefinder.cpp b/launcher/probefinder.cpp -index 6ab643b..d011a60 100644 ---- a/launcher/probefinder.cpp -+++ b/launcher/probefinder.cpp -@@ -50,7 +50,7 @@ QString findProbe(const QString &baseName) - #ifdef Q_OS_MAC - QFile plfile(QLatin1Literal("preloads:") % baseName % QLatin1Literal(".dylib")); - #else -- QFile plfile(QLatin1Literal("preloads:") % baseName % QLatin1Literal(".so")); -+ QFile plfile(QLatin1Literal("preloads:") % QLatin1Literal("lib") % baseName % QLatin1Literal(".so." GAMMARAY_PROBE_SOVERSION)); - #endif - if (plfile.exists()) { - return plfile.fileName(); diff -Nru gammaray-1.2.2/debian/patches/graphviz-2.36.0.patch gammaray-2.0.1/debian/patches/graphviz-2.36.0.patch --- gammaray-1.2.2/debian/patches/graphviz-2.36.0.patch 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/patches/graphviz-2.36.0.patch 2014-03-18 16:15:59.000000000 +0000 @@ -0,0 +1,50 @@ +From e3b0fc71869fcf77a390b6b31e2186ad91cafac0 Mon Sep 17 00:00:00 2001 +From: Kevin Funk +Date: Tue, 18 Mar 2014 12:11:21 +0100 +Subject: [PATCH] Make compile with GraphViz >= 2.36.0 + +Fixes #70 +--- + cmake/FindGraphviz.cmake | 7 +++++++ + plugins/statemachineviewer/CMakeLists.txt | 1 + + 2 files changed, 8 insertions(+) + +diff --git a/cmake/FindGraphviz.cmake b/cmake/FindGraphviz.cmake +index 945b461..523325e 100644 +--- a/cmake/FindGraphviz.cmake ++++ b/cmake/FindGraphviz.cmake +@@ -8,6 +8,7 @@ + # GRAPHVIZ_MAJOR_VERSION = The library major version number + # GRAPHVIZ_MINOR_VERSION = The library minor version number + # GRAPHVIZ_PATCH_VERSION = The library patch version number ++# GRAPHVIZ_COMPILE_FLAGS = List of compile flags needed by the GraphViz installation headers + # + # This module reads hints about search locations from the following env variables: + # GRAPHVIZ_ROOT - Graphviz installation prefix +@@ -147,6 +148,12 @@ if(GRAPHVIZ_FOUND) + list(GET VL 2 GRAPHVIZ_PATCH_VERSION) + endif() + ++ set(GRAPHVIZ_COMPILE_FLAGS "") ++ check_include_files(string.h HAVE_STRING_H) ++ if (HAVE_STRING_H) ++ list(APPEND GRAPHVIZ_COMPILE_FLAGS "-DHAVE_STRING_H=1") ++ endif() ++ + if(NOT GRAPHVIZ_FIND_QUIETLY) + message(STATUS "Found Graphviz: ${GRAPHVIZ_CDT_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY} ${GRAPHVIZ_GRAPH_LIBRARY} ${GRAPHVIZ_PATHPLAN_LIBRARY}") + endif() +diff --git a/plugins/statemachineviewer/CMakeLists.txt b/plugins/statemachineviewer/CMakeLists.txt +index 26896fe..97a5e44 100644 +--- a/plugins/statemachineviewer/CMakeLists.txt ++++ b/plugins/statemachineviewer/CMakeLists.txt +@@ -69,6 +69,7 @@ else() + ${GRAPHVIZ_GRAPH_LIBRARY} + ) + endif() ++add_definitions(${GRAPHVIZ_COMPILE_FLAGS}) + + qt4_wrap_ui(gammaray_statemachineviewer_ui_plugin_srcs statemachineviewer.ui) + +-- +1.8.5.5 diff -Nru gammaray-1.2.2/debian/patches/harfbuzz-search-path.patch gammaray-2.0.1/debian/patches/harfbuzz-search-path.patch --- gammaray-1.2.2/debian/patches/harfbuzz-search-path.patch 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/patches/harfbuzz-search-path.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -From: Jakub Adam -Date: Sun, 8 Jul 2012 14:47:26 +0200 -Subject: harfbuzz-search-path - ---- - CMakeLists.txt | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 126dfb3..70208fa 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -114,8 +114,8 @@ if(QT_PRIVATE_INCLUDE_DIR) - # not enough, some of them include harfbuzz headers, so we need to find those as well - # for now we assume a regular Qt4 source build layout, but that probably should be generalized - find_path( -- HARFBUZZ_INCLUDE_DIR harfbuzz.h -- PATH ${QT_PRIVATE_INCLUDE_DIR}/../../src/3rdparty/harfbuzz/src -+ HARFBUZZ_INCLUDE_DIR harfbuzz-shaper.h -+ PATH ${QT_PRIVATE_INCLUDE_DIR}/../../src/corelib/tools - ) - endif() - diff -Nru gammaray-1.2.2/debian/patches/series gammaray-2.0.1/debian/patches/series --- gammaray-1.2.2/debian/patches/series 2012-12-22 17:15:45.000000000 +0000 +++ gammaray-2.0.1/debian/patches/series 2014-03-18 16:16:09.000000000 +0000 @@ -1,4 +1,2 @@ -widget-export-actions-location.patch -harfbuzz-search-path.patch -find-widget-export-actions-when-attaching.patch -gammaray-probe-versioned-soname.patch +use-empty-rpath.patch +graphviz-2.36.0.patch diff -Nru gammaray-1.2.2/debian/patches/use-empty-rpath.patch gammaray-2.0.1/debian/patches/use-empty-rpath.patch --- gammaray-1.2.2/debian/patches/use-empty-rpath.patch 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/debian/patches/use-empty-rpath.patch 2014-03-05 18:28:22.000000000 +0000 @@ -0,0 +1,21 @@ +From: Jakub Adam +Date: Thu, 10 Jan 2013 20:16:29 +0100 +Subject: use-empty-rpath + +--- + CMakeLists.txt | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 92e1955..6cbe7de 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -36,8 +36,6 @@ set(GAMMARAY_VERSION_STRING "${GAMMARAY_VERSION}") + set(GAMMARAY_SOVERSION "${GAMMARAY_VERSION}") + set(GAMMARAY_PLUGIN_VERSION "2.0") + +-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +- + enable_testing() + + if(EXISTS "${CMAKE_SOURCE_DIR}/.git") diff -Nru gammaray-1.2.2/debian/patches/widget-export-actions-location.patch gammaray-2.0.1/debian/patches/widget-export-actions-location.patch --- gammaray-1.2.2/debian/patches/widget-export-actions-location.patch 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/patches/widget-export-actions-location.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ -From: Jakub Adam -Date: Thu, 5 Jan 2012 00:57:49 +0100 -Subject: widget-export-actions-location - -Install libgammaray_widget_export_actions.so to /usr/lib/gammaray -as it is application private library. Fixes lintian warnings/errors: - -package-name-doesnt-match-sonames -shlib-without-versioned-soname -postinst-must-call-ldconfig ---- - CMakeLists.txt | 1 + - core/tools/widgetinspector/CMakeLists.txt | 2 +- - core/tools/widgetinspector/widgetinspector.cpp | 2 +- - 3 files changed, 3 insertions(+), 2 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 74548df..971ecbf 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -87,6 +87,7 @@ endif() - set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") - set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}") - set(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/qt4/plugins") -+set(MODULE_INSTALL_DIR "${LIB_INSTALL_DIR}/gammaray") - - set( - INSTALL_TARGETS_DEFAULT_ARGS -diff --git a/core/tools/widgetinspector/CMakeLists.txt b/core/tools/widgetinspector/CMakeLists.txt -index eefa624..e851f8d 100644 ---- a/core/tools/widgetinspector/CMakeLists.txt -+++ b/core/tools/widgetinspector/CMakeLists.txt -@@ -10,4 +10,4 @@ target_link_libraries(gammaray_widget_export_actions - ${QT_QTDESIGNER_LIBRARIES} - ) - --install(TARGETS gammaray_widget_export_actions ${INSTALL_TARGETS_DEFAULT_ARGS}) -+install(TARGETS gammaray_widget_export_actions DESTINATION ${MODULE_INSTALL_DIR}) -diff --git a/core/tools/widgetinspector/widgetinspector.cpp b/core/tools/widgetinspector/widgetinspector.cpp -index dcd9e1a..1fafc92 100644 ---- a/core/tools/widgetinspector/widgetinspector.cpp -+++ b/core/tools/widgetinspector/widgetinspector.cpp -@@ -246,7 +246,7 @@ void WidgetInspector::callExternalExportAction(const char *name, - { - if (!m_externalExportActions.isLoaded()) { - const QString probePath = -- QString::fromLocal8Bit(qgetenv("GAMMARAY_PROBE_PATH")); -+ QString::fromLocal8Bit(qgetenv("GAMMARAY_PROBE_PATH") + "/gammaray"); - - m_externalExportActions.setFileName( - probePath + QLatin1String("/libgammaray_widget_export_actions")); diff -Nru gammaray-1.2.2/debian/rules gammaray-2.0.1/debian/rules --- gammaray-1.2.2/debian/rules 2012-08-21 08:46:59.000000000 +0000 +++ gammaray-2.0.1/debian/rules 2014-01-21 19:11:56.000000000 +0000 @@ -1,6 +1,8 @@ #!/usr/bin/make -f -.PHONY: override_dh_auto_configure override_dh_auto_test override_dh_auto_install override_dh_installdocs override_dh_strip override_dh_clean +.PHONY: override_dh_auto_configure override_dh_auto_build override_dh_auto_test override_dh_auto_install override_dh_installdocs override_dh_strip override_dh_clean + +export DEB_LDFLAGS_MAINT_APPEND=-Wl,--as-needed %: dh $@ --parallel @@ -11,13 +13,19 @@ mv 3rdparty/qt/private 3rdparty/qt/private.dont.use; \ fi - dh_auto_configure + dh_auto_configure -B obj-qt5 + dh_auto_configure -B obj-qt4 -- -DGAMMARAY_ENFORCE_QT4_BUILD=ON -DGAMMARAY_PROBE_ONLY_BUILD=ON + +override_dh_auto_build: + dh_auto_build -B obj-qt5 -O--parallel + dh_auto_build -B obj-qt4 -O--parallel override_dh_auto_test: xvfb-run dh_auto_test override_dh_auto_install: - dh_auto_install + dh_auto_install -B obj-qt5 + dh_auto_install -B obj-qt4 rm -f debian/tmp/usr/share/doc/gammaray/License.txt override_dh_installdocs: diff -Nru gammaray-1.2.2/debian.changelog gammaray-2.0.1/debian.changelog --- gammaray-1.2.2/debian.changelog 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/debian.changelog 2014-02-28 19:07:57.000000000 +0000 @@ -1,3 +1,45 @@ +gammaray (2.0.1) final; urgency=low + + * 2.0.1 final release + + -- Allen Winter Fri, 28 Feb 2014 11:30:00 -0500 + +gammaray (2.0.0) final; urgency=low + + * 2.0.0 final release + + -- Allen Winter Fri, 17 Jan 2014 11:00:00 -0500 + +gammaray (1.9.96) final; urgency=low + + * 2.0.0 beta2 release + + -- Allen Winter Sat, 11 Jan 2014 11:00:00 -0500 + +gammaray (1.9.95) final; urgency=low + + * 2.0.0 beta1 release + + -- Allen Winter Fri, 20 Dec 2013 11:00:00 -0500 + +gammaray (1.3.2) final; urgency=low + + * 1.3.2 patch release + + -- Allen Winter Thu, 03 Oct 2013 11:00:00 -0500 + +gammaray (1.3.1) final; urgency=low + + * 1.3.1 patch release + + -- Allen Winter Tues, 30 Apr 2013 16:30:00 -0500 + +gammaray (1.3.0) final; urgency=low + + * 1.3.0 final release + + -- Allen Winter Sun, 27 Jan 2013 18:00:00 -0500 + gammaray (1.2.2) patch; urgency=low * 1.2.2 patch release @@ -27,4 +69,3 @@ * 1.1.98 beta release -- Allen Winter Wed, 27 Jun 2012 14:10:14 +0000 - diff -Nru gammaray-1.2.2/docs/footer.html gammaray-2.0.1/docs/footer.html --- gammaray-1.2.2/docs/footer.html 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/docs/footer.html 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,19 @@ +
+
+ + Klarälvdalens Datakonsult AB (KDAB) +
+ "The Cross-Platform Experts"
+ http://www.kdab.com/ +
+ +
+ + GammaRay +
+ Qt-application inspection and manipulation tool
+ http://www.kdab.com/kdab-products/gammaray/ +
+ + + Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/docs/kdab-gammaray-logo-16x16.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/docs/kdab-gammaray-logo-16x16.png differ Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/docs/kdab-logo-16x16.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/docs/kdab-logo-16x16.png differ diff -Nru gammaray-1.2.2/docs/Mainpage.dox gammaray-2.0.1/docs/Mainpage.dox --- gammaray-1.2.2/docs/Mainpage.dox 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/docs/Mainpage.dox 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,80 @@ +/*! +@mainpage GammaRay - Qt-application inspection and manipulation tool. + +@section about About + +GammaRay is a tool to poke around in a Qt-application and also +to manipulate the application to some extent. GammaRay uses various DLL +injection techniques to hook into an application at runtime and provide +access to a lot of interesting information. + +@section plugins Plugins + +Starting with version 1.2, GammaRay provides the ability to write your +own plugins. This documentation describes the API for doing just that. + +@section features Features + +GammaRay can: + +- Browse the QObject tree with live updates. +- View, and to some extent, edit QObject static and dynamic properties. +- View and call slots of a QObject (similar to qdbusviewer). +- View other QObject elements such as signals, enums and class information + introspectively. +- List all QObject inbound and outbound signal/slot connections. +- Provide live widget preview. Useful for finding layout issues). +- View the content of any QAbstractItemModel (QAIM). Very useful when + debugging a proxy model chain for example. +- Browse the QAbstractProxyModel (QAPM) hierarchy. +- Browse the QGraphicsView (QGV) item tree of any QGV scene. +- Show a live preview of QGV items, including showing their coordinate system, + transformation origin, rotate/zoom/pan, etc. +- Act as a complete java script debugger, attachable to any QScriptEngine + (including the usually not accessible one used by QML internally). +- Perform HTML/CSS/DOM/JS introspection/editing/profiling on any QWebPage, + thanks to QWebInspector. +- Browse the QResource tree and its content. +- Browse QStateMachines, along with their states and transitions. +- Show all registered meta types. +- Show all installed fonts. +- Show all available codecs. +- Browse all QTextDocuments, along with the ability to edit them and view + their internal structures. +- Show all QTimers and their statistics (number of wakeups, wakeup time, ...) + + +@section license License + +Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, \ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +@section about-KDAB About KDAB + +GammaRay is supported and maintained by Klarälvdalens Datakonsult AB (KDAB) + +KDAB, the Qt experts, provide consulting and mentoring for developing +Qt applications from scratch and in porting from all popular and legacy +frameworks to Qt. Our software products increase Qt productivity and our +Qt trainers have trained 50% of commercial Qt developers globally. + +Please visit http://www.kdab.com to meet the people who write code like this. +We also offer Qt training courses. + + +@namespace GammaRay All GammaRay classes. + +*/ diff -Nru gammaray-1.2.2/Doxyfile gammaray-2.0.1/Doxyfile --- gammaray-1.2.2/Doxyfile 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/Doxyfile 1970-01-01 00:00:00.000000000 +0000 @@ -1,195 +0,0 @@ -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = GammaRay -PROJECT_NUMBER = 1.2 -OUTPUT_DIRECTORY = apidocs -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The \$name class" \ - "The \$name widget" \ - "The \$name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 8 -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -BUILTIN_STL_SUPPORT = NO -DISTRIBUTE_GROUP_DOC = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -EXTRACT_PRIVATE = YES -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = YES -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = YES -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_MEMBERS_CTORS_1ST = YES -SORT_BRIEF_DOCS = YES -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = NO -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST = YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = NO -FILE_VERSION_FILTER = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = YES -WARN_FORMAT = "\$file:\$line: \$text" -WARN_LOGFILE = doxygen.log -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = include -FILE_PATTERNS = *.cpp \ - *.cc \ - *.cxx \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.dox -RECURSIVE = YES -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = */.svn/* \ - */.git/* \ - */cmake/* \ - *.moc.* \ - moc* \ - *.all_cpp.* \ - *unload.* \ - */test/* \ - */tests/* \ - *_p.cpp \ - *_export.h -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = images -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = NO -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# do NOT generate any formats other than html -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -GENERATE_HTML = YES -GENERATE_LATEX = NO -GENERATE_RTF = NO -GENERATE_XML = NO -GENERATE_AUTOGEN_DEF = NO -GENERATE_PERLMOD = NO -DISABLE_INDEX = YES -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = images/footer.html -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = Q_DECL_IMPORT="" GAMMARAY_EXPORT="" -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -CLASS_GRAPH = YES -COLLABORATION_GRAPH = NO -GROUP_GRAPHS = NO -UML_LOOK = NO -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -CALLER_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -MAX_DOT_GRAPH_DEPTH = 1000 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = YES -SERVER_BASED_SEARCH = NO diff -Nru gammaray-1.2.2/Doxyfile.cmake gammaray-2.0.1/Doxyfile.cmake --- gammaray-1.2.2/Doxyfile.cmake 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/Doxyfile.cmake 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,197 @@ +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = GammaRay +PROJECT_NUMBER = @GAMMARAY_VERSION@ +OUTPUT_DIRECTORY = apidocs +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The \$name class" \ + "The \$name widget" \ + "The \$name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = YES +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = YES +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_MEMBERS_CTORS_1ST = YES +SORT_BRIEF_DOCS = YES +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = NO +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST = YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = YES +WARN_FORMAT = "\$file:\$line: \$text" +WARN_LOGFILE = doxygen.log +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = @DOXYGEN_INPUT@ +FILE_PATTERNS = *.cpp \ + *.cc \ + *.cxx \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.dox +RECURSIVE = YES +EXCLUDE = @CMAKE_SOURCE_DIR@/common/gammaray_common_export.h \ + @CMAKE_SOURCE_DIR@/core/gammaray_core_export.h \ + @CMAKE_SOURCE_DIR@/ui/gammaray_ui_export.h +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */.svn/* \ + */.git/* \ + */cmake/* \ + *.moc.* \ + moc* \ + *.all_cpp.* \ + *unload.* \ + */test/* \ + */tests/* \ + *_p.cpp \ + *_export.h +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = @CMAKE_SOURCE_DIR@/docs +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# do NOT generate any formats other than html +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +GENERATE_HTML = YES +GENERATE_LATEX = NO +GENERATE_RTF = NO +GENERATE_XML = NO +GENERATE_AUTOGEN_DEF = NO +GENERATE_PERLMOD = NO +DISABLE_INDEX = YES +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = @CMAKE_SOURCE_DIR@/docs/footer.html +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = Q_DECL_IMPORT="" GAMMARAY_COMMON_EXPORT="" GAMMARAY_CORE_EXPORT="" GAMMARAY_UI_EXPORT="" +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = NO +GROUP_GRAPHS = NO +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_DEPTH = 1000 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = YES +SERVER_BASED_SEARCH = NO diff -Nru gammaray-1.2.2/GammaRayConfig.cmake.in gammaray-2.0.1/GammaRayConfig.cmake.in --- gammaray-1.2.2/GammaRayConfig.cmake.in 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/GammaRayConfig.cmake.in 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,18 @@ +@PACKAGE_INIT@ + +if(@Qt5Core_FOUND@) + find_package(Qt5 @Qt5Core_VERSION_MAJOR@.@Qt5Core_VERSION_MINOR@ NO_MODULE REQUIRED COMPONENTS Core Network) + find_package(Qt5 @Qt5Core_VERSION_MAJOR@.@Qt5Core_VERSION_MINOR@ NO_MODULE COMPONENTS Widgets) +else() + find_package(Qt4 @QT_VERSION_MAJOR@.@QT_VERSION_MINOR@) +endif() + +set_and_check(GammaRay_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") +list(APPEND GammaRay_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@/..") + +set(GAMMARAY_PLUGIN_INSTALL_DIR @PLUGIN_INSTALL_DIR@) +set(GAMMARAY_PLUGIN_VERSION @GAMMARAY_PLUGIN_VERSION@) +set(GAMMARAY_PROBE_ABI @GAMMARAY_PROBE_ABI@) + +include("${CMAKE_CURRENT_LIST_DIR}/GammaRayTarget.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/GammaRayMacros.cmake") diff -Nru gammaray-1.2.2/gammaray.dsc gammaray-2.0.1/gammaray.dsc --- gammaray-1.2.2/gammaray.dsc 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/gammaray.dsc 2014-02-28 19:07:57.000000000 +0000 @@ -1,10 +1,10 @@ Format: 1.0 Source: gammaray -Version: 1.2.2 +Version: 2.0.1 Binary: gammaray Maintainer: Allen Winter Architecture: any -Build-Depends: debhelper (>= 4.1.16), cdbs, cmake, libqt4-dev, libqtwebkit-dev, graphviz-dev libvtk5-dev +Build-Depends: debhelper (>= 4.1.16), cdbs, cmake, libqt4-dev, libqtwebkit-dev, graphviz-dev Files: - 00000000000000000000000000000000 00000 gammaray-1.2.2.tar.gz + 00000000000000000000000000000000 00000 gammaray-2.0.1.tar.gz diff -Nru gammaray-1.2.2/gammaray.pod gammaray-2.0.1/gammaray.pod --- gammaray-1.2.2/gammaray.pod 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/gammaray.pod 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ =head1 SYNOPSIS -gammaray [--injector ] [--pid | ] +gammaray [--pid | | --connect [:] =head1 DESCRIPTION @@ -46,6 +46,44 @@ style windll (Windows) +=item B<--inprocess> + +Use the Gammaray 1.x in-process UI. This is not necessary in most cases, +apart from using tools that do not work remotely. + +=item B<--inject-only> + +This will only inject the GammaRay probe into a process, but not start +the GammaRay UI. This is useful for example when doing remote debugging +on embedded devices. + +=item B<--listen
> + +Specify on which network address the GammaRay server should listen, +default is 0.0.0.0 (ie. all of them). This can be used for example +on Windows to avoid firewall warnings by setting the address to +127.0.0.1 if you don't need remote access. + +=item B<--no-listen> + +Disables the GammaRay server. This implies --inprocess as there is no +other way to connect to the GammaRay probe in this case. + +=item B<--list-probes> + +List all installed probes. + +=item B<--probe > + +Explicitly specify which probe to use. You should use this if you have +more than one probe installed (e.g. one for Qt4 and one for Qt5), until +probe ABI auto-detection is implemented. + +=item B<--connect [:port]> + +Connect to a target with an already injected GammaRay probe. Useful for +example for remote debugging. + =back =head1 EXAMPLES @@ -74,7 +112,7 @@ =head1 COPYRIGHT -Copyright (C) 2010-2012 Klaralvdalens Datakonsult AB, a KDAB Group company, +Copyright (C) 2010-2014 Klaralvdalens Datakonsult AB, a KDAB Group company, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff -Nru gammaray-1.2.2/gammaray.spec gammaray-2.0.1/gammaray.spec --- gammaray-1.2.2/gammaray.spec 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/gammaray.spec 2014-02-28 19:07:57.000000000 +0000 @@ -1,33 +1,52 @@ Name: gammaray -Version: 1.2.2 -Release: 1.2 -Summary: A tool to poke around in a Qt-application +Version: 2.0.1 +Release: 2 +Summary: An introspection tool for Qt applications Source: %{name}-%{version}.tar.gz -Url: git@github.com:KDAB/GammaRay.git +Url: http://github.com/KDAB/GammaRay Group: Development/Tools/Debuggers -License: GPL v2, or any later version +License: GPL-2.0+ BuildRoot: %{_tmppath}/%{name}-%{version}-build +Vendor: Klaralvdalens Datakonsult AB (KDAB) +Packager: Klaralvdalens Datakonsult AB (KDAB) + +%define rel 2.0 +%define sover 2.0.1 +%define qtver qt4.8 +%define this_arch %(uname -p) +%if %{this_arch} == "athlon" +%define this_arch i686 +%endif +%define abi %{qtver}-%{this_arch} -#VTK devel is only available on some newer openSUSE and Fedora distros %if %{defined suse_version} -%if %{suse_version} <= 1210 -BuildRequires: libqt4-devel libQtWebKit-devel cmake graphviz-devel update-desktop-files -%else -BuildRequires: libqt4-devel libQtWebKit-devel cmake graphviz-devel update-desktop-files vtk-devel +BuildRequires: libqt4-devel libQtWebKit-devel cmake graphviz-devel update-desktop-files libkde4-devel +%if 0%{?suse_version} >= 1220 +BuildRequires: vtk-devel +%endif +# missing dependency for VTK in openSUSE Factory +%if 0%{?suse_version} > 1230 +BuildRequires: python-devel %endif Requires: graphviz %endif %if %{defined fedora} -%if %{fedora} < 17 -BuildRequires: gcc-c++ libqt4-devel qtwebkit-devel cmake desktop-file-utils graphviz-devel -%else -BuildRequires: gcc-c++ libqt4-devel qtwebkit-devel cmake desktop-file-utils graphviz-devel vtk-devel +BuildRequires: gcc-c++ qt-devel qtwebkit-devel cmake desktop-file-utils graphviz-devel kdelibs-devel +%if 0%{?fedora} >= 17 +BuildRequires: vtk-devel +%endif +# dependency ambiguity for vtk-java needed by vtk-devel in Fedora >= 19 +%if 0%{?fedora} >= 19 +BuildRequires: java-1.8.0-openjdk +%endif +# for pod2man +%if 0%{?fedora} >= 19 +BuildRequires: perl-podlators %endif Requires: graphviz %endif - %description GammaRay is a tool for examining the internals of a Qt application and to some extent also manipulate it. GammaRay uses injection @@ -41,6 +60,34 @@ -------- The GammaRay Team +%package kde4-plugins +Summary: GammaRay plug-ins to introspect KDE4 applications +Group: Development/Tools/Debuggers +Requires: %{name} = %{version} + +%description kde4-plugins +Plug-ins for the GammaRay introspection tool to debug KDE4 applications, +such as a KJob tracker. + +%if 0%{?suse_version} >= 1220 || 0%{?fedora} >= 17 +%package vtk-plugins +Summary: GammaRay visualization plug-ins using VTK +Group: Development/Tools/Debuggers +Requires: %{name} = %{version} + +%description vtk-plugins +Visualization plug-ins for the GammaRay introspection tool that depend on VTK. +%endif + +%package devel +Summary: Development files for %{name} +Group: Development/Libraries/C and C++ +Requires: %{name} = %{version} + +%description devel +The %{name}-devel package contains libraries and header files for +developing GammaRay plug-ins. + %prep %setup -q @@ -56,6 +103,9 @@ %endif %__make %{?_smp_mflags} +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + %install %make_install @@ -72,24 +122,96 @@ %{_prefix}/share/icons/hicolor %{_prefix}/share/doc/gammaray %{_mandir}/man1/gammaray.1.gz -%{_libdir}/gammaray_probe.so -%{_libdir}/libgammaray_widget_export_actions.so %{_bindir}/gammaray -%{_libdir}/qt4/plugins/gammaray -%{_libdir}/qt4/plugins/styles -%{_libdir}/qt4/plugins/styles/gammaray_injector_style.so -%{_prefix}/include/gammaray +%dir %{_libdir}/gammaray/libexec/ +%{_libdir}/gammaray/libexec/gammaray-client +%{_libdir}/gammaray/libexec/gammaray-launcher +%{_libdir}/libgammaray_common-%{abi}.so.%{sover} +%{_libdir}/libgammaray_core-%{abi}.so.%{sover} +%{_libdir}/libgammaray_ui-%{abi}.so.%{sover} +%dir %{_libdir}/gammaray/ +%dir %{_libdir}/gammaray/%{rel}/ +%dir %{_libdir}/gammaray/%{rel}/%{abi}/ +%{_libdir}/gammaray/%{rel}/%{abi}/libgammaray_widget_export_actions.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_probe.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_inprocessui.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_codecbrowser_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_codecbrowser.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_codecbrowser_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_codecbrowser_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_fontbrowser_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_fontbrowser.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_fontbrowser_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_fontbrowser_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_selectionmodelinspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_selectionmodelinspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_selectionmodelinspector_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_selectionmodelinspector_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_statemachineviewer_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_statemachineviewer.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_statemachineviewer_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_statemachineviewer_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_timertop_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_timertop.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_timertop_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_timertop_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_actioninspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_actioninspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_widgetinspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_widgetinspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_sceneinspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_sceneinspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_styleinspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_styleinspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_scriptenginedebugger_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_scriptenginedebugger.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_webinspector_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_webinspector.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_webinspector_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_webinspector_ui.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/styles/ + +%files kde4-plugins +%defattr(-,root,root) +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_kjobtracker_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_kjobtracker.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_kjobtracker_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_kjobtracker_ui.desktop + + +%if 0%{?suse_version} >= 1220 || 0%{?fedora} >= 17 +%files vtk-plugins +%defattr(-,root,root) +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_objectvisualizer_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_objectvisualizer.desktop +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_objectvisualizer_ui_plugin.so +%{_libdir}/gammaray/%{rel}/%{abi}/gammaray_objectvisualizer_ui.desktop +%endif + +%files devel +%defattr(-,root,root) +%{_includedir}/gammaray +%{_libdir}/libgammaray_common-%{abi}.so +%{_libdir}/libgammaray_core-%{abi}.so +%{_libdir}/libgammaray_ui-%{abi}.so +%{_libdir}/cmake/GammaRay/ %changelog -* Fri Dec 21 2012 Allen Winter 1.2.2 -- Update to 1.2.2 release -* Thu Aug 16 2012 Allen Winter 1.2.1 -- Update to 1.2.1 release -* Tue Jul 05 2012 Allen Winter 1.2.0 -- Update to 1.2.0 release -* Tue Jul 03 2012 Allen Winter 1.1.99 -- Update to beta2 release -* Tue Jun 27 2012 Allen Winter 1.1.98 +* Fri Feb 28 2014 Allen Winter 2.0.1 + 2.0.1 final +* Fri Jan 17 2014 Allen Winter 2.0.0 + 2.0.0 final +* Sat Jan 11 2014 Allen Winter 1.9.96 + Second 2.0 beta release +* Fri Dec 20 2013 Allen Winter 1.9.95 + First 2.0 beta release +* Thu Oct 03 2013 Allen Winter 1.3.2 + Second 1.3 bugfix release +* Tue Apr 30 2013 Allen Winter 1.3.1 + First 1.3 bugfix release +* Sun Jan 27 2013 Allen Winter 1.3.0 + Update to latest release +* Wed Jun 27 2012 Allen Winter 1.1.98 - Rename version to use all integers * Tue Jun 26 2012 Allen Winter 1.2beta - Update to beta release diff -Nru gammaray-1.2.2/.gitignore gammaray-2.0.1/.gitignore --- gammaray-1.2.2/.gitignore 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/.gitignore 2014-02-28 19:07:57.000000000 +0000 @@ -7,7 +7,7 @@ .* CMakeLists.txt.user -# from git merge +# from kdiff3 *.BACKUP.* *.BASE.* *.LOCAL.* diff -Nru gammaray-1.2.2/hooking/abstractfunctionoverwriter.cpp gammaray-2.0.1/hooking/abstractfunctionoverwriter.cpp --- gammaray-1.2.2/hooking/abstractfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/abstractfunctionoverwriter.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,215 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "abstractfunctionoverwriter.h" +#include + +#ifdef ARCH_X86 +const long worstSizeForLongJump = 10; +#elif defined(ARCH_64) +const long worstSizeForLongJump = 14; +#else +# error "Unsupported hardware architecture!" +#endif + +using namespace GammaRay; + +bool AbstractFunctionOverwriter::writeShortJump(void *target, void *const func) +{ + quint8 *cur = (quint8 *) target; + + //E9 relative short jump is 5 bytes long + bool ret = unprotectMemory(page_align(target), roundToNextPage(5)); + + if (!ret) { + std::cerr << "Failed to unprotect memory: " << page_align(target) << std::endl; + return false; + } + + *cur = 0xE9; + cur++; + *reinterpret_cast(cur) = reinterpret_cast(func) - reinterpret_cast(cur + 4); + + ret = reprotectMemory(page_align(target), roundToNextPage(5)); + + if (!ret) { + std::cerr << "Failed to reprotect memory: " << page_align(target) << std::endl; + return false; + } + + return true; +} + +bool AbstractFunctionOverwriter::writeLongJump(void *target, void *const func) +{ + quint8 *cur = (quint8 *) target; + + bool ret = unprotectMemory(page_align(target), roundToNextPage(worstSizeForLongJump)); + + if (!ret) { + std::cerr << "Failed to unprotect memory: " << page_align(target) << std::endl; + return false; + } + + *cur = 0xff; + *(++cur) = 0x25; + +#ifdef ARCH_X86 + *reinterpret_cast(++cur) = reinterpret_cast(cur) + sizeof (quint32); + cur += sizeof (quint32); + *reinterpret_cast(cur) = reinterpret_cast(func); +#elif defined(ARCH_64) + *reinterpret_cast(++cur) = 0; + cur += sizeof (quint32); + *reinterpret_cast(cur) = reinterpret_cast(func); +#else +# error "Unsupported hardware architecture!" +#endif + + ret = reprotectMemory(page_align(target), roundToNextPage(worstSizeForLongJump)); + + if (!ret) { + std::cerr << "Failed to reprotect memory: " << page_align(target) << std::endl; + return false; + } + + return true; +} + +void *AbstractFunctionOverwriter::getMemoryNearAddress(void *const addr, size_t size) +{ + Q_ASSERT(blocksize() > size); + +#if defined(ARCH_64) + intptr_t minAddr; + intptr_t maxAddr; + + getAddressRange(minAddr, maxAddr); + + minAddr = std::max(minAddr, reinterpret_cast(addr) - 0x20000000); + maxAddr = std::min(maxAddr, reinterpret_cast(addr) + 0x20000000); +#endif + + for (QList::Iterator it = memoryPool.begin(); it != memoryPool.end(); ++it) { + if (it->free >= size) { +#if defined(ARCH_64) + if (!((intptr_t)it->mem > minAddr && (intptr_t)it->mem < maxAddr)) { + continue; + } +#endif + quint8 *mem = (quint8 *)it->mem + (it->size - it->free); + it->free -= size; + return mem; + } + } + + void *mem = 0; +#ifdef ARCH_X86 + Q_UNUSED(addr); + mem = reserveMemory(0, blocksize()); +#elif defined(ARCH_64) + intptr_t min = minAddr / blocksize(); + intptr_t max = maxAddr / blocksize(); + int rel = 0; + for (int i = 0; i < (max - min + 1); ++i) { + rel = -rel + (i & 1); + void* query = reinterpret_cast(((min + max) / 2 + rel) * blocksize()); + + Q_ASSERT(!((size_t)query & (pagesize() - 1))); + + if (isMemoryFree(query, blocksize())) { + mem = reserveMemory(query, blocksize()); + if (mem != 0 && + reinterpret_cast(mem) > minAddr && + reinterpret_cast(mem) < maxAddr) { + break; + } + } + } +#else +#error "Unsupported hardware architecture!" +#endif + if (!mem) { + std::cerr << "Error could not find memory close to: " << addr << std::endl; + return 0; + } + if (!commitMemory(mem, blocksize())) { + return 0; + } + MemorySegment memSegment; + memSegment.mem = mem; + memSegment.size = blocksize(); + memSegment.free = blocksize() - size; + memoryPool.append(memSegment); + return mem; +} + +void *AbstractFunctionOverwriter::createTrampoline(void *const func, void *const replacement) +{ + void *mem = getMemoryNearAddress(func, worstSizeForLongJump); + if (!mem) { + return 0; + } + bool ret = writeLongJump(mem, replacement); + if (!ret) { + return 0; + } + return mem; +} + +AbstractFunctionOverwriter::~AbstractFunctionOverwriter() +{ +} + +bool AbstractFunctionOverwriter::overwriteFunction(const QString &orignalFunc, + void * const replacementFunc) +{ + void *func = qtCoreFunctionLookup(orignalFunc); + if (!func) { + std::cerr << "Failed to lookup: " << orignalFunc.toLatin1().data() << std::endl; + return false; + } + void *mem = createTrampoline(func, replacementFunc); + if (!mem) { + return false; + } + + bool ret = writeShortJump(func, mem); + + return ret; +} + +void *AbstractFunctionOverwriter::page_align(void *addr) const +{ + Q_ASSERT(addr != 0); + return (void *)((size_t)addr & ~(pagesize() - 1)); +} + +size_t AbstractFunctionOverwriter::roundToNextPage(size_t addr) const +{ + Q_ASSERT(addr != 0); + return (size_t)page_align((void*)(addr + (pagesize() - 1))); +} + +size_t GammaRay::AbstractFunctionOverwriter::blocksize() +{ + return roundToNextPage(std::max((worstSizeForLongJump * 4), pagesize())); +} diff -Nru gammaray-1.2.2/hooking/abstractfunctionoverwriter.h gammaray-2.0.1/hooking/abstractfunctionoverwriter.h --- gammaray-1.2.2/hooking/abstractfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/abstractfunctionoverwriter.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,157 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ABSTRACTFUNCTIONOVERWRITER_H +#define GAMMARAY_ABSTRACTFUNCTIONOVERWRITER_H + +#include "config-gammaray.h" + +#include +#include + +#define __STDC_LIMIT_MACROS +#if defined(HAVE_STDINT_H) +#include +#endif + +#if defined(_M_X64) || defined(__amd64) || defined(__x86_64) +#define ARCH_64 +#elif defined(_M_IX86) || defined(__i386__) +#define ARCH_X86 +#endif + +namespace GammaRay { + +class AbstractFunctionOverwriter +{ + public: + virtual ~AbstractFunctionOverwriter(); + + /** + * Overwrites a given Qt Core 4 function with a replacement function. + * @param orignalFunc original Qt Core 4 function + * @param replacementFunc replacement function + */ + bool overwriteFunction(const QString &orignalFunc, + void * const replacementFunc); + + protected: + /** + * Unprotects a memory region so that the memory can get written + * @param mem start address of the memory that should be unprotected + * @param size size of the memory region + */ + virtual bool unprotectMemory(void *mem, size_t size) = 0; + + /** + * Restore the protection of the memory region that has been + * unproteced before with unprotectMemory + * @param mem start address of the memory that should be protected + * @param size size of the memory region + */ + virtual bool reprotectMemory(void *mem, size_t size) = 0; + + /** + * Writes a short jump at a given target to jump to a function. + * NOTE: A short jump takes 5 bytes, so make sure these 5 bytes + * can be written. + * @param target position where the jump should be written to + * @param size size of the memory region + */ + virtual bool writeShortJump(void *target, void * const func); + + /** + * Writes a long jump at a given target to jump to a function. + * NOTE: A short jump takes 10 bytes for x86 and 14 bytes for x64, + * so make sure these 5 bytes can be written. + * @param target position where the jump should be written to + * @param size size of the memory region + */ + virtual bool writeLongJump(void *target, void * const func); + + /** + * Get memory close to a target address. + * @param addr position that should the memory be close to + * @param size size of the memory region + */ + virtual void *getMemoryNearAddress(void * const addr, size_t size); + + /** + * Creates a tranpoline function close to another function. + * @param func function that the tranpoline should be close to + * @param replacement function that the trampoline should point to + */ + virtual void *createTrampoline(void * const func, void * const replacement); + + /** + * Get address range in which the program resists. + * @param min min address + * @param max max address + */ + virtual bool getAddressRange(intptr_t &min, intptr_t &max) = 0; + + /** + * Check if the memory region is not already taken. + * @param mem start address + * @param size size of the memory region + */ + virtual bool isMemoryFree(void * const mem, size_t size) = 0; + + /** + * Allocate memory at the griven position + * @param mem start address + * @param size size of the memory region + */ + virtual void *reserveMemory(void *mem, size_t size) = 0; + + /** + * Commit memory at the griven position + * @param mem start address + * @param size size of the memory region + */ + virtual bool commitMemory(void *mem, size_t size) = 0; + + /** + * Lookup function address of a given Qt Core 4 function. + * @param function function name + */ + virtual void *qtCoreFunctionLookup(const QString &function) = 0; + + virtual long pagesize() const = 0; + + virtual size_t blocksize(); + + private: + void *page_align(void *addr) const; + size_t roundToNextPage(size_t addr) const; + + struct MemorySegment { + void *mem; + size_t size; + size_t free; + }; + + QList memoryPool; +}; + +} + +#endif // ABSTRACTFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/hooking/CMakeLists.txt gammaray-2.0.1/hooking/CMakeLists.txt --- gammaray-1.2.2/hooking/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,34 @@ +set(gammaray_probe_srcs + probecreator.cpp + hooks.cpp +) + +if(WIN32 OR APPLE) + set(gammaray_probe_srcs + ${gammaray_probe_srcs} + abstractfunctionoverwriter.cpp + functionoverwriterfactory.cpp + winfunctionoverwriter.cpp + unixfunctionoverwriter.cpp + ) +endif() + +# probe lib +if(APPLE) # DYLD_INSERT_LIBRARIES only works with real shared libraries, not modules + add_library(gammaray_probe SHARED ${gammaray_probe_srcs}) +else() + add_library(gammaray_probe MODULE ${gammaray_probe_srcs}) +endif() +target_link_libraries(gammaray_probe + gammaray_core +) + +if(NOT WIN32 AND NOT QNXNTO) + target_link_libraries(gammaray_probe dl) +endif() + +set_target_properties(gammaray_probe PROPERTIES + PREFIX "" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}" +) +install(TARGETS gammaray_probe DESTINATION ${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}/) diff -Nru gammaray-1.2.2/hooking/functionoverwriterfactory.cpp gammaray-2.0.1/hooking/functionoverwriterfactory.cpp --- gammaray-1.2.2/hooking/functionoverwriterfactory.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/functionoverwriterfactory.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "functionoverwriterfactory.h" +#include "winfunctionoverwriter.h" +#include "unixfunctionoverwriter.h" + +using namespace GammaRay; + +AbstractFunctionOverwriter *FunctionOverwriterFactory::createFunctionOverwriter() +{ + static AbstractFunctionOverwriter *overwriter = 0; + +#ifdef Q_OS_WIN + if (!overwriter) { + overwriter = new WinFunctionOverwriter(); + } +#else + if (!overwriter) { + overwriter = new UnixFunctionOverwriter(); + } +#endif + return overwriter; +} diff -Nru gammaray-1.2.2/hooking/functionoverwriterfactory.h gammaray-2.0.1/hooking/functionoverwriterfactory.h --- gammaray-1.2.2/hooking/functionoverwriterfactory.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/functionoverwriterfactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_FUNCTIONOVERWRITERFACTORY_H +#define GAMMARAY_FUNCTIONOVERWRITERFACTORY_H + +#include "abstractfunctionoverwriter.h" + +namespace GammaRay { + +class FunctionOverwriterFactory +{ + public: + static AbstractFunctionOverwriter *createFunctionOverwriter(); + + private: + FunctionOverwriterFactory() + { + } +}; + +} + +#endif // FUNCTIONOVERWRITERFACTORY_H diff -Nru gammaray-1.2.2/hooking/hooks.cpp gammaray-2.0.1/hooking/hooks.cpp --- gammaray-1.2.2/hooking/hooks.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/hooks.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,196 @@ +/* + hooks.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "core/probe.h" +#include "functionoverwriterfactory.h" +#include "probecreator.h" + +#include + +#ifndef Q_OS_WIN +#include +#else +#include +#endif + +#include +#include + +#ifdef Q_OS_MAC +#include +#include +#include +#include +#include +#endif + +#define IF_DEBUG(x) + +using namespace GammaRay; + +bool functionsOverwritten = false; + +extern "C" Q_DECL_EXPORT void qt_startup_hook() +{ + Probe::startupHookReceived(); + + new ProbeCreator(ProbeCreator::CreateOnly); +#if !defined Q_OS_WIN && !defined Q_OS_MAC + if (!functionsOverwritten) { + static void(*next_qt_startup_hook)() = (void (*)()) dlsym(RTLD_NEXT, "qt_startup_hook"); + next_qt_startup_hook(); + } +#endif +} + +extern "C" Q_DECL_EXPORT void qt_addObject(QObject *obj) +{ + Probe::objectAdded(obj, true); + +#if !defined Q_OS_WIN && !defined Q_OS_MAC + if (!functionsOverwritten) { + static void (*next_qt_addObject)(QObject *obj) = + (void (*)(QObject *obj)) dlsym(RTLD_NEXT, "qt_addObject"); + next_qt_addObject(obj); + } +#endif +} + +extern "C" Q_DECL_EXPORT void qt_removeObject(QObject *obj) +{ + Probe::objectRemoved(obj); + +#if !defined Q_OS_WIN && !defined Q_OS_MAC + if (!functionsOverwritten) { + static void (*next_qt_removeObject)(QObject *obj) = + (void (*)(QObject *obj)) dlsym(RTLD_NEXT, "qt_removeObject"); + next_qt_removeObject(obj); + } +#endif +} + +#ifndef GAMMARAY_UNKNOWN_CXX_MANGLED_NAMES +#ifndef Q_OS_WIN +Q_DECL_EXPORT const char *qFlagLocation(const char *method) +#else +Q_DECL_EXPORT const char *myFlagLocation(const char *method) +#endif +{ + SignalSlotsLocationStore::flagLocation(method); + +#ifndef Q_OS_WIN + static const char *(*next_qFlagLocation)(const char *method) = + (const char * (*)(const char *method)) dlsym(RTLD_NEXT, "_Z13qFlagLocationPKc"); + + Q_ASSERT_X(next_qFlagLocation, "", + "Recompile with GAMMARAY_UNKNOWN_CXX_MANGLED_NAMES enabled, " + "your compiler uses an unsupported C++ name mangling scheme"); + return next_qFlagLocation(method); +#else + return method; +#endif +} +#endif + +#if defined(Q_OS_WIN) || defined(Q_OS_MAC) +void overwriteQtFunctions() +{ + functionsOverwritten = true; + AbstractFunctionOverwriter *overwriter = FunctionOverwriterFactory::createFunctionOverwriter(); + + overwriter->overwriteFunction(QLatin1String("qt_startup_hook"), (void*)qt_startup_hook); + overwriter->overwriteFunction(QLatin1String("qt_addObject"), (void*)qt_addObject); + overwriter->overwriteFunction(QLatin1String("qt_removeObject"), (void*)qt_removeObject); +#if defined(Q_OS_WIN) +#ifdef ARCH_64 +#ifdef __MINGW32__ + overwriter->overwriteFunction( + QLatin1String("_Z13qFlagLocationPKc"), (void*)myFlagLocation); +#else + overwriter->overwriteFunction( + QLatin1String("?qFlagLocation@@YAPEBDPEBD@Z"), (void*)myFlagLocation); +#endif +#else +# ifdef __MINGW32__ + overwriter->overwriteFunction( + QLatin1String("_Z13qFlagLocationPKc"), (void*)myFlagLocation); +# else + overwriter->overwriteFunction( + QLatin1String("?qFlagLocation@@YAPBDPBD@Z"), (void*)myFlagLocation); +# endif +#endif +#endif +} +#endif + +#ifdef Q_OS_WIN +extern "C" Q_DECL_EXPORT void gammaray_probe_inject(); + +extern "C" BOOL WINAPI DllMain(HINSTANCE/*hInstance*/, DWORD dwReason, LPVOID/*lpvReserved*/) +{ + switch(dwReason) { + case DLL_THREAD_ATTACH: + { + if (!functionsOverwritten) { + overwriteQtFunctions(); + } + if (!Probe::isInitialized()) { + gammaray_probe_inject(); + } + break; + } + case DLL_PROCESS_DETACH: + { + //Unloading does not work, because we overwrite existing code + exit(-1); + break; + } + }; + return TRUE; //krazy:exclude=captruefalse +} +#endif + +extern "C" Q_DECL_EXPORT void gammaray_probe_inject() +{ + if (!qApp) { + return; + } + printf("gammaray_probe_inject()\n"); + // make it possible to re-attach + new ProbeCreator(ProbeCreator::CreateAndFindExisting); +} + +#ifdef Q_OS_MAC +// we need a way to execute some code upon load, so let's abuse +// static initialization +class HitMeBabyOneMoreTime +{ + public: + HitMeBabyOneMoreTime() + { + overwriteQtFunctions(); + } + +}; +static HitMeBabyOneMoreTime britney; +#endif diff -Nru gammaray-1.2.2/hooking/probecreator.cpp gammaray-2.0.1/hooking/probecreator.cpp --- gammaray-1.2.2/hooking/probecreator.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/probecreator.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,80 @@ +/* + probecreator.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "probecreator.h" + +#include +#include + +#include +#include +#include +#include + +#include + +#define IF_DEBUG(x) + +using namespace GammaRay; +using namespace std; + +ProbeCreator::ProbeCreator(Type type) + : m_type(type) +{ + //push object into the main thread, as windows creates a + //different thread where this runs in + moveToThread(QCoreApplication::instance()->thread()); + // delay to foreground thread + QMetaObject::invokeMethod(this, "createProbe", Qt::QueuedConnection); + + // don't propagate the probe to child processes + if (qgetenv("GAMMARAY_UNSET_PRELOAD") == "1") { + qputenv("LD_PRELOAD", ""); + } + if (qgetenv("GAMMARAY_UNSET_DYLD") == "1") { + qputenv("DYLD_INSERT_LIBRARIES", ""); + qputenv("DYLD_FORCE_FLAT_NAMESPACE", ""); + } + + // HACK the webinspector plugin does this as well, but if the web view is created + // too early the env var from there isn't going to reach the web process + qputenv("QTWEBKIT_INSPECTOR_SERVER", "0.0.0.0:" + QByteArray::number(Endpoint::defaultPort() + 1)); +} + +void ProbeCreator::createProbe() +{ + // make sure we are in the ui thread + Q_ASSERT(QThread::currentThread() == qApp->thread()); + + if (!qApp || Probe::isInitialized()) { + // never create it twice + deleteLater(); + return; + } + + Probe::createProbe(m_type == GammaRay::ProbeCreator::CreateAndFindExisting); + Q_ASSERT(Probe::isInitialized()); + + deleteLater(); +} + diff -Nru gammaray-1.2.2/hooking/probecreator.h gammaray-2.0.1/hooking/probecreator.h --- gammaray-1.2.2/hooking/probecreator.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/probecreator.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + probecreator.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROBECREATOR_H +#define GAMMARAY_PROBECREATOR_H + +#include + +namespace GammaRay +{ + +/** + * Creates Probe instance in main thread and deletes self afterwards. + */ +class ProbeCreator : public QObject +{ + Q_OBJECT + public: + enum Type { + CreateOnly, + CreateAndFindExisting + }; + explicit ProbeCreator(Type t); + + private slots: + void createProbe(); + + private: + Type m_type; +}; + +} + +#endif // GAMMARAY_PROBECREATOR_H diff -Nru gammaray-1.2.2/hooking/unixfunctionoverwriter.cpp gammaray-2.0.1/hooking/unixfunctionoverwriter.cpp --- gammaray-1.2.2/hooking/unixfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/unixfunctionoverwriter.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,117 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "unixfunctionoverwriter.h" + +#if !defined(Q_OS_WIN) + +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace GammaRay; + +UnixFunctionOverwriter::UnixFunctionOverwriter() +{ + m_pagesize = sysconf(_SC_PAGESIZE); +} + +bool UnixFunctionOverwriter::unprotectMemory(void *mem, size_t size) +{ + Q_ASSERT(!((size_t)mem & (pagesize() - 1))); + Q_ASSERT(!((size_t)size & (pagesize() - 1))); + const bool writable = (mprotect(mem, size, PROT_READ|PROT_WRITE|PROT_EXEC) == 0); + Q_ASSERT(writable); + return writable; +} + +bool UnixFunctionOverwriter::reprotectMemory(void *mem, size_t size) +{ + Q_ASSERT(!((size_t)mem & (pagesize() - 1))); + Q_ASSERT(!((size_t)size & (pagesize() - 1))); + const bool readOnly = (mprotect(mem, size, PROT_READ|PROT_EXEC) == 0); + Q_ASSERT(readOnly); + return readOnly; +} + +bool UnixFunctionOverwriter::getAddressRange(intptr_t &min, intptr_t &max) +{ + min = INTPTR_MIN; + max = INTPTR_MAX; + + return true; +} + +bool UnixFunctionOverwriter::isMemoryFree(void * const mem, size_t size) +{ + Q_ASSERT(!((size_t)mem & (pagesize() - 1))); + Q_ASSERT(!((size_t)size & (pagesize() - 1))); + Q_UNUSED(mem); + Q_UNUSED(size); + + //under unix there is no easy way to find out if a region is free or not + + return true; +} + +void *UnixFunctionOverwriter::reserveMemory(void *mem, size_t size) +{ + Q_ASSERT(!((size_t)mem & (pagesize() - 1))); + Q_ASSERT(!((size_t)size & (pagesize() - 1))); + + // reserve a memory region with a hint and hope that it is close to the other address + void *retmem = mmap(mem, size, PROT_READ|PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); + + if (retmem == MAP_FAILED) { + return 0; + } + + return retmem; +} + +bool UnixFunctionOverwriter::commitMemory(void *mem, size_t size) +{ + Q_ASSERT(!((size_t)mem & (pagesize() - 1))); + Q_ASSERT(!((size_t)size & (pagesize() - 1))); + Q_UNUSED(mem); + Q_UNUSED(size); + + //under unix we don't have a commit + return true; +} + +void *UnixFunctionOverwriter::qtCoreFunctionLookup(const QString &function) +{ + return dlsym(RTLD_NEXT, function.toLatin1()); +} + +long GammaRay::UnixFunctionOverwriter::pagesize() const +{ + return m_pagesize; +} + +#endif // Q_OS_WIN diff -Nru gammaray-1.2.2/hooking/unixfunctionoverwriter.h gammaray-2.0.1/hooking/unixfunctionoverwriter.h --- gammaray-1.2.2/hooking/unixfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/unixfunctionoverwriter.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_UNIXFUNCTIONOVERWRITER_H +#define GAMMARAY_UNIXFUNCTIONOVERWRITER_H + +#include + +#if !defined(Q_OS_WIN) + +#include "abstractfunctionoverwriter.h" + +namespace GammaRay { + +class UnixFunctionOverwriter : public AbstractFunctionOverwriter +{ + protected: + virtual bool unprotectMemory(void *mem, size_t size); + virtual bool reprotectMemory(void *mem, size_t size); + + virtual bool getAddressRange(intptr_t &min, intptr_t &max); + + virtual bool isMemoryFree(void * const mem, size_t size); + virtual void *reserveMemory(void *mem, size_t size); + virtual bool commitMemory(void *mem, size_t size); + + virtual void *qtCoreFunctionLookup(const QString &function); + virtual long pagesize() const; + + private: + UnixFunctionOverwriter(); + + long m_pagesize; + + friend class FunctionOverwriterFactory; +}; + +} + +#endif // !Q_OS_WIN + +#endif // UNIXFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/hooking/winfunctionoverwriter.cpp gammaray-2.0.1/hooking/winfunctionoverwriter.cpp --- gammaray-1.2.2/hooking/winfunctionoverwriter.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/winfunctionoverwriter.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,122 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +//krazy:excludeall=null since the WinAPI likes to use NULL + +#include "winfunctionoverwriter.h" + +#ifdef Q_OS_WIN + +#include + +using namespace std; +using namespace GammaRay; + +WinFunctionOverwriter::WinFunctionOverwriter():oldProtect(0) +{ +} + +bool WinFunctionOverwriter::unprotectMemory(void *mem, size_t size) +{ + BOOL ret = VirtualProtect(mem, size, PAGE_EXECUTE_READWRITE, &oldProtect); + return ret; +} + +bool WinFunctionOverwriter::reprotectMemory(void *mem, size_t size) +{ + BOOL ret = VirtualProtect(mem, size, oldProtect, &oldProtect); + return ret; +} + +bool WinFunctionOverwriter::getAddressRange(intptr_t &min, intptr_t &max) +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + + min = reinterpret_cast(si.lpMinimumApplicationAddress); + max = reinterpret_cast(si.lpMaximumApplicationAddress); + + return true; +} + +bool WinFunctionOverwriter::isMemoryFree(void * const mem, size_t size) +{ + Q_UNUSED(size); + MEMORY_BASIC_INFORMATION mi; + ZeroMemory(&mi, sizeof(MEMORY_BASIC_INFORMATION)); + + VirtualQuery(mem, &mi, sizeof(mi)); + if (mi.State != MEM_FREE) { + return false; + } + + return true; +} + +void *WinFunctionOverwriter::reserveMemory(void *mem, size_t size) +{ + void *retmem = 0; + + retmem = VirtualAlloc(mem, size, MEM_RESERVE, PAGE_EXECUTE_READ); + + return retmem; +} + +bool WinFunctionOverwriter::commitMemory(void *mem, size_t size) +{ + void *retmem = 0; + + retmem = VirtualAlloc(mem, size, MEM_COMMIT, PAGE_EXECUTE_READ); + + return retmem != 0; +} + +void *WinFunctionOverwriter::qtCoreFunctionLookup(const QString &function) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + static HMODULE qtCoreDllHandle = GetModuleHandle(L"QtCore4"); + if (qtCoreDllHandle == NULL) { + qtCoreDllHandle = GetModuleHandle(L"QtCored4"); + } +#else + static HMODULE qtCoreDllHandle = GetModuleHandle(L"Qt5Core"); + if (qtCoreDllHandle == NULL) { + qtCoreDllHandle = GetModuleHandle(L"Qt5Cored"); + } +#endif + + if (qtCoreDllHandle == NULL) { + cerr << "no handle for QtCore found!" << endl; + return 0; + } + + FARPROC qtfuncaddr = GetProcAddress(qtCoreDllHandle, function.toLatin1()); + + return (void*)qtfuncaddr; +} + +long WinFunctionOverwriter::pagesize() const +{ + SYSTEM_INFO si; + GetSystemInfo(&si); + return si.dwPageSize; +} + +#endif // Q_OS_WIN diff -Nru gammaray-1.2.2/hooking/winfunctionoverwriter.h gammaray-2.0.1/hooking/winfunctionoverwriter.h --- gammaray-1.2.2/hooking/winfunctionoverwriter.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/hooking/winfunctionoverwriter.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Andreas Holzammer + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WINFUNCTIONOVERWRITER_H +#define GAMMARAY_WINFUNCTIONOVERWRITER_H + +#include + +#ifdef Q_OS_WIN + +#include "abstractfunctionoverwriter.h" +#include + +namespace GammaRay { + +class WinFunctionOverwriter : public AbstractFunctionOverwriter +{ + protected: + virtual bool unprotectMemory(void *mem, size_t size); + virtual bool reprotectMemory(void *mem, size_t size); + + virtual bool getAddressRange(intptr_t &min, intptr_t &max); + + virtual bool isMemoryFree(void * const mem, size_t size); + virtual void *reserveMemory(void *mem, size_t size); + virtual bool commitMemory(void *mem, size_t size); + + virtual void *qtCoreFunctionLookup(const QString &function); + virtual long pagesize() const; + + private: + WinFunctionOverwriter(); + DWORD oldProtect; + + friend class FunctionOverwriterFactory; +}; + +} + +#endif // Q_OS_WIN + +#endif // WINFUNCTIONOVERWRITER_H diff -Nru gammaray-1.2.2/images/footer.html gammaray-2.0.1/images/footer.html --- gammaray-1.2.2/images/footer.html 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/images/footer.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,19 +0,0 @@ -
-
- - Klarälvdalens Datakonsult AB (KDAB) -
- "The Cross-Platform Experts"
- http://www.kdab.com/ -
- -
- - GammaRay -
- Qt-application inspection and manipulation tool
- http://www.kdab.com/kdab-products/gammaray/ -
- - - Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/images/kdab-gammaray-logo-16x16.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/images/kdab-gammaray-logo-16x16.png differ Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/images/kdab-logo-16x16.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/images/kdab-logo-16x16.png differ diff -Nru gammaray-1.2.2/include/CMakeLists.txt gammaray-2.0.1/include/CMakeLists.txt --- gammaray-1.2.2/include/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -set(GAMMARAY_HEADERS - metatypedeclarations.h - objectmodel.h - objectmodelbase.h - objecttypefilterproxymodel.h - probeinterface.h - singlecolumnobjectproxymodel.h - toolfactory.h - util.h -) - -install(FILES ${GAMMARAY_HEADERS} DESTINATION include/gammaray/) diff -Nru gammaray-1.2.2/include/gammaray_export.h gammaray-2.0.1/include/gammaray_export.h --- gammaray-1.2.2/include/gammaray_export.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/gammaray_export.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,40 +0,0 @@ -/* - gammaray_export.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_EXPORT_H -#define GAMMARAY_EXPORT_H - -#include - -#ifdef GAMMARAY_STATICLIB -# undef GAMMARAY_SHAREDLIB -# define GAMMARAY_EXPORT -#else -# ifdef MAKE_GAMMARAY_LIB -# define GAMMARAY_EXPORT Q_DECL_EXPORT -# else -# define GAMMARAY_EXPORT Q_DECL_IMPORT -# endif -#endif - -#endif /* GAMMARAY_EXPORT_H */ diff -Nru gammaray-1.2.2/include/Mainpage.dox gammaray-2.0.1/include/Mainpage.dox --- gammaray-1.2.2/include/Mainpage.dox 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/Mainpage.dox 1970-01-01 00:00:00.000000000 +0000 @@ -1,97 +0,0 @@ -/*! - * @mainpage GammaRay - Qt-application inspection and manipulation tool. - * - * @section about About - * - * GammaRay is a tool to poke around in a Qt-application and also - * to manipulate the application to some extent. GammaRay uses various DLL - * injection techniques to hook into an application at runtime and provide - * access to a lot of interesting information. - * - * @section plugins Plugins - * - * Starting with version 1.2, GammaRay provides the ability to write your - * own plugins. This documentation describes the API for doing just that. - * - * @section features Features - * - * GammaRay can: - * - * * Browse the QObject tree with live updates. - * - * * View, and to some extent, edit QObject static and dynamic properties. - * - * * View and call slots of a QObject (similar to qdbusviewer). - * - * * View other QObject elements such as signals, enums and class information - * introspectively. - * - * * List all QObject inbound and outbound signal/slot connections. - * - * * Provide live widget preview. Useful for finding layout issues). - * - * * View the content of any QAbstractItemModel (QAIM). Very useful when - * debugging a proxy model chain for example. - * - * * Browse the QAbstractProxyModel (QAPM) hierarchy. - * - * * Browse the QGraphicsView (QGV) item tree of any QGV scene. - * - * * Show a live preview of QGV items, including showing their coordinate system, - * transformation origin, rotate/zoom/pan, etc. - * - * * Act as a complete java script debugger, attachable to any QScriptEngine - * (including the usually not accessible one used by QML internally). - * - * * Perform HTML/CSS/DOM/JS introspection/editing/profiling on any QWebPage, - * thanks to QWebInspector. - * - * * Browse the QResource tree and its content. - * - * * Browse QStateMachines, along with their states and transitions. - * - * * Show all registered meta types. - * - * * Show all installed fonts. - * - * * Show all available codecs. - * - * * Browse all QTextDocuments, along with the ability to edit them and view - * their internal structures. - * - * * Show all QTimers and their statistics (number of wakeups, wakeup time, ...) - * - * Head Engineer for GammaRay is Volker Krause \ - * \image html kdab-gammaray-logo-16x16.png - * - * @section license License - * - * Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, \ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @section about-KDAB About KDAB - * - * GammaRay is supported and maintained by Klarälvdalens Datakonsult AB (KDAB) - * - * KDAB, the Qt experts, provide consulting and mentoring for developing - * Qt applications from scratch and in porting from all popular and legacy - * frameworks to Qt. Our software products increase Qt productivity and our - * Qt trainers have trained 50% of commercial Qt developers globally. - * - * Please visit http://www.kdab.com to meet the people who write code like this. - * We also offer Qt training courses. - * \image html kdab-logo-16x16.png - */ diff -Nru gammaray-1.2.2/include/metatypedeclarations.h gammaray-2.0.1/include/metatypedeclarations.h --- gammaray-1.2.2/include/metatypedeclarations.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/metatypedeclarations.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -/* - metatypedeclarations.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares the various metatypes. - - @brief - Declares the various metatypes. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_METATYPEDECLARATIONS_H -#define GAMMARAY_METATYPEDECLARATIONS_H - -#include -#include -#include -#include - -Q_DECLARE_METATYPE(Qt::FillRule) -Q_DECLARE_METATYPE(Qt::InputMethodHints) -Q_DECLARE_METATYPE(Qt::MouseButtons) -Q_DECLARE_METATYPE(Qt::TransformationMode) -Q_DECLARE_METATYPE(QGraphicsEffect *) -Q_DECLARE_METATYPE(QGraphicsItemGroup *) -Q_DECLARE_METATYPE(QGraphicsObject *) -Q_DECLARE_METATYPE(QGraphicsWidget *) -Q_DECLARE_METATYPE(QGraphicsItem::CacheMode) -Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags) -Q_DECLARE_METATYPE(QGraphicsItem::PanelModality) -Q_DECLARE_METATYPE(QGraphicsPixmapItem::ShapeMode) -Q_DECLARE_METATYPE(QPainterPath) -Q_DECLARE_METATYPE(QPolygonF) -Q_DECLARE_METATYPE(const QStyle *) - -#endif diff -Nru gammaray-1.2.2/include/objectmodelbase.h gammaray-2.0.1/include/objectmodelbase.h --- gammaray-1.2.2/include/objectmodelbase.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/objectmodelbase.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,132 +0,0 @@ -/* - objectmodelbase.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares a template for an ObjectModelBase class. - - @brief - Declares a template for an ObjectModelBase class. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_OBJECTMODELBASE_H -#define GAMMARAY_OBJECTMODELBASE_H - -#include "util.h" -#include "objectmodel.h" - -#include -#include - -namespace GammaRay { - -/** - * @brief A container for a generic Object Model derived from some Base. - */ -template -class ObjectModelBase : public Base -{ - public: - /** - * Constructor. - * @param parent is the parent object for this instance. - */ - explicit ObjectModelBase(QObject *parent) : Base(parent) {} - - /** - * Returns the number of columns in the specified model (currently this is - * always 2). - * @param parent is the model QModelIndex. - * @return the column count for specified model. - */ - int columnCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return 2; - } - - /** - * Returns the data for the specified object. - * @param object is a pointer to a QObject. - * @param index is the model QModelIndex. - * @param role is the Qt role. - * - * @return on success, a QVariant containing the data for the specified QObject; - * QVariant() if some anamoly occurs. - */ - QVariant dataForObject(QObject *object, const QModelIndex &index, int role) const - { - if (role == Qt::DisplayRole) { - if (index.column() == 0) { - return - object->objectName().isEmpty() ? - Util::addressToString(object) : - object->objectName(); - } else if (index.column() == 1) { - return object->metaObject()->className(); - } - } else if (role == ObjectModel::ObjectRole) { - return QVariant::fromValue(object); - } else if (role == Qt::ToolTipRole) { - return - QString("Object name: %1\nParent: %2 (Address: %3)\nNumber of children: %4"). - arg(object->objectName().isEmpty() ? "" : object->objectName()). - arg(object->parent() ? object->parent()->metaObject()->className() : ""). - arg(Util::addressToString(object->parent())). - arg(object->children().size()); - } else if (role == Qt::DecorationRole && index.column() == 0) { - return Util::iconForObject(object); - } - - return QVariant(); - } - - /** - * Returns the header data for the Object, given a section (column), - * orientation and role. - * @param section an integer (either 0 or 1) corresponding to the section (column). - * @param orientation is the Qt::Orientation. - * @param role is the Qt role. - * - * @return on success, a QVariant containing the header data; - * QVariant() if some anamoly occurs. - * - */ - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const - { - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - switch (section) { - case 0: - return QObject::tr("Object"); - case 1: - return QObject::tr("Type"); - } - } - return Base::headerData(section, orientation, role); - } -}; - -} - -#endif diff -Nru gammaray-1.2.2/include/objectmodel.h gammaray-2.0.1/include/objectmodel.h --- gammaray-1.2.2/include/objectmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/objectmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -/* - objectmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares the public object model roles. - - @brief - Declares the public object model roles. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_OBJECTMODEL_H -#define GAMMARAY_OBJECTMODEL_H - -#include - -namespace GammaRay { - -/** - * @brief GammaRay Object Models. - * - * Public object model roles, for use by tool plugins without needing access - * to the real object model classes. - */ -namespace ObjectModel { - - /** Role enum, to be used with the object list and tree models. */ - enum Role { - ObjectRole = Qt::UserRole + 1, /**< the Object role */ - UserRole /**< the UserRole, as defined by Qt */ - }; -} - -} - -#endif diff -Nru gammaray-1.2.2/include/objecttypefilterproxymodel.h gammaray-2.0.1/include/objecttypefilterproxymodel.h --- gammaray-1.2.2/include/objecttypefilterproxymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/objecttypefilterproxymodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,112 +0,0 @@ -/* - objecttypefilterproxymodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares a template - for an ObjectTypeFilterProxyModel class. - - @brief - Declares a template for an ObjectTypeFilterProxyModel class. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H -#define GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H - -#include "objectmodelbase.h" - -#include - -namespace GammaRay { - -/** - * @brief A QSortFilterProxyModel for generic Objects. - */ -class ObjectFilterProxyModelBase : public QSortFilterProxyModel -{ - public: - /** - * Constructor. - * @param parent is the parent object for this instance. - */ - explicit ObjectFilterProxyModelBase(QObject *parent = 0) : QSortFilterProxyModel(parent) - { - setDynamicSortFilter(true); - } - - protected: - /** - * Determines if the item in the specified row can be included in the model. - * @param source_row is a non-zero integer representing the row of the item. - * @param source_parent is the parent QModelIndex for this model. - * @return true if the item in the row can be included in the model; - * otherwise returns false. - */ - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const - { - const QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent); - if (!source_index.isValid()) { - return false; - } - - QObject *obj = source_index.data(ObjectModel::ObjectRole).value(); - Q_ASSERT(obj); - if (!filterAcceptsObject(obj)) { - return false; - } - - return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); - } - - /** - * Determines if the specified QObject can be included in the model. - * @param object is a pointer to the QObject to test. - * @return true if the QObject can be included in the model; false otherwise. - */ - virtual bool filterAcceptsObject(QObject *object) const = 0; -}; - -/** - * @brief A templated generic ObjectFilterProxyModelBase for some data type. - */ -template -class ObjectTypeFilterProxyModel : public ObjectFilterProxyModelBase -{ - public: - /** - * Constructor. - * @param parent is the parent object for this instance. - */ - explicit ObjectTypeFilterProxyModel(QObject *parent = 0) - : ObjectFilterProxyModelBase(parent) {} - - protected: - virtual bool filterAcceptsObject(QObject *object) const { - return qobject_cast(object); - } -}; - -} - -#endif // GAMMARAY_OBJECTTYPEFILTERPROXYMODEL_H diff -Nru gammaray-1.2.2/include/probeinterface.h gammaray-2.0.1/include/probeinterface.h --- gammaray-1.2.2/include/probeinterface.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/probeinterface.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,91 +0,0 @@ -/* - probeinterface.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares the ProbeInterface abstract base class. - - @brief - Declares the ProbeInterface abstract base class. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_PROBEINTERFACE_H -#define GAMMARAY_PROBEINTERFACE_H - -class QObject; -class QAbstractItemModel; - -namespace GammaRay { - -/** - * @brief An abstract interface for accessing the core GammaRay probe. - * - * The ProbeInterface is an abstract interface that allows one to access - * the core GammaRay probe without linking to it. - */ -class ProbeInterface -{ - public: - virtual inline ~ProbeInterface() {} - - /** - * Returns the object list model. - * @return a pointer to a QAbstractItemModel instance. - */ - virtual QAbstractItemModel *objectListModel() const = 0; - - /** - * Returns the object tree model. - * @return a pointer to a QAbstractItemModel instance. - */ - virtual QAbstractItemModel *objectTreeModel() const = 0; - - /** - * Returns the connection model. - * @return a pointer to a QAbstractItemModel instance. - */ - virtual QAbstractItemModel *connectionModel() const = 0; - - /** - * Determines if the specified QObject belongs to the GammaRay Probe or Window. - * - * These objects should not be tracked or shown to the user, - * hence must be explictly filtered. - * @param object is a pointer to a QObject instance. - * - * @return true if the specified QObject belongs to the GammaRay Probe - * or Window; false otherwise. - */ - virtual bool filterObject(QObject *object) const = 0; - - /** - * Returns the probe QObject for connecting signals. - * @return a pointer to a QObject instance. - */ - virtual QObject *probe() const = 0; -}; - -} - -#endif diff -Nru gammaray-1.2.2/include/singlecolumnobjectproxymodel.h gammaray-2.0.1/include/singlecolumnobjectproxymodel.h --- gammaray-1.2.2/include/singlecolumnobjectproxymodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/singlecolumnobjectproxymodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,86 +0,0 @@ -/* - singlecolumnobjectproxymodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares the SingleColumnObjectProxyModel class. - - @brief - Declares the SingleColumnObjectProxyModel class. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H -#define GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H - -#include "objectmodel.h" -#include "util.h" - -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) -#include -typedef QSortFilterProxyModel QIdentityProxyModel; -#else -#include -#endif - -namespace GammaRay { - -/** - * @brief A QIdentityProxyModel for generic Objects. - */ -class SingleColumnObjectProxyModel : public QIdentityProxyModel -{ - public: - /** - * Constructor. - * @param parent is the parent object for this instance. - */ - explicit SingleColumnObjectProxyModel(QObject *parent = 0) - : QIdentityProxyModel(parent) - { - } - - /** - * Returns the data for the specified model. - * @param proxyIndex is a QModelIndex. - * @param role is a Qt role. - * - * @return on success, a QVariant containing the data; - * QVariant() if some anamoly occurs. - */ - QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const - { - if (proxyIndex.isValid() && role == Qt::DisplayRole && proxyIndex.column() == 0) { - const QObject *obj = proxyIndex.data(ObjectModel::ObjectRole).value(); - if (obj) { - return Util::displayString(obj); - } - } - - return QIdentityProxyModel::data(proxyIndex, role); - } -}; - -} - -#endif // GAMMARAY_SINGLECOLUMNOBJECTPROXYMODEL_H diff -Nru gammaray-1.2.2/include/toolfactory.h gammaray-2.0.1/include/toolfactory.h --- gammaray-1.2.2/include/toolfactory.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/toolfactory.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,128 +0,0 @@ -/* - toolfactory.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares the ToolFactory abstract base class. - - @brief - Declares the ToolFactory abstract base class. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_TOOLFACTORY_H -#define GAMMARAY_TOOLFACTORY_H - -#include -#include -#include - -namespace GammaRay { - -class ProbeInterface; - -/** - * @brief An abstract interface for probe tools. - * - * The ToolFactory class is an abstract base class for creating probe tools - * for GammaRay. Each tool must have a unique identifier. - */ -class ToolFactory -{ - public: - virtual inline ~ToolFactory() {} - - /** - * Unique id of this tool - * @return a QString containing the tool id. - */ - virtual QString id() const = 0; - - /** - * Human readable name of this tool. - * @return a QString containing the tool name. - */ - virtual QString name() const = 0; - - /** - * Class names of types this tool can handle. - * The tool will only be activated if an object of one of these types - * is seen in the probed application. - * @return a QStringList of class names of types this tool supports. - */ - virtual QStringList supportedTypes() const = 0; - - /** - * Initialize the tool. - * Implement this method to do non-GUI initialization, such as creating - * object tracking models etc. - * @param probe The probe interface allowing access to the object models. - */ - virtual void init(ProbeInterface *probe) = 0; - - /** - * Create the UI part of this tool. - * @param probe The probe interface allowing access to the object models. - * @param parentWidget The parent widget for the visual elements of this tool. - * @return a pointer to the created QwWidget. - */ - virtual QWidget *createWidget(ProbeInterface *probe, QWidget *parentWidget) = 0; -}; - -/** - * @brief A templated generic ToolFactory for some data type and Tool. - */ -template -class StandardToolFactory : public ToolFactory -{ - public: - virtual inline QStringList supportedTypes() const - { - return QStringList(Type::staticMetaObject.className()); - } - - virtual inline QString id() const - { - return Tool::staticMetaObject.className(); - } - - virtual inline void init(ProbeInterface *) - { - } - - virtual inline QWidget *createWidget(ProbeInterface *probe, QWidget *parentWidget) - { - return new Tool(probe, parentWidget); - } -}; - -} - -Q_DECLARE_INTERFACE(GammaRay::ToolFactory, "com.kdab.GammaRay.ToolFactory/1.0") -Q_DECLARE_METATYPE(GammaRay::ToolFactory *) - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -#define Q_PLUGIN_METADATA(x) -#endif - -#endif diff -Nru gammaray-1.2.2/include/util.h gammaray-2.0.1/include/util.h --- gammaray-1.2.2/include/util.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/include/util.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,148 +0,0 @@ -/* - util.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -/** - @file - This file is part of the GammaRay Plugin API and declares various utility - methods needed when writing a plugin. - - @brief - Declares various utility methods needed when writing a GammaRay plugin. - - @author Volker Krause \ -*/ - -#ifndef GAMMARAY_UTIL_H -#define GAMMARAY_UTIL_H - -#include "gammaray_export.h" - -#include -#include - -class QObject; - -namespace GammaRay { - -/** - * @brief GammaRay utilities. - */ -namespace Util { - - /** - * Returns a human readable string name of the specified QObject. - * @param object is a pointer to a valid QObject. - * - * @return a QString containing the human readable display string. - */ - GAMMARAY_EXPORT QString displayString(const QObject *object); - - /** - * Returns a human readable string version of the QVariant value. - * Converts to the variant type and prints the string value accordingly. - * @param value is a QVariant. - * - * @return a QString containing the human readable string. - */ - GAMMARAY_EXPORT QString variantToString(const QVariant &value); - - /** - * Returns a value representing @p value in a itemview decoration role. - * @param value is a QVariant. - * - * @return a QVariant itemview decoration role. - */ - GAMMARAY_EXPORT QVariant decorationForVariant(const QVariant &value); - - /** - * Returns a string version (as a hex number starting with "0x") of the - * memory address @p p. - * @param p is a pointer to an address in memory. - * - * @return a QString containing the human readable address string. - */ - GAMMARAY_EXPORT QString addressToString(const void *p); - - /** - * Returns a string version of the memory address @p p. The resulting string - * can be used as a unique identifier in GammaRay. - * @param p is a pointer to an address in memory. - * - * @return a QString containing the Uid. - */ - GAMMARAY_EXPORT QString addressToUid(const void *p); - - /** - * Translates an enum or flag value into a human readable text. - * @param value The numerical value. Type information from the QVariant - * are used to find the corresponding QMetaEnum. - * @param typeName Use this if the @p value has type int - * (e.g. the case for QMetaProperty::read). - * @param object Additional QObject to search for QMetaEnums. - * - * @return a QString containing the string version of the specified @p value. - */ - GAMMARAY_EXPORT QString enumToString(const QVariant &value, - const char *typeName = 0, - QObject *object = 0); - - /** - * Determines if the QObject @p obj is a descendant of the QObject @p ascendant. - * @param ascendant is a pointer to a QObject. - * @param object is a pointer to a QObject. - * - * @return true if @p obj is a descendant of @p ascendant; false otherwise. - */ - GAMMARAY_EXPORT bool descendantOf(const QObject *ascendant, const QObject *object); - - /** - * Finds the parent QObject of the specified type T, if such exists. - * @param object is a pointer to a QObject. - * - * @return zero on failure; else a pointer to a data type T. - * - */ - template - T *findParentOfType(QObject *object) { - if (!object) { - return 0; - } - if (qobject_cast(object)) { - return qobject_cast(object); - } - return findParentOfType(object->parent()); - } - - /** - * Returns an icon for the given object. In normal operation a QIcon is - * returned containing the icon most closely associated with the data type - * pointed to by @p object - * @param object is a pointer to a QObject. - * - * @return on failure QVariant() is returned; else a QIcon - */ - GAMMARAY_EXPORT QVariant iconForObject(QObject *object); -} - -} - -#endif // GAMMARAY_UTIL_H diff -Nru gammaray-1.2.2/inprocessui/CMakeLists.txt gammaray-2.0.1/inprocessui/CMakeLists.txt --- gammaray-1.2.2/inprocessui/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/inprocessui/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,7 @@ +add_library(gammaray_inprocessui MODULE main.cpp) +target_link_libraries(gammaray_inprocessui gammaray_core gammaray_ui_internal) +set_target_properties(gammaray_inprocessui PROPERTIES + PREFIX "" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}" +) +install(TARGETS gammaray_inprocessui DESTINATION ${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}) diff -Nru gammaray-1.2.2/inprocessui/main.cpp gammaray-2.0.1/inprocessui/main.cpp --- gammaray-1.2.2/inprocessui/main.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/inprocessui/main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +/* + main.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include +#include + + +extern "C" { + +void Q_DECL_EXPORT gammaray_create_inprocess_mainwindow() +{ + GammaRay::MainWindow *window = new GammaRay::MainWindow; + window->setAttribute(Qt::WA_DeleteOnClose); + GammaRay::Probe::instance()->setWindow(window); + GammaRay::Probe::instance()->setParent(window); + window->show(); +} + +} diff -Nru gammaray-1.2.2/Install.txt gammaray-2.0.1/Install.txt --- gammaray-1.2.2/Install.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/Install.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,5 +1,4 @@ GammaRay uses the CMake buildsystem. -You must have CMake version 2.8 or higher. Please see the comments at the top of CMakeLists.txt for the available configuration options you can pass to cmake. @@ -12,9 +11,12 @@ To build a debug version pass -DCMAKE_BUILD_TYPE=Debug to cmake. To build GammaRay you will need: - - CMake 2.8 + - CMake 2.8.9 (or 2.8.11 on Windows) - Qt 4.7 or higher +Optional FOSS packages (eg. VTK, Graphviz, etc) provide extra functionality. +See the "Optional Dependencies" section below for more details. + Building on Unix with gcc or clang: % mkdir build % cd build @@ -29,7 +31,6 @@ % nmake % nmake install - Building on Windows with mingw: % mkdir build % cd build @@ -46,6 +47,20 @@ % export PATH=/data/Qt/4.8/bin:$PATH # on Linux using bash +== Optional Dependencies == +GammaRay relies on optional (FOSS) dependencies to help provide some of its +functionality. For example, you'll need VTK (http://www.vtk.org) to build +the object visualizer and Graphviz (http://www.graphviz.org) for the state +machine visualizer. + +When you run cmake it will inform you about these missing dependencies. + +You can also force CMake to ignore any or all of the optional dependencies +by passing the option -DCMAKE_DISABLE_FIND_PACKAGE_=True. +For instance: +# tell cmake to ignore Graphiz and VTK +cmake -DCMAKE_DISABLE_FIND_PACKAGE_GRAPHVIZ=True -DCMAKE_DISABLE_FIND_PACKAGE_VTK=True + == Warning! == If your Qt is linked with the "-Bsymbolic-function" option preloading will be diff -Nru gammaray-1.2.2/.krazy gammaray-2.0.1/.krazy --- gammaray-1.2.2/.krazy 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/.krazy 2014-02-28 19:07:57.000000000 +0000 @@ -1,17 +1,27 @@ CHECKSETS qt4,c++,foss +#KDAB-specific checks +EXTRA kdabcopyright + #additional checks EXTRA defines,null,style,camelcase +#coding style settings +STYLE_CPPSTYLE kde +STYLE_OFFSET 2 +STYLE_LINEMAX 100 + #no need to check 3rdparty stuff SKIP /3rdparty/ #nor Nokia's stuff SKIP /qmldebugcontrol/ -SKIP modeltest\.cpp\|modeltest\.h -SKIP processlist_unix\.cpp\|processlist_win\.cpp +SKIP /modeltest.cpp|/modeltest.h +SKIP /processlist_unix.cpp|/processlist_win.cpp|/processlist.h +SKIP /launcher/processlist.h|/launcher/injector/interactiveprocess.cpp|/launcher/injector/interactiveprocess.h SKIP StackWalker #if you have a build subdir, skip it SKIP /build +SKIP Doxyfile.cmake -#don't check cmake subdir because it's mostly borrowed code -SKIP /cmake/ +#skip the borrowed code in the cmake subdir +SKIP /cmake/MacroLogFeature.cmake|/cmake/ECMQt4To5Porting.cmake|/cmake/FindGraphviz.cmake|/cmake/Toolchain-QNX65.cmake diff -Nru gammaray-1.2.2/launcher/attachdialog.cpp gammaray-2.0.1/launcher/attachdialog.cpp --- gammaray-1.2.2/launcher/attachdialog.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/attachdialog.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,110 +0,0 @@ -/* - attachdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "attachdialog.h" - -#include "processfiltermodel.h" -#include "processmodel.h" - -#include -#include -#include -#include -#include -#include -#include - -using namespace GammaRay; - -AttachDialog::AttachDialog(QWidget *parent, Qt::WindowFlags f) -: QWidget(parent, f) -{ - ui.setupUi(this); - - m_model = new ProcessModel(this); - - m_proxyModel = new ProcessFilterModel(this); - m_proxyModel->setSourceModel(m_model); - m_proxyModel->setDynamicSortFilter(true); - - ui.view->setModel(m_proxyModel); - // hide state - ui.view->hideColumn(ProcessModel::StateColumn); - ui.view->sortByColumn(ProcessModel::NameColumn, Qt::AscendingOrder); - ui.view->setSortingEnabled(true); - - ui.view->setEditTriggers(QAbstractItemView::NoEditTriggers); - - ui.view->setSelectionBehavior(QAbstractItemView::SelectRows); - ui.view->setSelectionMode(QAbstractItemView::SingleSelection); - connect(ui.view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - this, SIGNAL(updateButtonState())); - - connect(ui.view, SIGNAL(activated(QModelIndex)), SIGNAL(activate())); - - ui.filter->setProxy(m_proxyModel); - - setWindowTitle(tr("GammaRay - Attach to Process")); - setWindowIcon(QIcon(":gammaray/GammaRay-128x128.png")); - - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(updateProcesses())); - m_timer->start(1000); - - ui.stackedWidget->setCurrentWidget(ui.loadingLabel); - emit updateButtonState(); - updateProcesses(); -} - -bool AttachDialog::isValid() const -{ - return ui.view->currentIndex().isValid(); -} - -QString AttachDialog::pid() const -{ - return ui.view->currentIndex().data(ProcessModel::PIDRole).toString(); -} - -void AttachDialog::updateProcesses() -{ - QFutureWatcher* watcher = new QFutureWatcher(this); - connect(watcher, SIGNAL(finished()), - this, SLOT(updateProcessesFinished())); - watcher->setFuture(QtConcurrent::run(processList, m_model->processes())); -} - -void AttachDialog::updateProcessesFinished() -{ - QFutureWatcher* watcher = dynamic_cast*>(sender()); - Q_ASSERT(watcher); - ui.stackedWidget->setCurrentWidget(ui.listViewPage); - const QString oldPid = pid(); - m_model->mergeProcesses(watcher->result()); - if (oldPid != pid()) { - ui.view->setCurrentIndex(QModelIndex()); - } - watcher->deleteLater(); -} - -#include "attachdialog.moc" diff -Nru gammaray-1.2.2/launcher/attachdialog.h gammaray-2.0.1/launcher/attachdialog.h --- gammaray-1.2.2/launcher/attachdialog.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/attachdialog.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -/* - attachdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_ATTACHDIALOG_H -#define GAMMARAY_ATTACHDIALOG_H - -#include - -#include "processlist.h" -#include "ui_attachdialog.h" - -namespace GammaRay { - -class ProcessModel; -class ProcessFilterModel; - -class AttachDialog : public QWidget -{ - Q_OBJECT - - public: - explicit AttachDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - - QString pid() const; - /// Returns @c true if a valid process is selected. - bool isValid() const; - - signals: - void updateButtonState(); - void activate(); - - private slots: - void updateProcesses(); - void updateProcessesFinished(); - - private: - Ui::AttachDialog ui; - ProcessModel *m_model; - ProcessFilterModel *m_proxyModel; - QTimer *m_timer; -}; - -} // namespace GammaRay - -#endif // ATTACHDIALOG_H diff -Nru gammaray-1.2.2/launcher/attachdialog.ui gammaray-2.0.1/launcher/attachdialog.ui --- gammaray-1.2.2/launcher/attachdialog.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/attachdialog.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ - - - GammaRay::AttachDialog - - - - 0 - 0 - 400 - 300 - - - - Dialog - - - - :/gammaray/GammaRay-128x128.png:/gammaray/GammaRay-128x128.png - - - - - - 1 - - - - <html><head/><body><p align="center"><img src=":/gammaray/GammaRay-48x48.png"/></p><p align="center">Retrieving the list of processes which use Qt ...</p></body></html> - - - - - - 0 - - - - - - - - false - - - - - - listViewPage - loadingLabel - - - - - - - KFilterProxySearchLine - QWidget -
kde/kfilterproxysearchline.h
- 1 -
-
- - - - -
diff -Nru gammaray-1.2.2/launcher/clientlauncher.cpp gammaray-2.0.1/launcher/clientlauncher.cpp --- gammaray-1.2.2/launcher/clientlauncher.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/clientlauncher.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,73 @@ +/* + clientlauncher.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "clientlauncher.h" +#include "launcherfinder.h" + +using namespace GammaRay; + +ClientLauncher::ClientLauncher() +{ + m_process.setProcessChannelMode(QProcess::ForwardedChannels); +} + +ClientLauncher::~ClientLauncher() +{ +} + +QString ClientLauncher::clientPath() +{ + return LauncherFinder::findLauncher(LauncherFinder::Client); +} + +QStringList ClientLauncher::makeArgs(const QString& hostName, quint16 port) +{ + QStringList args; + args.push_back(hostName); + if (port > 0) + args.push_back(QString::number(port)); + return args; +} + +bool ClientLauncher::launch(const QString& hostName, quint16 port) +{ + m_process.start(clientPath(), makeArgs(hostName, port)); + return m_process.waitForStarted(); +} + +void ClientLauncher::launchDetached(const QString& hostName, quint16 port) +{ + QProcess::startDetached(clientPath(), makeArgs(hostName, port)); +} + +void ClientLauncher::terminate() +{ + if (m_process.state() == QProcess::Running) + m_process.terminate(); +} + +void ClientLauncher::waitForFinished() +{ + if (m_process.state() == QProcess::Running) + m_process.waitForFinished(-1); +} diff -Nru gammaray-1.2.2/launcher/clientlauncher.h gammaray-2.0.1/launcher/clientlauncher.h --- gammaray-1.2.2/launcher/clientlauncher.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/clientlauncher.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + clientlauncher.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CLIENTLAUNCHER_H +#define GAMMARAY_CLIENTLAUNCHER_H + +#include + +namespace GammaRay { + +/** Launching/monitoring of the GammaRay client for out-of-process use. */ +class ClientLauncher +{ +public: + ClientLauncher(); + ~ClientLauncher(); + + bool launch(const QString &hostName, quint16 port = 0); + void terminate(); + void waitForFinished(); + + static void launchDetached(const QString &hostName, quint16 port = 0); + +private: + static QString clientPath(); + static QStringList makeArgs(const QString &hostName, quint16 port); + +private: + QProcess m_process; +}; +} + +#endif // GAMMARAY_CLIENTLAUNCHER_H diff -Nru gammaray-1.2.2/launcher/CMakeLists.txt gammaray-2.0.1/launcher/CMakeLists.txt --- gammaray-1.2.2/launcher/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -2,14 +2,12 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/3rdparty ) -set(gammaray_runner_srcs +# shared launcher code +set(gammaray_launcher_shared_srcs injector/abstractinjector.cpp + injector/processinjector.cpp injector/injectorfactory.cpp injector/preloadinjector.cpp injector/styleinjector.cpp @@ -18,48 +16,46 @@ injector/preloadcheck.cpp probefinder.cpp - main.cpp - promolabel.cpp - splashscreen.cpp - launcherwindow.cpp - launchpage.cpp - selftestpage.cpp - - attachdialog.cpp - processmodel.cpp - processfiltermodel.cpp - - ${CMAKE_SOURCE_DIR}/3rdparty/kde/krecursivefilterproxymodel.cpp - ${CMAKE_SOURCE_DIR}/3rdparty/kde/kfilterproxysearchline.cpp + launchoptions.cpp + clientlauncher.cpp + launcherfinder.cpp ) if(NOT WIN32) - set(gammaray_runner_srcs - ${gammaray_runner_srcs} + list(APPEND gammaray_launcher_shared_srcs + injector/debuggerinjector.cpp injector/gdbinjector.cpp - processlist_unix.cpp - ) -else() - set(gammaray_runner_srcs - ${gammaray_runner_srcs} - processlist_win.cpp + injector/lldbinjector.cpp ) endif() +add_library(gammaray_launcher_shared STATIC ${gammaray_launcher_shared_srcs}) +target_link_libraries(gammaray_launcher_shared ${QT_QTCORE_LIBRARIES} gammaray_common) +if(HAVE_QT_WIDGETS) + target_link_libraries(gammaray_launcher_shared ${QT_QTGUI_LIBRARIES}) +endif() -qt4_wrap_ui(gammaray_runner_srcs - attachdialog.ui - launcherwindow.ui - launchpage.ui - selftestpage.ui +# command line launcher +set(gammaray_runner_srcs + launcher.cpp + main.cpp ) -# TODO we don't need all the class icons here, so split the qrc file accordingly -qt4_add_resources(gammaray_runner_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc) -qt4_automoc(${gammaray_runner_srcs}) add_executable(gammaray ${gammaray_runner_srcs}) -target_link_libraries(gammaray ${QT_QTCORE_LIBRARIES} ${QT_QTGUI_LIBRARIES}) -if(UNIX AND NOT APPLE) +target_link_libraries(gammaray gammaray_launcher_shared) + +if(QNXNTO) + target_link_libraries(gammaray cpp) +endif() + +if(UNIX AND NOT APPLE AND NOT QNXNTO) target_link_libraries(gammaray dl) # for preload check endif() +gammaray_embed_info_plist(gammaray ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in) + install(TARGETS gammaray ${INSTALL_TARGETS_DEFAULT_ARGS}) + +# UI launcher +if(HAVE_QT_CONCURRENT AND HAVE_QT_WIDGETS) + add_subdirectory(ui) +endif() diff -Nru gammaray-1.2.2/launcher/Info.plist.in gammaray-2.0.1/launcher/Info.plist.in --- gammaray-1.2.2/launcher/Info.plist.in 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/Info.plist.in 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,16 @@ + + + CFBundleIdentifier + com.kdab.GammaRay.injector + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + gammaray + CFBundleVersion + @GAMMARAY_VERSION_STRING@ + CFBundleShortVersion + @GAMMARAY_VERSION@ + LSUIElement + 1 + + diff -Nru gammaray-1.2.2/launcher/injector/abstractinjector.cpp gammaray-2.0.1/launcher/injector/abstractinjector.cpp --- gammaray-1.2.2/launcher/injector/abstractinjector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/abstractinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/launcher/injector/abstractinjector.h gammaray-2.0.1/launcher/injector/abstractinjector.h --- gammaray-1.2.2/launcher/injector/abstractinjector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/abstractinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/launcher/injector/CMakeLists.txt gammaray-2.0.1/launcher/injector/CMakeLists.txt --- gammaray-1.2.2/launcher/injector/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,21 +1,20 @@ -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +if(Qt5Widgets_FOUND OR QT_QTGUI_FOUND) + set(gammaray_injector_style_srcs injectorstyleplugin.cpp) -set(gammaray_injector_style_srcs injectorstyleplugin.cpp) -qt4_automoc(${gammaray_injector_style_srcs}) + add_library(gammaray_injector_style MODULE ${gammaray_injector_style_srcs}) -add_library(gammaray_injector_style MODULE ${gammaray_injector_style_srcs}) + target_link_libraries(gammaray_injector_style + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ) -target_link_libraries(gammaray_injector_style - ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} -) + set_target_properties(gammaray_injector_style + PROPERTIES PREFIX "" + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}/styles + ) -set_target_properties(gammaray_injector_style - PROPERTIES PREFIX "" - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/plugins/styles -) - -install( - TARGETS gammaray_injector_style - DESTINATION ${PLUGIN_INSTALL_DIR}/styles -) + install( + TARGETS gammaray_injector_style + DESTINATION ${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}/styles + ) +endif() diff -Nru gammaray-1.2.2/launcher/injector/debuggerinjector.cpp gammaray-2.0.1/launcher/injector/debuggerinjector.cpp --- gammaray-1.2.2/launcher/injector/debuggerinjector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/debuggerinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,155 @@ +/* + debuggerinjector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "debuggerinjector.h" + +#include + +#include +#include + +using namespace GammaRay; + +DebuggerInjector::DebuggerInjector() : + mExitCode(-1), + mProcessError(QProcess::UnknownError), + mExitStatus(QProcess::NormalExit), + mManualError(false) +{ +} + +DebuggerInjector::~DebuggerInjector() +{ +} + +QString DebuggerInjector::errorString() +{ + return mErrorString; +} + +int DebuggerInjector::exitCode() +{ + return mExitCode; +} + +QProcess::ExitStatus DebuggerInjector::exitStatus() +{ + return mExitStatus; +} + +QProcess::ProcessError DebuggerInjector::processError() +{ + return mProcessError; +} + +void DebuggerInjector::readyReadStandardOutput() +{ +} + +void DebuggerInjector::readyReadStandardError() +{ + const QString error = m_process->readAllStandardError(); + std::cerr << qPrintable(error) << std::endl; +} + +bool DebuggerInjector::startDebugger(const QStringList& args) +{ + m_process.reset(new QProcess); + connect(m_process.data(), SIGNAL(readyReadStandardError()), + this, SLOT(readyReadStandardError())); + connect(m_process.data(), SIGNAL(readyReadStandardOutput()), + this, SLOT(readyReadStandardOutput())); + m_process->setProcessChannelMode(QProcess::SeparateChannels); + m_process->start(debuggerExecutable(), args); + bool status = m_process->waitForStarted(-1); + + mExitCode = m_process->exitCode(); + mExitStatus = m_process->exitStatus(); + if (!mManualError) { + mProcessError = m_process->error(); + mErrorString = m_process->errorString(); + } + + return status; +} + +bool DebuggerInjector::selfTest() +{ + if (startDebugger(QStringList() << QLatin1String("--version"))) { + return m_process->waitForFinished(-1); + } + return false; +} + +void DebuggerInjector::waitForMain() +{ + addFunctionBreakpoint("main"); + execCmd("run"); + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + loadSymbols("QtCore"); +#else + loadSymbols("Qt5Core"); +#endif + // either this + addMethodBreakpoint("QCoreApplication::exec"); + // or this for unit tests should hit + addMethodBreakpoint("QTest::qExec"); + execCmd("continue"); +} + +int DebuggerInjector::injectAndDetach(const QString &probeDll, const QString &probeFunc) +{ + Q_ASSERT(m_process); + loadSymbols("dl"); + execCmd(QString::fromLatin1("call (void) dlopen(\"%1\", %2)"). + arg(probeDll).arg(RTLD_NOW).toUtf8()); + loadSymbols(probeDll.toUtf8()); + execCmd(QString::fromLatin1("call (void) %1()").arg(probeFunc).toUtf8()); + + if (qgetenv("GAMMARAY_UNITTEST") != "1") { + execCmd("detach"); + execCmd("quit"); + } else { + execCmd("continue"); + // if we hit a crash or anything, print backtrace and quit + execCmd("backtrace", false); + execCmd("quit", false); + } + + m_process->waitForFinished(-1); + + mExitCode = m_process->exitCode(); + mExitStatus = m_process->exitStatus(); + if (!mManualError) { + mProcessError = m_process->error(); + mErrorString = m_process->errorString(); + } + + return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit; +} + +void DebuggerInjector::loadSymbols(const QByteArray& library) +{ + Q_UNUSED(library); +} diff -Nru gammaray-1.2.2/launcher/injector/debuggerinjector.h gammaray-2.0.1/launcher/injector/debuggerinjector.h --- gammaray-1.2.2/launcher/injector/debuggerinjector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/debuggerinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ +/* + debuggerinjector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_DEBUGGERINJECTOR_H +#define GAMMARAY_DEBUGGERINJECTOR_H + +#include "injector/abstractinjector.h" + +#include +#include + +namespace GammaRay { + +/** Base class for debugger-based injectors. */ +class DebuggerInjector : public QObject, public AbstractInjector +{ + Q_OBJECT + public: + DebuggerInjector(); + ~DebuggerInjector(); + + bool selfTest(); + + QString errorString(); + int exitCode(); + QProcess::ExitStatus exitStatus(); + QProcess::ProcessError processError(); + + protected: + virtual QString debuggerExecutable() const = 0; + /** Execute a raw command on the debugger. */ + virtual void execCmd(const QByteArray &cmd, bool waitForWritten = true) = 0; + /** Break in the function @p function, specify name without parenthesis. */ + virtual void addFunctionBreakpoint(const QByteArray &function) = 0; + /** Break in the method @p method, specify name without parenthesis. */ + virtual void addMethodBreakpoint(const QByteArray &method) = 0; + /** Load symbols for the given shared library. */ + virtual void loadSymbols(const QByteArray &library); + + /** Start the debugger with the given command line arguments. */ + bool startDebugger(const QStringList &args); + /** Add a breakpoint in common entry points and wait until they are hit. */ + void waitForMain(); + /** Given an interrupted process, this injects the probe and continues the process. */ + int injectAndDetach(const QString &probeDll, const QString &probeFunc); + + protected slots: + virtual void readyReadStandardError(); + virtual void readyReadStandardOutput(); + + protected: + QScopedPointer m_process; + int mExitCode; + QProcess::ProcessError mProcessError; + QProcess::ExitStatus mExitStatus; + QString mErrorString; + bool mManualError; +}; + +} + +#endif // GAMMARAY_DEBUGGERINJECTOR_H diff -Nru gammaray-1.2.2/launcher/injector/gdbinjector.cpp gammaray-2.0.1/launcher/injector/gdbinjector.cpp --- gammaray-1.2.2/launcher/injector/gdbinjector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/gdbinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,126 +21,53 @@ along with this program. If not, see . */ +#include #include "gdbinjector.h" -#include "splashscreen.h" - #include #include #include #include -#include - using namespace GammaRay; static QTextStream cout(stdout); static QTextStream cerr(stderr); -GdbInjector::GdbInjector() : - mManualError(false), - mExitCode(-1), - mProcessError(QProcess::UnknownError), - mExitStatus(QProcess::NormalExit) +GdbInjector::GdbInjector() +{ +} + +QString GdbInjector::debuggerExecutable() const { + return QLatin1String("gdb"); } bool GdbInjector::launch(const QStringList &programAndArgs, const QString &probeDll, const QString &probeFunc) { - showSplashScreen(); - QStringList gdbArgs; gdbArgs.push_back(QLatin1String("--args")); gdbArgs.append(programAndArgs); - if (!startGdb(gdbArgs)) { + if (!startDebugger(gdbArgs)) { return -1; } - execGdbCmd("break main"); - execGdbCmd("run"); - execGdbCmd("sha QtCore"); - // either this - addBreakpoint("QCoreApplication::exec"); - // or this for unit tests should hit - addBreakpoint("QTest::qExec"); - execGdbCmd("continue"); - + waitForMain(); return injectAndDetach(probeDll, probeFunc); } bool GdbInjector::attach(int pid, const QString &probeDll, const QString &probeFunc) { Q_ASSERT(pid > 0); - showSplashScreen(); - if (!startGdb(QStringList() << QLatin1String("-pid") << QString::number(pid))) { + if (!startDebugger(QStringList() << QLatin1String("-pid") << QString::number(pid))) { return false; } return injectAndDetach(probeDll, probeFunc); } -bool GdbInjector::startGdb(const QStringList &args) -{ - m_process.reset(new QProcess); - connect(m_process.data(), SIGNAL(readyReadStandardError()), - this, SLOT(readyReadStandardError())); - connect(m_process.data(), SIGNAL(readyReadStandardOutput()), - this, SLOT(readyReadStandardOutput())); - m_process->setProcessChannelMode(QProcess::SeparateChannels); - m_process->start(QLatin1String("gdb"), args); - bool status = m_process->waitForStarted(-1); - - mExitCode = m_process->exitCode(); - mExitStatus = m_process->exitStatus(); - if (!mManualError) { - mProcessError = m_process->error(); - mErrorString = m_process->errorString(); - } - - return status; -} - -bool GdbInjector::injectAndDetach(const QString &probeDll, const QString &probeFunc) -{ - Q_ASSERT(m_process); -#ifndef Q_OS_MAC - execGdbCmd("sha dl"); -#endif - execGdbCmd(qPrintable(QString::fromLatin1("call (void) dlopen(\"%1\", %2)"). - arg(probeDll).arg(RTLD_NOW))); -#ifndef Q_OS_MAC - execGdbCmd(qPrintable(QString::fromLatin1("sha %1").arg(probeDll))); -#endif -// execGdbCmd(qPrintable(QString::fromLatin1("call (void) %1()").arg(probeFunc))); - execGdbCmd(qPrintable(QString::fromLatin1("print %1").arg(probeFunc))); - execGdbCmd("call $()"); - - if (qgetenv("GAMMARAY_UNITTEST") != "1") { - execGdbCmd("detach"); - execGdbCmd("quit"); - } else { - execGdbCmd("continue"); - // if we hit a crash or anything, print backtrace and quit - execGdbCmd("backtrace", false); - execGdbCmd("quit", false); - } - - m_process->waitForFinished(-1); - - mExitCode = m_process->exitCode(); - mExitStatus = m_process->exitStatus(); - if (!mManualError) { - mProcessError = m_process->error(); - mErrorString = m_process->errorString(); - } - - hideSplashScreen(); - - return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit; -} - -void GdbInjector::execGdbCmd(const QByteArray &cmd, bool waitForWritten) +void GdbInjector::execCmd(const QByteArray &cmd, bool waitForWritten) { m_process->write(cmd + '\n'); @@ -149,26 +76,6 @@ } } -int GdbInjector::exitCode() -{ - return mExitCode; -} - -QProcess::ProcessError GdbInjector::processError() -{ - return mProcessError; -} - -QProcess::ExitStatus GdbInjector::exitStatus() -{ - return mExitStatus; -} - -QString GdbInjector::errorString() -{ - return mErrorString; -} - void GdbInjector::readyReadStandardError() { const QString error = m_process->readAllStandardError(); @@ -202,18 +109,25 @@ } } -void GdbInjector::addBreakpoint(const QByteArray &method) +void GdbInjector::addFunctionBreakpoint(const QByteArray& function) +{ + execCmd("break " + function); +} + +void GdbInjector::addMethodBreakpoint(const QByteArray& method) { #ifdef Q_OS_MAC - execGdbCmd("break " + method + "()"); + execCmd("break " + method + "()"); #else - execGdbCmd("break " + method); + execCmd("break " + method); #endif } -bool GdbInjector::selfTest() +void GdbInjector::loadSymbols(const QByteArray& library) { - return startGdb(QStringList() << QLatin1String("--version")); +#ifndef Q_OS_MAC + execCmd("sha " + library); +#else + Q_UNUSED(library); +#endif } - -#include "gdbinjector.moc" diff -Nru gammaray-1.2.2/launcher/injector/gdbinjector.h gammaray-2.0.1/launcher/injector/gdbinjector.h --- gammaray-1.2.2/launcher/injector/gdbinjector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/gdbinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,13 +24,11 @@ #ifndef GAMMARAY_GDBINJECTOR_H #define GAMMARAY_GDBINJECTOR_H -#include "injector/abstractinjector.h" - -#include +#include "injector/debuggerinjector.h" namespace GammaRay { -class GdbInjector : public QObject, public AbstractInjector +class GdbInjector : public DebuggerInjector { Q_OBJECT public: @@ -41,30 +39,17 @@ virtual bool launch(const QStringList &programAndArgs, const QString &probeDll, const QString &probeFunc); virtual bool attach(int pid, const QString &probeDll, const QString &probeFunc); - virtual bool selfTest(); - virtual int exitCode(); - virtual QProcess::ExitStatus exitStatus(); - virtual QProcess::ProcessError processError(); - virtual QString errorString(); - - private: - bool startGdb(const QStringList &args); - bool injectAndDetach(const QString &probeDll, const QString &probeFunc); - /** Method to break on, without arguments or parenthesis. */ - void addBreakpoint(const QByteArray &method); - void execGdbCmd(const QByteArray &cmd, bool waitForWritten = true); + + protected: + QString debuggerExecutable() const; + void execCmd(const QByteArray &cmd, bool waitForWritten = true); + void addFunctionBreakpoint(const QByteArray& function); + void addMethodBreakpoint(const QByteArray& method); + void loadSymbols(const QByteArray& library); private slots: void readyReadStandardError(); void readyReadStandardOutput(); - - private: - bool mManualError; - int mExitCode; - QProcess::ProcessError mProcessError; - QProcess::ExitStatus mExitStatus; - QString mErrorString; - QScopedPointer m_process; }; } diff -Nru gammaray-1.2.2/launcher/injector/injectorfactory.cpp gammaray-2.0.1/launcher/injector/injectorfactory.cpp --- gammaray-1.2.2/launcher/injector/injectorfactory.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/injectorfactory.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "injectorfactory.h" #include "gdbinjector.h" +#include "lldbinjector.h" #include "preloadinjector.h" #include "styleinjector.h" #include "windllinjector.h" @@ -40,6 +41,9 @@ if (name == QLatin1String("gdb")) { return AbstractInjector::Ptr(new GdbInjector); } + if (name == QLatin1String("lldb")) { + return AbstractInjector::Ptr(new LldbInjector); + } #endif if (name == QLatin1String("style")) { return AbstractInjector::Ptr(new StyleInjector); @@ -56,9 +60,21 @@ return AbstractInjector::Ptr(0); } +static AbstractInjector::Ptr findFirstWorkingInjector(const QStringList &types) +{ + foreach (const QString &type, types) { + AbstractInjector::Ptr injector = createInjector(type); + if (injector->selfTest()) + return injector; + } + return AbstractInjector::Ptr(0); +} + AbstractInjector::Ptr defaultInjectorForLaunch() { -#if defined(Q_OS_UNIX) +#if defined(Q_OS_MAC) + return findFirstWorkingInjector(QStringList() << QLatin1String("gdb") << QLatin1String("lldb")); +#elif defined(Q_OS_UNIX) return createInjector(QLatin1String("preload")); #else return createInjector(QLatin1String("windll")); @@ -68,7 +84,7 @@ AbstractInjector::Ptr defaultInjectorForAttach() { #ifndef Q_OS_WIN - return createInjector(QLatin1String("gdb")); + return findFirstWorkingInjector(QStringList() << QLatin1String("gdb") << QLatin1String("lldb")); #else return createInjector(QLatin1String("windll")); #endif @@ -78,7 +94,7 @@ { QStringList types; #ifndef Q_OS_WIN - types << QLatin1String("preload") << QLatin1String("gdb"); + types << QLatin1String("preload") << QLatin1String("gdb") << QLatin1String("lldb"); #else types << QLatin1String("windll"); #endif diff -Nru gammaray-1.2.2/launcher/injector/injectorfactory.h gammaray-2.0.1/launcher/injector/injectorfactory.h --- gammaray-1.2.2/launcher/injector/injectorfactory.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/injectorfactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/launcher/injector/injectorstyle.json gammaray-2.0.1/launcher/injector/injectorstyle.json --- gammaray-1.2.2/launcher/injector/injectorstyle.json 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/injectorstyle.json 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1 @@ +{ "Keys": [ "gammaray-injector" ] } diff -Nru gammaray-1.2.2/launcher/injector/injectorstyleplugin.cpp gammaray-2.0.1/launcher/injector/injectorstyleplugin.cpp --- gammaray-1.2.2/launcher/injector/injectorstyleplugin.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/injectorstyleplugin.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,7 +23,12 @@ #include "injectorstyleplugin.h" +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include //krazy:exclude=camelcase +#else +#include //krazy:exclude=camelcase +#include //krazy:exclude=camelcase +#endif #include #include @@ -42,7 +47,14 @@ static QGuiPlatformPlugin defaultGuiPlatform; return QStyleFactory::create(defaultGuiPlatform.styleName()); #else -#pragma message("Qt 5: port this") + const QStringList styleNameList = + QGuiApplicationPrivate::platform_theme->themeHint( + QPlatformTheme::StyleNames).toStringList(); + foreach (const QString &styleName, styleNameList) { + if (QStyle *style = QStyleFactory::create(styleName)) { + return style; + } + } return 0; #endif } @@ -85,4 +97,3 @@ Q_EXPORT_PLUGIN2(gammaray_injector_style, GammaRay::InjectorStylePlugin) #endif -#include "injectorstyleplugin.moc" diff -Nru gammaray-1.2.2/launcher/injector/injectorstyleplugin.h gammaray-2.0.1/launcher/injector/injectorstyleplugin.h --- gammaray-1.2.2/launcher/injector/injectorstyleplugin.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/injectorstyleplugin.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -31,6 +31,9 @@ class InjectorStylePlugin : public QStylePlugin { Q_OBJECT +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "injectorstyle.json") +#endif public: QStyle *create(const QString &); QStringList keys() const; diff -Nru gammaray-1.2.2/launcher/injector/interactiveprocess.cpp gammaray-2.0.1/launcher/injector/interactiveprocess.cpp --- gammaray-1.2.2/launcher/injector/interactiveprocess.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/interactiveprocess.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -25,13 +25,16 @@ #include -#ifdef Q_WS_WIN +#ifdef Q_OS_WIN #include #define dup _dup #define dup2 _dup2 #ifndef __MINGW32__ #define fileno _fileno #endif +#elif defined(Q_OS_QNX) +#include +using std::fileno; #else #include #endif @@ -51,4 +54,3 @@ ::dup2(stdinClone, fileno(stdin)); } -#include "interactiveprocess.moc" diff -Nru gammaray-1.2.2/launcher/injector/interactiveprocess.h gammaray-2.0.1/launcher/injector/interactiveprocess.h --- gammaray-1.2.2/launcher/injector/interactiveprocess.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/interactiveprocess.h 2014-02-28 19:07:57.000000000 +0000 @@ -24,6 +24,7 @@ #define GAMMARAY_INTERACTIVEPROCESS_H #include +#include //for EXIT_STATUS class InteractiveProcess : public QProcess { diff -Nru gammaray-1.2.2/launcher/injector/lldbinjector.cpp gammaray-2.0.1/launcher/injector/lldbinjector.cpp --- gammaray-1.2.2/launcher/injector/lldbinjector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/lldbinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,96 @@ +/* + lldbinjector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "lldbinjector.h" + +#include + +using namespace GammaRay; + +LldbInjector::LldbInjector() +{ +} + +LldbInjector::~LldbInjector() +{ +} + +QString LldbInjector::name() const +{ + return QLatin1String("lldb"); +} + +QString LldbInjector::debuggerExecutable() const +{ + return QLatin1String("lldb"); +} + +void LldbInjector::execCmd(const QByteArray& cmd, bool waitForWritten) +{ + // wait for the prompt, otherwise LLDB loses the command + if (!m_process->bytesAvailable()) + m_process->waitForReadyRead(-1); + + if (qgetenv("GAMMARAY_UNITTEST") == "1") { + std::cout << m_process->readAllStandardOutput().constData(); + } + + m_process->write(cmd + '\n'); + + if (waitForWritten) { + m_process->waitForBytesWritten(-1); + } +} + +void LldbInjector::addFunctionBreakpoint(const QByteArray& function) +{ + execCmd("breakpoint set -b " + function); +} + +void LldbInjector::addMethodBreakpoint(const QByteArray& method) +{ + execCmd("breakpoint set -M " + method); +} + +bool LldbInjector::launch(const QStringList& programAndArgs, const QString& probeDll, const QString& probeFunc) +{ + QStringList args; + args.push_back(QLatin1String("--")); + args.append(programAndArgs); + + if (!startDebugger(args)) { + return -1; + } + + waitForMain(); + return injectAndDetach(probeDll, probeFunc); +} + +bool LldbInjector::attach(int pid, const QString& probeDll, const QString& probeFunc) +{ + Q_ASSERT(pid > 0); + if (!startDebugger(QStringList() << QLatin1String("-p") << QString::number(pid))) { + return false; + } + return injectAndDetach(probeDll, probeFunc); +} diff -Nru gammaray-1.2.2/launcher/injector/lldbinjector.h gammaray-2.0.1/launcher/injector/lldbinjector.h --- gammaray-1.2.2/launcher/injector/lldbinjector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/lldbinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + lldbinjector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LLDBINJECTOR_H +#define GAMMARAY_LLDBINJECTOR_H + +#include "injector/debuggerinjector.h" + +namespace GammaRay { + +class LldbInjector : public DebuggerInjector +{ + public: + LldbInjector(); + ~LldbInjector(); + + QString name() const; + bool launch(const QStringList& programAndArgs, const QString& probeDll, const QString& probeFunc); + bool attach(int pid, const QString& probeDll, const QString& probeFunc); + + protected: + QString debuggerExecutable() const; + void execCmd(const QByteArray& cmd, bool waitForWritten = true); + void addFunctionBreakpoint(const QByteArray& function); + void addMethodBreakpoint(const QByteArray& method); +}; +} + +#endif // GAMMARAY_LLDBINJECTOR_H diff -Nru gammaray-1.2.2/launcher/injector/preloadcheck.cpp gammaray-2.0.1/launcher/injector/preloadcheck.cpp --- gammaray-1.2.2/launcher/injector/preloadcheck.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/preloadcheck.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -32,7 +32,7 @@ #include -QString PreloadCheck::findSharedObjectFile(const QString &symbol) +static QString findSharedObjectFile(const QString &symbol) { void *sym = dlsym(RTLD_NEXT, qPrintable(symbol)); if (!sym) { @@ -70,9 +70,10 @@ if (!proc.waitForFinished()) { // TODO: Find out if we want to error out if 'readelf' is missing // The question is: Do all (major) distributions ship binutils by default? + // Major distros do, but not custom embedded ones... setErrorString(QObject::tr("Failed to run 'readelf' (binutils) binary: %1"). arg(QString(proc.errorString()))); - return false; + return true; } if (proc.exitCode() != 0) { @@ -99,10 +100,101 @@ } } +#ifdef __mips__ + // Mips, besides the plt, has another method of + // calling functions from .so files, and this method doesn't need JUMP_SLOT + // relocations (in fact, it doesn't need any relocations). This method uses .got + // entries and lazy binding stubs. + if (testMips(symbol, fileName)) { + qDebug() << "Call of function " << symbol << " will go through lazy binding stub"; + setErrorString(QString()); + return true; + } +#endif + setErrorString(QObject::tr("Symbol is not marked as relocatable: %1").arg(symbol)); return false; } +#ifdef __mips__ +// The way to determine whether the call to function will go +// through .got and lazy binding stub is: +// - find the value of dynamic symbol index of the function with the command +// "readelf --dyn-syms" +// - find the value of dynamic tag MIPS_GOTSYM with the command "readelf -d" +// - if (dyn_sym_index >= MIPS_GOTSYM) then the function has entry in the global +// part of the .got, and the call will go through lazy binding stub and be +// resolved by dynamic linker. +bool PreloadCheck::testMips(const QString &symbol, const QString &fileName) +{ + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); + proc.start("readelf", QStringList() << "--dyn-syms" << "-d" << fileName, QIODevice::ReadOnly); + + if (!proc.waitForFinished()) { + setErrorString(QObject::tr("Failed to run 'readelf' (binutils) binary: %1"). + arg(QString(proc.errorString()))); + return false; + } + + if (proc.exitCode() != 0) { + setErrorString(QObject::tr("Cannot read shared object: %1").arg(QString(proc.readAll()))); + return false; + } + + //Example line of dynamic symbol table on mips: + //3851: 001e66f4 8 FUNC GLOBAL DEFAULT 11 qt_startup_hook + QRegExp rxSym("^(\\d+):\\s+(?:[^ ]+\\s+){6}([^ ]+)(?:.*)$"); + + //Example line of dynamic tag on mips: + //0x70000013 (MIPS_GOTSYM) 0xec3 + QRegExp rxGot("^0x[0-9a-fA-F]+\\s+\\((.+)\\)\\s+(0x[0-9a-fA-F]+)(?:.*)$"); + + int dyn_sym_index = 0; + int mips_gotsym = 0; + bool foundDynSymbol = false; + bool foundGotTag = false; + + while (proc.canReadLine()) { + const QString line = proc.readLine().trimmed(); + QString currentMatch; + const QString tag = "MIPS_GOTSYM"; + + if (rxGot.exactMatch(line)) { + currentMatch = rxGot.cap(1); + + if (currentMatch == tag) { + bool conversionOk = false; + int value = rxGot.cap(2).toInt(&conversionOk, 16); + if (conversionOk){ + mips_gotsym = value; + foundGotTag = true; + } + } + } + else if (rxSym.exactMatch(line)) { + currentMatch = rxSym.cap(2); + if (currentMatch == symbol) { + dyn_sym_index = rxSym.cap(1).toInt(); + foundDynSymbol = true; + } + } + if (foundGotTag && foundDynSymbol) + break; + } + if (foundGotTag && foundDynSymbol && (dyn_sym_index >= mips_gotsym)) { + return true; + } + + return false; +} +#endif + +QString PreloadCheck::errorString() const +{ + return m_errorString; +} + void PreloadCheck::setErrorString(const QString &err) { m_errorString = err; diff -Nru gammaray-1.2.2/launcher/injector/preloadcheck.h gammaray-2.0.1/launcher/injector/preloadcheck.h --- gammaray-1.2.2/launcher/injector/preloadcheck.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/preloadcheck.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -26,27 +26,46 @@ #include +/** + * This class checks if it's possible to overwrite symbols + * by setting the LD_PRELOAD environment variable + */ class PreloadCheck { public: PreloadCheck(); + /** + * Test whether it is possible to overwrite @p symbol + * via LD_PRELOAD + * + * On Linux the 'readelf' binary is called to find out whether + * @p symbol is marked as relocatable + * + * @return True in case it's possible to overwrite @p symbol, otherwise false + * @sa errorString() + */ bool test(const QString &symbol); - QString errorString() const - { - return m_errorString; - } + QString errorString() const; protected: void setErrorString(const QString &err); private: - static QString findSharedObjectFile(const QString &symbol); +#ifdef __mips__ + /** + * Additional method for testing whether the call to the function will go + * through .got and lazy binding stub (MIPS specific) + * + * @see https://github.com/KDAB/GammaRay/issues/63 + */ + bool testMips(const QString &symbol, const QString &fileName); +#endif QString m_errorString; }; -#endif // Q_OS_UNIX +#endif #endif // GAMMARAY_PRELOADCHECK diff -Nru gammaray-1.2.2/launcher/injector/preloadinjector.cpp gammaray-2.0.1/launcher/injector/preloadinjector.cpp --- gammaray-1.2.2/launcher/injector/preloadinjector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/preloadinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -35,10 +35,7 @@ using namespace GammaRay; -PreloadInjector::PreloadInjector() : - mExitCode(-1), - mProcessError(QProcess::UnknownError), - mExitStatus(QProcess::NormalExit) +PreloadInjector::PreloadInjector() : ProcessInjector() { } @@ -52,9 +49,6 @@ #ifdef Q_OS_MAC env.insert("DYLD_FORCE_FLAT_NAMESPACE", QLatin1String("1")); env.insert("DYLD_INSERT_LIBRARIES", probeDll); - //env.insert("DYLD_PRINT_ENV", QLatin1String("1")); - //env.insert("DYLD_PRINT_LIBRARIES", QLatin1String("1")); - //env.insert("DYLD_PRINT_INITIALIZERS", QLatin1String("1")); env.insert("GAMMARAY_UNSET_DYLD", "1"); #else env.insert("LD_PRELOAD", probeDll); @@ -69,64 +63,7 @@ } #endif - InteractiveProcess proc; - proc.setProcessEnvironment(env); - proc.setProcessChannelMode(QProcess::ForwardedChannels); - - QStringList args = programAndArgs; - - if (env.value("GAMMARAY_GDB").toInt()) { - QStringList newArgs; - newArgs << "gdb" << "--eval-command" << "run" << "--args"; - newArgs += args; - args = newArgs; - } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { - QStringList newArgs; - newArgs << "valgrind" - << "--tool=memcheck" - << "--track-origins=yes" - << "--num-callers=25" - << "--leak-check=full"; - newArgs += args; - args = newArgs; - } else if (env.value("GAMMARAY_HELGRIND").toInt()) { - QStringList newArgs; - newArgs << "valgrind" << "--tool=helgrind"; - newArgs += args; - args = newArgs; - } - - const QString program = args.takeFirst(); - proc.start(program, args); - proc.waitForFinished(-1); - - mExitCode = proc.exitCode(); - mProcessError = proc.error(); - mExitStatus = proc.exitStatus(); - mErrorString = proc.errorString(); - - return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit - && mProcessError == QProcess::UnknownError; -} - -int PreloadInjector::exitCode() -{ - return mExitCode; -} - -QProcess::ProcessError PreloadInjector::processError() -{ - return mProcessError; -} - -QProcess::ExitStatus PreloadInjector::exitStatus() -{ - return mExitStatus; -} - -QString PreloadInjector::errorString() -{ - return mErrorString; + return launchProcess(programAndArgs, env); } #endif diff -Nru gammaray-1.2.2/launcher/injector/preloadinjector.h gammaray-2.0.1/launcher/injector/preloadinjector.h --- gammaray-1.2.2/launcher/injector/preloadinjector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/preloadinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,14 +24,14 @@ #ifndef GAMMARAY_PRELOADINJECTOR_H #define GAMMARAY_PRELOADINJECTOR_H -#include "abstractinjector.h" +#include "processinjector.h" #include #ifndef Q_OS_WIN namespace GammaRay { -class PreloadInjector : public AbstractInjector +class PreloadInjector : public ProcessInjector { public: PreloadInjector(); @@ -40,16 +40,6 @@ } virtual bool launch(const QStringList &programAndArgs, const QString &probeDll, const QString &probeFunc); - virtual int exitCode(); - virtual QProcess::ExitStatus exitStatus(); - virtual QProcess::ProcessError processError(); - virtual QString errorString(); - - private: - int mExitCode; - QProcess::ProcessError mProcessError; - QProcess::ExitStatus mExitStatus; - QString mErrorString; }; } diff -Nru gammaray-1.2.2/launcher/injector/processinjector.cpp gammaray-2.0.1/launcher/injector/processinjector.cpp --- gammaray-1.2.2/launcher/injector/processinjector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/processinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,109 @@ +/* + processinjector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include "processinjector.h" +#include "interactiveprocess.h" + +using namespace GammaRay; + +ProcessInjector::ProcessInjector() : + mExitCode(-1), + mProcessError(QProcess::UnknownError), + mExitStatus(QProcess::NormalExit) +{ +} + +ProcessInjector::~ProcessInjector() +{ +} + +bool ProcessInjector::launchProcess(const QStringList& programAndArgs, const QProcessEnvironment& env) +{ + InteractiveProcess proc; + proc.setProcessEnvironment(env); + proc.setProcessChannelMode(QProcess::ForwardedChannels); + + QStringList args = programAndArgs; + + if (env.value("GAMMARAY_GDB").toInt()) { + QStringList newArgs; + newArgs << "gdb"; +#ifndef Q_OS_MAC + newArgs << "--eval-command" << "run"; +#endif + newArgs << "--args"; + newArgs += args; + args = newArgs; + } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { + QStringList newArgs; + newArgs << "valgrind" + << "--tool=memcheck" + << "--track-origins=yes" + << "--num-callers=25" + << "--leak-check=full"; + newArgs += args; + args = newArgs; + } else if (env.value("GAMMARAY_HELGRIND").toInt()) { + QStringList newArgs; + newArgs << "valgrind" << "--tool=helgrind"; + newArgs += args; + args = newArgs; + } + + const QString program = args.takeFirst(); + proc.start(program, args); + proc.waitForFinished(-1); + + mExitCode = proc.exitCode(); + mProcessError = proc.error(); + mExitStatus = proc.exitStatus(); + mErrorString = proc.errorString(); + + if (mProcessError == QProcess::FailedToStart) { + mErrorString.prepend(QString("Could not start '%1': ").arg(program)); + } + + return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit + && mProcessError == QProcess::UnknownError; +} + +int ProcessInjector::exitCode() +{ + return mExitCode; +} + +QProcess::ExitStatus ProcessInjector::exitStatus() +{ + return mExitStatus; +} + +QProcess::ProcessError ProcessInjector::processError() +{ + return mProcessError; +} + +QString ProcessInjector::errorString() +{ + return mErrorString; +} diff -Nru gammaray-1.2.2/launcher/injector/processinjector.h gammaray-2.0.1/launcher/injector/processinjector.h --- gammaray-1.2.2/launcher/injector/processinjector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/processinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + processinjector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROCESSINJECTOR_H +#define GAMMARAY_PROCESSINJECTOR_H + +#include "abstractinjector.h" + +namespace GammaRay { + +/** Convenience base class for injectors using QProcess + * to launch the target process. + * Provides support for using gdb or valgrind for debugging the target. + */ +class ProcessInjector : public AbstractInjector +{ + public: + ProcessInjector(); + ~ProcessInjector(); + + int exitCode(); + QProcess::ExitStatus exitStatus(); + QProcess::ProcessError processError(); + QString errorString(); + + protected: + bool launchProcess(const QStringList &programAndArgs, const QProcessEnvironment &env); + int mExitCode; + QString mErrorString; + + private: + QProcess::ProcessError mProcessError; + QProcess::ExitStatus mExitStatus; +}; +} + +#endif // GAMMARAY_PROCESSINJECTOR_H diff -Nru gammaray-1.2.2/launcher/injector/styleinjector.cpp gammaray-2.0.1/launcher/injector/styleinjector.cpp --- gammaray-1.2.2/launcher/injector/styleinjector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/styleinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -26,20 +26,22 @@ #include "styleinjector.h" #include "interactiveprocess.h" +#include + #include #include +#include #include #include +#ifdef HAVE_QT_WIDGETS #include +#endif #include using namespace GammaRay; -StyleInjector::StyleInjector() : - mExitCode(-1), - mProcessError(QProcess::UnknownError), - mExitStatus(QProcess::NormalExit) +StyleInjector::StyleInjector() : ProcessInjector() { } @@ -54,49 +56,19 @@ if (!qtPluginPath.isEmpty()) { qtPluginPath.append(":"); } - qtPluginPath.append(GAMMARAY_LIB_INSTALL_DIR "/qt4/plugins"); + qtPluginPath.append(Paths::currentProbePath()); env.insert("QT_PLUGIN_PATH", qtPluginPath); - InteractiveProcess proc; - proc.setProcessEnvironment(env); - proc.setProcessChannelMode(QProcess::ForwardedChannels); - QStringList args = programAndArgs; - - if (env.value("GAMMARAY_GDB").toInt()) { - QStringList newArgs; - newArgs << "gdb" << "--eval-command" << "run" << "--args"; - newArgs += args; - args = newArgs; - } else if (env.value("GAMMARAY_MEMCHECK").toInt()) { - QStringList newArgs; - newArgs << "valgrind" << "--tool=memcheck" << "--track-origins=yes" << "--num-callers=25"; - newArgs += args; - args = newArgs; - } else if (env.value("GAMMARAY_HELGRIND").toInt()) { - QStringList newArgs; - newArgs << "valgrind" << "--tool=helgrind"; - newArgs += args; - args = newArgs; - } - - const QString program = args.takeFirst(); args << QLatin1String("-style") << QLatin1String("gammaray-injector"); - proc.start(program, args); - proc.waitForFinished(-1); - mExitCode = proc.exitCode(); - mProcessError = proc.error(); - mExitStatus = proc.exitStatus(); - mErrorString = proc.errorString(); - - return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit; + return launchProcess(args, env); } bool StyleInjector::selfTest() { - // TODO: be a bit more clever in finding the plugin location (also when actually using it above) - QCoreApplication::addLibraryPath(QLatin1String(GAMMARAY_LIB_INSTALL_DIR "/qt4/plugins")); +#ifdef HAVE_QT_WIDGETS + QCoreApplication::addLibraryPath(Paths::currentProbePath()); if (!QStyleFactory::keys().contains(QLatin1String("gammaray-injector"))) { mErrorString = QObject::tr("Injector style plugin is not found in the Qt style " "plug-in search path or cannot be loaded"); @@ -104,24 +76,8 @@ } return true; -} - -int StyleInjector::exitCode() -{ - return mExitCode; -} - -QProcess::ProcessError StyleInjector::processError() -{ - return mProcessError; -} - -QProcess::ExitStatus StyleInjector::exitStatus() -{ - return mExitStatus; -} - -QString StyleInjector::errorString() -{ - return mErrorString; +#else + mErrorString = QObject::tr("GammaRay was compiled without QtWidget support, style injector is not available."); + return false; +#endif } diff -Nru gammaray-1.2.2/launcher/injector/styleinjector.h gammaray-2.0.1/launcher/injector/styleinjector.h --- gammaray-1.2.2/launcher/injector/styleinjector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/styleinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,11 +24,11 @@ #ifndef GAMMARAY_STYLEINJECTOR_H #define GAMMARAY_STYLEINJECTOR_H -#include "injector/abstractinjector.h" +#include "processinjector.h" namespace GammaRay { -class StyleInjector : public GammaRay::AbstractInjector +class StyleInjector : public GammaRay::ProcessInjector { public: StyleInjector(); @@ -42,20 +42,6 @@ const QString &probeDll, const QString &probeFunc); virtual bool selfTest(); - - virtual int exitCode(); - - virtual QProcess::ExitStatus exitStatus(); - - virtual QProcess::ProcessError processError(); - - virtual QString errorString(); - - private: - int mExitCode; - QProcess::ProcessError mProcessError; - QProcess::ExitStatus mExitStatus; - QString mErrorString; }; } diff -Nru gammaray-1.2.2/launcher/injector/windllinjector.cpp gammaray-2.0.1/launcher/injector/windllinjector.cpp --- gammaray-1.2.2/launcher/injector/windllinjector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/windllinjector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Patrick Spendrin This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/launcher/injector/windllinjector.h gammaray-2.0.1/launcher/injector/windllinjector.h --- gammaray-1.2.2/launcher/injector/windllinjector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/injector/windllinjector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Patrick Spendrin This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/launcher/launcher.cpp gammaray-2.0.1/launcher/launcher.cpp --- gammaray-1.2.2/launcher/launcher.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launcher.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,325 @@ +/* + launcher.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include "launcher.h" +#include "probefinder.h" +#include "injector/abstractinjector.h" +#include "injector/injectorfactory.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace GammaRay; + +class SemaphoreWaiter : public QThread +{ + Q_OBJECT +public: + explicit SemaphoreWaiter(qint64 id, QObject *parent = 0) : QThread(parent), m_id(id) {} + ~SemaphoreWaiter() {} + void run() + { +#ifdef HAVE_SHM + QSystemSemaphore sem("gammaray-semaphore-" + QString::number(m_id), 0, QSystemSemaphore::Create); + sem.acquire(); + emit semaphoreReleased(); +#endif + } + +signals: + void semaphoreReleased(); + +private: + qint64 m_id; +}; + +class InjectorThread : public QThread +{ + Q_OBJECT +public: + explicit InjectorThread(const LaunchOptions &options, const QString &probeDll, QObject *parent = 0) + : QThread(parent), m_options(options), m_probeDll(probeDll) + { + Q_ASSERT(options.isValid()); + } + ~InjectorThread() {} + + AbstractInjector::Ptr createInjector() const + { + if (m_options.injectorType().isEmpty()) { + if (m_options.isAttach()) { + return InjectorFactory::defaultInjectorForAttach(); + } else { + return InjectorFactory::defaultInjectorForLaunch(); + } + } + return InjectorFactory::createInjector(m_options.injectorType()); + } + + void run() + { + const AbstractInjector::Ptr injector = createInjector(); + + if (!injector) { + if (m_options.injectorType().isEmpty()) { + if (m_options.isAttach()) { + emit error(-1, tr("Uh-oh, there is no default attach injector on this platform.")); + } else { + emit error(-1, tr("Uh-oh, there is no default launch injector on this platform.")); + } + } else { + emit error(-1, tr("Injector %1 not found.").arg(m_options.injectorType())); + } + return; + } + + bool success = false; + if (m_options.isLaunch()) { + success = injector->launch(m_options.launchArguments(), m_probeDll, QLatin1String("gammaray_probe_inject")); + } + if (m_options.isAttach()) { + success = injector->attach(m_options.pid(), m_probeDll, QLatin1String("gammaray_probe_inject")); + } + + if (!success) { + QString errorMessage; + if (m_options.isLaunch()) + errorMessage = tr("Failed to launch target '%1'.").arg(m_options.launchArguments().join(" ")); + if (m_options.isAttach()) + errorMessage = tr("Failed to attach to target with PID %1.").arg(m_options.pid()); + if (!injector->errorString().isEmpty()) + errorMessage += tr("\nError: %1").arg(injector->errorString()); + emit error(injector->exitCode(), errorMessage); + } + } + +signals: + void error(int exitCode, const QString &errorMessage); + +private: + LaunchOptions m_options; + QString m_probeDll; +}; + +Launcher::Launcher(const LaunchOptions& options, QObject* parent): + QObject(parent), + m_options(options), +#ifdef HAVE_SHM + m_shm(0), +#endif + m_state(Initial) +{ + Q_ASSERT(options.isValid()); + + m_safetyTimer.setSingleShot(true); + m_safetyTimer.setInterval(60 * 1000); + connect(&m_safetyTimer, SIGNAL(timeout()), SLOT(timeout())); + + // wait for the event loop to be available + QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection); +} + +Launcher::~Launcher() +{ + m_client.waitForFinished(); +} + +qint64 Launcher::instanceIdentifier() const +{ + if (m_options.isAttach()) + return m_options.pid(); + return QCoreApplication::applicationPid(); +} + +void Launcher::delayedInit() +{ + const QString probeDll = ProbeFinder::findProbe(QLatin1String("gammaray_probe"), m_options.probeABI()); + m_options.setProbeSetting("ProbePath", QFileInfo(probeDll).absolutePath()); + + sendLauncherId(); + sendProbeSettings(); + sendProbeSettingsFallback(); + + if (m_options.uiMode() != LaunchOptions::InProcessUi) { + SemaphoreWaiter *semWaiter = new SemaphoreWaiter(instanceIdentifier(), this); + connect(semWaiter, SIGNAL(semaphoreReleased()), this, SLOT(semaphoreReleased()), Qt::QueuedConnection); + semWaiter->start(); + + m_safetyTimer.start(); + } + + InjectorThread *injector = new InjectorThread(m_options, probeDll, this); + connect(injector, SIGNAL(finished()), this, SLOT(injectorFinished()), Qt::QueuedConnection); + connect(injector, SIGNAL(error(int,QString)), this, SLOT(injectorError(int,QString)), Qt::QueuedConnection); + injector->start(); +} + +void Launcher::sendLauncherId() +{ + // if we are launching a new process, make sure it knows how to talk to us + if (m_options.isLaunch()) { + qputenv("GAMMARAY_LAUNCHER_ID", QByteArray::number(instanceIdentifier())); + } else { +#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) + qputenv("GAMMARAY_LAUNCHER_ID", ""); +#else + qunsetenv("GAMMARAY_LAUNCHER_ID"); +#endif + } +} + +void Launcher::sendProbeSettings() +{ +#ifdef HAVE_SHM + QByteArray ba; // need a full copy of this first, since there's no QIODevice to directly work on void*... + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + + { + Message msg(Protocol::LauncherAddress, Protocol::ServerVersion); + msg.payload() << Protocol::version(); + msg.write(&buffer); + } + + { + Message msg(Protocol::LauncherAddress, Protocol::ProbeSettings); + msg.payload() << m_options.probeSettings(); + msg.write(&buffer); + } + + buffer.close(); + + m_shm = new QSharedMemory(QLatin1String("gammaray-") + QString::number(instanceIdentifier()), this); + if (!m_shm->create(ba.size())) { + qWarning() << Q_FUNC_INFO << "Failed to obtain shared memory for probe settings:" << m_shm->errorString(); + delete m_shm; + m_shm = 0; + return; + } + + SharedMemoryLocker locker(m_shm); + qMemCopy(m_shm->data(), ba.constData(), ba.size()); + if (m_shm->size() > ba.size()) // Windows... + qMemSet(static_cast(m_shm->data()) + ba.size(), 0xff, m_shm->size() - ba.size()); +#endif +} + +void Launcher::sendProbeSettingsFallback() +{ + if (!m_options.isAttach()) + return; + + const QHash probeSettings = m_options.probeSettings(); + for (QHash::const_iterator it = probeSettings.constBegin(); it != probeSettings.constEnd(); ++it) + qputenv("GAMMARAY_" + it.key(), it.value()); +} + +void Launcher::semaphoreReleased() +{ + m_safetyTimer.stop(); + +#ifdef HAVE_SHM + SharedMemoryLocker locker(m_shm); + QByteArray ba = QByteArray::fromRawData(static_cast(m_shm->data()), m_shm->size()); + QBuffer buffer(&ba); + buffer.open(QIODevice::ReadOnly); + + quint16 port = 0; + + while (Message::canReadMessage(&buffer)) { + const Message msg = Message::readMessage(&buffer); + switch (msg.type()) { + case Protocol::ServerPort: + { + msg.payload() >> port; + break; + } + default: + continue; + } + } + + if (port == 0) { + qWarning() << "Unable to receive port number."; + QCoreApplication::exit(1); + return; + } +#else + quint16 port = Endpoint::defaultPort(); +#endif + + std::cout << "GammaRay server listening on port: " << port << std::endl; + + if (m_options.uiMode() != LaunchOptions::OutOfProcessUi) // inject only, so we are done here + return; + + if (!m_client.launch("127.0.0.1", port)) { + qCritical("Unable to launch gammaray-client!"); + QCoreApplication::exit(1); + } + + m_state |= ClientStarted; + checkDone(); +} + +void Launcher::injectorFinished() +{ + m_state |= InjectorFinished; + checkDone(); +} + +void Launcher::injectorError(int exitCode, const QString& errorMessage) +{ + std::cerr << qPrintable(errorMessage) << std::endl; + std::cerr << "See for troubleshooting" << std::endl; + QCoreApplication::exit(exitCode); +} + +void Launcher::timeout() +{ + std::cerr << "Target not responding - timeout." << std::endl; + std::cerr << "See for troubleshooting" << std::endl; + m_client.terminate(); + QCoreApplication::exit(1); +} + +void Launcher::checkDone() +{ + if (m_state == Complete || (m_options.uiMode() != LaunchOptions::OutOfProcessUi && m_state == InjectorFinished)) + QCoreApplication::quit(); +} + +#include "launcher.moc" diff -Nru gammaray-1.2.2/launcher/launcherfinder.cpp gammaray-2.0.1/launcher/launcherfinder.cpp --- gammaray-1.2.2/launcher/launcherfinder.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launcherfinder.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,71 @@ +/* + launcherfinder.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "launcherfinder.h" + +#include + +#include +#include +#include +#include + +using namespace GammaRay; + +const char *executableNames[] = { + "gammaray", // the Injector + "gammaray-launcher", // the LauncherUI + "gammaray-client" // the Client +}; + +QString LauncherFinder::findLauncher(LauncherFinder::Type type) +{ + QString fileName = executableNames[type]; +#ifdef Q_OS_WIN + fileName += ".exe"; +#endif + + QStringList appPaths; //a list of all the paths we have searched + + QString appPath = Paths::binPath() + QDir::separator() + fileName; + QFileInfo fi(appPath); + if (fi.isExecutable()) { + return fi.absoluteFilePath(); + } + appPaths.append(appPath); + + appPath = Paths::libexecPath() + QDir::separator() + fileName; + if(!appPaths.contains(appPath)) { + fi.setFile(appPath); + if (fi.isExecutable()) { + return fi.absoluteFilePath(); + } + appPaths.append(appPath); + } + + qWarning() << fileName << "not found in the expected location(s):"; + qWarning() << appPaths.join(", ") << endl + << "continuing anyway, hoping for it to be in PATH."; + qWarning() << "This is likely a setup problem." << endl; + return fileName; +} diff -Nru gammaray-1.2.2/launcher/launcherfinder.h gammaray-2.0.1/launcher/launcherfinder.h --- gammaray-1.2.2/launcher/launcherfinder.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launcherfinder.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,45 @@ +/* + launcherfinder.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LAUNCHERFINDER_H +#define GAMMARAY_LAUNCHERFINDER_H + +#include + +namespace GammaRay { + +/** Utility function to find the various executables related to the launcher. */ +namespace LauncherFinder +{ + enum Type { + Injector, + LauncherUI, + Client + }; + + QString findLauncher(Type type); +} + +} + +#endif // GAMMARAY_LAUNCHERFINDER_H diff -Nru gammaray-1.2.2/launcher/launcher.h gammaray-2.0.1/launcher/launcher.h --- gammaray-1.2.2/launcher/launcher.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launcher.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,79 @@ +/* + launcher.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LAUNCHER_H +#define GAMMARAY_LAUNCHER_H + +#include +#include + +#include "launchoptions.h" +#include "clientlauncher.h" + +class QSharedMemory; + +namespace GammaRay { + +/** The actual launcher logic of gammaray.exe. */ +class Launcher : public QObject +{ + Q_OBJECT +public: + explicit Launcher(const LaunchOptions &options, QObject *parent = 0); + ~Launcher(); + + /** This is used to identify the communication channels used by the launcher and the target process. */ + qint64 instanceIdentifier() const; + +private slots: + void delayedInit(); + void semaphoreReleased(); + void injectorError(int exitCode, const QString &errorMessage); + void injectorFinished(); + void timeout(); + +private: + void sendLauncherId(); + void sendProbeSettings(); + // in case shared memory isn't available + void sendProbeSettingsFallback(); + void checkDone(); + +private: + LaunchOptions m_options; +#ifndef QT_NO_SHAREDMEMORY + QSharedMemory *m_shm; +#endif + ClientLauncher m_client; + QTimer m_safetyTimer; + enum State { + Initial = 0, + InjectorFinished = 1, + ClientStarted = 2, + Complete = InjectorFinished | ClientStarted + }; + int m_state; +}; +} + +#endif // GAMMARAY_LAUNCHER_H diff -Nru gammaray-1.2.2/launcher/launcherwindow.cpp gammaray-2.0.1/launcher/launcherwindow.cpp --- gammaray-1.2.2/launcher/launcherwindow.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launcherwindow.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,94 +0,0 @@ -/* - launcherwindow.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "launcherwindow.h" -#include "ui_launcherwindow.h" -#include "config-gammaray-version.h" - -#include -#include - -using namespace GammaRay; - -LauncherWindow::LauncherWindow(QWidget *parent) - : QDialog(parent), ui(new Ui::LauncherWindow) -{ - ui->setupUi(this); - ui->aboutLabel->setText(ui->aboutLabel->text().arg(GAMMARAY_VERSION_STRING)); - connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabChanged())); - connect(ui->attachPage, SIGNAL(updateButtonState()), SLOT(tabChanged())); - connect(ui->launchPage, SIGNAL(updateButtonState()), SLOT(tabChanged())); - connect(ui->attachPage, SIGNAL(activate()), - ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(click())); - - setWindowTitle(tr("GammaRay Launcher")); - - QSettings settings; - ui->tabWidget->setCurrentIndex(settings.value(QLatin1String("Launcher/TabIndex")).toInt()); -} - -LauncherWindow::~LauncherWindow() -{ - delete ui; -} - -QString LauncherWindow::pid() const -{ - if (ui->tabWidget->currentWidget() == ui->attachPage) { - return ui->attachPage->pid(); - } - return QString(); -} - -QStringList LauncherWindow::launchArguments() const -{ - if (ui->tabWidget->currentWidget() == ui->launchPage) { - return ui->launchPage->launchArguments(); - } - return QStringList(); -} - -void LauncherWindow::tabChanged() -{ - if (ui->tabWidget->currentWidget() == ui->attachPage) { - ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Attach")); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->attachPage->isValid()); - } else if (ui->tabWidget->currentWidget() == ui->launchPage) { - ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Launch")); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->launchPage->isValid()); - } else { - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - } -} - -void LauncherWindow::accept() -{ - QSettings settings; - settings.setValue(QLatin1String("Launcher/TabIndex"), ui->tabWidget->currentIndex()); - - ui->launchPage->writeSettings(); - - QDialog::accept(); -} - -#include "launcherwindow.moc" diff -Nru gammaray-1.2.2/launcher/launcherwindow.h gammaray-2.0.1/launcher/launcherwindow.h --- gammaray-1.2.2/launcher/launcherwindow.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launcherwindow.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ -/* - launcherwindow.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_LAUNCHERWINDOW_H -#define GAMMARAY_LAUNCHERWINDOW_H - -#include - -namespace GammaRay { - -namespace Ui { - class LauncherWindow; -} - -class LauncherWindow : public QDialog -{ - Q_OBJECT - public: - explicit LauncherWindow(QWidget *parent = 0); - ~LauncherWindow(); - - /// returns the selected PID, if the attach page is active - QString pid() const; - - /// returns the command and arguments, if the launch page is active - QStringList launchArguments() const; - - void accept(); - - private slots: - void tabChanged(); - - private: - Ui::LauncherWindow *ui; -}; - -} - -#endif // GAMMARAY_LAUNCHERWINDOW_H diff -Nru gammaray-1.2.2/launcher/launcherwindow.ui gammaray-2.0.1/launcher/launcherwindow.ui --- gammaray-1.2.2/launcher/launcherwindow.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launcherwindow.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,192 +0,0 @@ - - - GammaRay::LauncherWindow - - - - 0 - 0 - 748 - 482 - - - - Dialog - - - - :/gammaray/GammaRay-128x128.png:/gammaray/GammaRay-128x128.png - - - - - - 3 - - - - Attach - - - - - Launch - - - - - Self Test - - - - - About - - - - - - - - - 0 - 0 - - - - - - - :/gammaray/GammaRay-128x128.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 0 - - - - <html><head/><body><p><span style=" font-weight:600;">GammaRay %1</span></p><p>The Qt application inspection and manipulation tool. Learn more at <a href="http://www.kdab.com/gammaray"><span style=" text-decoration: underline; color:#0057ae;">http://www.kdab.com/gammaray</span></a>.</p><p>Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, <a href="mailto:info@kdab.com"><span style=" text-decoration: underline; color:#0057ae;">info@kdab.com</span></a></p><p><span style=" text-decoration: underline;">Authors:</span><br/>Allen Winter &lt;allen.winter@kdab.com&gt;<br/>Andreas Holzammer &lt;andreas.holzammer@kdab.com&gt;<br/>David Faure &lt;david.faure@kdab.com&gt;<br/>Kevin Funk &lt;kevin.funk@kdab.com&gt;<br/>Milian Wolff &lt;milian.wolff@kdab.com&gt;<br/>Patrick Spendrin &lt;patrick.spendrin@kdab.com&gt;<br/>Stephen Kelly &lt;stephen.kelly@kdab.com&gt;<br/>Till Adam &lt;till@kdab.com&gt;<br/>Thomas McGuire &lt;thomas.mcguire@kdab.com&gt;<br/>Tobias Koenig &lt;tobias.koenig@kdab.com&gt;<br/>Volker Krause &lt;volker.krause@kdab.com&gt;</p><p>StackWalker code Copyright (c) 2005-2009, Jochen Kalmbach, All rights reserved</p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - true - - - - - - - - - - - - 0 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Ok - - - - - - - - - - - GammaRay::PromoLabel - QWidget -
promolabel.h
- 1 -
- - GammaRay::AttachDialog - QWidget -
attachdialog.h
- 1 -
- - GammaRay::LaunchPage - QWidget -
launchpage.h
- 1 -
- - GammaRay::SelfTestPage - QWidget -
selftestpage.h
- 1 -
-
- - - - - - buttonBox - accepted() - GammaRay::LauncherWindow - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - GammaRay::LauncherWindow - reject() - - - 316 - 260 - - - 286 - 274 - - - - -
diff -Nru gammaray-1.2.2/launcher/launchoptions.cpp gammaray-2.0.1/launcher/launchoptions.cpp --- gammaray-1.2.2/launcher/launchoptions.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launchoptions.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,171 @@ +/* + launchoptions.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "launchoptions.h" + +#include +#include + +using namespace GammaRay; + +LaunchOptions::LaunchOptions() : + m_pid(-1), + m_uiMode(OutOfProcessUi) +{ +} + +LaunchOptions::~LaunchOptions() +{ +} + +bool LaunchOptions::isLaunch() const +{ + return !m_launchArguments.isEmpty(); +} + +bool LaunchOptions::isAttach() const +{ + return pid() > 0; +} + +bool LaunchOptions::isValid() const +{ + return isLaunch() != isAttach(); +} + +QStringList LaunchOptions::launchArguments() const +{ + return m_launchArguments; +} + +void LaunchOptions::setLaunchArguments(const QStringList& args) +{ + m_launchArguments = args; + Q_ASSERT(m_pid <= 0 || m_launchArguments.isEmpty()); +} + +int LaunchOptions::pid() const +{ + return m_pid; +} + +void LaunchOptions::setPid(int pid) +{ + m_pid = pid; + Q_ASSERT(m_pid <= 0 || m_launchArguments.isEmpty()); +} + +LaunchOptions::UiMode LaunchOptions::uiMode() const +{ + return m_uiMode; +} + +void LaunchOptions::setUiMode(LaunchOptions::UiMode mode) +{ + m_uiMode = mode; + setProbeSetting("InProcessUi", mode == InProcessUi); +} + +QString LaunchOptions::injectorType() const +{ + return m_injectorType; +} + +void LaunchOptions::setInjectorType(const QString& injectorType) +{ + m_injectorType = injectorType; +} + +QString LaunchOptions::probeABI() const +{ + return m_probeABI; +} + +void LaunchOptions::setProbeABI(const QString& abi) +{ + m_probeABI = abi; +} + +void LaunchOptions::setProbeSetting(const QString& key, const QVariant& value) +{ + QByteArray v; + switch (value.type()) { + case QVariant::String: + v = value.toString().toUtf8(); + break; + case QVariant::Bool: + v = value.toBool() ? "true" : "false"; + break; + case QVariant::Int: + v = QByteArray::number(value.toInt()); + break; + default: + qFatal("unsupported probe settings type"); + } + + m_probeSettings.insert(key.toUtf8(), v); +} + +QHash< QByteArray, QByteArray > LaunchOptions::probeSettings() const +{ + return m_probeSettings; +} + +bool LaunchOptions::execute(const QString& launcherPath) const +{ + Q_ASSERT(!launcherPath.isEmpty()); + Q_ASSERT(isValid()); + + QStringList args; + switch (uiMode()) { + case InProcessUi: + args.push_back("--inprocess"); + break; + case OutOfProcessUi: + args.push_back("--no-inprocess"); + break; + case NoUi: + args.push_back("--inject-only"); + break; + } + + if (!m_probeABI.isEmpty()) { + args.push_back("--probe"); + args.push_back(m_probeABI); + } + + if (m_probeSettings.contains("TCPServer")) { + args.push_back("--listen"); + args.push_back(m_probeSettings.value("TCPServer")); + } + if (m_probeSettings.value("RemoteAccessEnabled") == "false") + args.push_back("--no-listen"); + + if (isAttach()) { + args.push_back("--pid"); + args.push_back(QString::number(pid())); + } else { + args += launchArguments(); + } + return QProcess::startDetached(launcherPath, args); +} diff -Nru gammaray-1.2.2/launcher/launchoptions.h gammaray-2.0.1/launcher/launchoptions.h --- gammaray-1.2.2/launcher/launchoptions.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/launchoptions.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,93 @@ +/* + launchoptions.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LAUNCHOPTIONS_H +#define GAMMARAY_LAUNCHOPTIONS_H + +#include +#include + +class QVariant; + +namespace GammaRay { + +/** Describes the injection and probe options used for launching/attacing to a host process. */ +class LaunchOptions +{ +public: + LaunchOptions(); + ~LaunchOptions(); + + enum UiMode { + InProcessUi, + OutOfProcessUi, + NoUi + }; + + /** Returns @c true if this is valid and has launch arguments set. */ + bool isLaunch() const; + + /** Returns @c true if we are supposed to attach rather than start a new process. */ + bool isAttach() const; + + /** Returns @c true if no valid launch arguments or process id are set. */ + bool isValid() const; + + /** Generic key/value settings send to the probe. */ + void setProbeSetting(const QString &key, const QVariant &value); + QHash probeSettings() const; + + /** Program and command line arguments to launch. */ + void setLaunchArguments(const QStringList &args); + QStringList launchArguments() const; + + /** Process id for the process to attach to. */ + void setPid(int pid); + int pid() const; + + /** UI mode. */ + UiMode uiMode() const; + void setUiMode(UiMode mode); + + /** Injector type. */ + QString injectorType() const; + void setInjectorType(const QString &injectorType); + + /** Probe ABI. */ + QString probeABI() const; + void setProbeABI(const QString &abi); + + /** execute this launch options with the given command-line launcher. */ + bool execute(const QString& launcherPath) const; + +private: + QStringList m_launchArguments; + QString m_injectorType; + QString m_probeABI; + int m_pid; + UiMode m_uiMode; + QHash m_probeSettings; +}; +} + +#endif // GAMMARAY_LAUNCHOPTIONS_H diff -Nru gammaray-1.2.2/launcher/launchpage.cpp gammaray-2.0.1/launcher/launchpage.cpp --- gammaray-1.2.2/launcher/launchpage.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launchpage.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,141 +0,0 @@ -/* - launchpage.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "launchpage.h" -#include "ui_launchpage.h" - -#include -#include -#include -#include -#include - -using namespace GammaRay; - -LaunchPage::LaunchPage(QWidget *parent) - : QWidget(parent), - ui(new Ui::LaunchPage), - m_argsModel(new QStringListModel(this)) -{ - ui->setupUi(this); - connect(ui->progSelectButton, SIGNAL(clicked()), SLOT(showFileDialog())); - connect(ui->addArgButton, SIGNAL(clicked()), SLOT(addArgument())); - connect(ui->removeArgButton, SIGNAL(clicked()), SLOT(removeArgument())); - connect(ui->progEdit, SIGNAL(textChanged(QString)), SIGNAL(updateButtonState())); - - ui->argsBox->setModel(m_argsModel); - - QCompleter *pathCompleter = new QCompleter(this); - QFileSystemModel *fsModel = new QFileSystemModel(this); - fsModel->setRootPath(QDir::rootPath()); - pathCompleter->setModel(fsModel); - ui->progEdit->setCompleter(pathCompleter); - - QSettings settings; - ui->progEdit->setText(settings.value(QLatin1String("Launcher/Program")).toString()); - m_argsModel->setStringList(settings.value(QLatin1String("Launcher/Arguments")).toStringList()); - updateArgumentButtons(); -} - -LaunchPage::~LaunchPage() -{ - delete ui; -} - -void LaunchPage::writeSettings() -{ - QSettings settings; - settings.setValue(QLatin1String("Launcher/Program"), ui->progEdit->text()); - settings.setValue(QLatin1String("Launcher/Arguments"), notEmptyString(m_argsModel->stringList())); -} - -QStringList LaunchPage::notEmptyString(const QStringList &list) const -{ - QStringList notEmptyStringList; - const int numberOfArguments = list.count(); - for (int i = 0; i < numberOfArguments; ++i) { - if(!list.at(i).trimmed().isEmpty()) { - notEmptyStringList << list.at(i); - } - } - return notEmptyStringList; -} - -QStringList LaunchPage::launchArguments() const -{ - QStringList l; - l.push_back(ui->progEdit->text()); - l.append(notEmptyString(m_argsModel->stringList())); - return l; -} - -void LaunchPage::showFileDialog() -{ - const QString exeFilePath = - QFileDialog::getOpenFileName( - this, - tr("Executable to Launch"), - ui->progEdit->text() -#ifdef Q_OS_WIN - ,tr("Executable (*.exe)") -#endif - ); - - if (exeFilePath.isEmpty()) { - return; - } - - ui->progEdit->setText(exeFilePath); -} - -void LaunchPage::addArgument() -{ - m_argsModel->insertRows(m_argsModel->rowCount(), 1); - const QModelIndex newIndex = m_argsModel->index(m_argsModel->rowCount() - 1, 0); - ui->argsBox->edit(newIndex); - updateArgumentButtons(); -} - -void LaunchPage::removeArgument() -{ - // TODO check if there's a selection at all and update button state accordingly - m_argsModel->removeRows(ui->argsBox->currentIndex().row(), 1); - updateArgumentButtons(); -} - -bool LaunchPage::isValid() -{ - if (ui->progEdit->text().isEmpty()) { - return false; - } - - const QFileInfo fi(ui->progEdit->text()); - return fi.exists() && fi.isFile() && fi.isExecutable(); -} - -void LaunchPage::updateArgumentButtons() -{ - ui->removeArgButton->setEnabled(m_argsModel->rowCount() > 0); -} - -#include "launchpage.moc" diff -Nru gammaray-1.2.2/launcher/launchpage.h gammaray-2.0.1/launcher/launchpage.h --- gammaray-1.2.2/launcher/launchpage.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launchpage.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -/* - launchpage.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_LAUNCHPAGE_H -#define GAMMARAY_LAUNCHPAGE_H - -#include - -class QStringListModel; - -namespace GammaRay { - -namespace Ui { - class LaunchPage; -} - -class LaunchPage : public QWidget -{ - Q_OBJECT - public: - explicit LaunchPage(QWidget *parent = 0); - ~LaunchPage(); - - QStringList launchArguments() const; - bool isValid(); - - void writeSettings(); - - signals: - void updateButtonState(); - - private slots: - void showFileDialog(); - void addArgument(); - void removeArgument(); - void updateArgumentButtons(); - - private: - QStringList notEmptyString(const QStringList &list) const; - Ui::LaunchPage *ui; - QStringListModel *m_argsModel; -}; - -} - -#endif // GAMMARAY_LAUNCHPAGE_H diff -Nru gammaray-1.2.2/launcher/launchpage.ui gammaray-2.0.1/launcher/launchpage.ui --- gammaray-1.2.2/launcher/launchpage.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/launchpage.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,86 +0,0 @@ - - - GammaRay::LaunchPage - - - - 0 - 0 - 401 - 280 - - - - - - - - - &Executable: - - - progEdit - - - - - - - - - - ... - - - - - - - - - &Program arguments: - - - argsBox - - - - - - - - - - - - &Add - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 170 - - - - - - - - - - - diff -Nru gammaray-1.2.2/launcher/main.cpp gammaray-2.0.1/launcher/main.cpp --- gammaray-1.2.2/launcher/main.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -23,14 +23,23 @@ #include "config-gammaray.h" #include "config-gammaray-version.h" -#include "probefinder.h" #include "injector/injectorfactory.h" -#include "launcherwindow.h" +#include "launchoptions.h" +#include "launcherfinder.h" +#include "launcher.h" +#include "probefinder.h" + +#include +#ifdef HAVE_QT_WIDGETS #include +#else +#include +#endif + #include +#include #include -#include using namespace GammaRay; @@ -40,7 +49,7 @@ static void usage(const char *argv0) { out << "Usage: " << argv0 - << " [--injector ] [--pid | ]" << endl; + << " [options] [--pid | | --connect [:]]" << endl; out << "" << endl; out << "Inspect runtime internals of a Qt-application, such as:" << endl; out << " QObject tree, properties, signal/slots, widgets, models," << endl; @@ -48,46 +57,70 @@ out << " state machines, meta types, fonts, codecs, text documents" << endl; out << "" << endl; out << "Options:" << endl; - out << " -i, --injector \tset injection type, possible values:" << endl; - out << " \t" << InjectorFactory::availableInjectors().join(", ") + out << " -i, --injector \tset injection type, possible values:" << endl; + out << " \t" << InjectorFactory::availableInjectors().join(", ") << endl; - out << " -p, --pid \tattach to running Qt application" << endl; - out << " -h, --help \tprint program help and exit" << endl; - out << " -v, --version \tprint program version and exit" << endl; + out << " -p, --pid \tattach to running Qt application" << endl; + out << " --inprocess \tuse in-process UI" << endl; + out << " --inject-only \tonly inject the probe, don't show the UI" << endl; + out << " --listen
\tspecify the address the server should listen on [default: 0.0.0.0]" << endl; + out << " --no-listen \tdisables remote access entirely (implies --inprocess)" << endl; + out << " --list-probes \tlist all installed probes" << endl; + out << " --probe \tspecify which probe to use" << endl; + out << " --connect [:port]\tconnect to an already injected target" << endl; + out << " -h, --help \tprint program help and exit" << endl; + out << " -v, --version \tprint program version and exit" << endl; +#ifdef HAVE_QT_WIDGETS out << endl << "When run without any options, " << argv0 << " will present a list of running\n" << "Qt-applications from which you can attach the selected injector. Else,\n" << "you can attach to a running process by specifying its pid, or you can\n" << "start a new Qt-application by specifying its name (and optional arguments)." << endl; +#endif +} + +static bool startLauncher() +{ + const QString launcherPath = LauncherFinder::findLauncher(LauncherFinder::LauncherUI); + QProcess proc; + proc.setProcessChannelMode(QProcess::ForwardedChannels); + proc.start(launcherPath); + if (!proc.waitForFinished(-1)) + return false; + return proc.exitCode() == 0; } int main(int argc, char **argv) { - QApplication::setOrganizationName("KDAB"); - QApplication::setOrganizationDomain("kdab.com"); - QApplication::setApplicationName("GammaRay"); + QCoreApplication::setOrganizationName("KDAB"); + QCoreApplication::setOrganizationDomain("kdab.com"); + QCoreApplication::setApplicationName("GammaRay"); QStringList args; for (int i = 1; i < argc; ++i) { args.push_back(QString::fromLocal8Bit(argv[i])); } - QApplication app(argc, argv); +#ifdef HAVE_QT_WIDGETS + QApplication app(argc, argv); // for style inspector +#else + QCoreApplication app(argc, argv); +#endif + Paths::setRelativeRootPath(GAMMARAY_INVERSE_BIN_DIR); QStringList builtInArgs = QStringList() << QLatin1String("-style") << QLatin1String("-stylesheet") << QLatin1String("-graphicssystem"); - QString injectorType; - int pid = -1; + LaunchOptions options; while (!args.isEmpty() && args.first().startsWith('-')) { const QString arg = args.takeFirst(); if ((arg == QLatin1String("-i") || arg == QLatin1String("--injector")) && !args.isEmpty()) { - injectorType = args.takeFirst(); + options.setInjectorType(args.takeFirst()); continue; } if ((arg == QLatin1String("-p") || arg == QLatin1String("--pid")) && !args.isEmpty()) { - pid = args.takeFirst().toInt(); + options.setPid( args.takeFirst().toInt() ); continue; } if (arg == QLatin1String("-h") || arg == QLatin1String("--help")) { @@ -96,10 +129,51 @@ } if (arg == QLatin1String("-v") || arg == QLatin1String("--version")) { out << PROGRAM_NAME << " version " << GAMMARAY_VERSION_STRING << endl; - out << "Copyright (C) 2010-2012 Klaralvdalens Datakonsult AB, " + out << "Copyright (C) 2010-2014 Klaralvdalens Datakonsult AB, " << "a KDAB Group company, info@kdab.com" << endl; return 0; } + if (arg == QLatin1String("--inprocess")) { + options.setUiMode(LaunchOptions::InProcessUi); + } + if (arg == QLatin1String("--inject-only")) { + options.setUiMode(LaunchOptions::NoUi); + } + if (arg == QLatin1String("--listen") && !args.isEmpty()) { + options.setProbeSetting("TCPServer", args.takeFirst()); + } + if ( arg == QLatin1String("--no-listen")) { + options.setProbeSetting("RemoteAccessEnabled", false); + options.setUiMode(LaunchOptions::InProcessUi); + } + if ( arg == QLatin1String("--list-probes")) { + foreach( const QString &abi, ProbeFinder::listProbeABIs()) + out << abi << endl; + return 0; + } + if ( arg == QLatin1String("--probe") && !args.isEmpty()) { + const QString abi = args.takeFirst(); + if (!ProbeFinder::listProbeABIs().contains(abi)) { + out << abi << "is not a known probe, see --list-probes." << endl; + return 1; + } + options.setProbeABI(abi); + } + if ( arg == QLatin1String("--connect") && !args.isEmpty()) { + QString host = args.takeFirst(); + quint16 port = 0; + const int pos = host.lastIndexOf(":"); + if (pos > 0) { + port = host.mid(pos + 1).toUShort(); + host = host.left(pos); + } + ClientLauncher client; + client.launch(host, port); + client.waitForFinished(); + return 0; + } + + // debug/test options if (arg == QLatin1String("-filtertest")) { qputenv("GAMMARAY_TEST_FILTER", "1"); } @@ -116,74 +190,33 @@ } } } + options.setLaunchArguments(args); - if (args.isEmpty() && pid <= 0) { - LauncherWindow dialog; - if (dialog.exec() == QDialog::Accepted) { - args = dialog.launchArguments(); - bool ok; - pid = dialog.pid().toInt(&ok); - if (!ok && args.isEmpty()) { - return 0; - } - } else { + if (!options.isValid()) { + if (startLauncher()) return 0; - } - } - - const QString probeDll = ProbeFinder::findProbe(QLatin1String("gammaray_probe")); - qputenv("GAMMARAY_PROBE_PATH", QFileInfo(probeDll).absolutePath().toLocal8Bit()); - - AbstractInjector::Ptr injector; - if (injectorType.isEmpty()) { - if (pid > 0) { - injector = InjectorFactory::defaultInjectorForAttach(); - } else { - injector = InjectorFactory::defaultInjectorForLaunch(); - } - } else { - injector = InjectorFactory::createInjector(injectorType); - } - - if (injector) { - if (pid > 0) { - if (!injector->attach(pid, probeDll, QLatin1String("gammaray_probe_inject"))) { - err << "Unable to attach injector " << injector->name() << endl; - err << "Exit code: " << injector->exitCode() << endl; - if (!injector->errorString().isEmpty()) { - err << "Error: " << injector->errorString() << endl; - } - return 1; - } else { - return 0; - } - } else { - if (!injector->launch(args, probeDll, QLatin1String("gammaray_probe_inject"))) { - err << "Failed to launch injector " << injector->name() << endl; - err << "Exit code: " << injector->exitCode() << endl; - if (!injector->errorString().isEmpty()) { - err << "Error: " << injector->errorString() << endl; - } - return 1; - } - return injector->exitCode(); - } + usage(argv[0]); return 1; } - if (injectorType.isEmpty()) { - if (pid > 0) { -#if defined(Q_OS_WIN) - err << "Sorry, but at this time there is no attach injector on the Windows platform" << endl; - err << "Only the launch injector windll is available on Windows" << endl; -#else - err << "Uh-oh, there is no default attach injector" << endl; -#endif - } else { - err << "Uh-oh, there is no default launch injector" << endl; + if (!options.isValid()) + return 0; + Q_ASSERT(options.isValid()); + + // TODO auto-detect probe ABI + if (options.probeABI().isEmpty()) { + const QStringList availableProbes = ProbeFinder::listProbeABIs(); + if (availableProbes.isEmpty()) { + out << "No probes found, this is likely an installation problem." << endl; + return 1; + } + if (availableProbes.size() > 1) { + out << "No probe ABI specified and ABI auto-detection not implemented yet, picking " << availableProbes.first() << " at random." << endl; + out << "To specify the probe ABI explicitly use --probe , available probes are: " << availableProbes.join(", ") << endl; } - } else { - err << "Injector " << injectorType << " not found." << endl; + options.setProbeABI(availableProbes.first()); } - return 1; + + Launcher launcher(options); + return app.exec(); } diff -Nru gammaray-1.2.2/launcher/probefinder.cpp gammaray-2.0.1/launcher/probefinder.cpp --- gammaray-1.2.2/launcher/probefinder.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/probefinder.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -21,15 +21,15 @@ along with this program. If not, see . */ -#include "config-gammaray.h" - #include "probefinder.h" +#include + #include #include #include #include -#include +#include #include #include @@ -37,45 +37,42 @@ namespace ProbeFinder { -QString findProbe(const QString &baseName) +QString findProbe(const QString &baseName, const QString &probeAbi) { -#ifndef Q_OS_WIN - QStringList pldirs; - pldirs << GAMMARAY_LIB_INSTALL_DIR - << "/usr/local/lib64" << "/usr/local/lib" - << "/opt/lib64" << "/opt/lib" - << "/usr/lib64" << "/usr/lib" - << GAMMARAY_BUILD_DIR "/core"; - QDir::setSearchPaths("preloads", pldirs); -#ifdef Q_OS_MAC - QFile plfile(QLatin1Literal("preloads:") % baseName % QLatin1Literal(".dylib")); -#else - QFile plfile(QLatin1Literal("preloads:") % baseName % QLatin1Literal(".so")); -#endif - if (plfile.exists()) { - return plfile.fileName(); - } else { - qWarning() - << "Cannot locate" << baseName - << "in the typical places.\n" - "Try setting the $LD_PRELOAD environment variable to the fullpath,\n" - "For example:\n" - " export LD_PRELOAD=/opt/lib64/libgammaray_probe.so\n" - "Continuing nevertheless, some systems can also preload from just the library name..."; - return baseName; + const QString probePath = + Paths::probePath(probeAbi) % + QDir::separator() % + baseName % + fileExtension(); + + const QFileInfo fi(probePath); + const QString canonicalPath = fi.canonicalFilePath(); + if (!fi.isFile() || !fi.isReadable() || canonicalPath.isEmpty()) { + qWarning() << "Cannot locate probe" << probePath; + qWarning() << "This is likely a setup problem, due to an incomplete or partially moved installation."; + return QString(); } + return canonicalPath; +} + +QStringList listProbeABIs() +{ + const QDir dir(Paths::probePath(QString())); + return dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); +} + +QString fileExtension() +{ +#ifdef Q_OS_WIN + return QLatin1String(".dll"); +#elif defined(Q_OS_MAC) + return QLatin1String(".dylib"); #else - return - QCoreApplication::applicationDirPath() % - QDir::separator() % - baseName % - QLatin1Literal(".dll"); + return QLatin1String(".so"); #endif - - Q_ASSERT(false); - return QString(); } } + } diff -Nru gammaray-1.2.2/launcher/probefinder.h gammaray-2.0.1/launcher/probefinder.h --- gammaray-1.2.2/launcher/probefinder.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/probefinder.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ #ifndef GAMMARAY_PROBEFINDER_H #define GAMMARAY_PROBEFINDER_H +class QStringList; class QString; namespace GammaRay { @@ -33,7 +34,17 @@ /** * Attempts to find the full path of the probe DLL. */ - QString findProbe(const QString &baseName); + QString findProbe(const QString& baseName, const QString& probeAbi); + + /** + * List all available probe ABIs. + */ + QStringList listProbeABIs(); + + /** + * Returns the platform-specific file name extenstion. + */ + QString fileExtension(); } } diff -Nru gammaray-1.2.2/launcher/processfiltermodel.cpp gammaray-2.0.1/launcher/processfiltermodel.cpp --- gammaray-1.2.2/launcher/processfiltermodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processfiltermodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,105 +0,0 @@ -/* - processfiltermodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "processfiltermodel.h" -#include "processmodel.h" - -#include - -#if defined(_WIN32) -#include -#include -static QString qGetLogin() { - char winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H - DWORD winUserNameSize = sizeof(winUserName); - GetUserNameA(winUserName, &winUserNameSize); - return QString::fromLocal8Bit(winUserName); -} -#else -#include -#include -#include -static QString qGetLogin(){ - struct passwd *pw = getpwuid(getuid()); - if (!pw || !pw->pw_name) - return QString(); - return QString::fromLocal8Bit(pw->pw_name); -} -#endif - -using namespace GammaRay; - -ProcessFilterModel::ProcessFilterModel(QObject *parent) - : QSortFilterProxyModel(parent) -{ - m_currentProcId = QString::number(qApp->applicationPid()); - m_currentUser = qGetLogin(); -#ifndef Q_WS_WIN - if (m_currentUser == QLatin1String("root")) { - // empty current user == no filter. as root we want to show all - m_currentUser.clear(); - } -#endif -} - -bool ProcessFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const -{ - const QString l = sourceModel()->data(left).toString(); - const QString r = sourceModel()->data(right).toString(); - if (left.column() == ProcessModel::PIDColumn) { - return l.toInt() < r.toInt(); - } - - return l.compare(r, Qt::CaseInsensitive) <= 0; -} - -bool ProcessFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const -{ - ProcessModel *source = dynamic_cast(sourceModel()); - if (!source) { - return true; - } - - const ProcData &data = source->dataForRow(source_row); - - if (data.type == ProcData::NoQtApp) { - return false; - } - - if (data.ppid == m_currentProcId) { - return false; - } - - if (!m_currentUser.isEmpty() && data.user != m_currentUser) { - return false; - } - - return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); -} - -bool ProcessFilterModel::filterAcceptsColumn(int source_column, - const QModelIndex &/*source_parent*/) const -{ - // hide user row if current user was found - return m_currentUser.isEmpty() || source_column != ProcessModel::UserColumn; -} diff -Nru gammaray-1.2.2/launcher/processfiltermodel.h gammaray-2.0.1/launcher/processfiltermodel.h --- gammaray-1.2.2/launcher/processfiltermodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processfiltermodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -/* - processfiltermodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROCESSFILTERMODEL_H -#define GAMMARAY_PROCESSFILTERMODEL_H - -#include - -namespace GammaRay { - -// A filterable and sortable process model -class ProcessFilterModel : public QSortFilterProxyModel -{ - public: - explicit ProcessFilterModel(QObject *parent); - - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; - bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const; - - private: - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - QString m_currentProcId; - QString m_currentUser; -}; - -} - -#endif // GAMMARAY_PROCESSFILTERMODEL_H diff -Nru gammaray-1.2.2/launcher/processlist.h gammaray-2.0.1/launcher/processlist.h --- gammaray-1.2.2/launcher/processlist.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processlist.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -/************************************************************************** -** -** This code is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#ifndef GAMMARAY_PROCESSLIST_H -#define GAMMARAY_PROCESSLIST_H - -#include -#include - -struct ProcData -{ - QString ppid; - QString name; - QString image; - QString state; - QString user; - - enum AppType { - Unknown, - QtApp, - NoQtApp - }; - AppType type; - - ProcData() - : type(Unknown) - { - } -}; - -typedef QList ProcDataList; - -extern ProcDataList processList(const ProcDataList &previous); - -#endif // PROCESSLIST_H diff -Nru gammaray-1.2.2/launcher/processlist_unix.cpp gammaray-2.0.1/launcher/processlist_unix.cpp --- gammaray-1.2.2/launcher/processlist_unix.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processlist_unix.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,209 +0,0 @@ -/************************************************************************** -** -** This code is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#include "processlist.h" - -#include -#include - -#include -#include - -static bool isUnixProcessId(const QString &procname) -{ - for (int i = 0; i != procname.size(); ++i) { - if (!procname.at(i).isDigit()) { - return false; - } - } - return true; -} - -static bool processIsQtApp(const QString &pid) -{ - QProcess lsofProcess; - QStringList args; - args << QLatin1String("-Fn") << QLatin1String("-n") << QLatin1String("-p") << pid; - lsofProcess.start(QLatin1String("lsof"), args); - if (!lsofProcess.waitForStarted()) { - return false; - } - - lsofProcess.waitForFinished(); - const QByteArray output = lsofProcess.readAllStandardOutput(); - - if (output.contains("QtCore")) { - return true; - } - - return false; -} - -struct PidAndNameMatch : public std::unary_function { - - explicit PidAndNameMatch(const QString &ppid, const QString &name) - : m_ppid(ppid), m_name(name) - { - } - - bool operator()(const ProcData &p) const - { - return p.ppid == m_ppid && m_name == p.name; - } - - const QString m_ppid; - const QString m_name; -}; - -// Determine UNIX processes by running ps -static ProcDataList unixProcessListPS(const ProcDataList &previous) -{ -#ifdef Q_OS_MAC - // command goes last, otherwise it is cut off - static const char formatC[] = "pid state user command"; -#else - static const char formatC[] = "pid,state,user,cmd"; -#endif - ProcDataList rc; - QProcess psProcess; - QStringList args; - args << QLatin1String("-e") << QLatin1String("-o") << QLatin1String(formatC); - psProcess.start(QLatin1String("ps"), args); - if (!psProcess.waitForStarted()) { - return rc; - } - psProcess.waitForFinished(); - QByteArray output = psProcess.readAllStandardOutput(); - // Split "457 S+ /Users/foo.app" - const QStringList lines = QString::fromLocal8Bit(output).split(QLatin1Char('\n')); - const int lineCount = lines.size(); - const QChar blank = QLatin1Char(' '); - for (int l = 1; l < lineCount; l++) { // Skip header - const QString line = lines.at(l).simplified(); - // we can't just split on blank as the process name might - // contain them - const int endOfPid = line.indexOf(blank); - const int endOfState = line.indexOf(blank, endOfPid+1); - const int endOfUser = line.indexOf(blank, endOfState+1); - if (endOfPid >= 0 && endOfState >= 0 && endOfUser >= 0) { - ProcData procData; - procData.ppid = line.left(endOfPid); - procData.state = line.mid(endOfPid+1, endOfState-endOfPid-1); - procData.user = line.mid(endOfState+1, endOfUser-endOfState-1); - procData.name = line.right(line.size()-endOfUser-1); - ProcDataList::ConstIterator it = - std::find_if(previous.constBegin(), previous.constEnd(), - PidAndNameMatch(procData.ppid, procData.name)); - if (it != previous.constEnd()) { - procData.type = it->type; - } else { - procData.type = processIsQtApp(procData.ppid) ? - ProcData::QtApp : - ProcData::NoQtApp; - } - rc.push_back(procData); - } - } - - return rc; -} - -// Determine UNIX processes by reading "/proc". Default to ps if -// it does not exist -ProcDataList processList(const ProcDataList &previous) -{ - const QDir procDir(QLatin1String("/proc/")); - if (!procDir.exists()) { - return unixProcessListPS(previous); - } - ProcDataList rc; - const QStringList procIds = procDir.entryList(); - if (procIds.isEmpty()) { - return rc; - } - foreach (const QString &procId, procIds) { - if (!isUnixProcessId(procId)) { - continue; - } - QString filename = QLatin1String("/proc/"); - filename += procId; - filename += QLatin1String("/stat"); - QFile file(filename); - if (!file.open(QIODevice::ReadOnly)) { - continue; // process may have exited - } - - const QStringList data = QString::fromLocal8Bit(file.readAll()).split(' '); - ProcData proc; - proc.ppid = procId; - proc.name = data.at(1); - if (proc.name.startsWith(QLatin1Char('(')) && proc.name.endsWith(QLatin1Char(')'))) { - proc.name.truncate(proc.name.size() - 1); - proc.name.remove(0, 1); - } - proc.state = data.at(2); - // PPID is element 3 - - proc.user = QFileInfo(file).owner(); - file.close(); - - QFile cmdFile(QLatin1String("/proc/") + procId + QLatin1String("/cmdline")); - if(cmdFile.open(QFile::ReadOnly)) { - QByteArray cmd = cmdFile.readAll(); - cmd.replace('\0', ' '); - if (!cmd.isEmpty()) { - proc.name = QString::fromLocal8Bit(cmd); - } - } - cmdFile.close(); - - QFile maps(QLatin1String("/proc/") + procId + QLatin1String("/maps")); - if (!maps.open(QIODevice::ReadOnly)) { - continue; // process may have exited - } - - proc.type = ProcData::NoQtApp; - forever { - const QByteArray line = maps.readLine(); - if (line.isEmpty()) { - break; - } - if (line.contains(QByteArray("/libQtCore.so"))) { - proc.type = ProcData::QtApp; - break; - } - } - - rc.push_back(proc); - } - return rc; -} diff -Nru gammaray-1.2.2/launcher/processlist_win.cpp gammaray-2.0.1/launcher/processlist_win.cpp --- gammaray-1.2.2/launcher/processlist_win.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processlist_win.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,183 +0,0 @@ -/************************************************************************** -** -** This code is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#include "processlist.h" - -#include - -// Enable Win API of XP SP1 and later -#ifdef Q_OS_WIN -# define _WIN32_WINNT 0x0502 -# include -# if !defined(PROCESS_SUSPEND_RESUME) // Check flag for MinGW -# define PROCESS_SUSPEND_RESUME (0x0800) -# endif // PROCESS_SUSPEND_RESUME -#endif // Q_OS_WIN - -#include -#include -// Resolve QueryFullProcessImageNameW out of kernel32.dll due -// to incomplete MinGW import libs and it not being present -// on Windows XP. -static inline BOOL queryFullProcessImageName(HANDLE h, - DWORD flags, - LPWSTR buffer, - DWORD *size) -{ - // Resolve required symbols from the kernel32.dll - typedef BOOL (WINAPI *QueryFullProcessImageNameWProtoType)(HANDLE, DWORD, LPWSTR, PDWORD); - static QueryFullProcessImageNameWProtoType queryFullProcessImageNameW = 0; - if (!queryFullProcessImageNameW) { - QLibrary kernel32Lib(QLatin1String("kernel32.dll"), 0); - if (kernel32Lib.isLoaded() || kernel32Lib.load()) { - queryFullProcessImageNameW = - (QueryFullProcessImageNameWProtoType)kernel32Lib.resolve("QueryFullProcessImageNameW"); - } - } - if (!queryFullProcessImageNameW) { - return FALSE; - } - // Read out process - return (*queryFullProcessImageNameW)(h, flags, buffer, size); -} - -struct ProcessInfo { - QString imageName; - QString processOwner; -}; - -static inline ProcessInfo processInfo(DWORD processId) -{ - ProcessInfo pi; - HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, TOKEN_READ, processId); - if (handle == INVALID_HANDLE_VALUE) { - return pi; - } - WCHAR buffer[MAX_PATH]; - DWORD bufSize = MAX_PATH; - if (queryFullProcessImageName(handle, 0, buffer, &bufSize)) { - pi.imageName = QString::fromUtf16(reinterpret_cast(buffer)); - } - - HANDLE processTokenHandle = NULL; - if (!OpenProcessToken(handle, TOKEN_READ, &processTokenHandle) || !processTokenHandle) { - return pi; - } - - DWORD size = 0; - GetTokenInformation(processTokenHandle, TokenUser, NULL, 0, &size); - - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { - QByteArray buf; - buf.resize(size); - PTOKEN_USER userToken = reinterpret_cast(buf.data()); - if (userToken && GetTokenInformation(processTokenHandle, TokenUser, userToken, size, &size)) { - SID_NAME_USE sidNameUse; - TCHAR user[MAX_PATH] = { 0 }; - DWORD userNameLength = MAX_PATH; - TCHAR domain[MAX_PATH] = { 0 }; - DWORD domainNameLength = MAX_PATH; - - if (LookupAccountSid(NULL, - userToken->User.Sid, - user, - &userNameLength, - domain, - &domainNameLength, - &sidNameUse)) { - pi.processOwner = QString::fromUtf16(reinterpret_cast(user)); - } - } - } - - CloseHandle(processTokenHandle); - CloseHandle(handle); - return pi; -} - -static inline bool isQtApp(DWORD processId) -{ - MODULEENTRY32 me; - me.dwSize = sizeof(MODULEENTRY32); - HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId); - if (snapshot == INVALID_HANDLE_VALUE) { - return false; - } - - for (bool hasNext = Module32First(snapshot, &me); - hasNext; - hasNext = Module32Next(snapshot, &me)) { - const QString module = QString::fromUtf16(reinterpret_cast(me.szModule)); -//TODO: Do this check properly, probe does not need to have the same type -#ifdef NDEBUG - if (module == QLatin1String("QtCore4.dll")) { -#else - if (module == QLatin1String("QtCored4.dll")) { -#endif - CloseHandle(snapshot); - return true; - } - } - CloseHandle(snapshot); - return false; -} - -ProcDataList processList(const ProcDataList &previous) -{ - ProcDataList rc; - - PROCESSENTRY32 pe; - pe.dwSize = sizeof(PROCESSENTRY32); - HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - if (snapshot == INVALID_HANDLE_VALUE) { - return rc; - } - - for (bool hasNext = Process32First(snapshot, &pe); - hasNext; - hasNext = Process32Next(snapshot, &pe)) { - ProcData procData; - procData.ppid = QString::number(pe.th32ProcessID); - procData.name = QString::fromUtf16(reinterpret_cast(pe.szExeFile)); - const ProcessInfo processInf = processInfo(pe.th32ProcessID); - procData.image = processInf.imageName; - procData.user = processInf.processOwner; - if (isQtApp(pe.th32ProcessID)) { - procData.type = ProcData::QtApp; - } else { - procData.type = ProcData::NoQtApp; - } - rc.push_back(procData); - } - CloseHandle(snapshot); - return rc; -} diff -Nru gammaray-1.2.2/launcher/processmodel.cpp gammaray-2.0.1/launcher/processmodel.cpp --- gammaray-1.2.2/launcher/processmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processmodel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,195 +0,0 @@ -/* - processmodel.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "processmodel.h" -#include - -using namespace GammaRay; - -bool operator<(const ProcData &l, const ProcData &r) -{ - return l.ppid < r.ppid; -} - -bool operator==(const ProcData &l, const ProcData &r) -{ - return l.ppid == r.ppid; -} - -QDebug operator<<(QDebug d, const ProcData &data) { - d << "ProcData{.ppid=" << data.ppid << ", .name=" << data.name << ", .image=" << data.image - << ", .state=" << data.state << ", .user=" << data.user << ", .type=" << data.type << "}"; - return d; -} - -ProcessModel::ProcessModel(QObject *parent) -: QAbstractTableModel(parent) -{ -} - -ProcessModel::~ProcessModel() -{ -} - -void ProcessModel::setProcesses(const ProcDataList &processes) -{ - beginResetModel(); - m_data = processes; - // sort for merging to work properly - qStableSort(m_data); - endResetModel(); -} - -void ProcessModel::mergeProcesses(const ProcDataList &processes) -{ - // sort like m_data - ProcDataList sortedProcesses = processes; - qStableSort(sortedProcesses); - - // iterator over m_data - int i = 0; - - foreach (const ProcData &newProc, sortedProcesses) { - bool shouldInsert = true; - while (i < m_data.count()) { - const ProcData &oldProc = m_data.at(i); - if (oldProc < newProc) { - // remove old proc, seems to be outdated - beginRemoveRows(QModelIndex(), i, i); - m_data.removeAt(i); - endRemoveRows(); - continue; - } else if (newProc == oldProc) { - // already contained, hence increment and break - ++i; - shouldInsert = false; - break; - } else { // newProc < oldProc - // new entry, break and insert it - break; - } - } - if (shouldInsert) { - beginInsertRows(QModelIndex(), i, i); - m_data.insert(i, newProc); - endInsertRows(); - // let i point to old element again - ++i; - } - } - - // make sure the new data is properly inserted - Q_ASSERT(m_data == sortedProcesses); -} - -void ProcessModel::clear() -{ - beginRemoveRows(QModelIndex(), 0, m_data.count()); - m_data.clear(); - endRemoveRows(); -} - -ProcData ProcessModel::dataForIndex(const QModelIndex &index) const -{ - return m_data.at(index.row()); -} - -ProcData ProcessModel::dataForRow(int row) const -{ - return m_data.at(row); -} - -QModelIndex ProcessModel::indexForPid(const QString &pid) const -{ - for (int i = 0; i < m_data.size(); ++i) { - if (m_data.at(i).ppid == pid) { - return index(i, 0); - } - } - return QModelIndex(); -} - -QVariant ProcessModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole || orientation != Qt::Horizontal) { - return QVariant(); - } - - if (section == PIDColumn) { - return tr("Process ID"); - } else if (section == NameColumn) { - return tr("Name"); - } else if (section == StateColumn) { - return tr("State"); - } else if (section == UserColumn) { - return tr("User"); - } - - return QVariant(); -} - -QVariant ProcessModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - - const ProcData &data = m_data.at(index.row()); - - if (role == Qt::DisplayRole) { - if (index.column() == PIDColumn) { - return data.ppid; - } else if (index.column() == NameColumn) { - return data.image.isEmpty() ? data.name : data.image; - } else if (index.column() == StateColumn) { - return data.state; - } else if (index.column() == UserColumn) { - return data.user; - } - } else if (role == PIDRole) { - return data.ppid; - } else if (role == NameRole) { - return data.image.isEmpty() ? data.name : data.image; - } else if (role == StateRole) { - return data.state; - } else if (role == UserRole) { - return data.user; - } - - return QVariant(); -} - -int ProcessModel::columnCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : COLUMN_COUNT; -} - -int ProcessModel::rowCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : m_data.count(); -} - -ProcDataList ProcessModel::processes() const -{ - return m_data; -} diff -Nru gammaray-1.2.2/launcher/processmodel.h gammaray-2.0.1/launcher/processmodel.h --- gammaray-1.2.2/launcher/processmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/processmodel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -/* - processmodel.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROCESSMODEL_H -#define GAMMARAY_PROCESSMODEL_H - -#include - -#include "processlist.h" - -namespace GammaRay { - -class ProcessModel : public QAbstractTableModel -{ - public: - explicit ProcessModel(QObject *parent = 0); - virtual ~ProcessModel(); - - void setProcesses(const ProcDataList &processes); - void mergeProcesses(const ProcDataList &processes); - ProcData dataForIndex(const QModelIndex &index) const; - ProcData dataForRow(int row) const; - QModelIndex indexForPid(const QString &pid) const; - - ProcDataList processes() const; - - void clear(); - - enum Columns { - PIDColumn, - NameColumn, - StateColumn, - UserColumn, - COLUMN_COUNT - }; - - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - - enum CustomRoles { - PIDRole = Qt::UserRole, - NameRole, - StateRole, - UserRole - }; - - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - - private: - ProcDataList m_data; -}; - -} - -#endif // GAMMARAY_PROCESSMODEL_H diff -Nru gammaray-1.2.2/launcher/promolabel.cpp gammaray-2.0.1/launcher/promolabel.cpp --- gammaray-1.2.2/launcher/promolabel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/promolabel.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -/* - mainwindow.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "promolabel.h" - -#include -#include -#include -#include - -using namespace GammaRay; - -PromoLabel::PromoLabel(QWidget *parent, Qt::WindowFlags f) -: QLabel(parent, f) -{ - updatePixmap(); - - setCursor(QCursor(Qt::PointingHandCursor)); - setToolTip(tr("Visit KDAB Website")); -} - -bool PromoLabel::event(QEvent *e) -{ - if (e->type() == QEvent::PaletteChange) { - updatePixmap(); - } - return QLabel::event(e); -} - -void PromoLabel::mouseReleaseEvent(QMouseEvent *ev) -{ - if (ev->button() == Qt::LeftButton && ev->modifiers() == Qt::NoModifier) { - QDesktopServices::openUrl(QUrl("http://www.kdab.com")); - ev->accept(); - return; - } - - QLabel::mouseReleaseEvent(ev); -} - -QImage PromoLabel::tintedImage(const QString &image, const QColor &color) -{ - QImage img(image); - img = img.alphaChannel(); - QColor newColor = color; - for (int i = 0; i < img.colorCount(); ++i) { - newColor.setAlpha(qGray(img.color(i))); - img.setColor(i, newColor.rgba()); - } - return img; -} - -void PromoLabel::updatePixmap() -{ - // load image and adapt it to user's foreground color - setPixmap(QPixmap::fromImage(tintedImage(QString(":gammaray/kdabproducts.png"), - palette().foreground().color()))); -} - -#include "promolabel.moc" diff -Nru gammaray-1.2.2/launcher/promolabel.h gammaray-2.0.1/launcher/promolabel.h --- gammaray-1.2.2/launcher/promolabel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/promolabel.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -/* - mainwindow.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_PROMOLABEL_H -#define GAMMARAY_PROMOLABEL_H - -#include - -namespace GammaRay { - -class PromoLabel : public QLabel -{ - Q_OBJECT - - public: - explicit PromoLabel(QWidget *parent = 0, Qt::WindowFlags f = 0); - - static QImage tintedImage(const QString &image, const QColor &color); - - protected: - virtual bool event(QEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *ev); - - private: - void updatePixmap(); -}; - -} - -#endif // PROMOLABEL_H diff -Nru gammaray-1.2.2/launcher/selftestpage.cpp gammaray-2.0.1/launcher/selftestpage.cpp --- gammaray-1.2.2/launcher/selftestpage.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/selftestpage.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,121 +0,0 @@ -/* - selftestpage.cpp - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "selftestpage.h" -#include "probefinder.h" -#include "ui_selftestpage.h" - -#include "injector/injectorfactory.h" - -#include -#include - -using namespace GammaRay; - -SelfTestPage::SelfTestPage(QWidget *parent) - : QWidget(parent), ui(new Ui::SelfTestPage), m_resultModel(new QStandardItemModel(this)) -{ - ui->setupUi(this); - ui->resultView->setModel(m_resultModel); - run(); -} - -SelfTestPage::~SelfTestPage() -{ - delete ui; -} - -void SelfTestPage::run() -{ - m_resultModel->clear(); - testProbe(); - testAvailableInjectors(); - testInjectors(); -} - -void SelfTestPage::testProbe() -{ - const QString probePath = ProbeFinder::findProbe(QLatin1String("gammaray_probe")); - if (probePath.isEmpty()) { - error(tr("No probe found - GammaRay not functional.")); - return; - } - - QFileInfo fi(probePath); - if (!fi.exists() || !fi.isFile() || !fi.isReadable()) { - error(tr("Probe at %1 is invalid - GammaRay not functional.")); - return; - } - - information(tr("Found valid probe at %1.").arg(probePath)); -} - -void SelfTestPage::testAvailableInjectors() -{ - const QStringList injectors = InjectorFactory::availableInjectors(); - if (injectors.isEmpty()) { - error(tr("No injectors available - GammaRay not functional.")); - return; - } - - information(tr("The following injectors are available: %1"). - arg(injectors.join(QLatin1String(", ")))); -} - -void SelfTestPage::testInjectors() -{ - foreach (const QString &injectorType, InjectorFactory::availableInjectors()) { - AbstractInjector::Ptr injector = InjectorFactory::createInjector(injectorType); - if (!injector) { - error(tr("Unable to create instance of injector %1.").arg(injectorType)); - continue; - } - if (injector->selfTest()) { - information(tr("Injector %1 successfully passed its self-test."). - arg(injectorType)); - } else { - error(tr("Injector %1 failed to pass its self-test: %2."). - arg(injectorType, injector->errorString())); - } - } -} - -void SelfTestPage::error(const QString &msg) -{ - QStandardItem *item = new QStandardItem; - item->setEditable(false); - item->setText(msg); - item->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical)); - m_resultModel->appendRow(item); -} - -void SelfTestPage::information(const QString &msg) -{ - QStandardItem *item = new QStandardItem; - item->setEditable(false); - item->setText(msg); - item->setIcon(style()->standardIcon(QStyle::SP_MessageBoxInformation)); - m_resultModel->appendRow(item); -} - -#include "selftestpage.moc" diff -Nru gammaray-1.2.2/launcher/selftestpage.h gammaray-2.0.1/launcher/selftestpage.h --- gammaray-1.2.2/launcher/selftestpage.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/selftestpage.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -/* - selftestpage.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2011-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Volker Krause - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SELFTESTPAGE_H -#define GAMMARAY_SELFTESTPAGE_H - -#include - -class QStandardItemModel; - -namespace GammaRay { - -namespace Ui { - class SelfTestPage; -} - -class SelfTestPage : public QWidget -{ - Q_OBJECT - public: - explicit SelfTestPage(QWidget *parent = 0); - ~SelfTestPage(); - - public slots: - void run(); - - private: - void testProbe(); - void testAvailableInjectors(); - void testInjectors(); - - void error(const QString &msg); - void information(const QString &msg); - - private: - Ui::SelfTestPage *ui; - QStandardItemModel *m_resultModel; -}; - -} - -#endif // GAMMARAY_SELFTESTPAGE_H diff -Nru gammaray-1.2.2/launcher/selftestpage.ui gammaray-2.0.1/launcher/selftestpage.ui --- gammaray-1.2.2/launcher/selftestpage.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/selftestpage.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - GammaRay::SelfTestPage - - - - 0 - 0 - 400 - 300 - - - - - - - - - - - diff -Nru gammaray-1.2.2/launcher/splashscreen.cpp gammaray-2.0.1/launcher/splashscreen.cpp --- gammaray-1.2.2/launcher/splashscreen.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/splashscreen.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ -/* - attachdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "splashscreen.h" - -#include -#include - -QSplashScreen *splash = 0; - -namespace GammaRay { - -void showSplashScreen() -{ - if (!splash) { - QPixmap pixmap(QLatin1String(":gammaray/splashscreen.png")); - splash = new QSplashScreen(pixmap); - splash->setMask(pixmap.mask()); - } - - splash->show(); -} - -void hideSplashScreen() -{ - if (splash) { - splash->hide(); - } -} - -} diff -Nru gammaray-1.2.2/launcher/splashscreen.h gammaray-2.0.1/launcher/splashscreen.h --- gammaray-1.2.2/launcher/splashscreen.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/launcher/splashscreen.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -/* - attachdialog.h - - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Milian Wolff - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_SPLASHSCREEN_H -#define GAMMARAY_SPLASHSCREEN_H - -namespace GammaRay { - -void showSplashScreen(); -void hideSplashScreen(); - -} - -#endif // SPLASHSCREEN_H diff -Nru gammaray-1.2.2/launcher/ui/attachdialog.cpp gammaray-2.0.1/launcher/ui/attachdialog.cpp --- gammaray-1.2.2/launcher/ui/attachdialog.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/attachdialog.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,152 @@ +/* + attachdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "attachdialog.h" + +#include "launchoptions.h" +#include "processfiltermodel.h" +#include "processmodel.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +AttachDialog::AttachDialog(QWidget *parent, Qt::WindowFlags f) +: QWidget(parent, f) +{ + ui.setupUi(this); + + m_model = new ProcessModel(this); + + m_proxyModel = new ProcessFilterModel(this); + m_proxyModel->setSourceModel(m_model); + m_proxyModel->setDynamicSortFilter(true); + + ui.view->setModel(m_proxyModel); + // hide state + ui.view->hideColumn(ProcessModel::StateColumn); + ui.view->sortByColumn(ProcessModel::NameColumn, Qt::AscendingOrder); + ui.view->setSortingEnabled(true); + + ui.view->setEditTriggers(QAbstractItemView::NoEditTriggers); + + ui.view->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.view->setSelectionMode(QAbstractItemView::SingleSelection); + connect(ui.view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), + this, SIGNAL(updateButtonState())); + + connect(ui.view, SIGNAL(activated(QModelIndex)), SIGNAL(activate())); + + ui.filter->setProxy(m_proxyModel); + + QStringListModel *probeABIModel = new QStringListModel(this); + probeABIModel->setStringList(ProbeFinder::listProbeABIs()); + ui.probeBox->setModel(probeABIModel); + + QSettings settings; + ui.probeBox->setCurrentIndex(settings.value(QLatin1String("Launcher/AttachProbeABI")).toInt()); + ui.accessMode->setCurrentIndex(settings.value(QLatin1String("Launcher/AttachAccessMode")).toInt()); + + setWindowTitle(tr("GammaRay - Attach to Process")); + setWindowIcon(QIcon(":gammaray/GammaRay-128x128.png")); + + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(updateProcesses())); + m_timer->start(1000); + + ui.stackedWidget->setCurrentWidget(ui.loadingLabel); + emit updateButtonState(); + updateProcesses(); +} + +bool AttachDialog::isValid() const +{ + return ui.view->currentIndex().isValid(); +} + +void AttachDialog::writeSettings() +{ + QSettings settings; + settings.setValue(QLatin1String("Launcher/AttachProbeABI"), ui.probeBox->currentIndex()); + settings.setValue(QLatin1String("Launcher/AttachAccessMode"), ui.accessMode->currentIndex()); +} + +LaunchOptions AttachDialog::launchOptions() const +{ + LaunchOptions opt; + opt.setPid(pid()); + opt.setProbeABI(ui.probeBox->currentText()); + + switch (ui.accessMode->currentIndex()) { + case 0: // local, out-of-process + opt.setProbeSetting("TCPServer", "127.0.0.1"); + opt.setUiMode(LaunchOptions::OutOfProcessUi); + break; + case 1: // remote, out-of-process + opt.setProbeSetting("TCPServer", "0.0.0.0"); + opt.setUiMode(LaunchOptions::OutOfProcessUi); + break; + case 2: // in-process + opt.setProbeSetting("RemoteAccessEnabled", false); + opt.setUiMode(LaunchOptions::InProcessUi); + break; + } + + return opt; +} + +int AttachDialog::pid() const +{ + return ui.view->currentIndex().data(ProcessModel::PIDRole).toInt(); +} + +void AttachDialog::updateProcesses() +{ + QFutureWatcher* watcher = new QFutureWatcher(this); + connect(watcher, SIGNAL(finished()), + this, SLOT(updateProcessesFinished())); + watcher->setFuture(QtConcurrent::run(processList, m_model->processes())); +} + +void AttachDialog::updateProcessesFinished() +{ + QFutureWatcher* watcher = dynamic_cast*>(sender()); + Q_ASSERT(watcher); + ui.stackedWidget->setCurrentWidget(ui.listViewPage); + const int oldPid = pid(); + m_model->mergeProcesses(watcher->result()); + if (oldPid != pid()) { + ui.view->setCurrentIndex(QModelIndex()); + } + watcher->deleteLater(); +} + diff -Nru gammaray-1.2.2/launcher/ui/attachdialog.h gammaray-2.0.1/launcher/ui/attachdialog.h --- gammaray-1.2.2/launcher/ui/attachdialog.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/attachdialog.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + attachdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ATTACHDIALOG_H +#define GAMMARAY_ATTACHDIALOG_H + +#include + +#include "processlist.h" +#include "ui_attachdialog.h" + +namespace GammaRay { + +class LaunchOptions; +class ProcessModel; +class ProcessFilterModel; + +class AttachDialog : public QWidget +{ + Q_OBJECT + + public: + explicit AttachDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); + + LaunchOptions launchOptions() const; + int pid() const; + + /// Returns @c true if a valid process is selected. + bool isValid() const; + void writeSettings(); + + signals: + void updateButtonState(); + void activate(); + + private slots: + void updateProcesses(); + void updateProcessesFinished(); + + private: + Ui::AttachDialog ui; + ProcessModel *m_model; + ProcessFilterModel *m_proxyModel; + QTimer *m_timer; +}; + +} // namespace GammaRay + +#endif // ATTACHDIALOG_H diff -Nru gammaray-1.2.2/launcher/ui/attachdialog.ui gammaray-2.0.1/launcher/ui/attachdialog.ui --- gammaray-1.2.2/launcher/ui/attachdialog.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/attachdialog.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,115 @@ + + + GammaRay::AttachDialog + + + + 0 + 0 + 400 + 323 + + + + Dialog + + + + :/gammaray/GammaRay-128x128.png:/gammaray/GammaRay-128x128.png + + + + + + 1 + + + + <html><head/><body><p align="center"><img src=":/gammaray/GammaRay-48x48.png"/></p><p align="center">Retrieving the list of processes which use Qt ...</p></body></html> + + + + + + 0 + + + + + + + + false + + + + + + + + + Pro&be: + + + probeBox + + + + + + + + + + &Access mode: + + + accessMode + + + + + + + 0 + + + + Out-of-process, local debugging only + + + + + Out-of-process, remote debugging enabled + + + + + In-process + + + + + + + + + listViewPage + loadingLabel + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+ 1 +
+
+ + + + +
diff -Nru gammaray-1.2.2/launcher/ui/CMakeLists.txt gammaray-2.0.1/launcher/ui/CMakeLists.txt --- gammaray-1.2.2/launcher/ui/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +set(gammaray_launcher_ui_srcs + main.cpp + promolabel.cpp + launcherwindow.cpp + launchpage.cpp + selftestpage.cpp + connectpage.cpp + networkdiscoverymodel.cpp + attachdialog.cpp + processmodel.cpp + processfiltermodel.cpp +) +if(NOT WIN32) + list(APPEND gammaray_launcher_ui_srcs processlist_unix.cpp) +else() + list(APPEND gammaray_launcher_ui_srcs processlist_win.cpp) +endif() + +qt4_wrap_ui(gammaray_launcher_ui_srcs + attachdialog.ui + launcherwindow.ui + launchpage.ui + selftestpage.ui + connectpage.ui +) +# TODO we don't need all the class icons here, so split the qrc file accordingly +qt4_add_resources(gammaray_launcher_ui_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc) + +add_executable(gammaray-launcher WIN32 ${gammaray_launcher_ui_srcs}) + +target_link_libraries(gammaray-launcher + ${QT_QTCORE_LIBRARIES} + ${QT_QTCONCURRENT_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common_internal + gammaray_ui + gammaray_launcher_shared +) + +if(QNXNTO) + target_link_libraries(gammaray-launcher cpp) +endif() + +if(UNIX AND NOT APPLE AND NOT QNXNTO) + target_link_libraries(gammaray-launcher dl) # for preload check +endif() + +gammaray_embed_info_plist(gammaray-launcher ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in) +set_target_properties(gammaray-launcher PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${LIBEXEC_INSTALL_DIR}" +) + +install(TARGETS gammaray-launcher DESTINATION ${LIBEXEC_INSTALL_DIR}) + diff -Nru gammaray-1.2.2/launcher/ui/connectpage.cpp gammaray-2.0.1/launcher/ui/connectpage.cpp --- gammaray-1.2.2/launcher/ui/connectpage.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/connectpage.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ +/* + connectpage.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "connectpage.h" +#include "ui_connectpage.h" +#include "networkdiscoverymodel.h" +#include "clientlauncher.h" + +#include + +#include +#include + +using namespace GammaRay; + +ConnectPage::ConnectPage(QWidget* parent): QWidget(parent), ui(new Ui::ConnectPage) +{ + ui->setupUi(this); + + connect(ui->host, SIGNAL(textChanged(QString)), SIGNAL(updateButtonState())); + connect(ui->port, SIGNAL(valueChanged(int)), SIGNAL(updateButtonState())); + + NetworkDiscoveryModel* model = new NetworkDiscoveryModel(this); + ui->instanceView->setModel(model); + connect(ui->instanceView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(instanceSelected())); + + QSettings settings; + ui->host->setText(settings.value("Connect/Host", QString()).toString()); + ui->port->setValue(settings.value("Connect/Port", Endpoint::defaultPort()).toInt()); +} + +ConnectPage::~ConnectPage() +{ +} + +bool ConnectPage::isValid() const +{ + return !ui->host->text().isEmpty(); +} + +void ConnectPage::launchClient() +{ + ClientLauncher::launchDetached(ui->host->text(), ui->port->value()); +} + +void ConnectPage::writeSettings() +{ + QSettings settings; + settings.setValue("Connect/Host", ui->host->text()); + settings.setValue("Connect/Port", ui->port->value()); +} + +void ConnectPage::instanceSelected() +{ + const QModelIndexList rows = ui->instanceView->selectionModel()->selectedRows(); + if (rows.size() != 1) + return; + + ui->host->setText(rows.first().data(NetworkDiscoveryModel::HostNameRole).toString()); + ui->port->setValue(rows.first().data(NetworkDiscoveryModel::PortRole).toInt()); +} + diff -Nru gammaray-1.2.2/launcher/ui/connectpage.h gammaray-2.0.1/launcher/ui/connectpage.h --- gammaray-1.2.2/launcher/ui/connectpage.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/connectpage.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + connectpage.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CONNECTPAGE_H +#define GAMMARAY_CONNECTPAGE_H + +#include + +namespace GammaRay { + +namespace Ui { +class ConnectPage; +} + +/** UI for connecting to a running GammaRay instance. */ +class ConnectPage : public QWidget +{ + Q_OBJECT +public: + explicit ConnectPage(QWidget* parent = 0); + ~ConnectPage(); + + bool isValid() const; + void writeSettings(); + +public slots: + void launchClient(); + +signals: + void updateButtonState(); + +private slots: + void instanceSelected(); + +private: + QScopedPointer ui; + +}; +} + +#endif // GAMMARAY_CONNECTPAGE_H diff -Nru gammaray-1.2.2/launcher/ui/connectpage.ui gammaray-2.0.1/launcher/ui/connectpage.ui --- gammaray-1.2.2/launcher/ui/connectpage.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/connectpage.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ + + + GammaRay::ConnectPage + + + + 0 + 0 + 400 + 300 + + + + + + + Connect to a running remote instance. + + + + + + + + + &Host: + + + host + + + + + + + + + + &Port: + + + port + + + + + + + 65536 + + + + + + + + + false + + + true + + + + + + + + diff -Nru gammaray-1.2.2/launcher/ui/Info.plist.in gammaray-2.0.1/launcher/ui/Info.plist.in --- gammaray-1.2.2/launcher/ui/Info.plist.in 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/Info.plist.in 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,14 @@ + + + CFBundleIdentifier + com.kdab.GammaRay.launcherUi + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + GammaRay + CFBundleVersion + @GAMMARAY_VERSION_STRING@ + CFBundleShortVersion + @GAMMARAY_VERSION@ + + diff -Nru gammaray-1.2.2/launcher/ui/launcherwindow.cpp gammaray-2.0.1/launcher/ui/launcherwindow.cpp --- gammaray-1.2.2/launcher/ui/launcherwindow.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launcherwindow.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,99 @@ +/* + launcherwindow.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "launcherwindow.h" +#include "ui_launcherwindow.h" +#include "config-gammaray-version.h" +#include "launchoptions.h" + +#include +#include + +using namespace GammaRay; + +LauncherWindow::LauncherWindow(QWidget *parent) + : QDialog(parent), ui(new Ui::LauncherWindow) +{ + ui->setupUi(this); + ui->aboutLabel->setText(ui->aboutLabel->text().arg(GAMMARAY_VERSION_STRING)); + connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabChanged())); + connect(ui->attachPage, SIGNAL(updateButtonState()), SLOT(tabChanged())); + connect(ui->launchPage, SIGNAL(updateButtonState()), SLOT(tabChanged())); + connect(ui->connectPage, SIGNAL(updateButtonState()), SLOT(tabChanged())); + connect(ui->attachPage, SIGNAL(activate()), + ui->buttonBox->button(QDialogButtonBox::Ok), SLOT(click())); + + setWindowTitle(tr("GammaRay Launcher")); + + QSettings settings; + ui->tabWidget->setCurrentIndex(settings.value(QLatin1String("Launcher/TabIndex")).toInt()); +} + +LauncherWindow::~LauncherWindow() +{ + delete ui; +} + +LaunchOptions LauncherWindow::launchOptions() const +{ + QWidget *current = ui->tabWidget->currentWidget(); + if (current == ui->launchPage) { + return ui->launchPage->launchOptions(); + } else if (current == ui->attachPage) { + return ui->attachPage->launchOptions(); + } + return LaunchOptions(); +} + +void LauncherWindow::tabChanged() +{ + if (ui->tabWidget->currentWidget() == ui->attachPage) { + ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Attach")); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->attachPage->isValid()); + } else if (ui->tabWidget->currentWidget() == ui->launchPage) { + ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Launch")); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->launchPage->isValid()); + } else if (ui->tabWidget->currentWidget() == ui->connectPage) { + ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Connect")); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->connectPage->isValid()); + } else { + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } +} + +void LauncherWindow::accept() +{ + QSettings settings; + settings.setValue(QLatin1String("Launcher/TabIndex"), ui->tabWidget->currentIndex()); + + ui->launchPage->writeSettings(); + ui->attachPage->writeSettings(); + ui->connectPage->writeSettings(); + + if (ui->tabWidget->currentWidget() == ui->connectPage) { + ui->connectPage->launchClient(); + } + + QDialog::accept(); +} + diff -Nru gammaray-1.2.2/launcher/ui/launcherwindow.h gammaray-2.0.1/launcher/ui/launcherwindow.h --- gammaray-1.2.2/launcher/ui/launcherwindow.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launcherwindow.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + launcherwindow.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LAUNCHERWINDOW_H +#define GAMMARAY_LAUNCHERWINDOW_H + +#include + +namespace GammaRay { + +class LaunchOptions; +namespace Ui { + class LauncherWindow; +} + +class LauncherWindow : public QDialog +{ + Q_OBJECT + public: + explicit LauncherWindow(QWidget *parent = 0); + ~LauncherWindow(); + + /// returns all information required to perform the launch/attach + LaunchOptions launchOptions() const; + + void accept(); + + private slots: + void tabChanged(); + + private: + Ui::LauncherWindow *ui; +}; + +} + +#endif // GAMMARAY_LAUNCHERWINDOW_H diff -Nru gammaray-1.2.2/launcher/ui/launcherwindow.ui gammaray-2.0.1/launcher/ui/launcherwindow.ui --- gammaray-1.2.2/launcher/ui/launcherwindow.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launcherwindow.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,203 @@ + + + GammaRay::LauncherWindow + + + + 0 + 0 + 748 + 482 + + + + Dialog + + + + :/gammaray/GammaRay-128x128.png:/gammaray/GammaRay-128x128.png + + + + + + 3 + + + + Attach + + + + + Launch + + + + + Connect + + + + + Self Test + + + + + About + + + + + + + + + 0 + 0 + + + + + + + :/gammaray/GammaRay-128x128.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-weight:600;">GammaRay %1</span></p><p>The Qt application inspection and manipulation tool. Learn more at <a href="http://www.kdab.com/gammaray"><span style=" text-decoration: underline; color:#0057ae;">http://www.kdab.com/gammaray</span></a>.</p><p>Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, <a href="mailto:info@kdab.com"><span style=" text-decoration: underline; color:#0057ae;">info@kdab.com</span></a></p><p><span style=" text-decoration: underline;">Authors:</span><br/>Allen Winter &lt;allen.winter@kdab.com&gt;<br/>Andreas Holzammer &lt;andreas.holzammer@kdab.com&gt;<br/>David Faure &lt;david.faure@kdab.com&gt;<br/>Kevin Funk &lt;kevin.funk@kdab.com&gt;<br/>Milian Wolff &lt;milian.wolff@kdab.com&gt;<br/>Patrick Spendrin &lt;patrick.spendrin@kdab.com&gt;<br/>Stephen Kelly &lt;stephen.kelly@kdab.com&gt;<br/>Till Adam &lt;till@kdab.com&gt;<br/>Thomas McGuire &lt;thomas.mcguire@kdab.com&gt;<br/>Tobias Koenig &lt;tobias.koenig@kdab.com&gt;<br/>Volker Krause &lt;volker.krause@kdab.com&gt;</p><p>StackWalker code Copyright (c) 2005-2009, Jochen Kalmbach, All rights reserved</p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + + + + + + + + + + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Ok + + + + + + + + + + + GammaRay::PromoLabel + QWidget +
promolabel.h
+ 1 +
+ + GammaRay::AttachDialog + QWidget +
attachdialog.h
+ 1 +
+ + GammaRay::LaunchPage + QWidget +
launchpage.h
+ 1 +
+ + GammaRay::SelfTestPage + QWidget +
selftestpage.h
+ 1 +
+ + GammaRay::ConnectPage + QWidget +
connectpage.h
+ 1 +
+
+ + + + + + buttonBox + accepted() + GammaRay::LauncherWindow + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GammaRay::LauncherWindow + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff -Nru gammaray-1.2.2/launcher/ui/launchpage.cpp gammaray-2.0.1/launcher/ui/launchpage.cpp --- gammaray-1.2.2/launcher/ui/launchpage.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launchpage.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,179 @@ +/* + launchpage.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "launchpage.h" +#include "ui_launchpage.h" +#include "launchoptions.h" +#include "probefinder.h" + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +LaunchPage::LaunchPage(QWidget *parent) + : QWidget(parent), + ui(new Ui::LaunchPage), + m_argsModel(new QStringListModel(this)) +{ + ui->setupUi(this); + connect(ui->progSelectButton, SIGNAL(clicked()), SLOT(showFileDialog())); + connect(ui->addArgButton, SIGNAL(clicked()), SLOT(addArgument())); + connect(ui->removeArgButton, SIGNAL(clicked()), SLOT(removeArgument())); + connect(ui->progEdit, SIGNAL(textChanged(QString)), SIGNAL(updateButtonState())); + + ui->argsBox->setModel(m_argsModel); + + QCompleter *pathCompleter = new QCompleter(this); + QFileSystemModel *fsModel = new QFileSystemModel(this); + fsModel->setRootPath(QDir::rootPath()); + pathCompleter->setModel(fsModel); + ui->progEdit->setCompleter(pathCompleter); + + QStringListModel *probeABIModel = new QStringListModel(this); + probeABIModel->setStringList(ProbeFinder::listProbeABIs()); + ui->probeBox->setModel(probeABIModel); + + QSettings settings; + ui->progEdit->setText(settings.value(QLatin1String("Launcher/Program")).toString()); + m_argsModel->setStringList(settings.value(QLatin1String("Launcher/Arguments")).toStringList()); + ui->probeBox->setCurrentIndex(settings.value(QLatin1String("Launcher/ProbeABI")).toInt()); + ui->accessMode->setCurrentIndex(settings.value(QLatin1String("Launcher/AccessMode")).toInt()); + updateArgumentButtons(); +} + +LaunchPage::~LaunchPage() +{ + delete ui; +} + +void LaunchPage::writeSettings() +{ + QSettings settings; + settings.setValue(QLatin1String("Launcher/Program"), ui->progEdit->text()); + settings.setValue(QLatin1String("Launcher/Arguments"), notEmptyString(m_argsModel->stringList())); + settings.setValue(QLatin1String("Launcher/ProbeABI"), ui->probeBox->currentIndex()); + settings.setValue(QLatin1String("Launcher/AccessMode"), ui->accessMode->currentIndex()); +} + +QStringList LaunchPage::notEmptyString(const QStringList &list) const +{ + QStringList notEmptyStringList; + const int numberOfArguments = list.count(); + for (int i = 0; i < numberOfArguments; ++i) { + if(!list.at(i).trimmed().isEmpty()) { + notEmptyStringList << list.at(i); + } + } + return notEmptyStringList; +} + +LaunchOptions LaunchPage::launchOptions() const +{ + LaunchOptions opt; + + QStringList l; + l.push_back(ui->progEdit->text()); + l.append(notEmptyString(m_argsModel->stringList())); + opt.setLaunchArguments(l); + opt.setProbeABI(ui->probeBox->currentText()); + + switch (ui->accessMode->currentIndex()) { + case 0: // local, out-of-process + opt.setProbeSetting("RemoteAccessEnabled", true); + opt.setProbeSetting("TCPServer", "127.0.0.1"); + opt.setUiMode(LaunchOptions::OutOfProcessUi); + break; + case 1: // remote, out-of-process + opt.setProbeSetting("RemoteAccessEnabled", true); + opt.setProbeSetting("TCPServer", "0.0.0.0"); + opt.setUiMode(LaunchOptions::OutOfProcessUi); + break; + case 2: // in-process + opt.setProbeSetting("RemoteAccessEnabled", false); + opt.setUiMode(LaunchOptions::InProcessUi); + break; + } + + return opt; +} + +void LaunchPage::showFileDialog() +{ + const QString exeFilePath = + QFileDialog::getOpenFileName( + this, + tr("Executable to Launch"), + ui->progEdit->text() +#ifdef Q_OS_WIN + ,tr("Executable (*.exe)") +#endif + ); + + if (exeFilePath.isEmpty()) { + return; + } + + ui->progEdit->setText(exeFilePath); +} + +void LaunchPage::addArgument() +{ + m_argsModel->insertRows(m_argsModel->rowCount(), 1); + const QModelIndex newIndex = m_argsModel->index(m_argsModel->rowCount() - 1, 0); + ui->argsBox->edit(newIndex); + updateArgumentButtons(); +} + +void LaunchPage::removeArgument() +{ + // TODO check if there's a selection at all and update button state accordingly + m_argsModel->removeRows(ui->argsBox->currentIndex().row(), 1); + updateArgumentButtons(); +} + +bool LaunchPage::isValid() +{ + if (ui->progEdit->text().isEmpty()) { + return false; + } + + const QFileInfo fi(ui->progEdit->text()); + +#ifdef Q_OS_MAC + if (fi.isBundle() && (fi.suffix() == "app")) { + return true; + } +#endif + + return fi.exists() && fi.isFile() && fi.isExecutable(); +} + +void LaunchPage::updateArgumentButtons() +{ + ui->removeArgButton->setEnabled(m_argsModel->rowCount() > 0); +} + diff -Nru gammaray-1.2.2/launcher/ui/launchpage.h gammaray-2.0.1/launcher/ui/launchpage.h --- gammaray-1.2.2/launcher/ui/launchpage.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launchpage.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ +/* + launchpage.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LAUNCHPAGE_H +#define GAMMARAY_LAUNCHPAGE_H + +#include + +class QStringListModel; + +namespace GammaRay { + +class LaunchOptions; +namespace Ui { + class LaunchPage; +} + +class LaunchPage : public QWidget +{ + Q_OBJECT + public: + explicit LaunchPage(QWidget *parent = 0); + ~LaunchPage(); + + LaunchOptions launchOptions() const; + + bool isValid(); + + void writeSettings(); + + signals: + void updateButtonState(); + + private slots: + void showFileDialog(); + void addArgument(); + void removeArgument(); + void updateArgumentButtons(); + + private: + QStringList notEmptyString(const QStringList &list) const; + Ui::LaunchPage *ui; + QStringListModel *m_argsModel; +}; + +} + +#endif // GAMMARAY_LAUNCHPAGE_H diff -Nru gammaray-1.2.2/launcher/ui/launchpage.ui gammaray-2.0.1/launcher/ui/launchpage.ui --- gammaray-1.2.2/launcher/ui/launchpage.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/launchpage.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,141 @@ + + + GammaRay::LaunchPage + + + + 0 + 0 + 401 + 305 + + + + + + + + + &Executable: + + + progEdit + + + + + + + + + + ... + + + + + + + + + &Program arguments: + + + argsBox + + + + + + + + + + + + &Add + + + + + + + &Remove + + + + + + + Qt::Vertical + + + + 20 + 170 + + + + + + + + + + + + Pro&be: + + + probeBox + + + + + + + + + + + 0 + 0 + + + + &Access Mode: + + + accessMode + + + + + + + 0 + + + + Out-of-process, local-only + + + + + Out-of-process, remote debugging enabled + + + + + In-process + + + + + + + + + + + diff -Nru gammaray-1.2.2/launcher/ui/main.cpp gammaray-2.0.1/launcher/ui/main.cpp --- gammaray-1.2.2/launcher/ui/main.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + main.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#include "launcherwindow.h" +#include "launchoptions.h" +#include "launcherfinder.h" + +#include + +#include + +using namespace GammaRay; + +int main(int argc, char **argv) +{ + QCoreApplication::setOrganizationName("KDAB"); + QCoreApplication::setOrganizationDomain("kdab.com"); + QCoreApplication::setApplicationName("GammaRay"); + + QApplication app(argc, argv); + Paths::setRelativeRootPath(GAMMARAY_INVERSE_LIBEXEC_DIR); + + LauncherWindow launcher; + launcher.show(); + const int result = app.exec(); + + if (launcher.result() == QDialog::Accepted) { + const LaunchOptions opts = launcher.launchOptions(); + if (opts.isValid()) { + opts.execute(LauncherFinder::findLauncher(LauncherFinder::Injector)); + } + } + + return result; +} diff -Nru gammaray-1.2.2/launcher/ui/networkdiscoverymodel.cpp gammaray-2.0.1/launcher/ui/networkdiscoverymodel.cpp --- gammaray-1.2.2/launcher/ui/networkdiscoverymodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/networkdiscoverymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,158 @@ +/* + networkdiscoverymodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "networkdiscoverymodel.h" + +#include + +#include +#include +#include + +using namespace GammaRay; + +bool NetworkDiscoveryModel::ServerInfo::operator==(const NetworkDiscoveryModel::ServerInfo& other) +{ + return host == other.host && port == other.port; +} + +NetworkDiscoveryModel::NetworkDiscoveryModel(QObject* parent): + QAbstractTableModel(parent), + m_socket(new QUdpSocket(this)) +{ + m_socket->bind(Endpoint::broadcastPort(), QUdpSocket::ShareAddress); + connect(m_socket, SIGNAL(readyRead()), SLOT(processPendingDatagrams())); + + QTimer *expireTimer = new QTimer(this); + expireTimer->setInterval(15 * 1000); + expireTimer->setSingleShot(false); + connect(expireTimer, SIGNAL(timeout()), SLOT(expireEntries())); + expireTimer->start(); +} + +NetworkDiscoveryModel::~NetworkDiscoveryModel() +{ +} + +void NetworkDiscoveryModel::processPendingDatagrams() +{ + while (m_socket->hasPendingDatagrams()) { + QByteArray datagram; + datagram.resize(m_socket->pendingDatagramSize()); + m_socket->readDatagram(datagram.data(), datagram.size()); + + QDataStream stream(datagram); + qint32 broadcastVersion; + stream >> broadcastVersion; + if (broadcastVersion != Protocol::broadcastFormatVersion()) + continue; + + ServerInfo info; + stream >> info.version >> info.host >> info.port >> info.label; + info.lastSeen = QDateTime::currentDateTime(); + + QVector::iterator it = std::find(m_data.begin(), m_data.end(), info); + if (it == m_data.end()) { + beginInsertRows(QModelIndex(), m_data.size(), m_data.size()); + m_data.push_back(info); + endInsertRows(); + } else { + it->lastSeen = info.lastSeen; + } + } +} + +void NetworkDiscoveryModel::expireEntries() +{ + const QDateTime threshold = QDateTime::currentDateTime().addSecs(-30); + for (QVector::iterator it = m_data.begin(); it != m_data.end();) { + if (it->lastSeen >= threshold) { + ++it; + } else { + const int currentRow = std::distance(m_data.begin(), it); + beginRemoveRows(QModelIndex(), currentRow, currentRow); + it = m_data.erase(it); + endRemoveRows(); + } + } +} + +QVariant NetworkDiscoveryModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + const ServerInfo &info = m_data.at(index.row()); + if (role == Qt::DisplayRole) { + switch (index.column()) { + case 0: return info.label; + case 1: return QVariant(info.host + QLatin1Char(':') + QString::number(info.port)); + } + } else if (role == Qt::ToolTipRole) { + if (info.version != Protocol::version()) + return tr("Incompatible GammaRay version."); + } else if (role == HostNameRole) { + return info.host; + } else if (role == PortRole) { + return info.port; + } + + return QVariant(); +} + +int NetworkDiscoveryModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return 2; +} + +int NetworkDiscoveryModel::rowCount(const QModelIndex& parent) const +{ + if (parent.isValid()) + return 0; + return m_data.size(); +} + +QVariant NetworkDiscoveryModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch (section) { + case 0: return tr("Name"); + case 1: return tr("Host"); + } + } + return QVariant(); +} + +Qt::ItemFlags NetworkDiscoveryModel::flags(const QModelIndex& index) const +{ + const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); + if (!index.isValid()) + return baseFlags; + + const ServerInfo &info = m_data.at(index.row()); + if (info.version != Protocol::version()) + return baseFlags & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + return baseFlags; +} + diff -Nru gammaray-1.2.2/launcher/ui/networkdiscoverymodel.h gammaray-2.0.1/launcher/ui/networkdiscoverymodel.h --- gammaray-1.2.2/launcher/ui/networkdiscoverymodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/networkdiscoverymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,75 @@ +/* + networkdiscoverymodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_NETWORKDISCOVERYMODEL_H +#define GAMMARAY_NETWORKDISCOVERYMODEL_H + +#include +#include +#include + +class QUdpSocket; + +namespace GammaRay { + +/** Lists all active server instances found via network autodiscovery. */ +class NetworkDiscoveryModel : public QAbstractTableModel +{ + Q_OBJECT +public: + enum Role { + HostNameRole = Qt::UserRole + 1, + PortRole + }; + + explicit NetworkDiscoveryModel(QObject* parent); + ~NetworkDiscoveryModel(); + + QVariant data(const QModelIndex& index, int role) const; + int columnCount(const QModelIndex& parent) const; + int rowCount(const QModelIndex& parent) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + Qt::ItemFlags flags(const QModelIndex& index) const; + +private slots: + void processPendingDatagrams(); + void expireEntries(); + +private: + QUdpSocket *m_socket; + + struct ServerInfo { + bool operator==(const ServerInfo &other); + qint32 version; + QString host; + quint16 port; + QString label; + QDateTime lastSeen; + }; + QVector m_data; + +}; + +} + +#endif // GAMMARAY_NETWORKDISCOVERYMODEL_H diff -Nru gammaray-1.2.2/launcher/ui/processfiltermodel.cpp gammaray-2.0.1/launcher/ui/processfiltermodel.cpp --- gammaray-1.2.2/launcher/ui/processfiltermodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processfiltermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,106 @@ +/* + processfiltermodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "processfiltermodel.h" +#include "processmodel.h" + +#include + +#if defined(_WIN32) +#include +#include +static QString qGetLogin() { + char winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H + DWORD winUserNameSize = sizeof(winUserName); + GetUserNameA(winUserName, &winUserNameSize); + return QString::fromLocal8Bit(winUserName); +} +#else +#include +#include +#include +static QString qGetLogin(){ + struct passwd *pw = getpwuid(getuid()); + if (!pw || !pw->pw_name) { + return QString(); + } + return QString::fromLocal8Bit(pw->pw_name); +} +#endif + +using namespace GammaRay; + +ProcessFilterModel::ProcessFilterModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ + m_currentProcId = QString::number(qApp->applicationPid()); + m_currentUser = qGetLogin(); +#ifndef Q_OS_WIN + if (m_currentUser == QLatin1String("root")) { + // empty current user == no filter. as root we want to show all + m_currentUser.clear(); + } +#endif +} + +bool ProcessFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + const QString l = sourceModel()->data(left).toString(); + const QString r = sourceModel()->data(right).toString(); + if (left.column() == ProcessModel::PIDColumn) { + return l.toInt() < r.toInt(); + } + + return l.compare(r, Qt::CaseInsensitive) <= 0; +} + +bool ProcessFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + ProcessModel *source = dynamic_cast(sourceModel()); + if (!source) { + return true; + } + + const ProcData &data = source->dataForRow(source_row); + + if (data.type == ProcData::NoQtApp) { + return false; + } + + if (data.ppid == m_currentProcId) { + return false; + } + + if (!m_currentUser.isEmpty() && data.user != m_currentUser) { + return false; + } + + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} + +bool ProcessFilterModel::filterAcceptsColumn(int source_column, + const QModelIndex &/*source_parent*/) const +{ + // hide user row if current user was found + return m_currentUser.isEmpty() || source_column != ProcessModel::UserColumn; +} diff -Nru gammaray-1.2.2/launcher/ui/processfiltermodel.h gammaray-2.0.1/launcher/ui/processfiltermodel.h --- gammaray-1.2.2/launcher/ui/processfiltermodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processfiltermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + processfiltermodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROCESSFILTERMODEL_H +#define GAMMARAY_PROCESSFILTERMODEL_H + +#include + +namespace GammaRay { + +// A filterable and sortable process model +class ProcessFilterModel : public QSortFilterProxyModel +{ + public: + explicit ProcessFilterModel(QObject *parent); + + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const; + + private: + bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + QString m_currentProcId; + QString m_currentUser; +}; + +} + +#endif // GAMMARAY_PROCESSFILTERMODEL_H diff -Nru gammaray-1.2.2/launcher/ui/processlist.h gammaray-2.0.1/launcher/ui/processlist.h --- gammaray-1.2.2/launcher/ui/processlist.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processlist.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,64 @@ +/************************************************************************** +** +** This code is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#ifndef GAMMARAY_PROCESSLIST_H +#define GAMMARAY_PROCESSLIST_H + +#include +#include + +struct ProcData +{ + QString ppid; + QString name; + QString image; + QString state; + QString user; + + enum AppType { + Unknown, + QtApp, + NoQtApp + }; + AppType type; + + ProcData() + : type(Unknown) + { + } +}; + +typedef QList ProcDataList; + +extern ProcDataList processList(const ProcDataList &previous); + +#endif // PROCESSLIST_H diff -Nru gammaray-1.2.2/launcher/ui/processlist_unix.cpp gammaray-2.0.1/launcher/ui/processlist_unix.cpp --- gammaray-1.2.2/launcher/ui/processlist_unix.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processlist_unix.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,228 @@ +/************************************************************************** +** +** This code is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#include "processlist.h" + +#include +#include + +#include +#include + +static bool isUnixProcessId(const QString &procname) +{ + for (int i = 0; i != procname.size(); ++i) { + if (!procname.at(i).isDigit()) { + return false; + } + } + return true; +} + +static bool processIsQtApp(const QString &pid) +{ + QProcess lsofProcess; + QStringList args; + args << QLatin1String("-Fn") << QLatin1String("-n") << QLatin1String("-p") << pid; + lsofProcess.start(QLatin1String("lsof"), args); + if (!lsofProcess.waitForStarted()) { + return false; + } + + lsofProcess.waitForFinished(); + const QByteArray output = lsofProcess.readAllStandardOutput(); + +// Mac uses "Versions//QtCore" for frameworks, and normal Unix/Linux style names for non-frameworks (Qt5 only) +#ifdef Q_OS_MAC +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + if (output.contains("4/QtCore")) { +#else + if (output.contains("5/QtCore") || output.contains("Qt5Core")) { +#endif +#else + +// normal UNIX/Linux +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + if (output.contains("QtCore")) { +#else + if (output.contains("Qt5Core")) { +#endif +#endif + return true; + } + + return false; +} + +struct PidAndNameMatch : public std::unary_function { + + explicit PidAndNameMatch(const QString &ppid, const QString &name) + : m_ppid(ppid), m_name(name) + { + } + + bool operator()(const ProcData &p) const + { + return p.ppid == m_ppid && m_name == p.name; + } + + const QString m_ppid; + const QString m_name; +}; + +// Determine UNIX processes by running ps +static ProcDataList unixProcessListPS(const ProcDataList &previous) +{ +#ifdef Q_OS_MAC + // command goes last, otherwise it is cut off + static const char formatC[] = "pid state user command"; +#else + static const char formatC[] = "pid,state,user,cmd"; +#endif + ProcDataList rc; + QProcess psProcess; + QStringList args; + args << QLatin1String("-e") << QLatin1String("-o") << QLatin1String(formatC); + psProcess.start(QLatin1String("ps"), args); + if (!psProcess.waitForStarted()) { + return rc; + } + psProcess.waitForFinished(); + QByteArray output = psProcess.readAllStandardOutput(); + // Split "457 S+ /Users/foo.app" + const QStringList lines = QString::fromLocal8Bit(output).split(QLatin1Char('\n')); + const int lineCount = lines.size(); + const QChar blank = QLatin1Char(' '); + for (int l = 1; l < lineCount; l++) { // Skip header + const QString line = lines.at(l).simplified(); + // we can't just split on blank as the process name might + // contain them + const int endOfPid = line.indexOf(blank); + const int endOfState = line.indexOf(blank, endOfPid+1); + const int endOfUser = line.indexOf(blank, endOfState+1); + if (endOfPid >= 0 && endOfState >= 0 && endOfUser >= 0) { + ProcData procData; + procData.ppid = line.left(endOfPid); + procData.state = line.mid(endOfPid+1, endOfState-endOfPid-1); + procData.user = line.mid(endOfState+1, endOfUser-endOfState-1); + procData.name = line.right(line.size()-endOfUser-1); + ProcDataList::ConstIterator it = + std::find_if(previous.constBegin(), previous.constEnd(), + PidAndNameMatch(procData.ppid, procData.name)); + if (it != previous.constEnd()) { + procData.type = it->type; + } else { + procData.type = processIsQtApp(procData.ppid) ? + ProcData::QtApp : + ProcData::NoQtApp; + } + rc.push_back(procData); + } + } + + return rc; +} + +// Determine UNIX processes by reading "/proc". Default to ps if +// it does not exist +ProcDataList processList(const ProcDataList &previous) +{ + const QDir procDir(QLatin1String("/proc/")); + if (!procDir.exists()) { + return unixProcessListPS(previous); + } + ProcDataList rc; + const QStringList procIds = procDir.entryList(); + if (procIds.isEmpty()) { + return rc; + } + foreach (const QString &procId, procIds) { + if (!isUnixProcessId(procId)) { + continue; + } + QString filename = QLatin1String("/proc/"); + filename += procId; + filename += QLatin1String("/stat"); + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) { + continue; // process may have exited + } + + const QStringList data = QString::fromLocal8Bit(file.readAll()).split(' '); + ProcData proc; + proc.ppid = procId; + proc.name = data.at(1); + if (proc.name.startsWith(QLatin1Char('(')) && proc.name.endsWith(QLatin1Char(')'))) { + proc.name.truncate(proc.name.size() - 1); + proc.name.remove(0, 1); + } + proc.state = data.at(2); + // PPID is element 3 + + proc.user = QFileInfo(file).owner(); + file.close(); + + QFile cmdFile(QLatin1String("/proc/") + procId + QLatin1String("/cmdline")); + if(cmdFile.open(QFile::ReadOnly)) { + QByteArray cmd = cmdFile.readAll(); + cmd.replace('\0', ' '); + if (!cmd.isEmpty()) { + proc.name = QString::fromLocal8Bit(cmd); + } + } + cmdFile.close(); + + QFile maps(QLatin1String("/proc/") + procId + QLatin1String("/maps")); + if (!maps.open(QIODevice::ReadOnly)) { + continue; // process may have exited + } + + proc.type = ProcData::NoQtApp; + forever { + const QByteArray line = maps.readLine(); + if (line.isEmpty()) { + break; + } +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + if (line.contains(QByteArray("/libQtCore.so"))) { +#else + if (line.contains(QByteArray("/libQt5Core.so"))) { +#endif + proc.type = ProcData::QtApp; + break; + } + } + + rc.push_back(proc); + } + return rc; +} diff -Nru gammaray-1.2.2/launcher/ui/processlist_win.cpp gammaray-2.0.1/launcher/ui/processlist_win.cpp --- gammaray-1.2.2/launcher/ui/processlist_win.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processlist_win.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,191 @@ +/************************************************************************** +** +** This code is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#include "processlist.h" + +#include + +// Enable Win API of XP SP1 and later +#ifdef Q_OS_WIN +# define _WIN32_WINNT 0x0502 +# include +# if !defined(PROCESS_SUSPEND_RESUME) // Check flag for MinGW +# define PROCESS_SUSPEND_RESUME (0x0800) +# endif // PROCESS_SUSPEND_RESUME +#endif // Q_OS_WIN + +#include +#include +// Resolve QueryFullProcessImageNameW out of kernel32.dll due +// to incomplete MinGW import libs and it not being present +// on Windows XP. +static inline BOOL queryFullProcessImageName(HANDLE h, + DWORD flags, + LPWSTR buffer, + DWORD *size) +{ + // Resolve required symbols from the kernel32.dll + typedef BOOL (WINAPI *QueryFullProcessImageNameWProtoType)(HANDLE, DWORD, LPWSTR, PDWORD); + static QueryFullProcessImageNameWProtoType queryFullProcessImageNameW = 0; + if (!queryFullProcessImageNameW) { + QLibrary kernel32Lib(QLatin1String("kernel32.dll"), 0); + if (kernel32Lib.isLoaded() || kernel32Lib.load()) { + queryFullProcessImageNameW = + (QueryFullProcessImageNameWProtoType)kernel32Lib.resolve("QueryFullProcessImageNameW"); + } + } + if (!queryFullProcessImageNameW) { + return FALSE; + } + // Read out process + return (*queryFullProcessImageNameW)(h, flags, buffer, size); +} + +struct ProcessInfo { + QString imageName; + QString processOwner; +}; + +static inline ProcessInfo processInfo(DWORD processId) +{ + ProcessInfo pi; + HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, TOKEN_READ, processId); + if (handle == INVALID_HANDLE_VALUE) { + return pi; + } + WCHAR buffer[MAX_PATH]; + DWORD bufSize = MAX_PATH; + if (queryFullProcessImageName(handle, 0, buffer, &bufSize)) { + pi.imageName = QString::fromUtf16(reinterpret_cast(buffer)); + } + + HANDLE processTokenHandle = NULL; + if (!OpenProcessToken(handle, TOKEN_READ, &processTokenHandle) || !processTokenHandle) { + return pi; + } + + DWORD size = 0; + GetTokenInformation(processTokenHandle, TokenUser, NULL, 0, &size); + + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + QByteArray buf; + buf.resize(size); + PTOKEN_USER userToken = reinterpret_cast(buf.data()); + if (userToken && GetTokenInformation(processTokenHandle, TokenUser, userToken, size, &size)) { + SID_NAME_USE sidNameUse; + TCHAR user[MAX_PATH] = { 0 }; + DWORD userNameLength = MAX_PATH; + TCHAR domain[MAX_PATH] = { 0 }; + DWORD domainNameLength = MAX_PATH; + + if (LookupAccountSid(NULL, + userToken->User.Sid, + user, + &userNameLength, + domain, + &domainNameLength, + &sidNameUse)) { + pi.processOwner = QString::fromUtf16(reinterpret_cast(user)); + } + } + } + + CloseHandle(processTokenHandle); + CloseHandle(handle); + return pi; +} + +static inline bool isQtApp(DWORD processId) +{ + MODULEENTRY32 me; + me.dwSize = sizeof(MODULEENTRY32); + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId); + if (snapshot == INVALID_HANDLE_VALUE) { + return false; + } + + for (bool hasNext = Module32First(snapshot, &me); + hasNext; + hasNext = Module32Next(snapshot, &me)) { + const QString module = QString::fromUtf16(reinterpret_cast(me.szModule)); +//TODO: Do this check properly, probe does not need to have the same type +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#ifdef NDEBUG + if (module == QLatin1String("QtCore4.dll")) { +#else + if (module == QLatin1String("QtCored4.dll")) { +#endif +#else +#ifdef NDEBUG + if (module == QLatin1String("Qt5Core.dll")) { +#else + if (module == QLatin1String("Qt5Cored.dll")) { +#endif +#endif + CloseHandle(snapshot); + return true; + } + } + CloseHandle(snapshot); + return false; +} + +ProcDataList processList(const ProcDataList &/*previous*/) +{ + ProcDataList rc; + + PROCESSENTRY32 pe; + pe.dwSize = sizeof(PROCESSENTRY32); + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return rc; + } + + for (bool hasNext = Process32First(snapshot, &pe); + hasNext; + hasNext = Process32Next(snapshot, &pe)) { + ProcData procData; + procData.ppid = QString::number(pe.th32ProcessID); + procData.name = QString::fromUtf16(reinterpret_cast(pe.szExeFile)); + const ProcessInfo processInf = processInfo(pe.th32ProcessID); + procData.image = processInf.imageName; + procData.user = processInf.processOwner; + if (isQtApp(pe.th32ProcessID)) { + procData.type = ProcData::QtApp; + } else { + procData.type = ProcData::NoQtApp; + } + rc.push_back(procData); + } + CloseHandle(snapshot); + return rc; +} diff -Nru gammaray-1.2.2/launcher/ui/processmodel.cpp gammaray-2.0.1/launcher/ui/processmodel.cpp --- gammaray-1.2.2/launcher/ui/processmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,195 @@ +/* + processmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "processmodel.h" +#include + +using namespace GammaRay; + +bool operator<(const ProcData &l, const ProcData &r) +{ + return l.ppid < r.ppid; +} + +bool operator==(const ProcData &l, const ProcData &r) +{ + return l.ppid == r.ppid; +} + +QDebug operator<<(QDebug d, const ProcData &data) { + d << "ProcData{.ppid=" << data.ppid << ", .name=" << data.name << ", .image=" << data.image + << ", .state=" << data.state << ", .user=" << data.user << ", .type=" << data.type << "}"; + return d; +} + +ProcessModel::ProcessModel(QObject *parent) +: QAbstractTableModel(parent) +{ +} + +ProcessModel::~ProcessModel() +{ +} + +void ProcessModel::setProcesses(const ProcDataList &processes) +{ + beginResetModel(); + m_data = processes; + // sort for merging to work properly + qStableSort(m_data); + endResetModel(); +} + +void ProcessModel::mergeProcesses(const ProcDataList &processes) +{ + // sort like m_data + ProcDataList sortedProcesses = processes; + qStableSort(sortedProcesses); + + // iterator over m_data + int i = 0; + + foreach (const ProcData &newProc, sortedProcesses) { + bool shouldInsert = true; + while (i < m_data.count()) { + const ProcData &oldProc = m_data.at(i); + if (oldProc < newProc) { + // remove old proc, seems to be outdated + beginRemoveRows(QModelIndex(), i, i); + m_data.removeAt(i); + endRemoveRows(); + continue; + } else if (newProc == oldProc) { + // already contained, hence increment and break + ++i; + shouldInsert = false; + break; + } else { // newProc < oldProc + // new entry, break and insert it + break; + } + } + if (shouldInsert) { + beginInsertRows(QModelIndex(), i, i); + m_data.insert(i, newProc); + endInsertRows(); + // let i point to old element again + ++i; + } + } + + // make sure the new data is properly inserted + Q_ASSERT(m_data == sortedProcesses); +} + +void ProcessModel::clear() +{ + beginRemoveRows(QModelIndex(), 0, m_data.count()); + m_data.clear(); + endRemoveRows(); +} + +ProcData ProcessModel::dataForIndex(const QModelIndex &index) const +{ + return m_data.at(index.row()); +} + +ProcData ProcessModel::dataForRow(int row) const +{ + return m_data.at(row); +} + +QModelIndex ProcessModel::indexForPid(const QString &pid) const +{ + for (int i = 0; i < m_data.size(); ++i) { + if (m_data.at(i).ppid == pid) { + return index(i, 0); + } + } + return QModelIndex(); +} + +QVariant ProcessModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole || orientation != Qt::Horizontal) { + return QVariant(); + } + + if (section == PIDColumn) { + return tr("Process ID"); + } else if (section == NameColumn) { + return tr("Name"); + } else if (section == StateColumn) { + return tr("State"); + } else if (section == UserColumn) { + return tr("User"); + } + + return QVariant(); +} + +QVariant ProcessModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const ProcData &data = m_data.at(index.row()); + + if (role == Qt::DisplayRole) { + if (index.column() == PIDColumn) { + return data.ppid; + } else if (index.column() == NameColumn) { + return data.image.isEmpty() ? data.name : data.image; + } else if (index.column() == StateColumn) { + return data.state; + } else if (index.column() == UserColumn) { + return data.user; + } + } else if (role == PIDRole) { + return data.ppid.toInt(); // why is this a QString in the first place!? + } else if (role == NameRole) { + return data.image.isEmpty() ? data.name : data.image; + } else if (role == StateRole) { + return data.state; + } else if (role == UserRole) { + return data.user; + } + + return QVariant(); +} + +int ProcessModel::columnCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : COLUMN_COUNT; +} + +int ProcessModel::rowCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : m_data.count(); +} + +ProcDataList ProcessModel::processes() const +{ + return m_data; +} diff -Nru gammaray-1.2.2/launcher/ui/processmodel.h gammaray-2.0.1/launcher/ui/processmodel.h --- gammaray-1.2.2/launcher/ui/processmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/processmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,78 @@ +/* + processmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROCESSMODEL_H +#define GAMMARAY_PROCESSMODEL_H + +#include + +#include "processlist.h" + +namespace GammaRay { + +class ProcessModel : public QAbstractTableModel +{ + public: + explicit ProcessModel(QObject *parent = 0); + virtual ~ProcessModel(); + + void setProcesses(const ProcDataList &processes); + void mergeProcesses(const ProcDataList &processes); + ProcData dataForIndex(const QModelIndex &index) const; + ProcData dataForRow(int row) const; + QModelIndex indexForPid(const QString &pid) const; + + ProcDataList processes() const; + + void clear(); + + enum Columns { + PIDColumn, + NameColumn, + StateColumn, + UserColumn, + COLUMN_COUNT + }; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + enum CustomRoles { + PIDRole = Qt::UserRole, + NameRole, + StateRole, + UserRole + }; + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + private: + ProcDataList m_data; +}; + +} + +#endif // GAMMARAY_PROCESSMODEL_H diff -Nru gammaray-1.2.2/launcher/ui/promolabel.cpp gammaray-2.0.1/launcher/ui/promolabel.cpp --- gammaray-1.2.2/launcher/ui/promolabel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/promolabel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,79 @@ +/* + mainwindow.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "promolabel.h" + +#include +#include +#include +#include + +using namespace GammaRay; + +PromoLabel::PromoLabel(QWidget *parent, Qt::WindowFlags f) +: QLabel(parent, f) +{ + updatePixmap(); + + setCursor(QCursor(Qt::PointingHandCursor)); + setToolTip(tr("Visit KDAB Website")); +} + +bool PromoLabel::event(QEvent *e) +{ + if (e->type() == QEvent::PaletteChange) { + updatePixmap(); + } + return QLabel::event(e); +} + +void PromoLabel::mouseReleaseEvent(QMouseEvent *ev) +{ + if (ev->button() == Qt::LeftButton && ev->modifiers() == Qt::NoModifier) { + QDesktopServices::openUrl(QUrl("http://www.kdab.com")); + ev->accept(); + return; + } + + QLabel::mouseReleaseEvent(ev); +} + +QImage PromoLabel::tintedImage(const QString &image, const QColor &color) +{ + QImage img(image); + img = img.alphaChannel(); + QColor newColor = color; + for (int i = 0; i < img.colorCount(); ++i) { + newColor.setAlpha(qGray(img.color(i))); + img.setColor(i, newColor.rgba()); + } + return img; +} + +void PromoLabel::updatePixmap() +{ + // load image and adapt it to user's foreground color + setPixmap(QPixmap::fromImage(tintedImage(QString(":gammaray/kdabproducts.png"), + palette().foreground().color()))); +} + diff -Nru gammaray-1.2.2/launcher/ui/promolabel.h gammaray-2.0.1/launcher/ui/promolabel.h --- gammaray-1.2.2/launcher/ui/promolabel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/promolabel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + mainwindow.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROMOLABEL_H +#define GAMMARAY_PROMOLABEL_H + +#include + +namespace GammaRay { + +class PromoLabel : public QLabel +{ + Q_OBJECT + + public: + explicit PromoLabel(QWidget *parent = 0, Qt::WindowFlags f = 0); + + static QImage tintedImage(const QString &image, const QColor &color); + + protected: + virtual bool event(QEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *ev); + + private: + void updatePixmap(); +}; + +} + +#endif // PROMOLABEL_H diff -Nru gammaray-1.2.2/launcher/ui/selftestpage.cpp gammaray-2.0.1/launcher/ui/selftestpage.cpp --- gammaray-1.2.2/launcher/ui/selftestpage.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/selftestpage.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,129 @@ +/* + selftestpage.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "selftestpage.h" +#include "probefinder.h" +#include "ui_selftestpage.h" + +#include "injector/injectorfactory.h" + +#include +#include + +using namespace GammaRay; + +SelfTestPage::SelfTestPage(QWidget *parent) + : QWidget(parent), ui(new Ui::SelfTestPage), m_resultModel(new QStandardItemModel(this)) +{ + ui->setupUi(this); + ui->resultView->setModel(m_resultModel); + run(); +} + +SelfTestPage::~SelfTestPage() +{ + delete ui; +} + +void SelfTestPage::run() +{ + m_resultModel->clear(); + testProbe(); + testAvailableInjectors(); + testInjectors(); +} + +void SelfTestPage::testProbe() +{ + int validProbeCount = 0; + const QStringList probeABIs = ProbeFinder::listProbeABIs(); + foreach (const QString &abi, probeABIs) { + const QString probePath = ProbeFinder::findProbe(QLatin1String("gammaray_probe"), abi); + if (probePath.isEmpty()) { + error(tr("No probe found for ABI %1.").arg(abi)); + continue; + } + + QFileInfo fi(probePath); + if (!fi.exists() || !fi.isFile() || !fi.isReadable()) { + error(tr("Probe at %1 is invalid.")); + continue; + } + + information(tr("Found valid probe for ABI %1 at %2.").arg(abi).arg(probePath)); + ++validProbeCount; + } + + if (validProbeCount == 0) { + error(tr("No probes found - GammaRay no functional.")); + } +} + +void SelfTestPage::testAvailableInjectors() +{ + const QStringList injectors = InjectorFactory::availableInjectors(); + if (injectors.isEmpty()) { + error(tr("No injectors available - GammaRay not functional.")); + return; + } + + information(tr("The following injectors are available: %1"). + arg(injectors.join(QLatin1String(", ")))); +} + +void SelfTestPage::testInjectors() +{ + foreach (const QString &injectorType, InjectorFactory::availableInjectors()) { + AbstractInjector::Ptr injector = InjectorFactory::createInjector(injectorType); + if (!injector) { + error(tr("Unable to create instance of injector %1.").arg(injectorType)); + continue; + } + if (injector->selfTest()) { + information(tr("Injector %1 successfully passed its self-test."). + arg(injectorType)); + } else { + error(tr("Injector %1 failed to pass its self-test: %2."). + arg(injectorType, injector->errorString())); + } + } +} + +void SelfTestPage::error(const QString &msg) +{ + QStandardItem *item = new QStandardItem; + item->setEditable(false); + item->setText(msg); + item->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical)); + m_resultModel->appendRow(item); +} + +void SelfTestPage::information(const QString &msg) +{ + QStandardItem *item = new QStandardItem; + item->setEditable(false); + item->setText(msg); + item->setIcon(style()->standardIcon(QStyle::SP_MessageBoxInformation)); + m_resultModel->appendRow(item); +} + diff -Nru gammaray-1.2.2/launcher/ui/selftestpage.h gammaray-2.0.1/launcher/ui/selftestpage.h --- gammaray-1.2.2/launcher/ui/selftestpage.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/selftestpage.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + selftestpage.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SELFTESTPAGE_H +#define GAMMARAY_SELFTESTPAGE_H + +#include + +class QStandardItemModel; + +namespace GammaRay { + +namespace Ui { + class SelfTestPage; +} + +class SelfTestPage : public QWidget +{ + Q_OBJECT + public: + explicit SelfTestPage(QWidget *parent = 0); + ~SelfTestPage(); + + public slots: + void run(); + + private: + void testProbe(); + void testAvailableInjectors(); + void testInjectors(); + + void error(const QString &msg); + void information(const QString &msg); + + private: + Ui::SelfTestPage *ui; + QStandardItemModel *m_resultModel; +}; + +} + +#endif // GAMMARAY_SELFTESTPAGE_H diff -Nru gammaray-1.2.2/launcher/ui/selftestpage.ui gammaray-2.0.1/launcher/ui/selftestpage.ui --- gammaray-1.2.2/launcher/ui/selftestpage.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/launcher/ui/selftestpage.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,21 @@ + + + GammaRay::SelfTestPage + + + + 0 + 0 + 400 + 300 + + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/actioninspector/actioninspector.cpp gammaray-2.0.1/plugins/actioninspector/actioninspector.cpp --- gammaray-1.2.2/plugins/actioninspector/actioninspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actioninspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -22,87 +22,35 @@ #include "actioninspector.h" #include "actionmodel.h" -#include "include/objectmodel.h" -#include "include/probeinterface.h" -#include "include/objecttypefilterproxymodel.h" - -#include "kde/kfilterproxysearchline.h" -#include "kde/krecursivefilterproxymodel.h" - -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include +#include + using namespace GammaRay; +using namespace std; -ActionInspector::ActionInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - mProbeIface(probe) +ActionInspector::ActionInspector(ProbeInterface *probe, QObject *parent) + : QObject(parent) { + ObjectBroker::registerObject("com.kdab.GammaRay.ActionInspector", this); + ActionModel *actionFilterProxy = new ActionModel(this); actionFilterProxy->setSourceModel(probe->objectListModel()); - - QSortFilterProxyModel *searchFilterProxy = new KRecursiveFilterProxyModel(this); - searchFilterProxy->setSourceModel(actionFilterProxy); - searchFilterProxy->setDynamicSortFilter(true); - - QVBoxLayout *vbox = new QVBoxLayout; - - KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this); - objectSearchLine->setProxy(searchFilterProxy); - vbox->addWidget(objectSearchLine); - - QTreeView *objectTreeView = new QTreeView(this); - objectTreeView->setModel(searchFilterProxy); - objectTreeView->setSortingEnabled(true); - objectTreeView->sortByColumn(ActionModel::ShortcutsPropColumn); - objectTreeView->setRootIsDecorated(false); - vbox->addWidget(objectTreeView); - connect(objectTreeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - SLOT(handleRowChanged(QModelIndex))); - connect(objectTreeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(triggerAction(QModelIndex))); - mObjectTreeView = objectTreeView; - - QWidget *treeViewWidget = new QWidget(this); - treeViewWidget->setLayout(vbox); - - QHBoxLayout *hbox = new QHBoxLayout(this); - hbox->addWidget(treeViewWidget); - - QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection); + probe->registerModel("com.kdab.GammaRay.ActionModel", actionFilterProxy); } ActionInspector::~ActionInspector() { } -void ActionInspector::delayedInit() -{ - // select the qApp object (if any) in the object treeView - const QAbstractItemModel *viewModel = mObjectTreeView->model(); - const QModelIndexList matches = viewModel->match(viewModel->index(0, 0), - ObjectModel::ObjectRole, - QVariant::fromValue(qApp)); - if (!matches.isEmpty()) { - mObjectTreeView->setCurrentIndex(matches.first()); - } -} - -void ActionInspector::handleRowChanged(const QModelIndex &index) -{ - Q_UNUSED(index); - // TODO: Unused -} - -void ActionInspector::triggerAction(const QModelIndex &index) +void ActionInspector::triggerAction(int row) { + QAbstractItemModel *model = ObjectBroker::model("com.kdab.GammaRay.ActionModel"); + const QModelIndex index = model->index(row, 0); if (!index.isValid()) { return; } @@ -118,5 +66,3 @@ #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) Q_EXPORT_PLUGIN(ActionInspectorFactory) #endif - -#include "actioninspector.moc" diff -Nru gammaray-1.2.2/plugins/actioninspector/actioninspector.h gammaray-2.0.1/plugins/actioninspector/actioninspector.h --- gammaray-1.2.2/plugins/actioninspector/actioninspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actioninspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -22,46 +22,36 @@ #ifndef GAMMARAY_ACTIONINSPECTOR_ACTIONINSPECTOR_H #define GAMMARAY_ACTIONINSPECTOR_ACTIONINSPECTOR_H -#include "include/toolfactory.h" +#include +#include "actioninspectorwidget.h" #include -#include - -class QTreeView; -class QModelIndex; namespace GammaRay { -class ProbeInterface; - -class ActionInspector : public QWidget +class ActionInspector : public QObject { Q_OBJECT public: - explicit ActionInspector(ProbeInterface *probe, QWidget *parent = 0); + explicit ActionInspector(ProbeInterface *probe, QObject *parent = 0); virtual ~ActionInspector(); - private Q_SLOTS: - void delayedInit(); - - void handleRowChanged(const QModelIndex &index); - void triggerAction(const QModelIndex &index); - - private: - QTreeView *mObjectTreeView; - ProbeInterface *mProbeIface; + public Q_SLOTS: + void triggerAction(int row); }; class ActionInspectorFactory : public QObject, - public StandardToolFactory + public StandardToolFactory2 { Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) + Q_INTERFACES(GammaRay::ToolFactory GammaRay::ToolUiFactory) Q_PLUGIN_METADATA(IID "com.kdab.gammaray.ActionInspector") public: - explicit ActionInspectorFactory(QObject *parent = 0) : QObject(parent) {} + explicit ActionInspectorFactory(QObject *parent = 0) : QObject(parent) + { + } virtual inline QString name() const { diff -Nru gammaray-1.2.2/plugins/actioninspector/actioninspectorwidget.cpp gammaray-2.0.1/plugins/actioninspector/actioninspectorwidget.cpp --- gammaray-1.2.2/plugins/actioninspector/actioninspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actioninspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,78 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "actioninspectorwidget.h" +#include "actionmodel.h" // for column enum only + +#include +#include + +#include "kde/kfilterproxysearchline.h" +#include "kde/krecursivefilterproxymodel.h" + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +ActionInspectorWidget::ActionInspectorWidget(QWidget *parent) + : QWidget(parent) +{ + QAbstractItemModel *actionModel = ObjectBroker::model("com.kdab.GammaRay.ActionModel"); + + QSortFilterProxyModel *searchFilterProxy = new KRecursiveFilterProxyModel(this); + searchFilterProxy->setSourceModel(actionModel); + searchFilterProxy->setDynamicSortFilter(true); + m_proxy = searchFilterProxy; + + QVBoxLayout *vbox = new QVBoxLayout(this); + + KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this); + objectSearchLine->setProxy(searchFilterProxy); + vbox->addWidget(objectSearchLine); + + QTreeView *objectTreeView = new QTreeView(this); + objectTreeView->setModel(searchFilterProxy); + objectTreeView->setSortingEnabled(true); + objectTreeView->sortByColumn(ActionModel::ShortcutsPropColumn); + objectTreeView->setRootIsDecorated(false); + vbox->addWidget(objectTreeView); + connect(objectTreeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(triggerAction(QModelIndex))); + mObjectTreeView = objectTreeView; +} + +ActionInspectorWidget::~ActionInspectorWidget() +{ +} + +void ActionInspectorWidget::triggerAction(const QModelIndex &index) +{ + if (!index.isValid()) { + return; + } + + Q_ASSERT(index.model() == m_proxy); + Endpoint::instance()->invokeObject("com.kdab.GammaRay.ActionInspector", "triggerAction", + QVariantList() << m_proxy->mapToSource(index).row()); +} diff -Nru gammaray-1.2.2/plugins/actioninspector/actioninspectorwidget.h gammaray-2.0.1/plugins/actioninspector/actioninspectorwidget.h --- gammaray-1.2.2/plugins/actioninspector/actioninspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actioninspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ACTIONINSPECTOR_ACTIONINSPECTORWIDGET_H +#define GAMMARAY_ACTIONINSPECTOR_ACTIONINSPECTORWIDGET_H + +#include +#include + +class QAbstractProxyModel; +class QTreeView; +class QModelIndex; + +namespace GammaRay { + +class ActionInspectorWidget : public QWidget +{ + Q_OBJECT + + public: + explicit ActionInspectorWidget(QWidget *parent = 0); + ~ActionInspectorWidget(); + + private Q_SLOTS: + void triggerAction(const QModelIndex &index); + + private: + QTreeView *mObjectTreeView; + QAbstractProxyModel *m_proxy; +}; + +} + +#endif // GAMMARAY_ACTIONINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/plugins/actioninspector/actionmodel.cpp gammaray-2.0.1/plugins/actioninspector/actionmodel.cpp --- gammaray-1.2.2/plugins/actioninspector/actionmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actionmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -22,6 +22,9 @@ */ #include "actionmodel.h" +#include "actionvalidator.h" + +#include #include #include @@ -39,7 +42,8 @@ } ActionModel::ActionModel(QObject *parent) - : ObjectFilterProxyModelBase(parent) + : ObjectFilterProxyModelBase(parent), + m_duplicateFinder(new ActionValidator(this)) { connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(handleRowsInserted(QModelIndex,int,int))); @@ -74,20 +78,20 @@ void ActionModel::handleModelReset() { - m_duplicateFinder.setActions(actions()); + m_duplicateFinder->setActions(actions()); } void ActionModel::handleRowsInserted(const QModelIndex &parent, int start, int end) { Q_FOREACH (QAction *action, actions(parent, start, end)) { - m_duplicateFinder.insert(action); + m_duplicateFinder->insert(action); } } void ActionModel::handleRowsRemoved(const QModelIndex &parent, int start, int end) { Q_FOREACH (QAction *action, actions(parent, start, end)) { - m_duplicateFinder.remove(action); + m_duplicateFinder->remove(action); } } @@ -157,9 +161,9 @@ case CheckablePropColumn: return action->isCheckable(); case CheckedPropColumn: - return Util::variantToString(action->isChecked()); + return VariantHandler::displayString(action->isChecked()); case PriorityPropColumn: - return Util::variantToString(action->priority()); + return VariantHandler::displayString(action->priority()); case ShortcutsPropColumn: return toString(action->shortcuts()); default: @@ -168,7 +172,7 @@ } else if (role == Qt::DecorationRole) { if (column == NameColumn) { return action->icon(); - } else if (column == ShortcutsPropColumn && m_duplicateFinder.hasAmbiguousShortcut(action)) { + } else if (column == ShortcutsPropColumn && m_duplicateFinder->hasAmbiguousShortcut(action)) { QIcon icon = QIcon::fromTheme("dialog-warning"); if (!icon.isNull()) { return icon; @@ -177,7 +181,7 @@ } } } else if (role == Qt::ToolTipRole) { - if (column == ShortcutsPropColumn && m_duplicateFinder.hasAmbiguousShortcut(action)) { + if (column == ShortcutsPropColumn && m_duplicateFinder->hasAmbiguousShortcut(action)) { return tr("Warning: Ambiguous shortcut detected."); } } @@ -216,5 +220,3 @@ { return qobject_cast(object); } - -#include "actionmodel.moc" diff -Nru gammaray-1.2.2/plugins/actioninspector/actionmodel.h gammaray-2.0.1/plugins/actioninspector/actionmodel.h --- gammaray-1.2.2/plugins/actioninspector/actionmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actionmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -24,14 +24,14 @@ #ifndef GAMMARAY_ACTIONINSPECTOR_ACTIONMODEL_H #define GAMMARAY_ACTIONINSPECTOR_ACTIONMODEL_H -#include "actionvalidator.h" - -#include "include/objecttypefilterproxymodel.h" +#include class QAction; namespace GammaRay { +class ActionValidator; + /** * This QSFPM additionally overwrites index(...) and flags(...) * to support additional columns @@ -84,7 +84,7 @@ QList actions() const; QList actions(const QModelIndex &parent, int start, int end); - ActionValidator m_duplicateFinder; + ActionValidator *m_duplicateFinder; }; } diff -Nru gammaray-1.2.2/plugins/actioninspector/actionvalidator.cpp gammaray-2.0.1/plugins/actioninspector/actionvalidator.cpp --- gammaray-1.2.2/plugins/actioninspector/actionvalidator.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actionvalidator.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -121,5 +121,3 @@ } return false; } - -#include "actionvalidator.moc" diff -Nru gammaray-1.2.2/plugins/actioninspector/actionvalidator.h gammaray-2.0.1/plugins/actioninspector/actionvalidator.h --- gammaray-1.2.2/plugins/actioninspector/actionvalidator.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/actionvalidator.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -38,7 +38,7 @@ Q_OBJECT public: - ActionValidator(QObject *parent = 0); + explicit ActionValidator(QObject *parent = 0); QList actions() const; QList actions(const QKeySequence &sequence) const; diff -Nru gammaray-1.2.2/plugins/actioninspector/CMakeLists.txt gammaray-2.0.1/plugins/actioninspector/CMakeLists.txt --- gammaray-1.2.2/plugins/actioninspector/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,18 +1,10 @@ -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} -) - set(gammaray_actioninspector_plugin_srcs - ../../3rdparty/kde/kfilterproxysearchline.cpp - ../../3rdparty/kde/krecursivefilterproxymodel.cpp - actionvalidator.cpp actioninspector.cpp + actioninspectorwidget.cpp actionmodel.cpp ) -qt4_automoc(${gammaray_actioninspector_plugin_srcs}) - gammaray_add_plugin(gammaray_actioninspector_plugin gammaray_actioninspector.desktop ${gammaray_actioninspector_plugin_srcs} @@ -21,5 +13,6 @@ target_link_libraries(gammaray_actioninspector_plugin ${QT_QTCORE_LIBRARIES} ${QT_QTGUI_LIBRARIES} - gammaray_probe + gammaray_core + gammaray_ui ) diff -Nru gammaray-1.2.2/plugins/actioninspector/gammaray_actioninspector.desktop gammaray-2.0.1/plugins/actioninspector/gammaray_actioninspector.desktop --- gammaray-1.2.2/plugins/actioninspector/gammaray_actioninspector.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/actioninspector/gammaray_actioninspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,5 @@ [Desktop Entry] Name=Action Inspector X-GammaRay-Types=QAction; +X-GammaRay-ServiceTypes="com.kdab.GammaRay.ToolFactory;com.kdab.GammaRay.ToolUiFactory" Exec=gammaray_actioninspector_plugin diff -Nru gammaray-1.2.2/plugins/CMakeLists.txt gammaray-2.0.1/plugins/CMakeLists.txt --- gammaray-1.2.2/plugins/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,18 +1,21 @@ -include_directories( - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/3rdparty -) - -add_subdirectory(actioninspector) +add_subdirectory(codecbrowser) +add_subdirectory(fontbrowser) +add_subdirectory(kjobtracker) add_subdirectory(objectvisualizer) +add_subdirectory(selectionmodelinspector) +add_subdirectory(statemachineviewer) +add_subdirectory(timertop) +add_subdirectory(webinspector) + +if(Qt5Widgets_FOUND OR QT_QTGUI_FOUND) + add_subdirectory(actioninspector) + add_subdirectory(widgetinspector) + add_subdirectory(sceneinspector) + add_subdirectory(styleinspector) +endif() if(QT_QTSCRIPTTOOLS_FOUND OR Qt5ScriptTools_FOUND) add_subdirectory(scriptenginedebugger) endif() -add_subdirectory(statemachineviewer) -add_subdirectory(timertop) -if(QT_QTWEBKIT_FOUND OR Qt5Webkit_FOUND) - add_subdirectory(webinspector) -endif() diff -Nru gammaray-1.2.2/plugins/codecbrowser/CMakeLists.txt gammaray-2.0.1/plugins/codecbrowser/CMakeLists.txt --- gammaray-1.2.2/plugins/codecbrowser/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +# probe part +set(gammaray_codecbrowser_plugin_srcs + codecbrowser.cpp + codecmodel.cpp +) + +gammaray_add_plugin(gammaray_codecbrowser_plugin + gammaray_codecbrowser.desktop + ${gammaray_codecbrowser_plugin_srcs} +) + +target_link_libraries(gammaray_codecbrowser_plugin + ${QT_QTCORE_LIBRARIES} + gammaray_core +) + +# ui part +if((Qt5Widgets_FOUND OR QT_QTGUI_FOUND) AND NOT GAMMARAY_PROBE_ONLY_BUILD) + + set(gammaray_codecbrowser_plugin_ui_srcs + codecbrowserwidget.cpp + ) + + qt4_wrap_ui(gammaray_codecbrowser_plugin_ui_srcs + codecbrowserwidget.ui + ) + + gammaray_add_plugin(gammaray_codecbrowser_ui_plugin + gammaray_codecbrowser_ui.desktop + ${gammaray_codecbrowser_plugin_ui_srcs} + ) + + target_link_libraries(gammaray_codecbrowser_ui_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common + gammaray_ui + ) + +endif() diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecbrowser.cpp gammaray-2.0.1/plugins/codecbrowser/codecbrowser.cpp --- gammaray-1.2.2/plugins/codecbrowser/codecbrowser.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecbrowser.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,73 @@ +/* + codecbrowser.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "codecbrowser.h" +#include "codecmodel.h" + +#include + +#include + +#include + +using namespace GammaRay; + +CodecBrowser::CodecBrowser(ProbeInterface* probe, QObject* parent) + : QObject(parent) +{ + ObjectBroker::registerObject("com.kdab.GammaRay.CodecBrowser", this); + + AllCodecsModel* model = new AllCodecsModel(this); + probe->registerModel("com.kdab.GammaRay.AllCodecsModel", model); + + m_codecSelectionModel = ObjectBroker::selectionModel(model); + connect(m_codecSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(updateCodecs(QItemSelection,QItemSelection))); + + m_selectedCodecsModel = new SelectedCodecsModel(this); + probe->registerModel("com.kdab.GammaRay.SelectedCodecsModel", m_selectedCodecsModel); +} + +void CodecBrowser::textChanged(const QString &text) +{ + m_selectedCodecsModel->updateText(text); +} + +void CodecBrowser::updateCodecs(const QItemSelection &selected, + const QItemSelection &deselected) +{ + Q_UNUSED(selected); + Q_UNUSED(deselected); + + QStringList currentCodecNames; + foreach (const QModelIndex &index, m_codecSelectionModel->selectedRows()) { + const QString codecName = index.data().toString(); + currentCodecNames.append(codecName); + } + + m_selectedCodecsModel->setCodecs(currentCodecNames); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(CodecBrowserFactory) +#endif diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecbrowser.h gammaray-2.0.1/plugins/codecbrowser/codecbrowser.h --- gammaray-1.2.2/plugins/codecbrowser/codecbrowser.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecbrowser.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,75 @@ +/* + codecbrowser.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CODECBROWSER_CODECBROWSER_H +#define GAMMARAY_CODECBROWSER_CODECBROWSER_H + +#include + +class QItemSelection; +class QItemSelectionModel; + +namespace GammaRay { + +class SelectedCodecsModel; + +namespace Ui { + class CodecBrowser; +} + +class CodecBrowser : public QObject +{ + Q_OBJECT + public: + explicit CodecBrowser(ProbeInterface *probe, QObject *parent = 0); + + public slots: + void textChanged(const QString &text); + + private slots: + void updateCodecs(const QItemSelection &selected, const QItemSelection &deselected); + + private: + SelectedCodecsModel *m_selectedCodecsModel; + QItemSelectionModel *m_codecSelectionModel; +}; + +class CodecBrowserFactory : public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.CodecBrowser") + public: + explicit CodecBrowserFactory(QObject *parent = 0) : QObject(parent) + { + } + + virtual inline QString name() const + { + return tr("Text Codecs"); + } +}; + +} + +#endif // GAMMARAY_CODECBROWSER_H diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.cpp gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.cpp --- gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + codecbrowserwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "codecbrowserwidget.h" +#include "ui_codecbrowserwidget.h" + +#include +#include +#include + +using namespace GammaRay; + +CodecBrowserWidget::CodecBrowserWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::CodecBrowserWidget) +{ + ui->setupUi(this); + + ui->codecList->setRootIsDecorated(false); + ui->codecList->setModel(ObjectBroker::model("com.kdab.GammaRay.AllCodecsModel")); + ui->codecList->setSelectionModel(ObjectBroker::selectionModel(ui->codecList->model())); + ui->codecList->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui->selectedCodecs->setRootIsDecorated(false); + ui->selectedCodecs->setModel(ObjectBroker::model("com.kdab.GammaRay.SelectedCodecsModel")); + + new DeferredResizeModeSetter(ui->codecList->header(), 0, QHeaderView::ResizeToContents); + new DeferredResizeModeSetter(ui->selectedCodecs->header(), 0, QHeaderView::ResizeToContents); + + connect(ui->codecText, SIGNAL(textChanged(QString)), SLOT(textChanged(QString))); +} + +CodecBrowserWidget::~CodecBrowserWidget() +{ +} + +void CodecBrowserWidget::textChanged(const QString& text) +{ + Endpoint::instance()->invokeObject("com.kdab.GammaRay.CodecBrowser", "textChanged", QVariantList() << text); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(CodecBrowserUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.h gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.h --- gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + codecbrowserwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CODECBROWSERWIDGET_H +#define GAMMARAY_CODECBROWSERWIDGET_H + +#include + +#include + +namespace GammaRay { + +namespace Ui { + class CodecBrowserWidget; +} + +class CodecBrowserWidget : public QWidget +{ + Q_OBJECT + public: + explicit CodecBrowserWidget(QWidget *parent = 0); + ~CodecBrowserWidget(); + + private slots: + void textChanged(const QString &text); + + private: + QScopedPointer ui; +}; + +class CodecBrowserUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.CodecBrowserUi") +}; + +} + +#endif // GAMMARAY_CODECBROWSERWIDGET_H diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.ui gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.ui --- gammaray-1.2.2/plugins/codecbrowser/codecbrowserwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecbrowserwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ + + + GammaRay::CodecBrowserWidget + + + + 0 + 0 + 400 + 300 + + + + + + + Qt::Horizontal + + + + + + + + + + + Enter text for preview... + + + + + + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecmodel.cpp gammaray-2.0.1/plugins/codecbrowser/codecmodel.cpp --- gammaray-1.2.2/plugins/codecbrowser/codecmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,191 @@ +/* + codecmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "codecmodel.h" + +#include + +using namespace GammaRay; + +AllCodecsModel::AllCodecsModel(QObject *parent) + : QAbstractItemModel(parent) +{ +} + +int AllCodecsModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 2; +} + +QVariant AllCodecsModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole) { + if (index.column() == 0) { + return QTextCodec::availableCodecs().at(index.row()); + } + if (index.column() == 1) { + QList aliases = + QTextCodec::codecForName(QTextCodec::availableCodecs().at(index.row()))->aliases(); + + QString result; + int size = aliases.size(); + int i = 0; + foreach (const QByteArray &ba, aliases) { + result.append(ba); + + ++i; + if (i != size) { + result.append(", "); + } + } + return result; + } + } + return QVariant(); +} + +QVariant AllCodecsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) { + return "Codec"; + } else if (section == 1) { + return "Aliases"; + } + } + return QVariant(); +} + +QModelIndex AllCodecsModel::index(int row, int column, const QModelIndex &parent) const +{ + if (parent.isValid()) { + return QModelIndex(); + } + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + return createIndex(row, column); +} + +QModelIndex AllCodecsModel::parent(const QModelIndex &child) const +{ + Q_UNUSED(child); + return QModelIndex(); +} + +int AllCodecsModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return QTextCodec::availableCodecs().size(); +} + +SelectedCodecsModel::SelectedCodecsModel(QObject *parent) + : QAbstractItemModel(parent) +{ +} + +void SelectedCodecsModel::setCodecs(const QStringList &codecs) +{ + beginResetModel(); + m_codecs = codecs; + endResetModel(); +} + +QStringList SelectedCodecsModel::currentCodecs() const +{ + return m_codecs; +} + +void SelectedCodecsModel::updateText(const QString &text) +{ + m_text = text; + if (!m_codecs.isEmpty()) { + emit dataChanged(index(0, 1), index(m_codecs.size() - 1, 1)); + } +} + +QVariant SelectedCodecsModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) { + return "Codec"; + } + if (section == 1) { + return "Data"; + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +int SelectedCodecsModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return m_codecs.size(); +} + +QModelIndex SelectedCodecsModel::index(int row, int column, const QModelIndex &parent) const +{ + if (parent.isValid()) { + return QModelIndex(); + } + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + return createIndex(row, column); +} + +QModelIndex SelectedCodecsModel::parent(const QModelIndex &child) const +{ + Q_UNUSED(child); + return QModelIndex(); +} + +int SelectedCodecsModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 2; +} + +QVariant SelectedCodecsModel::data(const QModelIndex &index, int role) const +{ + if (index.column() == 0) { + if (role == Qt::DisplayRole) { + return m_codecs.at(index.row()); + } + } else if (index.column() == 1) { + if (role == Qt::DisplayRole) { + const QByteArray ba = + QTextCodec::codecForName(m_codecs.at(index.row()).toLatin1())->fromUnicode(m_text); +// QString result; +// foreach () + return ba.toHex(); + } + } + + return QVariant(); +} diff -Nru gammaray-1.2.2/plugins/codecbrowser/codecmodel.h gammaray-2.0.1/plugins/codecbrowser/codecmodel.h --- gammaray-1.2.2/plugins/codecbrowser/codecmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/codecmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,89 @@ +/* + codecmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CODECBROWSER_CODECMODEL_H +#define GAMMARAY_CODECBROWSER_CODECMODEL_H + +#include +#include +#include + +namespace GammaRay { + +class AllCodecsModel : public QAbstractItemModel +{ + Q_OBJECT + public: + explicit AllCodecsModel(QObject *parent); + + virtual QVariant headerData(int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const; + + virtual QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex parent(const QModelIndex &child) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; +}; + +class SelectedCodecsModel : public QAbstractItemModel +{ + Q_OBJECT + public: + explicit SelectedCodecsModel(QObject *parent); + + void setCodecs(const QStringList &codecs); + QStringList currentCodecs() const; + + virtual QVariant headerData(int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const; + + virtual QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex parent(const QModelIndex &child) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + public slots: + void updateText(const QString &text); + + private: + QStringList m_codecs; + QString m_text; +}; + +} + +#endif diff -Nru gammaray-1.2.2/plugins/codecbrowser/gammaray_codecbrowser.desktop gammaray-2.0.1/plugins/codecbrowser/gammaray_codecbrowser.desktop --- gammaray-1.2.2/plugins/codecbrowser/gammaray_codecbrowser.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/gammaray_codecbrowser.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Text Codecs +X-GammaRay-Types=QObject; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory +Exec=gammaray_codecbrowser_plugin diff -Nru gammaray-1.2.2/plugins/codecbrowser/gammaray_codecbrowser_ui.desktop gammaray-2.0.1/plugins/codecbrowser/gammaray_codecbrowser_ui.desktop --- gammaray-1.2.2/plugins/codecbrowser/gammaray_codecbrowser_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/codecbrowser/gammaray_codecbrowser_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_codecbrowser +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_codecbrowser_ui_plugin diff -Nru gammaray-1.2.2/plugins/fontbrowser/CMakeLists.txt gammaray-2.0.1/plugins/fontbrowser/CMakeLists.txt --- gammaray-1.2.2/plugins/fontbrowser/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +# probe part +set(gammaray_fontbrowser_plugin_srcs + fontbrowserinterface.cpp + fontbrowser.cpp + fontmodel.cpp + fontbrowserserver.cpp +) + +gammaray_add_plugin(gammaray_fontbrowser_plugin + gammaray_fontbrowser.desktop + ${gammaray_fontbrowser_plugin_srcs} +) + +target_link_libraries(gammaray_fontbrowser_plugin gammaray_core) +if(Qt5Core_FOUND) + target_link_libraries(gammaray_fontbrowser_plugin Qt5::Gui) +else() + target_link_libraries(gammaray_fontbrowser_plugin ${QT_QTGUI_LIBRARIES}) +endif() + +# ui part +if((Qt5Widgets_FOUND OR QT_QTGUI_FOUND) AND NOT GAMMARAY_PROBE_ONLY_BUILD) + + set(gammaray_fontbrowser_plugin_ui_srcs + fontbrowserinterface.cpp + fontbrowserwidget.cpp + fontbrowserclient.cpp + ) + + qt4_wrap_ui(gammaray_fontbrowser_plugin_ui_srcs + fontbrowserwidget.ui + ) + + gammaray_add_plugin(gammaray_fontbrowser_ui_plugin + gammaray_fontbrowser_ui.desktop + ${gammaray_fontbrowser_plugin_ui_srcs} + ) + + target_link_libraries(gammaray_fontbrowser_ui_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common + gammaray_ui + ) + +endif() diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserclient.cpp gammaray-2.0.1/plugins/fontbrowser/fontbrowserclient.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + fontbrowserclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontbrowserclient.h" + +#include + +#include + +using namespace GammaRay; + +FontBrowserClient::FontBrowserClient(QObject *parent) + : FontBrowserInterface(parent) +{ + +} + +#define WRAP_REMOTE(func, type) \ +void FontBrowserClient::func(type arg) \ +{ \ + Endpoint::instance()->invokeObject(objectName(), #func, QVariantList() << arg); \ +} + +WRAP_REMOTE(setPointSize, int) +WRAP_REMOTE(toggleBoldFont, bool) +WRAP_REMOTE(toggleItalicFont, bool) +WRAP_REMOTE(toggleUnderlineFont, bool) +WRAP_REMOTE(updateText, const QString&) + +void FontBrowserClient::setColors(const QColor &foreground, const QColor &background) +{ + Endpoint::instance()->invokeObject(objectName(), "setColors", QVariantList() << foreground << background); +} diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserclient.h gammaray-2.0.1/plugins/fontbrowser/fontbrowserclient.h --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + fontbrowserclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_FONTBROWSERCLIENT_H +#define GAMMARAY_FONTBROWSERCLIENT_H + +#include "fontbrowserinterface.h" + +namespace GammaRay { + +class FontBrowserClient : public FontBrowserInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::FontBrowserInterface) + public: + explicit FontBrowserClient(QObject *parent = 0); + + public slots: + virtual void setPointSize(int size); + virtual void toggleBoldFont(bool bold); + virtual void toggleItalicFont(bool italic); + virtual void toggleUnderlineFont(bool underline); + virtual void updateText(const QString &text); + virtual void setColors(const QColor &foreground, const QColor &background); +}; + +} + +#endif // GAMMARAY_FONTBROWSERCLIENT_H diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowser.cpp gammaray-2.0.1/plugins/fontbrowser/fontbrowser.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontbrowser.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowser.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,33 @@ +/* + fontbrowser.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontbrowser.h" + +#include + +using namespace GammaRay; + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(FontBrowserFactory) +#endif diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowser.h gammaray-2.0.1/plugins/fontbrowser/fontbrowser.h --- gammaray-1.2.2/plugins/fontbrowser/fontbrowser.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowser.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,66 @@ +/* + fontbrowser.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_FONTBROWSER_FONTBROWSER_H +#define GAMMARAY_FONTBROWSER_FONTBROWSER_H + +#include + +#include "fontbrowserserver.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#include +#else +#include +#endif + +namespace GammaRay { + +class FontBrowserFactory : public QObject +#ifndef Q_MOC_RUN // Qt4 moc fails on the ifdef'ed multi-inheritance and generates invalid code +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +, public StandardToolFactory +#else +, public StandardToolFactory +#endif +#endif +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.FontBrowser") + + public: + explicit FontBrowserFactory(QObject *parent = 0) : QObject(parent) + { + } + + virtual inline QString name() const + { + return tr("Fonts"); + } +}; + +} + +#endif // GAMMARAY_FONTBROWSER_H diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserinterface.cpp gammaray-2.0.1/plugins/fontbrowser/fontbrowserinterface.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + fontbrowserinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontbrowserinterface.h" + +#include + +using namespace GammaRay; + +FontBrowserInterface::FontBrowserInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +FontBrowserInterface::~FontBrowserInterface() +{ + +} diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserinterface.h gammaray-2.0.1/plugins/fontbrowser/fontbrowserinterface.h --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + fontbrowserinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef FONTBROWSERINTERFACE_H +#define FONTBROWSERINTERFACE_H + +#include + +class QColor; + +namespace GammaRay { + +class FontBrowserInterface : public QObject +{ + Q_OBJECT + public: + explicit FontBrowserInterface(QObject *parent); + virtual ~FontBrowserInterface(); + + public slots: + virtual void updateText(const QString &text) = 0; + virtual void toggleBoldFont(bool bold) = 0; + virtual void toggleItalicFont(bool italic) = 0; + virtual void toggleUnderlineFont(bool underline) = 0; + virtual void setPointSize(int size) = 0; + virtual void setColors(const QColor &foreground, const QColor &background) = 0; +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::FontBrowserInterface, "com.kdab.GammaRay.FontBrowser") + +#endif // FONTBROWSERINTERFACE_H diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserserver.cpp gammaray-2.0.1/plugins/fontbrowser/fontbrowserserver.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserserver.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserserver.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,117 @@ +/* + fontbrowserserver.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontbrowserserver.h" + +#include "fontmodel.h" + +#include +#include + +#include +#include +#include + +using namespace GammaRay; + +FontBrowserServer::FontBrowserServer(ProbeInterface *probe, QObject *parent) + : FontBrowserInterface(parent) + , m_selectedFontModel(new FontModel(this)) +{ + QStandardItemModel *model = new QStandardItemModel(this); + model->setHorizontalHeaderLabels(QStringList() << tr("Fonts") << tr("Smooth sizes")); + QFontDatabase database; + foreach (const QString &family, database.families()) { + QStandardItem *familyItem = new QStandardItem; + familyItem->setText(family); + familyItem->setEditable(false); + familyItem->setData(QFont(family)); + + foreach (const QString &style, database.styles(family)) { + QStandardItem *styleItem0 = new QStandardItem; + styleItem0->setText(style); + styleItem0->setEditable(false); + styleItem0->setData(database.font(family, style, 10)); + + QString sizes; + foreach (int points, database.smoothSizes(family, style)) { + sizes += QString::number(points) + ' '; + } + + QStandardItem *styleItem1 = new QStandardItem; + styleItem1->setText(sizes.trimmed()); + styleItem1->setEditable(false); + styleItem1->setToolTip(sizes.trimmed()); + + familyItem->appendRow(QList() << styleItem0 << styleItem1); + } + + model->appendRow(familyItem); + } + + probe->registerModel("com.kdab.GammaRay.FontModel", model); + m_fontSelectionModel = ObjectBroker::selectionModel(model); + connect(m_fontSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(updateFonts())); + probe->registerModel("com.kdab.GammaRay.SelectedFontModel", m_selectedFontModel); +} + +void FontBrowserServer::updateFonts() +{ + QList currentFonts; + foreach (const QModelIndex &index, m_fontSelectionModel->selectedRows()) { + currentFonts << index.data(Qt::UserRole + 1).value(); + } + m_selectedFontModel->updateFonts(currentFonts); +} + +void FontBrowserServer::setPointSize(int size) +{ + m_selectedFontModel->setPointSize(size); +} + +void FontBrowserServer::toggleBoldFont(bool bold) +{ + m_selectedFontModel->toggleBoldFont(bold); +} + +void FontBrowserServer::toggleItalicFont(bool italic) +{ + m_selectedFontModel->toggleItalicFont(italic); +} + +void FontBrowserServer::toggleUnderlineFont(bool underline) +{ + m_selectedFontModel->toggleUnderlineFont(underline); +} + +void FontBrowserServer::updateText(const QString &text) +{ + m_selectedFontModel->updateText(text); +} + +void FontBrowserServer::setColors(const QColor &foreground, const QColor &background) +{ + m_selectedFontModel->setColors(foreground, background); +} diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserserver.h gammaray-2.0.1/plugins/fontbrowser/fontbrowserserver.h --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserserver.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserserver.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + fontbrowserserver.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef FONTBROWSERSERVER_H +#define FONTBROWSERSERVER_H + +#include "fontbrowserinterface.h" + +class QItemSelectionModel; + +namespace GammaRay { + +class ProbeInterface; +class FontModel; + +class FontBrowserServer : public FontBrowserInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::FontBrowserInterface) + public: + explicit FontBrowserServer(ProbeInterface *probe, QObject *parent = 0); + + private slots: + void updateFonts(); + + virtual void setPointSize(int size); + virtual void toggleBoldFont(bool bold); + virtual void toggleItalicFont(bool italic); + virtual void toggleUnderlineFont(bool underline); + virtual void updateText(const QString &text); + virtual void setColors(const QColor &foreground, const QColor &background); + + private: + FontModel *m_selectedFontModel; + QItemSelectionModel *m_fontSelectionModel; +}; + +} + +#endif // FONTBROWSERSERVER_H diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.cpp gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,100 @@ +/* + fontbrowserwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontbrowserwidget.h" +#include "ui_fontbrowserwidget.h" + +#include "fontbrowserclient.h" + +#include +#include + +#include +#include + +using namespace GammaRay; + +static QObject* fontBrowserClientFactory(const QString &/*name*/, QObject *parent) +{ + return new FontBrowserClient(parent); +} + +FontBrowserWidget::FontBrowserWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::FontBrowserWidget) + , m_selectedFontModel(0) + , m_fontBrowser(0) +{ + ObjectBroker::registerClientObjectFactoryCallback(fontBrowserClientFactory); + m_fontBrowser = ObjectBroker::object(); + + ui->setupUi(this); + + m_selectedFontModel = ObjectBroker::model("com.kdab.GammaRay.SelectedFontModel"); + + ui->selectedFontsView->setModel(m_selectedFontModel); + ui->selectedFontsView->setRootIsDecorated(false); + new DeferredResizeModeSetter(ui->selectedFontsView->header(), 0, QHeaderView::ResizeToContents); + + connect(ui->fontText, SIGNAL(textChanged(QString)), + m_fontBrowser, SLOT(updateText(QString))); + connect(ui->boldBox, SIGNAL(toggled(bool)), + m_fontBrowser, SLOT(toggleBoldFont(bool))); + connect(ui->italicBox, SIGNAL(toggled(bool)), + m_fontBrowser, SLOT(toggleItalicFont(bool))); + connect(ui->underlineBox, SIGNAL(toggled(bool)), + m_fontBrowser, SLOT(toggleUnderlineFont(bool))); + connect(ui->pointSize, SIGNAL(valueChanged(int)), + m_fontBrowser, SLOT(setPointSize(int))); + + QAbstractItemModel *fontModel = ObjectBroker::model("com.kdab.GammaRay.FontModel"); + ui->fontTree->setSelectionMode(QAbstractItemView::ExtendedSelection); + ui->fontTree->setModel(fontModel); + ui->fontTree->setSelectionModel(ObjectBroker::selectionModel(fontModel)); + new DeferredResizeModeSetter(ui->fontTree->header(), 0, QHeaderView::ResizeToContents); + + ui->pointSize->setValue(font().pointSize()); + + // init + m_fontBrowser->updateText(ui->fontText->text()); + m_fontBrowser->toggleBoldFont(ui->boldBox->isChecked()); + m_fontBrowser->toggleItalicFont(ui->italicBox->isChecked()); + m_fontBrowser->toggleUnderlineFont(ui->underlineBox->isChecked()); + m_fontBrowser->setPointSize(ui->pointSize->value()); + + QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection); +} + +FontBrowserWidget::~FontBrowserWidget() +{ +} + +void FontBrowserWidget::delayedInit() +{ + m_fontBrowser->setColors(palette().color(QPalette::Foreground), palette().color(QPalette::Base)); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(FontBrowserUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.h gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.h --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + fontbrowserwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_FONTBROWSER_FONTBROWSERWIDGET_H +#define GAMMARAY_FONTBROWSER_FONTBROWSERWIDGET_H + +#include + +#include + +class QAbstractItemModel; +class QItemSelection; + +namespace GammaRay { + +class FontBrowserInterface; + +namespace Ui { + class FontBrowserWidget; +} + +class FontBrowserWidget : public QWidget +{ + Q_OBJECT + public: + explicit FontBrowserWidget(QWidget *parent = 0); + ~FontBrowserWidget(); + + private slots: + void delayedInit(); + + private: + QScopedPointer ui; + QAbstractItemModel *m_selectedFontModel; + FontBrowserInterface *m_fontBrowser; +}; + +class FontBrowserUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.FontBrowserUi") +}; + + +} + +#endif // GAMMARAY_FONTBROWSERWIDGET_H diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.ui gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.ui --- gammaray-1.2.2/plugins/fontbrowser/fontbrowserwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontbrowserwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,100 @@ + + + GammaRay::FontBrowserWidget + + + + 0 + 0 + 742 + 300 + + + + + + + Qt::Horizontal + + + + true + + + + + + + + The quick brown fox jumps over the lazy dog + + + Enter some text here... + + + + + + + + 0 + + + + + Point Size: + + + + + + + + + + Bold + + + + + + + Italic + + + + + + + Underline + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontmodel.cpp gammaray-2.0.1/plugins/fontbrowser/fontmodel.cpp --- gammaray-1.2.2/plugins/fontbrowser/fontmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,227 @@ +/* + fontmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fontmodel.h" + +#include +#include +#include + +using namespace GammaRay; + +FontModel::FontModel(QObject *parent) + : QAbstractItemModel(parent) + , m_size(12) + , m_bold(false) + , m_italic(false) + , m_underline(false) +{ +} + +QList FontModel::currentFonts() const +{ + return m_fonts; +} + +void FontModel::updateFonts(const QList &fonts) +{ + for (int i = 0; i < m_fonts.size(); ++i) { + QFont &font = m_fonts[i]; + font.setPointSize(m_size); + font.setBold(m_bold); + font.setItalic(m_italic); + font.setUnderline(m_underline); + } + + beginResetModel(); + m_fonts = fonts; + endResetModel(); +} + +void FontModel::updateText(const QString &text) +{ + if (text == m_text) { + return; + } + beginResetModel(); + m_text = text; + endResetModel(); +} + +QVariant FontModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) { + return "Font Family"; + } else if (section == 1) { + return "Style Name"; + } else if (section == 2) { + return "Text Preview"; + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +int FontModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return m_fonts.size(); +} + +QModelIndex FontModel::index(int row, int column, const QModelIndex &parent) const +{ + if (parent.isValid()) { + return QModelIndex(); + } + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + return createIndex(row, column); +} + +QModelIndex FontModel::parent(const QModelIndex &child) const +{ + Q_UNUSED(child); + return QModelIndex(); +} + +int FontModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 3; +} + +QVariant FontModel::data(const QModelIndex &index, int role) const +{ + if (index.column() == 0) { + if (role == Qt::DisplayRole) { + return m_fonts.at(index.row()).family(); + } + } else if (index.column() == 1) { + if (role == Qt::DisplayRole) { + return m_fonts.at(index.row()).styleName(); + } + } else if (index.column() == 2) { + if (role == Qt::DecorationRole || role == Qt::SizeHintRole) { + const QFont &font = m_fonts.at(index.row()); + QFontMetrics metrics(font); + const QString text = m_text.isEmpty() ? tr("") : m_text; + const QRect rect = metrics.boundingRect(text.left(100)); + if (role == Qt::SizeHintRole) { + return rect.size(); + } + QPixmap pixmap(rect.size()); + pixmap.fill(m_background); + QPainter painter(&pixmap); + painter.setPen(m_foreground); + painter.setFont(font); + painter.drawText(0, -rect.y(), text); + return pixmap; + } + } + + return QVariant(); +} + +void FontModel::setPointSize(int size) +{ + if (size == m_size) { + return; + } + + m_size = size; + + for (int i = 0; i < m_fonts.size(); ++i) { + m_fonts[i].setPointSize(size); + } + + fontDataChanged(); +} + +void FontModel::toggleItalicFont(bool italic) +{ + if (italic == m_italic) { + return; + } + + m_italic = italic; + + for (int i = 0; i < m_fonts.size(); ++i) { + m_fonts[i].setItalic(italic); + } + + fontDataChanged(); +} + +void FontModel::toggleUnderlineFont(bool underline) +{ + if (underline == m_underline) { + return; + } + + m_underline = underline; + + for (int i = 0; i < m_fonts.size(); ++i) { + m_fonts[i].setUnderline(underline); + } + + fontDataChanged(); +} + +void FontModel::toggleBoldFont(bool bold) +{ + if (bold == m_bold) { + return; + } + + m_bold = bold; + + for (int i = 0; i < m_fonts.size(); ++i) { + m_fonts[i].setBold(bold); + } + + fontDataChanged(); +} + +void FontModel::setColors(const QColor &foreground, const QColor &background) +{ + if (foreground == m_foreground && background == m_background) { + return; + } + + m_foreground = foreground; + m_background = background; + + fontDataChanged(); +} + +void FontModel::fontDataChanged() +{ + if (m_fonts.isEmpty()) { + return; + } + + emit dataChanged(index(0, 2), index(rowCount() - 1, 2)); +} diff -Nru gammaray-1.2.2/plugins/fontbrowser/fontmodel.h gammaray-2.0.1/plugins/fontbrowser/fontmodel.h --- gammaray-1.2.2/plugins/fontbrowser/fontmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/fontmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,80 @@ +/* + fontmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_FONTBROWSER_FONTMODEL_H +#define GAMMARAY_FONTBROWSER_FONTMODEL_H + +#include +#include +#include + +namespace GammaRay { + +class FontModel : public QAbstractItemModel +{ + Q_OBJECT + public: + explicit FontModel(QObject *parent); + + void updateFonts(const QList &fonts); + QList currentFonts() const; + + virtual QVariant headerData(int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const; + + virtual QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + + virtual QModelIndex parent(const QModelIndex &child) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + public slots: + void updateText(const QString &text); + void toggleBoldFont(bool bold); + void toggleItalicFont(bool italic); + void toggleUnderlineFont(bool underline); + void setPointSize(int size); + void setColors(const QColor &foreground, const QColor &background); + + private: + void fontDataChanged(); + + QList m_fonts; + QString m_text; + int m_size; + bool m_bold; + bool m_italic; + bool m_underline; + QColor m_foreground; + QColor m_background; +}; + +} + +#endif diff -Nru gammaray-1.2.2/plugins/fontbrowser/gammaray_fontbrowser.desktop gammaray-2.0.1/plugins/fontbrowser/gammaray_fontbrowser.desktop --- gammaray-1.2.2/plugins/fontbrowser/gammaray_fontbrowser.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/gammaray_fontbrowser.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Font Browser +X-GammaRay-Types="QGuiApplication;QApplication;" +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory +Exec=gammaray_fontbrowser_plugin diff -Nru gammaray-1.2.2/plugins/fontbrowser/gammaray_fontbrowser_ui.desktop gammaray-2.0.1/plugins/fontbrowser/gammaray_fontbrowser_ui.desktop --- gammaray-1.2.2/plugins/fontbrowser/gammaray_fontbrowser_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/fontbrowser/gammaray_fontbrowser_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_fontbrowser +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_fontbrowser_ui_plugin diff -Nru gammaray-1.2.2/plugins/kjobtracker/CMakeLists.txt gammaray-2.0.1/plugins/kjobtracker/CMakeLists.txt --- gammaray-1.2.2/plugins/kjobtracker/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +if(NOT Qt5Core_FOUND) + # ugly workaround for FindKDE4Internal messing with the install rpath (https://github.com/KDAB/GammaRay/issues/36) + set(_old_CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}) + find_package(KDE4) + set(CMAKE_INSTALL_RPATH ${_old_CMAKE_INSTALL_RPATH}) +endif() + +if(KDE4_FOUND AND NOT Qt5Core_FOUND) + set(_KDE4_USABLE TRUE) +else() + set(_KDE4_USABLE FALSE) +endif() + +macro_log_feature( + _KDE4_USABLE + "KDE4" + "KDE libraries" + "http://www.kde.org/" + FALSE + "" + "Required for the KJob tracker plug-in" +) + +# probe part +if(KDE4_FOUND AND NOT Qt5Core_FOUND) + include_directories(${KDE4_INCLUDES}) + add_definitions(${KDE4_DEFINITIONS}) + + set(gammaray_kjob_plugin_srcs + kjobmodel.cpp + kjobtracker.cpp + ) + + gammaray_add_plugin(gammaray_kjobtracker_plugin + gammaray_kjobtracker.desktop + ${gammaray_kjob_plugin_srcs} + ) + + target_link_libraries(gammaray_kjobtracker_plugin + ${KDE4_KDECORE_LIBS} + gammaray_core + ) +endif() + +# ui part +if((Qt5Widgets_FOUND OR QT_QTGUI_FOUND) AND NOT GAMMARAY_PROBE_ONLY_BUILD) + set(gammaray_kjob_ui_plugin_srcs + kjobtrackerwidget.cpp + ) + + qt4_wrap_ui(gammaray_kjob_ui_plugin_srcs + kjobtrackerwidget.ui + ) + + gammaray_add_plugin(gammaray_kjobtracker_ui_plugin + gammaray_kjobtracker_ui.desktop + ${gammaray_kjob_ui_plugin_srcs} + ) + + target_link_libraries(gammaray_kjobtracker_ui_plugin + gammaray_ui + ) +endif() diff -Nru gammaray-1.2.2/plugins/kjobtracker/gammaray_kjobtracker.desktop gammaray-2.0.1/plugins/kjobtracker/gammaray_kjobtracker.desktop --- gammaray-1.2.2/plugins/kjobtracker/gammaray_kjobtracker.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/gammaray_kjobtracker.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=KJobs +X-GammaRay-Types=KJob; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory +Exec=gammaray_kjobtracker_plugin diff -Nru gammaray-1.2.2/plugins/kjobtracker/gammaray_kjobtracker_ui.desktop gammaray-2.0.1/plugins/kjobtracker/gammaray_kjobtracker_ui.desktop --- gammaray-1.2.2/plugins/kjobtracker/gammaray_kjobtracker_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/gammaray_kjobtracker_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_kjobtracker +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_kjobtracker_ui_plugin diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobmodel.cpp gammaray-2.0.1/plugins/kjobtracker/kjobmodel.cpp --- gammaray-1.2.2/plugins/kjobtracker/kjobmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,207 @@ +/* + kjobmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "kjobmodel.h" +#include + +#include + +#include +#include + +using namespace GammaRay; + +/* + * TODO + * - show job hierarchy + * - show all job info messages + * - show progress information + * - allow to cancel/suspend if job supports that + * - track runtime + * - allow to clear the model + * - tooltips with additional information (capabilities etc) + */ + +KJobModel::KJobModel(QObject *parent) : QAbstractTableModel(parent) +{ +} + +QVariant KJobModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + const KJobInfo &job = m_data.at(index.row()); + if (role == Qt::DisplayRole) { + switch (index.column()) { + case 0: + return job.name; + case 1: + return job.type; + case 2: + return job.statusText; + } + } else if (role == Qt::ForegroundRole) { + switch (job.state) { + case KJobInfo::Finished: + case KJobInfo::Deleted: + return QApplication::palette().brush(QPalette::Disabled, QPalette::Foreground); + case KJobInfo::Error: + return Qt::red; + case KJobInfo::Killed: + return QApplication::palette().link(); + default: + return QVariant(); + } + } + + return QVariant(); +} + +int KJobModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 3; +} + +int KJobModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return m_data.size(); +} + +QVariant KJobModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch (section) { + case 0: + return tr("Job"); + case 1: + return tr("Type"); + case 2: + return tr("Status"); + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +void KJobModel::objectAdded(QObject *obj) +{ + KJob *job = qobject_cast(obj); + if (!job) { + return; + } + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + KJobInfo jobInfo; + jobInfo.job = job; + connect(job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*))); + connect(job, SIGNAL(finished(KJob*)), SLOT(jobFinished(KJob*))); + connect(job, SIGNAL(infoMessage(KJob*,QString,QString)), SLOT(jobInfo(KJob*,QString))); + jobInfo.name = obj->objectName().isEmpty() ? Util::addressToString(obj) : obj->objectName(); + jobInfo.type = obj->metaObject()->className(); + jobInfo.state = KJobInfo::Running; + m_data.push_back(jobInfo); + endInsertRows(); +} + +void KJobModel::objectRemoved(QObject *obj) +{ + const int pos = indexOfJob(obj); + if (pos < 0) { + return; + } + + // KJob dtor emits finished, so this shouldn't happen, in theory + // We however seem to get here for very short-lived jobs that emit before objectAdded() + // is called (while we wait for the vtable to be complete), so we only see the result + // of their deleteLater(). + if (m_data[pos].state == KJobInfo::Running) { + m_data[pos].state = KJobInfo::Deleted; + m_data[pos].statusText = tr("Deleted"); + emit dataChanged(index(pos, 0), index(pos, columnCount() - 1)); + } +} + +void KJobModel::jobResult(KJob *job) +{ + const int pos = indexOfJob(job); + if (pos < 0) { + return; + } + + if (job->error()) { + m_data[pos].state = KJobInfo::Error; + m_data[pos].statusText = job->errorString(); + } else { + if (m_data.at(pos).state == KJobInfo::Killed) { + // we can get finished() before result(), which is perfectly fine + m_data[pos].statusText.clear(); + } + m_data[pos].state = KJobInfo::Finished; + } + + emit dataChanged(index(pos, 0), index(pos, columnCount()-1)); +} + +void KJobModel::jobFinished(KJob *obj) +{ + const int pos = indexOfJob(obj); + if (pos < 0) { + return; + } + + if (m_data.at(pos).state == KJobInfo::Running) { + m_data[pos].state = KJobInfo::Killed; + m_data[pos].statusText = tr("Killed"); + } + + emit dataChanged(index(pos, 0), index(pos, columnCount()-1)); +} + +void KJobModel::jobInfo(KJob *job, const QString &plainMessage) +{ + const int pos = indexOfJob(job); + if (pos < 0) { + return; + } + + if (m_data.at(pos).state == KJobInfo::Running) { + m_data[pos].statusText = plainMessage; + } + + emit dataChanged(index(pos, 0), index(pos, columnCount()-1)); +} + +int KJobModel::indexOfJob(QObject *obj) const +{ + for (int i = 0; i < m_data.size(); ++i) { + if (m_data.at(i).job == obj) { + return i; + } + } + return -1; +} diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobmodel.h gammaray-2.0.1/plugins/kjobtracker/kjobmodel.h --- gammaray-1.2.2/plugins/kjobtracker/kjobmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,77 @@ +/* + kjobmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_KJOBMODEL_H +#define GAMMARAY_KJOBMODEL_H + +#include +#include + +class KJob; + +namespace GammaRay { + +class KJobModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit KJobModel(QObject *parent = 0); + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + private slots: + void objectAdded(QObject *obj); + void objectRemoved(QObject *obj); + void jobResult(KJob *job); + void jobFinished(KJob *obj); + void jobInfo(KJob *job, const QString &plainMessage); + + private: + int indexOfJob(QObject *obj) const; + + struct KJobInfo { + KJob *job; + QString name; + QString type; + QString statusText; + enum { + Running, + Finished, + Error, + Killed, + Deleted + } state; + }; + QVector m_data; +}; + +} + +#endif // GAMMARAY_KJOBMODEL_H diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobtracker.cpp gammaray-2.0.1/plugins/kjobtracker/kjobtracker.cpp --- gammaray-1.2.2/plugins/kjobtracker/kjobtracker.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobtracker.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + kjobtracker.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "kjobtracker.h" +#include "kjobmodel.h" + +#include + +#include +#include + +using namespace GammaRay; + +KJobTracker::KJobTracker(ProbeInterface *probe, QObject *parent) + : QObject(parent), m_jobModel(new KJobModel(this)) +{ + connect(probe->probe(), SIGNAL(objectCreated(QObject*)), + m_jobModel, SLOT(objectAdded(QObject*))); + connect(probe->probe(), SIGNAL(objectDestroyed(QObject*)), + m_jobModel, SLOT(objectRemoved(QObject*))); + + probe->registerModel("com.kdab.GammaRay.KJobModel", m_jobModel); +} + +KJobTracker::~KJobTracker() +{ +} + +Q_EXPORT_PLUGIN(KJobTrackerFactory) diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobtracker.h gammaray-2.0.1/plugins/kjobtracker/kjobtracker.h --- gammaray-1.2.2/plugins/kjobtracker/kjobtracker.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobtracker.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,65 @@ +/* + kjobtracker.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_KJOBTRACKER_H +#define GAMMARAY_KJOBTRACKER_H + +#include + +#include + +class KJob; +namespace GammaRay { + +class KJobModel; + +class KJobTracker : public QObject +{ + Q_OBJECT + public: + explicit KJobTracker(ProbeInterface *probe, QObject *parent = 0); + virtual ~KJobTracker(); + + private: + KJobModel *m_jobModel; +}; + +class KJobTrackerFactory : public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + + public: + explicit KJobTrackerFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("KJobs"); + } +}; + +} + +#endif // GAMMARAY_KJOBTRACKER_H diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.cpp gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.cpp --- gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + kjobtrackerwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "kjobtrackerwidget.h" +#include "ui_kjobtrackerwidget.h" + +#include + +using namespace GammaRay; + +#include +#include +#include + +using namespace GammaRay; + +KJobTrackerWidget::KJobTrackerWidget(QWidget *parent) + : QWidget(parent), ui(new Ui::KJobTrackerWidget) +{ + ui->setupUi(this); + + QSortFilterProxyModel *filter = new QSortFilterProxyModel(this); + filter->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.KJobModel")); + ui->searchLine->setProxy(filter); + ui->jobView->setModel(filter); +} + +KJobTrackerWidget::~KJobTrackerWidget() +{ +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(KJobTrackerUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.h gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.h --- gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + kjobtrackerwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_KJOBTRACKERWIDGET_H +#define GAMMARAY_KJOBTRACKERWIDGET_H + +#include + +#include + +namespace GammaRay { + +namespace Ui { + class KJobTrackerWidget; +} + +class KJobTrackerWidget : public QWidget +{ + Q_OBJECT + public: + explicit KJobTrackerWidget(QWidget *parent = 0); + ~KJobTrackerWidget(); + + private: + QScopedPointer ui; +}; + +class KJobTrackerUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.KJobTrackerUi") +}; + +} + +#endif // GAMMARAY_KJOBTRACKERWIDGET_H diff -Nru gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.ui gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.ui --- gammaray-1.2.2/plugins/kjobtracker/kjobtrackerwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/kjobtracker/kjobtrackerwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,41 @@ + + + GammaRay::KJobTrackerWidget + + + + 0 + 0 + 400 + 300 + + + + + + + + + + false + + + true + + + true + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/plugins/objectvisualizer/CMakeLists.txt gammaray-2.0.1/plugins/objectvisualizer/CMakeLists.txt --- gammaray-1.2.2/plugins/objectvisualizer/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,42 +1,67 @@ +# probe part +set(gammaray_objectvisualizer_plugin_srcs + objectvisualizer.cpp + objectvisualizermodel.cpp +) + +gammaray_add_plugin(gammaray_objectvisualizer_plugin + gammaray_objectvisualizer.desktop + ${gammaray_objectvisualizer_plugin_srcs} +) + +target_link_libraries(gammaray_objectvisualizer_plugin + ${QT_QTCORE_LIBRARIES} + gammaray_core +) + +######## START VTK VISUALIZATION # VTK includes QtGui/... stuff => breaks compilation with Qt5 -if(NOT Qt5Core_FOUND) +if(VTK_FOUND AND NOT Qt5Core_FOUND AND NOT GAMMARAY_PROBE_ONLY_BUILD) -if(VTK_FOUND) +set(OPTIONAL_VTK_LIBRARIES +) -add_definitions(-DHAVE_VTK -DVTK_EXCLUDE_STRSTREAM_HEADERS) +add_definitions(-DVTKGUI_ENABLED -DVTK_EXCLUDE_STRSTREAM_HEADERS) include_directories( - ${CMAKE_CURRENT_BINARY_DIR} ${VTK_INCLUDE_DIRS} ) -link_directories(${VTK_LIBRARY_DIRS}) +include(${VTK_USE_FILE}) -set(gammaray_objectvisualizer_plugin_srcs - ../../3rdparty/kde/kfilterproxysearchline.cpp - ../../3rdparty/kde/krecursivefilterproxymodel.cpp +link_directories(${VTK_LIBRARY_DIRS}) - objectvisualizer.cpp +set(gammaray_objectvisualizer_ui_plugin_srcs + objectvisualizerwidget.cpp vtkcontainer.cpp vtkpanel.cpp vtkwidget.cpp ) -qt4_automoc(${gammaray_objectvisualizer_plugin_srcs}) +list(APPEND OPTIONAL_VTK_LIBRARIES + ${VTK_LIBRARIES} +) -gammaray_add_plugin(gammaray_objectvisualizer_plugin - gammaray_objectvisualizer.desktop - ${gammaray_objectvisualizer_plugin_srcs} +if(${VTK_MAJOR_VERSION} EQUAL 5) + list(APPEND OPTIONAL_VTK_LIBRARIES QVTK) +elseif(${VTK_MAJOR_VERSION} EQUAL 6) + list(APPEND OPTIONAL_VTK_LIBRARIES vtkGUISupportQt) +endif() + +gammaray_add_plugin(gammaray_objectvisualizer_ui_plugin + gammaray_objectvisualizer_ui.desktop + ${gammaray_objectvisualizer_ui_plugin_srcs} ) -target_link_libraries(gammaray_objectvisualizer_plugin +target_link_libraries(gammaray_objectvisualizer_ui_plugin ${QT_QTCORE_LIBRARIES} ${QT_QTGUI_LIBRARIES} - ${VTK_LIBRARIES} - QVTK - gammaray_probe + ${OPTIONAL_VTK_LIBRARIES} + ${VTK_QT_LIBRARY} + gammaray_common + gammaray_ui ) endif() -endif() +######## END VTK VISUALIZATION diff -Nru gammaray-1.2.2/plugins/objectvisualizer/gammaray_objectvisualizer.desktop gammaray-2.0.1/plugins/objectvisualizer/gammaray_objectvisualizer.desktop --- gammaray-1.2.2/plugins/objectvisualizer/gammaray_objectvisualizer.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/gammaray_objectvisualizer.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,5 @@ [Desktop Entry] Name=Object Visualization X-GammaRay-Types=QObject; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory Exec=gammaray_objectvisualizer_plugin diff -Nru gammaray-1.2.2/plugins/objectvisualizer/gammaray_objectvisualizer_ui.desktop gammaray-2.0.1/plugins/objectvisualizer/gammaray_objectvisualizer_ui.desktop --- gammaray-1.2.2/plugins/objectvisualizer/gammaray_objectvisualizer_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/gammaray_objectvisualizer_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_objectvisualizer +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_objectvisualizer_ui_plugin diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizer.cpp gammaray-2.0.1/plugins/objectvisualizer/objectvisualizer.cpp --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizer.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizer.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -20,97 +20,24 @@ */ #include "objectvisualizer.h" -#include "vtkcontainer.h" -#include "vtkpanel.h" -#include "vtkwidget.h" - -#include "include/objectmodel.h" -#include "include/probeinterface.h" - -#include "kde/kfilterproxysearchline.h" -#include "kde/krecursivefilterproxymodel.h" - -#include -#include -#include -#include -#include -#include -#include +#include "objectvisualizermodel.h" #include using namespace GammaRay; -GraphViewer::GraphViewer(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - mWidget(new GraphWidget(this)), - mProbeIface(probe) +GraphViewer::GraphViewer(ProbeInterface *probe, QObject *parent) + : QObject(parent) { - QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this); - objectFilter->setSourceModel(probe->objectTreeModel()); - objectFilter->setDynamicSortFilter(true); - - QVBoxLayout *vbox = new QVBoxLayout; - KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this); - objectSearchLine->setProxy(objectFilter); - vbox->addWidget(objectSearchLine); - QTreeView *objectTreeView = new QTreeView(this); - objectTreeView->setModel(objectFilter); - objectTreeView->setSortingEnabled(true); - vbox->addWidget(objectTreeView); - connect(objectTreeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - SLOT(handleRowChanged(QModelIndex))); - mObjectTreeView = objectTreeView; - - QWidget *treeViewWidget = new QWidget(this); - treeViewWidget->setLayout(vbox); - - QSplitter *splitter = new QSplitter(this); - splitter->addWidget(treeViewWidget); - splitter->addWidget(mWidget); - QHBoxLayout *hbox = new QHBoxLayout(this); - hbox->addWidget(splitter); - - QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection); + ObjectVisualizerModel *model = new ObjectVisualizerModel(this); + model->setSourceModel(probe->objectTreeModel()); + probe->registerModel("com.kdab.GammaRay.ObjectVisualizerModel", model); } GraphViewer::~GraphViewer() { } -void GraphViewer::delayedInit() -{ - // make all existing objects known to the vtk widget - const QAbstractItemModel *listModel = mProbeIface->objectListModel(); - for (int i = 0; i < listModel->rowCount(); ++i) { - const QModelIndex index = listModel->index(i, 0); - QObject *object = index.data(ObjectModel::ObjectRole).value(); - Q_ASSERT(object); - mWidget->vtkWidget()->addObject(object); - } - connect(mProbeIface->probe(), SIGNAL(objectCreated(QObject*)), - mWidget->vtkWidget(), SLOT(addObject(QObject*))); - connect(mProbeIface->probe(), SIGNAL(objectDestroyed(QObject*)), - mWidget->vtkWidget(), SLOT(removeObject(QObject*))); - - // select the qApp object (if any) in the object treeView - const QAbstractItemModel *viewModel = mObjectTreeView->model(); - const QModelIndexList matches = viewModel->match(viewModel->index(0, 0), - ObjectModel::ObjectRole, - QVariant::fromValue(qApp)); - if (!matches.isEmpty()) { - mObjectTreeView->setCurrentIndex(matches.first()); - } -} - -void GraphViewer::handleRowChanged(const QModelIndex &index) -{ - QObject *object = index.data(ObjectModel::ObjectRole).value(); - Q_ASSERT(object); - mWidget->vtkWidget()->setObjectFilter(object); -} - +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) Q_EXPORT_PLUGIN(GraphViewerFactory) - -#include "objectvisualizer.moc" +#endif diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizer.h gammaray-2.0.1/plugins/objectvisualizer/objectvisualizer.h --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizer.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizer.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -22,44 +22,29 @@ #ifndef GAMMARAY_OBJECTVISUALIZER_OBJECTVISUALIZER_H #define GAMMARAY_OBJECTVISUALIZER_OBJECTVISUALIZER_H -#include "include/toolfactory.h" - -#include - -class QTreeView; -class QModelIndex; +#include namespace GammaRay { -class GraphWidget; -class ProbeInterface; - -class GraphViewer : public QWidget +class GraphViewer : public QObject { Q_OBJECT - Q_PLUGIN_METADATA(IID "com.kdab.gammaray.GraphViewer") public: - explicit GraphViewer(ProbeInterface *probe, QWidget *parent = 0); - virtual ~GraphViewer(); - - private Q_SLOTS: - void delayedInit(); - void handleRowChanged(const QModelIndex &index); - - private: - QTreeView *mObjectTreeView; - GraphWidget *mWidget; - ProbeInterface *mProbeIface; + explicit GraphViewer(ProbeInterface *probe, QObject *parent = 0); + ~GraphViewer(); }; class GraphViewerFactory : public QObject, public StandardToolFactory { Q_OBJECT Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.GraphViewer") public: - explicit GraphViewerFactory(QObject *parent = 0) : QObject(parent) {} + explicit GraphViewerFactory(QObject *parent = 0) : QObject(parent) + { + } virtual inline QString name() const { diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizermodel.cpp gammaray-2.0.1/plugins/objectvisualizer/objectvisualizermodel.cpp --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizermodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,64 @@ +/* + objectvisualizermodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "objectvisualizermodel.h" + +#include + +using namespace GammaRay; + +ObjectVisualizerModel::ObjectVisualizerModel(QObject* parent) : QIdentityProxyModel(parent) +{ +} + +ObjectVisualizerModel::~ObjectVisualizerModel() +{ +} + +QVariant ObjectVisualizerModel::data(const QModelIndex& proxyIndex, int role) const +{ + if (role == ObjectDisplayName) { + QObject *obj = data(proxyIndex, ObjectModel::ObjectRole).value(); + return Util::displayString(obj); + } + else if (role == ObjectId) { + QObject *obj = data(proxyIndex, ObjectModel::ObjectRole).value(); + return static_cast(reinterpret_cast(obj)); + } + else if (role == ClassName) { + QObject *obj = data(proxyIndex, ObjectModel::ObjectRole).value(); + Q_ASSERT(obj); + return obj->metaObject()->className(); + } + + return QIdentityProxyModel::data(proxyIndex, role); +} + +QMap< int, QVariant > ObjectVisualizerModel::itemData(const QModelIndex& index) const +{ + QMap d = QIdentityProxyModel::itemData(index); + d.insert(ObjectId, data(index, ObjectId)); + d.insert(ObjectDisplayName, data(index, ObjectDisplayName)); + d.insert(ClassName, data(index, ClassName)); + return d; +} diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizermodel.h gammaray-2.0.1/plugins/objectvisualizer/objectvisualizermodel.h --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizermodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + objectvisualizermodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_OBJECTVISUALIZERMODEL_H +#define GAMMARAY_OBJECTVISUALIZERMODEL_H + +#include + +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) +#include +typedef QSortFilterProxyModel QIdentityProxyModel; +#else +#include +#endif + +#include + +namespace GammaRay { + +/** Augment the regular object tree by some information needed for the visualization + * on the client side. + */ +class ObjectVisualizerModel : public QIdentityProxyModel +{ + Q_OBJECT +public: + enum Role { + ObjectId = ObjectModel::UserRole, + ObjectDisplayName, + ClassName + }; + + explicit ObjectVisualizerModel(QObject *parent); + ~ObjectVisualizerModel(); + + QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const; + QMap itemData(const QModelIndex& index) const; +}; +} + +#endif // GAMMARAY_OBJECTVISUALIZERMODEL_H diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizerwidget.cpp gammaray-2.0.1/plugins/objectvisualizer/objectvisualizerwidget.cpp --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizerwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizerwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,100 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "objectvisualizerwidget.h" +#include "vtkcontainer.h" +#include "vtkpanel.h" +#include "vtkwidget.h" + +#include "kde/kfilterproxysearchline.h" +#include "kde/krecursivefilterproxymodel.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +GraphViewerWidget::GraphViewerWidget(QWidget *parent) + : QWidget(parent), + mWidget(new GraphWidget(this)) +{ + mModel = ObjectBroker::model("com.kdab.GammaRay.ObjectVisualizerModel"); + + QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this); + objectFilter->setSourceModel(mModel); + objectFilter->setDynamicSortFilter(true); + + QVBoxLayout *vbox = new QVBoxLayout; + KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this); + objectSearchLine->setProxy(objectFilter); + vbox->addWidget(objectSearchLine); + QTreeView *objectTreeView = new QTreeView(this); + objectTreeView->setModel(objectFilter); + objectTreeView->setSortingEnabled(true); + vbox->addWidget(objectTreeView); + + mObjectTreeView = objectTreeView; + + QWidget *treeViewWidget = new QWidget(this); + treeViewWidget->setLayout(vbox); + + QSplitter *splitter = new QSplitter(this); + splitter->addWidget(treeViewWidget); + splitter->addWidget(mWidget); + QHBoxLayout *hbox = new QHBoxLayout(this); + hbox->addWidget(splitter); + + QMetaObject::invokeMethod(this, "delayedInit", Qt::QueuedConnection); +} + +GraphViewerWidget::~GraphViewerWidget() +{ +} + +void GraphViewerWidget::delayedInit() +{ + // make all existing objects known to the vtk widget + mWidget->vtkWidget()->setModel(mModel); + mWidget->vtkWidget()->setSelectionModel(mObjectTreeView->selectionModel()); + + /// FIXME: This won't work for remote clients! + // select the qApp object (if any) in the object treeView + const QAbstractItemModel *viewModel = mObjectTreeView->model(); + const QModelIndexList matches = viewModel->match(viewModel->index(0, 0), + ObjectModel::ObjectRole, QVariant::fromValue(qApp), 1, + Qt::MatchFlags(Qt::MatchExactly|Qt::MatchRecursive)); + + if (!matches.isEmpty()) { + Q_ASSERT(matches.first().data(ObjectModel::ObjectRole).value() == qApp); + mObjectTreeView->setCurrentIndex(matches.first()); + } +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(ObjectVisualizerUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/objectvisualizer/objectvisualizerwidget.h gammaray-2.0.1/plugins/objectvisualizer/objectvisualizerwidget.h --- gammaray-1.2.2/plugins/objectvisualizer/objectvisualizerwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/objectvisualizerwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_OBJECTVISUALIZER_OBJECTVISUALIZERWIDGET_H +#define GAMMARAY_OBJECTVISUALIZER_OBJECTVISUALIZERWIDGET_H + +#include + +#include + +class QAbstractItemModel; +class QTreeView; +class QModelIndex; + +namespace GammaRay { + +class GraphWidget; + +class GraphViewerWidget : public QWidget +{ + Q_OBJECT + public: + explicit GraphViewerWidget(QWidget *parent = 0); + virtual ~GraphViewerWidget(); + + private Q_SLOTS: + void delayedInit(); + + private: + QAbstractItemModel* mModel; + QTreeView *mObjectTreeView; + GraphWidget *mWidget; +}; + +class ObjectVisualizerUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.ObjectVisualizerUi") +}; + +} + +#endif // GAMMARAY_GRAPHVIEWER_H diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkcontainer.cpp gammaray-2.0.1/plugins/objectvisualizer/vtkcontainer.cpp --- gammaray-1.2.2/plugins/objectvisualizer/vtkcontainer.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkcontainer.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -21,7 +21,6 @@ #include "vtkcontainer.h" -#include #include #include "vtkwidget.h" @@ -43,7 +42,4 @@ GraphWidget::~GraphWidget() { - qDebug() << Q_FUNC_INFO; } - -#include "vtkcontainer.moc" diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkcontainer.h gammaray-2.0.1/plugins/objectvisualizer/vtkcontainer.h --- gammaray-1.2.2/plugins/objectvisualizer/vtkcontainer.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkcontainer.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkpanel.cpp gammaray-2.0.1/plugins/objectvisualizer/vtkpanel.cpp --- gammaray-1.2.2/plugins/objectvisualizer/vtkpanel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkpanel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -120,5 +120,3 @@ VtkPanel::~VtkPanel() { } - -#include "vtkpanel.moc" diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkpanel.h gammaray-2.0.1/plugins/objectvisualizer/vtkpanel.h --- gammaray-1.2.2/plugins/objectvisualizer/vtkpanel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkpanel.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkwidget.cpp gammaray-2.0.1/plugins/objectvisualizer/vtkwidget.cpp --- gammaray-1.2.2/plugins/objectvisualizer/vtkwidget.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk Author: Volker Krause @@ -21,9 +21,14 @@ */ #include "vtkwidget.h" +#include "objectvisualizermodel.h" -#include "include/util.h" +#include "common/objectmodel.h" +#include "core/util.h" +#include +#include +#include #include #include @@ -66,7 +71,9 @@ : QVTKWidget(parent), m_mousePressed(false), m_updateTimer(new QTimer(this)), - m_objectFilter(0), + m_model(0), + m_selectionModel(0), + m_repopulateTimer(new QTimer(this)), m_colorIndex(0) { setupRenderer(); @@ -76,6 +83,10 @@ m_updateTimer->setInterval(0); m_updateTimer->setSingleShot(true); connect(m_updateTimer, SIGNAL(timeout()), SLOT(renderViewImpl())); + + m_repopulateTimer->setInterval(100); + m_repopulateTimer->setSingleShot(true); + connect(m_repopulateTimer, SIGNAL(timeout()), SLOT(doRepopulate())); } VtkWidget::~VtkWidget() @@ -85,6 +96,29 @@ DEBUG("") } +void VtkWidget::setModel(QAbstractItemModel *model) +{ + m_model = model; + + connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), + SLOT(objectRowsInserted(QModelIndex,int,int))); + + connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + SLOT(objectRowsAboutToBeRemoved(QModelIndex,int,int))); + + connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + SLOT(objectDataChanged(QModelIndex,QModelIndex))); + + doRepopulate(); // no delay here, otherwise we race against the signals +} + +void VtkWidget::setSelectionModel(QItemSelectionModel *selectionModel) +{ + m_selectionModel = selectionModel; + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(selectionChanged())); +} + void VtkWidget::setupRenderer() { } @@ -211,14 +245,7 @@ DEBUG("end") } -bool VtkWidget::addObject(QObject *object) -{ - m_availableObjects << object; - - return addObjectInternal(object); -} - -bool VtkWidget::addObjectInternal(QObject *object) +qulonglong VtkWidget::addObject(const QModelIndex &index) { // ignore new objects during scene interaction // TODO: Add some code to add the objects later on => queue objects @@ -227,23 +254,26 @@ << object << " " << object->metaObject()->className()) - return false; + return 0; } - const QString className = QLatin1String(object->metaObject()->className()); + qulonglong objectId = index.data(ObjectVisualizerModel::ObjectId).toULongLong(); + const QString className = index.data(ObjectVisualizerModel::ClassName).toString(); +#if 0 // FIXME this breaks the graph structure since this will cause orphan children! if (className == "QVTKInteractorInternal") { - return false; + return 0; } +#endif - if (m_objectIdMap.contains(object)) { - return false; + if (!objectId || m_objectIdMap.contains(objectId)) { + return 0; } - if (!filterAcceptsObject(object)) { - return false; + if (!filterAcceptsObject(index)) { + return 0; } - const QString label = Util::displayString(object); + const QString label = index.data(ObjectVisualizerModel::ObjectDisplayName).toString(); const int weight = 1; // TODO: Make weight somewhat usable? m_vertexPropertyArr->SetValue(0, vtkUnicodeString::from_utf16(label.utf16())); m_vertexPropertyArr->SetValue(1, weight); @@ -261,38 +291,45 @@ const vtkIdType type = m_graph->AddVertex(m_vertexPropertyArr); DEBUG("Add: " << type << " " << object->metaObject()->className()) - m_objectIdMap[object] = type; + m_objectIdMap[objectId] = type; - QObject *parentObject = object->parent(); - if (parentObject) { - if (!m_objectIdMap.contains(parentObject)) { - addObject(parentObject); - } - if (m_objectIdMap.contains(parentObject)) { - const vtkIdType parentType = m_objectIdMap[parentObject]; + // recursively add our children + for (int i = 0; i < index.model()->rowCount(index); ++i) { + addObject(index.child(i, 0)); + } + + // add edge to parent + if (index.parent().isValid()) { + const qulonglong parentId = index.parent().data(ObjectVisualizerModel::ObjectId).toULongLong(); + if (parentId) { + Q_ASSERT(m_objectIdMap.contains(parentId)); + const vtkIdType parentType = m_objectIdMap.value(parentId); m_graph->AddEdge(parentType, type); } } renderView(); - return true; + return objectId; } -bool VtkWidget::removeObject(QObject *object) +bool VtkWidget::removeObject(const QModelIndex &index) { - m_availableObjects.remove(object); + for (int i = 0; i < index.model()->rowCount(index); ++i) { + removeObject(index.child(i, 0)); + } - return removeObjectInternal(object); + const qulonglong objectId = index.data(ObjectVisualizerModel::ObjectId).toULongLong(); + return removeObjectInternal(objectId); } -bool VtkWidget::removeObjectInternal(QObject *object) +bool VtkWidget::removeObjectInternal(qulonglong objectId) { - if (!m_objectIdMap.contains(object)) { + if (!m_objectIdMap.contains(objectId)) { return false; } // Remove id-for-object from VTK's graph data structure - const vtkIdType type = m_objectIdMap[object]; + const vtkIdType type = m_objectIdMap[objectId]; const int size = m_graph->GetNumberOfVertices(); m_graph->RemoveVertex(type); @@ -301,14 +338,14 @@ const vtkIdType lastId = m_objectIdMap.size() - 1; DEBUG("Type: " << type << " Last: " << lastId) if (type != lastId) { - QObject *lastObject = m_objectIdMap.key(lastId); - Q_ASSERT(lastObject); - m_objectIdMap[lastObject] = type; + qulonglong lastObjectId = m_objectIdMap.key(lastId); + Q_ASSERT(lastObjectId); + m_objectIdMap[lastObjectId] = type; } // Remove object from our map if (size > m_graph->GetNumberOfVertices()) { - const bool count = m_objectIdMap.remove(object); + const bool count = m_objectIdMap.remove(objectId); Q_ASSERT(count == 1); } else { DEBUG("Warning: Should not happen: Could not remove vertice with id: " << type) @@ -328,8 +365,8 @@ { // TODO: there must be an easier/faster way to clean the graph data // Just re-create the vtk graph data object? - Q_FOREACH (QObject *object, m_objectIdMap.keys()) { - removeObjectInternal(object); + Q_FOREACH (const qulonglong &objectId, m_objectIdMap) { + removeObjectInternal(objectId); } m_objectIdMap.clear(); @@ -344,33 +381,36 @@ m_view->ResetCamera(); } -void VtkWidget::setObjectFilter(QObject *object) +void VtkWidget::selectionChanged() { - if (m_objectFilter == object) { - return; - } - - m_objectFilter = object; repopulate(); resetCamera(); } void VtkWidget::repopulate() { + if (!m_repopulateTimer->isActive()) { + m_repopulateTimer->start(); + } +} + +void VtkWidget::doRepopulate() +{ DEBUG("") clear(); - Q_FOREACH (QObject *object, m_availableObjects) { - addObject(object); + for (int i = 0; i < m_model->rowCount(); ++i) { + const QModelIndex index = m_model->index(i, 0); + addObject(index); } } // TODO: Move to Util.h? -static bool descendantOf(QObject *ascendant, QObject *obj) +static bool descendantOf(const QModelIndex &ascendant, const QModelIndex &index) { - QObject *parent = obj->parent(); - if (!parent) { + const QModelIndex parent = index.parent(); + if (!parent.isValid()) { return false; } if (parent == ascendant) { @@ -379,18 +419,60 @@ return descendantOf(ascendant, parent); } -bool VtkWidget::filterAcceptsObject(QObject *object) const +static QModelIndex mapToSource(const QModelIndex &proxyIndex) { - if (m_objectFilter) { - if (object == m_objectFilter) { - return true; - } else if (descendantOf(m_objectFilter, object)) { + if (proxyIndex.model()->inherits("GammaRay::ObjectVisualizerModel")) { + return proxyIndex; + } + + const QAbstractProxyModel *proxyModel = + qobject_cast(proxyIndex.model()); + + if (proxyModel) { + return mapToSource(proxyModel->mapToSource(proxyIndex)); + } else { + return proxyIndex; + } +} + +bool VtkWidget::filterAcceptsObject(const QModelIndex &index) const +{ + if (!m_selectionModel) { + return true; + } + + QModelIndexList rows = m_selectionModel->selectedRows(); + foreach (const QModelIndex &row, rows) { + const QModelIndex sourceRow = mapToSource(row); + if (index == sourceRow) { return true; - } else { - return false; } + return descendantOf(sourceRow, index); + } + + return true; // empty selection +} + +void VtkWidget::objectRowsInserted(const QModelIndex &parent, int start, int end) +{ + for (int i = start; i <= end; ++i) { + const QModelIndex index = m_model->index(i, 0, parent); + addObject(index); } - return true; } -#include "vtkwidget.moc" +void VtkWidget::objectRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) +{ + for (int i = start; i <= end; ++i) { + const QModelIndex index = m_model->index(i, 0, parent); + removeObject(index); + } +} + +void VtkWidget::objectDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + for (int i = topLeft.row(); i <= bottomRight.row(); ++i) { + const QModelIndex index = m_model->index(i, 0, topLeft.parent()); + addObject(index); + } +} diff -Nru gammaray-1.2.2/plugins/objectvisualizer/vtkwidget.h gammaray-2.0.1/plugins/objectvisualizer/vtkwidget.h --- gammaray-1.2.2/plugins/objectvisualizer/vtkwidget.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/objectvisualizer/vtkwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk Author: Volker Krause @@ -30,6 +30,9 @@ #include #include +class QItemSelectionModel; +class QModelIndex; +class QAbstractItemModel; class vtkGraphLayoutStrategy; class vtkVariantArray; class vtkGraphLayoutView; @@ -48,39 +51,40 @@ explicit VtkWidget(QWidget *parent = 0); virtual ~VtkWidget(); - QObject *objectFilter() const - { - return m_objectFilter; - } - vtkGraphLayoutView *layoutView() const { return m_view; } + void setModel(QAbstractItemModel* model); + void setSelectionModel(QItemSelectionModel* selectionModel); + public Q_SLOTS: void resetCamera(); - bool addObject(QObject *); - bool removeObject(QObject *); - - void setObjectFilter(QObject *object); + qulonglong addObject(const QModelIndex& index); + bool removeObject(const QModelIndex &index); void clear(); void repopulate(); private Q_SLOTS: - bool addObjectInternal(QObject *object); - bool removeObjectInternal(QObject *object); + bool removeObjectInternal(qulonglong objectId); + void doRepopulate(); + void selectionChanged(); void renderViewImpl(); void renderView(); + void objectRowsInserted(const QModelIndex &parent, int start, int end); + void objectRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + void objectDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + protected: virtual void mousePressEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event); - bool filterAcceptsObject(QObject *object) const; + bool filterAcceptsObject(const QModelIndex &index) const; private: void setupGraph(); @@ -88,11 +92,12 @@ bool m_mousePressed; QTimer *m_updateTimer; - QObject *m_objectFilter; + QAbstractItemModel* m_model; + QItemSelectionModel* m_selectionModel; + QTimer *m_repopulateTimer; // TODO: Instead of tracking all available objects, make Probe::m_validObjects public? - QSet m_availableObjects; - QMap m_objectIdMap; + QMap m_objectIdMap; int m_colorIndex; QMap m_typeColorMap; diff -Nru gammaray-1.2.2/plugins/sceneinspector/CMakeLists.txt gammaray-2.0.1/plugins/sceneinspector/CMakeLists.txt --- gammaray-1.2.2/plugins/sceneinspector/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,26 @@ +set(gammaray_sceneinspector_plugin_srcs + graphicsview.cpp + graphicssceneview.cpp + scenemodel.cpp + sceneinspectorinterface.cpp + sceneinspector.cpp + sceneinspectorclient.cpp + sceneinspectorwidget.cpp +) + +qt4_wrap_ui(gammaray_sceneinspector_plugin_srcs + graphicssceneview.ui + sceneinspectorwidget.ui +) + +gammaray_add_plugin(gammaray_sceneinspector_plugin + gammaray_sceneinspector.desktop + ${gammaray_sceneinspector_plugin_srcs} +) + +target_link_libraries(gammaray_sceneinspector_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_core + gammaray_ui +) diff -Nru gammaray-1.2.2/plugins/sceneinspector/gammaray_sceneinspector.desktop gammaray-2.0.1/plugins/sceneinspector/gammaray_sceneinspector.desktop --- gammaray-1.2.2/plugins/sceneinspector/gammaray_sceneinspector.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/gammaray_sceneinspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Graphics Scenes +X-GammaRay-Types=QGraphicsScene; +X-GammaRay-ServiceTypes="com.kdab.GammaRay.ToolFactory;com.kdab.GammaRay.ToolUiFactory" +Exec=gammaray_sceneinspector_plugin diff -Nru gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.cpp gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.cpp --- gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,77 @@ +/* + graphicssceneview.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "graphicssceneview.h" +#include "ui_graphicssceneview.h" + +using namespace GammaRay; + +GraphicsSceneView::GraphicsSceneView(QWidget *parent) + : QWidget(parent), + ui(new Ui::GraphicsSceneView) +{ + ui->setupUi(this); + + QFontMetrics fm(ui->sceneCoordLabel->font()); + ui->sceneCoordLabel->setFixedWidth(fm.width("00000.00 x 00000.00")); + ui->itemCoordLabel->setFixedWidth(fm.width("00000.00 x 00000.00")); + + connect(ui->graphicsView, SIGNAL(sceneCoordinatesChanged(QPointF)), + SLOT(sceneCoordinatesChanged(QPointF))); + connect(ui->graphicsView, SIGNAL(itemCoordinatesChanged(QPointF)), + SLOT(itemCoordinatesChanged(QPointF))); +} + +GraphicsSceneView::~GraphicsSceneView() +{ + delete ui; +} + +GraphicsView * GraphicsSceneView::view() const +{ + return ui->graphicsView; +} + +void GraphicsSceneView::showGraphicsItem(QGraphicsItem *item) +{ + ui->graphicsView->showItem(item); +} + +void GraphicsSceneView::setGraphicsScene(QGraphicsScene *scene) +{ + ui->graphicsView->setScene(scene); +} + +void GraphicsSceneView::sceneCoordinatesChanged(const QPointF &coord) +{ + ui->sceneCoordLabel->setText(QString::fromLatin1("%1 x %2"). + arg(coord.x(), 0, 'f', 2). + arg(coord.y(), 0, 'f', 2)); +} + +void GraphicsSceneView::itemCoordinatesChanged(const QPointF &coord) +{ + ui->itemCoordLabel->setText(QString::fromLatin1("%1 x %2"). + arg(coord.x(), 0, 'f', 2). + arg(coord.y(), 0, 'f', 2)); +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.h gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.h --- gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + graphicssceneview.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTOR_GRAPHICSSCENEVIEW_H +#define GAMMARAY_SCENEINSPECTOR_GRAPHICSSCENEVIEW_H + +#include + +class QGraphicsScene; +class QGraphicsItem; + +namespace GammaRay { + +class GraphicsView; + +namespace Ui { + class GraphicsSceneView; +} + +class GraphicsSceneView : public QWidget +{ + Q_OBJECT + public: + explicit GraphicsSceneView(QWidget *parent = 0); + ~GraphicsSceneView(); + + GraphicsView* view() const; + + void showGraphicsItem(QGraphicsItem *item); + void setGraphicsScene(QGraphicsScene *scene); + + private slots: + void sceneCoordinatesChanged(const QPointF &coord); + void itemCoordinatesChanged(const QPointF &coord); + + private: + Ui::GraphicsSceneView *ui; +}; + +} + +#endif // GAMMARAY_GRAPHICSSCENEVIEW_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.ui gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.ui --- gammaray-1.2.2/plugins/sceneinspector/graphicssceneview.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/graphicssceneview.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,70 @@ + + + GammaRay::GraphicsSceneView + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + + + Scene Coordinates: + + + + + + + 0x0 + + + + + + + Item Coordinates: + + + + + + + 0x0 + + + + + + + + + false + + + QGraphicsView::ScrollHandDrag + + + + + + + + GammaRay::GraphicsView + QGraphicsView +
graphicsview.h
+
+
+ + +
diff -Nru gammaray-1.2.2/plugins/sceneinspector/graphicsview.cpp gammaray-2.0.1/plugins/sceneinspector/graphicsview.cpp --- gammaray-1.2.2/plugins/sceneinspector/graphicsview.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/graphicsview.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,95 @@ +/* + graphicsview.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "graphicsview.h" +#include "sceneinspectorinterface.h" + +#include +#include + +using namespace GammaRay; + +GraphicsView::GraphicsView(QWidget *parent) + : QGraphicsView(parent), + m_currentItem(0) +{ + setMouseTracking(true); +} + +void GraphicsView::showItem(QGraphicsItem *item) +{ + m_currentItem = item; + if (!item) + return; + + fitInView(item, Qt::KeepAspectRatio); + scale(0.8f, 0.8f); + emit transformChanged(); +} + +void GraphicsView::keyPressEvent(QKeyEvent *event) +{ + if (event->modifiers() == Qt::CTRL) { + switch (event->key()) { + case Qt::Key_Plus: + scale(1.2, 1.2); + emit transformChanged(); + event->accept(); + return; + case Qt::Key_Minus: + scale(0.8, 0.8); + emit transformChanged(); + event->accept(); + return; + case Qt::Key_Left: + rotate(-5); + emit transformChanged(); + event->accept(); + break; + case Qt::Key_Right: + rotate(5); + emit transformChanged(); + event->accept(); + break; + } + } + QGraphicsView::keyPressEvent(event); +} + +void GraphicsView::mouseMoveEvent(QMouseEvent *event) +{ + emit sceneCoordinatesChanged(mapToScene(event->pos())); + if (m_currentItem) { + emit itemCoordinatesChanged(m_currentItem->mapFromScene(mapToScene(event->pos()))); + } + QGraphicsView::mouseMoveEvent(event); +} + +void GraphicsView::drawForeground(QPainter *painter, const QRectF &rect) +{ + QGraphicsView::drawForeground(painter, rect); + if (m_currentItem) { + SceneInspectorInterface::paintItemDecoration(m_currentItem, transform(), painter); + } +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/graphicsview.h gammaray-2.0.1/plugins/sceneinspector/graphicsview.h --- gammaray-1.2.2/plugins/sceneinspector/graphicsview.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/graphicsview.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + graphicsview.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTOR_GRAPHICSVIEW_H +#define GAMMARAY_SCENEINSPECTOR_GRAPHICSVIEW_H + +#include + +namespace GammaRay { + +class GraphicsView : public QGraphicsView +{ + Q_OBJECT + public: + explicit GraphicsView(QWidget *parent = 0); + + void showItem(QGraphicsItem *item); + + signals: + void sceneCoordinatesChanged(const QPointF &sceneCoord); + void itemCoordinatesChanged(const QPointF &itemCoord); + void transformChanged(); + + protected: + void keyPressEvent(QKeyEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void drawForeground(QPainter *painter, const QRectF &rect); + + private: + QGraphicsItem *m_currentItem; +}; + +} + +#endif // GAMMARAY_GRAPHICSVIEW_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorclient.cpp gammaray-2.0.1/plugins/sceneinspector/sceneinspectorclient.cpp --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + sceneinspectorclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "sceneinspectorclient.h" + +#include + +#include + +using namespace GammaRay; + +SceneInspectorClient::SceneInspectorClient(QObject *parent) + : SceneInspectorInterface(parent) +{ + +} + +SceneInspectorClient::~SceneInspectorClient() +{ + +} + +void SceneInspectorClient::initializeGui() +{ + Endpoint::instance()->invokeObject(objectName(), "initializeGui"); +} + +void SceneInspectorClient::renderScene(const QTransform &transform, const QSize &size) +{ + Endpoint::instance()->invokeObject(objectName(), "renderScene", QVariantList() << transform << size); +} + +void SceneInspectorClient::sceneClicked(const QPointF &pos) +{ + Endpoint::instance()->invokeObject(objectName(), "sceneClicked", QVariantList() << pos); +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorclient.h gammaray-2.0.1/plugins/sceneinspector/sceneinspectorclient.h --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + sceneinspectorclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTORCLIENT_H +#define GAMMARAY_SCENEINSPECTORCLIENT_H + +#include "sceneinspectorinterface.h" + +namespace GammaRay { + +class SceneInspectorClient : public SceneInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::SceneInspectorInterface) + public: + explicit SceneInspectorClient(QObject *parent = 0); + virtual ~SceneInspectorClient(); + + virtual void initializeGui(); + virtual void renderScene(const QTransform &transform, const QSize &size); + virtual void sceneClicked(const QPointF &pos); +}; + +} + +#endif // GAMMARAY_SCENEINSPECTORCLIENT_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspector.cpp gammaray-2.0.1/plugins/sceneinspector/sceneinspector.cpp --- gammaray-1.2.2/plugins/sceneinspector/sceneinspector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,393 @@ +/* + sceneinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "sceneinspector.h" + +#include "scenemodel.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace GammaRay; +using namespace std; + +Q_DECLARE_METATYPE(QGraphicsEffect *) +Q_DECLARE_METATYPE(QGraphicsItemGroup *) +Q_DECLARE_METATYPE(QGraphicsObject *) +Q_DECLARE_METATYPE(QGraphicsWidget *) +Q_DECLARE_METATYPE(QGraphicsItem::CacheMode) +Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags) +Q_DECLARE_METATYPE(QGraphicsItem::PanelModality) +Q_DECLARE_METATYPE(QGraphicsPixmapItem::ShapeMode) + +SceneInspector::SceneInspector(ProbeInterface *probe, QObject *parent) + : SceneInspectorInterface(parent), + m_propertyController(new PropertyController("com.kdab.GammaRay.SceneInspector", this)), + m_clientConnected(false) +{ + Server::instance()->registerMonitorNotifier(Endpoint::instance()->objectAddress(objectName()), this, "clientConnectedChanged"); + + registerGraphicsViewMetaTypes(); + registerVariantHandlers(); + + connect(probe->probe(), SIGNAL(objectSelected(QObject*,QPoint)), + SLOT(objectSelected(QObject*,QPoint))); + + ObjectTypeFilterProxyModel *sceneFilterProxy = + new ObjectTypeFilterProxyModel(this); + sceneFilterProxy->setSourceModel(probe->objectListModel()); + SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); + singleColumnProxy->setSourceModel(sceneFilterProxy); + probe->registerModel("com.kdab.GammaRay.SceneList", singleColumnProxy); + + QItemSelectionModel* sceneSelection = ObjectBroker::selectionModel(singleColumnProxy); + connect(sceneSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(sceneSelected(QItemSelection))); + + m_sceneModel = new SceneModel(this); + probe->registerModel("com.kdab.GammaRay.SceneGraphModel", m_sceneModel); + m_itemSelectionModel = ObjectBroker::selectionModel(m_sceneModel); + connect(m_itemSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(sceneItemSelected(QItemSelection))); + + if (singleColumnProxy->rowCount()) { + sceneSelection->setCurrentIndex(singleColumnProxy->index(0, 0), QItemSelectionModel::ClearAndSelect); + } +} + +void SceneInspector::sceneSelected(const QItemSelection& selection) +{ + if (selection.isEmpty()) + return; + const QModelIndex index = selection.first().topLeft(); + + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + QGraphicsScene *scene = qobject_cast(obj); + + if (m_sceneModel->scene()) { + disconnect(m_sceneModel->scene(), 0, this, 0); + } + + m_sceneModel->setScene(scene); + connectToScene(); + // TODO remote support when a different graphics scene was selected +// ui->graphicsSceneView->setGraphicsScene(scene); +} + +void SceneInspector::connectToScene() +{ + QGraphicsScene *scene = m_sceneModel->scene(); + if (!scene || !m_clientConnected) { + return; + } + + connect(scene, SIGNAL(sceneRectChanged(QRectF)), + this, SIGNAL(sceneRectChanged(QRectF))); + connect(scene, SIGNAL(changed(QList)), + this, SIGNAL(sceneChanged())); + + initializeGui(); +} + +void SceneInspector::initializeGui() +{ + if (!Endpoint::isConnected()) { + // only do something if we are connected to a remote client + return; + } + + QGraphicsScene *scene = m_sceneModel->scene(); + if (!scene) { + return; + } + + emit sceneRectChanged(scene->sceneRect()); +} + +void SceneInspector::clientConnectedChanged(bool clientConnected) +{ + m_clientConnected = clientConnected; + connectToScene(); +} + +void SceneInspector::renderScene(const QTransform &transform, const QSize &size) +{ + if (!Endpoint::isConnected()) { + // only do something if we are connected to a remote client + return; + } + + QGraphicsScene *scene = m_sceneModel->scene(); + if (!scene) { + return; + } + + // initialize transparent pixmap + QPixmap view(size); + view.fill(Qt::transparent); + + // setup painter and apply transformation of client view + QPainter painter(&view); + painter.setWorldTransform(transform); + + // the area we want to paint has the size of the client's viewport _after_ applying + // the transformation. Thus first apply the inverse to yield the desired area afterwards + QRectF area(QPointF(0, 0), size); + area = transform.inverted().mapRect(area); + + scene->render(&painter, area, area, Qt::IgnoreAspectRatio); + + QGraphicsItem *currentItem = m_itemSelectionModel->currentIndex().data(SceneModel::SceneItemRole).value(); + if (currentItem) { + paintItemDecoration(currentItem, transform, &painter); + } + + emit sceneRendered(view); +} + +void SceneInspector::sceneItemSelected(const QItemSelection& selection) +{ + QModelIndex index; + if (!selection.isEmpty()) + index = selection.first().topLeft(); + + if (index.isValid()) { + QGraphicsItem *item = index.data(SceneModel::SceneItemRole).value(); + QGraphicsObject *obj = item->toGraphicsObject(); + if (obj) { + m_propertyController->setObject(obj); + } else { + m_propertyController->setObject(item, findBestType(item)); + } + emit itemSelected(item->mapRectToScene(item->boundingRect())); + } else { + m_propertyController->setObject(0); + emit sceneChanged(); + } +} + +void SceneInspector::objectSelected(QObject *object, const QPoint &pos) +{ + QWidget *widget = qobject_cast(object); + QGraphicsView *qgv = Util::findParentOfType(object); + if (qgv) { + // TODO: select qgv->scene() first, right now this only works for a single scene + QGraphicsItem *item = qgv->itemAt(widget ? widget->mapTo(qgv, pos) : pos); + if (item) { + sceneItemSelected(item); + } + } +} + +void SceneInspector::sceneItemSelected(QGraphicsItem *item) +{ + const QModelIndexList indexList = + m_sceneModel->match(m_sceneModel->index(0, 0), + SceneModel::SceneItemRole, + QVariant::fromValue(item), 1, + Qt::MatchExactly | Qt::MatchRecursive); + if (indexList.isEmpty()) { + return; + } + const QModelIndex index = indexList.first(); + m_itemSelectionModel->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); +} + +void SceneInspector::sceneClicked(const QPointF &pos) +{ + QGraphicsItem *item = m_sceneModel->scene()->itemAt(pos); + if (item) { + sceneItemSelected(item); + } +} + +#define QGV_CHECK_TYPE(Class) \ + if (dynamic_cast(item) && MetaObjectRepository::instance()->hasMetaObject(#Class)) \ + return QLatin1String(#Class) + +QString SceneInspector::findBestType(QGraphicsItem *item) +{ + // keep this in reverse topological order of the class hierarchy! + // QObject-based types are covered elsewhere, so we don't need those here + QGV_CHECK_TYPE(QGraphicsEllipseItem); + QGV_CHECK_TYPE(QGraphicsPathItem); + QGV_CHECK_TYPE(QGraphicsPolygonItem); + QGV_CHECK_TYPE(QGraphicsSimpleTextItem); + QGV_CHECK_TYPE(QGraphicsRectItem); + QGV_CHECK_TYPE(QAbstractGraphicsShapeItem); + QGV_CHECK_TYPE(QGraphicsLineItem); + QGV_CHECK_TYPE(QGraphicsItemGroup); + QGV_CHECK_TYPE(QGraphicsPixmapItem); + + return QLatin1String("QGraphicsItem"); +} + +void SceneInspector::registerGraphicsViewMetaTypes() +{ + MetaObject *mo = 0; + MO_ADD_METAOBJECT0(QGraphicsItem); + MO_ADD_PROPERTY (QGraphicsItem, bool, acceptDrops, setAcceptDrops); + MO_ADD_PROPERTY (QGraphicsItem, bool, acceptHoverEvents, setAcceptHoverEvents); + MO_ADD_PROPERTY (QGraphicsItem, bool, acceptTouchEvents, setAcceptTouchEvents); + MO_ADD_PROPERTY (QGraphicsItem, Qt::MouseButtons, acceptedMouseButtons, setAcceptedMouseButtons); + MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, boundingRect); + MO_ADD_PROPERTY (QGraphicsItem, qreal, boundingRegionGranularity, setBoundingRegionGranularity); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem::CacheMode, cacheMode); + MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, childrenBoundingRect); + MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, clipPath); + MO_ADD_PROPERTY_CR(QGraphicsItem, QCursor, cursor, setCursor); + MO_ADD_PROPERTY_RO(QGraphicsItem, qreal, effectiveOpacity); + MO_ADD_PROPERTY (QGraphicsItem, bool, filtersChildEvents, setFiltersChildEvents); + MO_ADD_PROPERTY (QGraphicsItem, QGraphicsItem::GraphicsItemFlags, flags, setFlags); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, focusItem); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, focusProxy); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsEffect*, graphicsEffect); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItemGroup*, group); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, hasCursor); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, hasFocus); + MO_ADD_PROPERTY (QGraphicsItem, Qt::InputMethodHints, inputMethodHints, setInputMethodHints); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isActive); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isClipped); + MO_ADD_PROPERTY (QGraphicsItem, bool, isEnabled, setEnabled); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isObscured); +#endif + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isPanel); + MO_ADD_PROPERTY (QGraphicsItem, bool, isSelected, setSelected); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isUnderMouse); + MO_ADD_PROPERTY (QGraphicsItem, bool, isVisible, setVisible); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isWidget); + MO_ADD_PROPERTY_RO(QGraphicsItem, bool, isWindow); + MO_ADD_PROPERTY (QGraphicsItem, qreal, opacity, setOpacity); + MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, opaqueArea); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, panel); + MO_ADD_PROPERTY (QGraphicsItem, QGraphicsItem::PanelModality, panelModality, setPanelModality); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, parentItem); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsObject*, parentObject); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, parentWidget); + MO_ADD_PROPERTY_CR(QGraphicsItem, QPointF, pos, setPos); + MO_ADD_PROPERTY (QGraphicsItem, qreal, rotation, setRotation); + MO_ADD_PROPERTY (QGraphicsItem, qreal, scale, setScale); + MO_ADD_PROPERTY_RO(QGraphicsItem, QRectF, sceneBoundingRect); + MO_ADD_PROPERTY_RO(QGraphicsItem, QPointF, scenePos); + MO_ADD_PROPERTY_RO(QGraphicsItem, QTransform, sceneTransform); + MO_ADD_PROPERTY_RO(QGraphicsItem, QPainterPath, shape); + MO_ADD_PROPERTY_CR(QGraphicsItem, QString, toolTip, setToolTip); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsItem*, topLevelItem); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, topLevelWidget); + MO_ADD_PROPERTY_RO(QGraphicsItem, QTransform, transform/*, setTransform*/); // TODO: support setTransform + MO_ADD_PROPERTY_CR(QGraphicsItem, QPointF, transformOriginPoint, setTransformOriginPoint); + MO_ADD_PROPERTY_RO(QGraphicsItem, int, type); + MO_ADD_PROPERTY_RO(QGraphicsItem, QGraphicsWidget*, window); + MO_ADD_PROPERTY (QGraphicsItem, qreal, x, setX); + MO_ADD_PROPERTY (QGraphicsItem, qreal, y, setY); + MO_ADD_PROPERTY (QGraphicsItem, qreal, zValue, setZValue); + + MO_ADD_METAOBJECT1(QAbstractGraphicsShapeItem, QGraphicsItem); + MO_ADD_PROPERTY_CR(QAbstractGraphicsShapeItem, QBrush, brush, setBrush); + MO_ADD_PROPERTY_CR(QAbstractGraphicsShapeItem, QPen, pen, setPen); + + MO_ADD_METAOBJECT1(QGraphicsEllipseItem, QAbstractGraphicsShapeItem); + MO_ADD_PROPERTY_CR(QGraphicsEllipseItem, QRectF, rect, setRect); + MO_ADD_PROPERTY (QGraphicsEllipseItem, int, spanAngle, setSpanAngle); + MO_ADD_PROPERTY (QGraphicsEllipseItem, int, startAngle, setStartAngle); + + MO_ADD_METAOBJECT1(QGraphicsPathItem, QAbstractGraphicsShapeItem); + MO_ADD_PROPERTY_CR(QGraphicsPathItem, QPainterPath, path, setPath); + + MO_ADD_METAOBJECT1(QGraphicsPolygonItem, QAbstractGraphicsShapeItem); + MO_ADD_PROPERTY (QGraphicsPolygonItem, Qt::FillRule, fillRule, setFillRule); + MO_ADD_PROPERTY_CR(QGraphicsPolygonItem, QPolygonF, polygon, setPolygon); + + MO_ADD_METAOBJECT1(QGraphicsSimpleTextItem, QAbstractGraphicsShapeItem); + MO_ADD_PROPERTY_CR(QGraphicsSimpleTextItem, QFont, font, setFont); + MO_ADD_PROPERTY_CR(QGraphicsSimpleTextItem, QString, text, setText); + + MO_ADD_METAOBJECT1(QGraphicsRectItem, QAbstractGraphicsShapeItem); + MO_ADD_PROPERTY_CR(QGraphicsRectItem, QRectF, rect, setRect); + + MO_ADD_METAOBJECT1(QGraphicsLineItem, QGraphicsItem); + MO_ADD_PROPERTY_CR(QGraphicsLineItem, QLineF, line, setLine); + MO_ADD_PROPERTY_CR(QGraphicsLineItem, QPen, pen, setPen); + + MO_ADD_METAOBJECT1(QGraphicsPixmapItem, QGraphicsItem); + MO_ADD_PROPERTY_CR(QGraphicsPixmapItem, QPointF, offset, setOffset); + MO_ADD_PROPERTY_CR(QGraphicsPixmapItem, QPixmap, pixmap, setPixmap); + MO_ADD_PROPERTY (QGraphicsPixmapItem, QGraphicsPixmapItem::ShapeMode, shapeMode, setShapeMode); + MO_ADD_PROPERTY (QGraphicsPixmapItem, Qt::TransformationMode, transformationMode, setTransformationMode); + + // no extra properties, but we need the inheritance connection for anything above to work + MO_ADD_METAOBJECT2(QGraphicsObject, QGraphicsItem, QObject); + + MO_ADD_METAOBJECT0(QGraphicsLayoutItem); + MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, QRectF, contentsRect); + MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, bool, isLayout); + MO_ADD_PROPERTY_RO(QGraphicsLayoutItem, bool, ownedByLayout); + + MO_ADD_METAOBJECT2(QGraphicsWidget, QGraphicsObject, QGraphicsLayoutItem); + MO_ADD_PROPERTY_RO(QGraphicsWidget, QRectF, windowFrameGeometry); + MO_ADD_PROPERTY_RO(QGraphicsWidget, QRectF, windowFrameRect); + + MO_ADD_METAOBJECT1(QGraphicsProxyWidget, QGraphicsWidget); + MO_ADD_PROPERTY_RO(QGraphicsProxyWidget, QWidget*, widget); +} + +void SceneInspector::registerVariantHandlers() +{ + VariantHandler::registerStringConverter(Util::addressToString); + VariantHandler::registerStringConverter(Util::addressToString); + +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) + VariantHandler::registerStringConverter(Util::displayString); + VariantHandler::registerStringConverter(Util::displayString); + VariantHandler::registerStringConverter(Util::displayString); +#endif +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(SceneInspectorFactory) +#endif diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspector.h gammaray-2.0.1/plugins/sceneinspector/sceneinspector.h --- gammaray-1.2.2/plugins/sceneinspector/sceneinspector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,94 @@ +/* + sceneinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTOR_SCENEINSPECTOR_H +#define GAMMARAY_SCENEINSPECTOR_SCENEINSPECTOR_H + +#include +#include "sceneinspectorwidget.h" +#include "sceneinspectorinterface.h" + +#include + +class QItemSelectionModel; +class QItemSelection; +class QModelIndex; + +namespace GammaRay { + +class PropertyController; +class SceneModel; + +class SceneInspector : public SceneInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::SceneInspectorInterface) + public: + explicit SceneInspector(ProbeInterface *probe, QObject *parent = 0); + + private slots: + virtual void initializeGui(); + virtual void renderScene(const QTransform &transform, const QSize &size); + + void sceneSelected(const QItemSelection &selection); + void sceneItemSelected(const QItemSelection &selection); + void sceneItemSelected(QGraphicsItem *item); + void objectSelected(QObject *object, const QPoint &pos); + void sceneClicked(const QPointF &pos); + + void clientConnectedChanged(bool clientConnected); + + private: + QString findBestType(QGraphicsItem *item); + void registerGraphicsViewMetaTypes(); + void registerVariantHandlers(); + void connectToScene(); + + private: + SceneModel *m_sceneModel; + QItemSelectionModel* m_itemSelectionModel; + PropertyController *m_propertyController; + bool m_clientConnected; +}; + +class SceneInspectorFactory : public QObject, + public StandardToolFactory2 +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.SceneInspector") + public: + explicit SceneInspectorFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("Graphics Scenes"); + } +}; + +} + +#endif // GAMMARAY_SCENEINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorinterface.cpp gammaray-2.0.1/plugins/sceneinspector/sceneinspectorinterface.cpp --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + sceneinspectorinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "sceneinspectorinterface.h" + +#include + +#include +#include + +using namespace GammaRay; + +SceneInspectorInterface::SceneInspectorInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +SceneInspectorInterface::~SceneInspectorInterface() +{ + +} + +void SceneInspectorInterface::paintItemDecoration(QGraphicsItem *item, const QTransform &transform, QPainter *painter) +{ + const QRectF itemBoundingRect = item->boundingRect(); + // coord system, TODO: nicer axis with arrows, tics, markers for current mouse position etc. + painter->setPen(Qt::black); + const qreal maxX = qMax(qAbs(itemBoundingRect.left()), qAbs(itemBoundingRect.right())); + const qreal maxY = qMax(qAbs(itemBoundingRect.top()), qAbs(itemBoundingRect.bottom())); + const qreal maxXY = qMax(maxX, maxY) * 1.5f; + painter->drawLine(item->mapToScene(-maxXY, 0), item->mapToScene(maxXY, 0)); + painter->drawLine(item->mapToScene(0, -maxXY), item->mapToScene(0, maxXY)); + + painter->setPen(Qt::blue); + const QPolygonF boundingBox = item->mapToScene(itemBoundingRect); + painter->drawPolygon(boundingBox); + + painter->setPen(Qt::green); + const QPainterPath shape = item->mapToScene(item->shape()); + painter->drawPath(shape); + + painter->setPen(Qt::red); + const QPointF transformOrigin = + item->mapToScene(item->transformOriginPoint()); + painter->drawEllipse(transformOrigin, + 5.0 / transform.m11(), + 5.0 / transform.m22()); +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorinterface.h gammaray-2.0.1/plugins/sceneinspector/sceneinspectorinterface.h --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,65 @@ +/* + sceneinspectorinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTORINTERFACE_H +#define GAMMARAY_SCENEINSPECTORINTERFACE_H + +#include + +class QPainter; +class QGraphicsItem; +class QSize; +class QTransform; +class QRectF; +class QPixmap; +class QPointF; + +namespace GammaRay { + +class SceneInspectorInterface : public QObject +{ + Q_OBJECT + public: + explicit SceneInspectorInterface(QObject *parent = 0); + virtual ~SceneInspectorInterface(); + + virtual void initializeGui() = 0; + + static void paintItemDecoration(QGraphicsItem *item, const QTransform &transform, QPainter *painter); + + public slots: + virtual void renderScene(const QTransform &transform, const QSize &size) = 0; + virtual void sceneClicked(const QPointF &pos) = 0; + + signals: + void sceneRectChanged(const QRectF &rect); + void sceneChanged(); + void sceneRendered(const QPixmap &view); + void itemSelected(const QRectF &boundingRect); +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::SceneInspectorInterface, "com.kdab.GammaRay.SceneInspector") + +#endif // GAMMARAY_SCENEINSPECTORINTERFACE_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.cpp gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.cpp --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,218 @@ +/* + sceneinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "sceneinspectorwidget.h" + +#include "scenemodel.h" +#include "sceneinspectorclient.h" +#include "graphicsview.h" +#include "ui_sceneinspectorwidget.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace GammaRay; +using namespace std; + +static QObject* createClientSceneInspector(const QString &/*name*/, QObject *parent) +{ + return new SceneInspectorClient(parent); +} + +SceneInspectorWidget::SceneInspectorWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::SceneInspectorWidget) + , m_interface(0) + , m_scene(new QGraphicsScene(this)) + , m_pixmap(new QGraphicsPixmapItem) + , m_updateTimer(new QTimer(this)) +{ + ObjectBroker::registerClientObjectFactoryCallback(createClientSceneInspector); + m_interface = ObjectBroker::object(); + + ui->setupUi(this); + ui->scenePropertyWidget->setObjectBaseName("com.kdab.GammaRay.SceneInspector"); + + ui->sceneComboBox->setModel(ObjectBroker::model("com.kdab.GammaRay.SceneList")); + connect(ui->sceneComboBox, SIGNAL(currentIndexChanged(int)), SLOT(sceneSelected(int))); + + QSortFilterProxyModel *sceneFilter = new KRecursiveFilterProxyModel(this); + sceneFilter->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.SceneGraphModel")); + ui->sceneTreeView->setModel(sceneFilter); + ui->screneTreeSearchLine->setProxy(sceneFilter); + + QItemSelectionModel *itemSelection = ObjectBroker::selectionModel(sceneFilter); + ui->sceneTreeView->setSelectionModel(itemSelection); + connect(itemSelection, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(sceneItemSelected(QItemSelection))); + + ui->graphicsSceneView->setGraphicsScene(m_scene); + connect(m_interface, SIGNAL(sceneRectChanged(QRectF)), + this, SLOT(sceneRectChanged(QRectF))); + connect(m_interface, SIGNAL(sceneChanged()), + this, SLOT(sceneChanged())); + connect(m_interface, SIGNAL(sceneRendered(QPixmap)), + this, SLOT(sceneRendered(QPixmap))); + connect(m_interface, SIGNAL(itemSelected(QRectF)), + this, SLOT(itemSelected(QRectF))); + + m_interface->initializeGui(); + + m_pixmap->setFlag(QGraphicsItem::ItemIgnoresTransformations); + m_scene->addItem(m_pixmap); + connect(ui->graphicsSceneView->view(), SIGNAL(transformChanged()), + this, SLOT(visibleSceneRectChanged())); + connect(ui->graphicsSceneView->view()->horizontalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(visibleSceneRectChanged())); + connect(ui->graphicsSceneView->view()->verticalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(visibleSceneRectChanged())); + + if (Endpoint::instance()->isRemoteClient()) { + ui->graphicsSceneView->view()->viewport()->installEventFilter(this); + } + + QItemSelectionModel *selection = ObjectBroker::selectionModel(ui->sceneComboBox->model()); + if (selection->currentIndex().isValid()) { + sceneSelected(selection->currentIndex().row()); + } + + // limit fps to prevent bad performance, and to group update requests which is esp. required + // for scrolling and similar high-frequency update requests + m_updateTimer->setSingleShot(true); + m_updateTimer->setInterval(100); + connect(m_updateTimer, SIGNAL(timeout()), SLOT(requestSceneUpdate())); +} + +SceneInspectorWidget::~SceneInspectorWidget() +{ +} + +bool SceneInspectorWidget::eventFilter(QObject *obj, QEvent *event) +{ + Q_ASSERT(obj == ui->graphicsSceneView->view()->viewport()); + if (event->type() == QEvent::Resize) { + QMetaObject::invokeMethod(this, "visibleSceneRectChanged", Qt::QueuedConnection); + } else if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *e = static_cast(event); + if (e->button() == Qt::LeftButton && + e->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) + { + m_interface->sceneClicked(ui->graphicsSceneView->view()->mapToScene(e->pos())); + } + } + return QObject::eventFilter(obj, event); +} + +void SceneInspectorWidget::itemSelected(const QRectF &boundingRect) +{ + ui->graphicsSceneView->view()->fitInView(boundingRect, Qt::KeepAspectRatio); + ui->graphicsSceneView->view()->scale(0.8, 0.8); + visibleSceneRectChanged(); +} + +void SceneInspectorWidget::sceneRectChanged(const QRectF &rect) +{ + m_scene->setSceneRect(rect); + visibleSceneRectChanged(); +} + +void SceneInspectorWidget::sceneChanged() +{ + if (!m_updateTimer->isActive()) { + m_updateTimer->start(); + } +} + +void SceneInspectorWidget::requestSceneUpdate() +{ + if (!Endpoint::instance()->isRemoteClient()) { + return; + } + + if (ui->graphicsSceneView->view()->rect().isEmpty()) { + // when the splitter is moved to hide the view, don't request updates + return; + } + + m_interface->renderScene(ui->graphicsSceneView->view()->viewportTransform(), + ui->graphicsSceneView->view()->viewport()->rect().size()); +} + +void SceneInspectorWidget::sceneRendered(const QPixmap &view) +{ + m_pixmap->setPixmap(view); +} + +void SceneInspectorWidget::visibleSceneRectChanged() +{ + m_pixmap->setPos(ui->graphicsSceneView->view()->mapToScene(0, 0)); + sceneChanged(); +} + +void SceneInspectorWidget::sceneSelected(int index) +{ + const QModelIndex mi = ui->sceneComboBox->model()->index(index, 0); + ObjectBroker::selectionModel(ui->sceneComboBox->model())->select(mi, QItemSelectionModel::ClearAndSelect); + + if (!Endpoint::instance()->isRemoteClient()) { + // for in-process mode, use the user scene directly. This is much more performant and we can + // skip the pixmap conversions and fps limitations thereof. + QObject *obj = ui->sceneComboBox->itemData(index, ObjectModel::ObjectRole).value(); + QGraphicsScene *scene = qobject_cast(obj); + cout << Q_FUNC_INFO << ' ' << scene << ' ' << obj << endl; + + if (scene) { + ui->graphicsSceneView->setGraphicsScene(scene); + } + } +} + +void SceneInspectorWidget::sceneItemSelected(const QItemSelection &selection) +{ + if (Endpoint::instance()->isRemoteClient()) { + return; + } + + QModelIndex index; + if (!selection.isEmpty()) + index = selection.first().topLeft(); + + if (index.isValid()) { + QGraphicsItem *item = index.data(SceneModel::SceneItemRole).value(); + ui->graphicsSceneView->showGraphicsItem(item); + ui->sceneTreeView->scrollTo(index); // in case selection does not come from us + } +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.h gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.h --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,71 @@ +/* + sceneinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTOR_SCENEINSPECTORWIDGET_H +#define GAMMARAY_SCENEINSPECTOR_SCENEINSPECTORWIDGET_H + +#include + +class QGraphicsPixmapItem; +class QGraphicsScene; +class QItemSelection; + +namespace GammaRay { + +class SceneInspectorInterface; + +namespace Ui { + class SceneInspectorWidget; +} + +class SceneInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit SceneInspectorWidget(QWidget *parent = 0); + ~SceneInspectorWidget(); + + private slots: + void sceneSelected(int index); + void sceneItemSelected(const QItemSelection &selection); + void sceneRectChanged(const QRectF &rect); + void sceneChanged(); + void requestSceneUpdate(); + void sceneRendered(const QPixmap &view); + void visibleSceneRectChanged(); + void itemSelected(const QRectF &boundingRect); + + private: + virtual bool eventFilter(QObject *obj, QEvent *event); + + QScopedPointer ui; + SceneInspectorInterface *m_interface; + QGraphicsScene *m_scene; + QGraphicsPixmapItem *m_pixmap; + QTimer *m_updateTimer; +}; + +} + +#endif // GAMMARAY_SCENEINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.ui gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.ui --- gammaray-1.2.2/plugins/sceneinspector/sceneinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/sceneinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ + + + GammaRay::SceneInspectorWidget + + + + 0 + 0 + 400 + 300 + + + + + + + + + + Qt::Horizontal + + + + Qt::Vertical + + + + + + + + + + true + + + + + + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+ + GammaRay::PropertyWidget + QWidget +
ui/propertywidget.h
+ 1 +
+ + GammaRay::GraphicsSceneView + QWidget +
graphicssceneview.h
+ 1 +
+
+
diff -Nru gammaray-1.2.2/plugins/sceneinspector/scenemodel.cpp gammaray-2.0.1/plugins/sceneinspector/scenemodel.cpp --- gammaray-1.2.2/plugins/sceneinspector/scenemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/scenemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,195 @@ +/* + scenemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "scenemodel.h" + +#include +#include +#include +#include + +using namespace GammaRay; + +#define QGV_ITEMTYPE(Type) \ +{ \ + Type t; \ + m_typeNames.insert(t.type(), QLatin1String(#Type)); \ +} + +SceneModel::SceneModel(QObject *parent) + : QAbstractItemModel(parent), + m_scene(0) +{ + QGV_ITEMTYPE(QGraphicsLineItem) + QGV_ITEMTYPE(QGraphicsPixmapItem) + QGV_ITEMTYPE(QGraphicsRectItem) + QGV_ITEMTYPE(QGraphicsEllipseItem) + QGV_ITEMTYPE(QGraphicsPathItem) + QGV_ITEMTYPE(QGraphicsPolygonItem) + QGV_ITEMTYPE(QGraphicsSimpleTextItem) + QGV_ITEMTYPE(QGraphicsItemGroup) +} + +void SceneModel::setScene(QGraphicsScene *scene) +{ + beginResetModel(); + m_scene = scene; + endResetModel(); +} + +QGraphicsScene *SceneModel::scene() const +{ + return m_scene; +} + +QVariant SceneModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + QGraphicsItem *item = static_cast(index.internalPointer()); + + if (item && role == Qt::DisplayRole) { + QGraphicsObject *obj = item->toGraphicsObject(); + if (index.column() == 0) { + if (obj && !obj->objectName().isEmpty()) { + return obj->objectName(); + } + return + QString::fromLatin1("0x%1"). + arg(QString::number(reinterpret_cast(item), 16)); + } else if (index.column() == 1) { + if (obj) { + return obj->metaObject()->className(); + } + return typeName(item->type()); + } + } else if (role == SceneItemRole) { + return QVariant::fromValue(item); + } else if (item && role == Qt::ForegroundRole) { + if (!item->isVisible()) { + return qApp->palette().color(QPalette::Disabled, QPalette::Text); + } + } + return QVariant(); +} + +int SceneModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 2; +} + +int SceneModel::rowCount(const QModelIndex &parent) const +{ + if (!m_scene) { + return 0; + } + if (parent.isValid()) { + if (parent.column() != 0) { + return 0; + } + QGraphicsItem* item = static_cast(parent.internalPointer()); + if (item) { + return item->childItems().size(); + } else { + return 0; + } + } + return topLevelItems().size(); +} + +QModelIndex SceneModel::parent(const QModelIndex &child) const +{ + if (!child.isValid()) { + return QModelIndex(); + } + QGraphicsItem *item = static_cast(child.internalPointer()); + if (!item->parentItem()) { + return QModelIndex(); + } + int row = 0; + if (item->parentItem()->parentItem()) { + row = item->parentItem()->parentItem()->childItems().indexOf(item->parentItem()); + } + return createIndex(row, 0, item->parentItem()); +} + +QModelIndex SceneModel::index(int row, int column, const QModelIndex &parent) const +{ + if (column < 0 || column >= columnCount()) { + return QModelIndex(); + } + if (!parent.isValid() && row >= 0 && row < topLevelItems().size()) { + return createIndex(row, column, topLevelItems().at(row)); + } + QGraphicsItem *parentItem = static_cast(parent.internalPointer()); + if (!parentItem || row < 0 || row >= parentItem->childItems().size()) { + return QModelIndex(); + } + return createIndex(row, column, parentItem->childItems().at(row)); +} + +QList SceneModel::topLevelItems() const +{ + QList topLevel; + if (!m_scene) { + return topLevel; + } + Q_FOREACH (QGraphicsItem *item, m_scene->items()) { + if (!item->parentItem()) { + topLevel.push_back(item); + } + } + return topLevel; +} + +QVariant SceneModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return tr("Item"); + case 1: + return tr("Type"); + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +QString SceneModel::typeName(int itemType) const +{ + const QHash::const_iterator it = m_typeNames.find(itemType); + if (it != m_typeNames.end()) { + return it.value(); + } + if (itemType == QGraphicsItem::UserType) { + return QLatin1String("UserType"); + } + if (itemType > QGraphicsItem::UserType) { + return + QString::fromLatin1("UserType + %1"). + arg(itemType - static_cast(QGraphicsItem::UserType)); + } + return QString::number(itemType); +} diff -Nru gammaray-1.2.2/plugins/sceneinspector/scenemodel.h gammaray-2.0.1/plugins/sceneinspector/scenemodel.h --- gammaray-1.2.2/plugins/sceneinspector/scenemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/sceneinspector/scenemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + scenemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCENEINSPECTOR_SCENEMODEL_H +#define GAMMARAY_SCENEINSPECTOR_SCENEMODEL_H + +#include +#include + +class QGraphicsScene; +class QGraphicsItem; + +namespace GammaRay { + +class SceneModel : public QAbstractItemModel +{ + Q_OBJECT + public: + enum Role { + SceneItemRole = UserRole + 1 + }; + explicit SceneModel(QObject *parent = 0); + void setScene(QGraphicsScene *scene); + QGraphicsScene *scene() const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &child) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + private: + QList topLevelItems() const; + /// Returns a string type name for the given QGV item type id + QString typeName(int itemType) const; + + QGraphicsScene *m_scene; + QHash m_typeNames; +}; + +} + +#endif // GAMMARAY_SCENEMODEL_H diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/CMakeLists.txt gammaray-2.0.1/plugins/scriptenginedebugger/CMakeLists.txt --- gammaray-1.2.2/plugins/scriptenginedebugger/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,14 +1,9 @@ -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} -) - set(gammaray_scriptenginedebugger_plugin_srcs scriptenginedebugger.cpp + scriptenginedebuggerwidget.cpp ) -qt4_automoc(${gammaray_scriptenginedebugger_plugin_srcs}) - -qt4_wrap_ui(gammaray_scriptenginedebugger_plugin_srcs scriptenginedebugger.ui) +qt4_wrap_ui(gammaray_scriptenginedebugger_plugin_srcs scriptenginedebuggerwidget.ui) gammaray_add_plugin(gammaray_scriptenginedebugger_plugin gammaray_scriptenginedebugger.desktop @@ -20,5 +15,5 @@ ${QT_QTGUI_LIBRARIES} ${QT_QTSCRIPT_LIBRARIES} ${QT_QTSCRIPTTOOLS_LIBRARIES} - gammaray_probe + gammaray_core ) diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/gammaray_scriptenginedebugger.desktop gammaray-2.0.1/plugins/scriptenginedebugger/gammaray_scriptenginedebugger.desktop --- gammaray-1.2.2/plugins/scriptenginedebugger/gammaray_scriptenginedebugger.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/gammaray_scriptenginedebugger.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,6 @@ [Desktop Entry] Name=Script Engines X-GammaRay-Types=QScriptEngine; +X-GammaRay-ServiceTypes="com.kdab.GammaRay.ToolFactory;com.kdab.GammaRay.ToolUiFactory" Exec=gammaray_scriptenginedebugger_plugin +X-GammaRay-Remote=false diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.cpp gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.cpp --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,16 +22,13 @@ */ #include "scriptenginedebugger.h" -#include "ui_scriptenginedebugger.h" -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" -#include "include/singlecolumnobjectproxymodel.h" +#include +#include +#include #include -#include #include -#include #include using namespace GammaRay; @@ -41,46 +38,23 @@ /// Also it seems that we get another crash when the interrupt action /// was triggered and we close the mainwindow. -ScriptEngineDebugger::ScriptEngineDebugger(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), ui(new Ui::ScriptEngineDebugger), debugger(new QScriptEngineDebugger(this)) +ScriptEngineDebugger::ScriptEngineDebugger(ProbeInterface *probe, QObject *parent) + : QObject(parent) { - ui->setupUi(this); - ObjectTypeFilterProxyModel *scriptEngineFilter = new ObjectTypeFilterProxyModel(this); scriptEngineFilter->setSourceModel(probe->objectListModel()); SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); singleColumnProxy->setSourceModel(scriptEngineFilter); - ui->scriptEngineComboBox->setModel(singleColumnProxy); - connect(ui->scriptEngineComboBox, SIGNAL(activated(int)), SLOT(scriptEngineSelected(int))); - - ui->verticalLayout_10->addWidget(debugger->standardWindow()); - if (ui->scriptEngineComboBox->count()) { - scriptEngineSelected(0); - } + probe->registerModel("com.kdab.GammaRay.ScriptEngines", singleColumnProxy); } ScriptEngineDebugger::~ScriptEngineDebugger() { - debugger->detach(); -} - -void ScriptEngineDebugger::scriptEngineSelected(int index) -{ - QObject *obj = - ui->scriptEngineComboBox->itemData(index, ObjectModel::ObjectRole).value(); - QScriptEngine *engine = qobject_cast(obj); - if (engine) { - debugger->attachTo(engine); -// FIXME: if we'd do that, we'd get crashes on shutdown. -// debugger->action(QScriptEngineDebugger::InterruptAction)->trigger(); - } } #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) Q_EXPORT_PLUGIN(ScriptEngineDebuggerFactory) #endif - -#include "scriptenginedebugger.moc" diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.h gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.h --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,43 +24,37 @@ #ifndef GAMMARAY_SCRIPTENGINEDEBUGGER_SCRIPTENGINEDEBUGGER_H #define GAMMARAY_SCRIPTENGINEDEBUGGER_SCRIPTENGINEDEBUGGER_H -#include "include/toolfactory.h" +#include "scriptenginedebuggerwidget.h" +#include -#include #include -class QScriptEngineDebugger; - namespace GammaRay { -namespace Ui { - class ScriptEngineDebugger; -} - -class ScriptEngineDebugger : public QWidget +class ScriptEngineDebugger : public QObject { Q_OBJECT public: - explicit ScriptEngineDebugger(ProbeInterface *probe, QWidget *parent = 0); + explicit ScriptEngineDebugger(ProbeInterface *probe, QObject *parent = 0); virtual ~ScriptEngineDebugger(); - private slots: - void scriptEngineSelected(int index); - - private: - QScopedPointer ui; - QScriptEngineDebugger *debugger; }; class ScriptEngineDebuggerFactory - : public QObject, public StandardToolFactory + : public QObject, public StandardToolFactory2 { Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) + Q_INTERFACES(GammaRay::ToolFactory GammaRay::ToolUiFactory) Q_PLUGIN_METADATA(IID "org.qt-project.Qt.ScriptEngineDebugger") public: - explicit ScriptEngineDebuggerFactory(QObject *parent = 0) : QObject(parent) {} - inline QString name() const { return tr("Script Engines"); } + explicit ScriptEngineDebuggerFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("Script Engines"); + } }; } diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.ui gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.ui --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebugger.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebugger.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - GammaRay::ScriptEngineDebugger - - - - 0 - 0 - 400 - 300 - - - - - - - - - - - diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.cpp gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.cpp --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,72 @@ +/* + scriptenginedebuggerwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "scriptenginedebuggerwidget.h" +#include "ui_scriptenginedebuggerwidget.h" + +#include +#include + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +///NOTE: for crashes related to script engine debugger on shutdown, see: +/// https://bugreports.qt.nokia.com/browse/QTBUG-21548 +/// Also it seems that we get another crash when the interrupt action +/// was triggered and we close the mainwindow. + +ScriptEngineDebuggerWidget::ScriptEngineDebuggerWidget(QWidget *parent) + : QWidget(parent), ui(new Ui::ScriptEngineDebuggerWidget), debugger(new QScriptEngineDebugger(this)) +{ + ui->setupUi(this); + ui->scriptEngineComboBox->setModel(ObjectBroker::model("com.kdab.GammaRay.ScriptEngines")); + connect(ui->scriptEngineComboBox, SIGNAL(activated(int)), SLOT(scriptEngineSelected(int))); + + ui->verticalLayout_10->addWidget(debugger->standardWindow()); + + if (ui->scriptEngineComboBox->count()) { + scriptEngineSelected(0); + } +} + +ScriptEngineDebuggerWidget::~ScriptEngineDebuggerWidget() +{ + debugger->detach(); +} + +void ScriptEngineDebuggerWidget::scriptEngineSelected(int index) +{ + QObject *obj = + ui->scriptEngineComboBox->itemData(index, ObjectModel::ObjectRole).value(); + QScriptEngine *engine = qobject_cast(obj); + if (engine) { + debugger->attachTo(engine); +// FIXME: if we'd do that, we'd get crashes on shutdown. +// debugger->action(QScriptEngineDebugger::InterruptAction)->trigger(); + } +} diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.h gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.h --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + scriptenginedebuggerwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SCRIPTENGINEDEBUGGER_SCRIPTENGINEDEBUGGERWIDGET_H +#define GAMMARAY_SCRIPTENGINEDEBUGGER_SCRIPTENGINEDEBUGGERWIDGET_H + +#include +#include + +class QScriptEngineDebugger; + +namespace GammaRay { + +namespace Ui { + class ScriptEngineDebuggerWidget; +} + +class ScriptEngineDebuggerWidget : public QWidget +{ + Q_OBJECT + public: + explicit ScriptEngineDebuggerWidget(QWidget *parent = 0); + virtual ~ScriptEngineDebuggerWidget(); + private slots: + void scriptEngineSelected(int index); + + private: + QScopedPointer ui; + QScriptEngineDebugger *debugger; +}; + +} + +#endif // GAMMARAY_SCRIPTENGINEDEBUGGER_H diff -Nru gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.ui gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.ui --- gammaray-1.2.2/plugins/scriptenginedebugger/scriptenginedebuggerwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/scriptenginedebugger/scriptenginedebuggerwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,21 @@ + + + GammaRay::ScriptEngineDebuggerWidget + + + + 0 + 0 + 400 + 300 + + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/CMakeLists.txt gammaray-2.0.1/plugins/selectionmodelinspector/CMakeLists.txt --- gammaray-1.2.2/plugins/selectionmodelinspector/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ +# probe part +set(gammaray_selectionmodelinspector_plugin_srcs + selectionmodelinspector.cpp +) + +gammaray_add_plugin(gammaray_selectionmodelinspector_plugin + gammaray_selectionmodelinspector.desktop + ${gammaray_selectionmodelinspector_plugin_srcs} +) + +target_link_libraries(gammaray_selectionmodelinspector_plugin + ${QT_QTCORE_LIBRARIES} + gammaray_core +) + +# ui part +if((Qt5Widgets_FOUND OR QT_QTGUI_FOUND) AND NOT GAMMARAY_PROBE_ONLY_BUILD) + + set(gammaray_selectionmodelinspector_plugin_ui_srcs + selectionmodelinspectorwidget.cpp + ) + + qt4_wrap_ui(gammaray_selectionmodelinspector_plugin_ui_srcs + selectionmodelinspectorwidget.ui + ) + + gammaray_add_plugin(gammaray_selectionmodelinspector_ui_plugin + gammaray_selectionmodelinspector_ui.desktop + ${gammaray_selectionmodelinspector_plugin_ui_srcs} + ) + + target_link_libraries(gammaray_selectionmodelinspector_ui_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common + ) + +endif() diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/gammaray_selectionmodelinspector.desktop gammaray-2.0.1/plugins/selectionmodelinspector/gammaray_selectionmodelinspector.desktop --- gammaray-1.2.2/plugins/selectionmodelinspector/gammaray_selectionmodelinspector.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/gammaray_selectionmodelinspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Selection Models +X-GammaRay-Types=QItemSelectionModel; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory +Exec=gammaray_selectionmodelinspector_plugin diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/gammaray_selectionmodelinspector_ui.desktop gammaray-2.0.1/plugins/selectionmodelinspector/gammaray_selectionmodelinspector_ui.desktop --- gammaray-1.2.2/plugins/selectionmodelinspector/gammaray_selectionmodelinspector_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/gammaray_selectionmodelinspector_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_selectionmodelinspector +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_selectionmodelinspector_ui_plugin diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspector.cpp gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspector.cpp --- gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,71 @@ +/* + selectionmodelinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "selectionmodelinspector.h" + +#include +#include + +#include + +#include + +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) +#include +typedef QSortFilterProxyModel QIdentityProxyModel; +#else +#include +#endif + +using namespace GammaRay; + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(SelectionModelInspectorFactory) +#endif + +SelectionModelInspector::SelectionModelInspector(ProbeInterface *probe, QObject *parent) + : QObject(parent) + , m_current(new QIdentityProxyModel(this)) +{ + ObjectTypeFilterProxyModel *selectionModelProxy = + new ObjectTypeFilterProxyModel(this); + selectionModelProxy->setSourceModel(probe->objectListModel()); + probe->registerModel("com.kdab.GammaRay.SelectionModelsModel", selectionModelProxy); + + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(selectionModelProxy); + connect(selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), + SLOT(currentChanged(QModelIndex))); + + probe->registerModel("com.kdab.GammaRay.CurrentSelectionModel", m_current); +} + +void SelectionModelInspector::currentChanged(const QModelIndex ¤t) +{ + QObject *selectionModelObject = current.data(ObjectModel::ObjectRole).value(); + QItemSelectionModel *selectionModel = qobject_cast(selectionModelObject); + if (selectionModel && selectionModel->model()) { + m_current->setSourceModel(const_cast(selectionModel->model())); + } else { + m_current->setSourceModel(0); + } +} diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspector.h gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspector.h --- gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,67 @@ +/* + selectionmodelinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTOR_H +#define GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTOR_H + +#include + +#include + +class QAbstractProxyModel; + +namespace GammaRay { + +class SelectionModelInspector : public QObject +{ + Q_OBJECT + public: + explicit SelectionModelInspector(ProbeInterface *probe, QObject *parent = 0); + + private slots: + void currentChanged(const QModelIndex ¤t); + + private: + QAbstractProxyModel *m_current; +}; + +class SelectionModelInspectorFactory : + public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.SelectionModelInspector") + public: + explicit SelectionModelInspectorFactory(QObject *parent = 0) : QObject(parent) + { + } + + virtual inline QString name() const + { + return tr("Selection Models"); + } +}; + +} + +#endif // GAMMARAY_SELECTIONMODELINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.cpp gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.cpp --- gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + selectionmodelinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "selectionmodelinspectorwidget.h" +#include "ui_selectionmodelinspectorwidget.h" + +#include +#include + +using namespace GammaRay; + +SelectionModelInspectorWidget::SelectionModelInspectorWidget(QWidget *widget) + : QWidget(widget), ui(new Ui::SelectionModelInspectorWidget) +{ + ui->setupUi(this); + + ui->selectionModelView->setModel(ObjectBroker::model("com.kdab.GammaRay.SelectionModelsModel")); + ui->selectionModelView->setRootIsDecorated(false); + ui->selectionModelView->setSelectionModel(ObjectBroker::selectionModel(ui->selectionModelView->model())); + ui->selectionModelVisualizer->setRootIsDecorated(false); + ui->selectionModelVisualizer->setModel(ObjectBroker::model("com.kdab.GammaRay.CurrentSelectionModel")); +} + +SelectionModelInspectorWidget::~SelectionModelInspectorWidget() +{ +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(SelectionModelInspectorUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.h gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.h --- gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + selectionmodelinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTORWIDGET_H +#define GAMMARAY_SELECTIONMODELINSPECTOR_SELECTIONMODELINSPECTORWIDGET_H + +#include + +#include + +class QItemSelection; + +namespace GammaRay { + +namespace Ui { + class SelectionModelInspectorWidget; +} + +class SelectionModelInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit SelectionModelInspectorWidget(QWidget *widget = 0); + ~SelectionModelInspectorWidget(); + + private: + QScopedPointer ui; +}; + +class SelectionModelInspectorUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.SelectionModelInspectorUi") +}; + + +} + +#endif // GAMMARAY_SELECTIONMODELINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.ui gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.ui --- gammaray-1.2.2/plugins/selectionmodelinspector/selectionmodelinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/selectionmodelinspector/selectionmodelinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,27 @@ + + + GammaRay::SelectionModelInspectorWidget + + + + 0 + 0 + 400 + 300 + + + + + + + Qt::Horizontal + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/statemachineviewer/CMakeLists.txt gammaray-2.0.1/plugins/statemachineviewer/CMakeLists.txt --- gammaray-1.2.2/plugins/statemachineviewer/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,53 +1,97 @@ -if(GRAPHVIZ_FOUND) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${GRAPHVIZ_INCLUDE_DIR} +# shared part +set(gammaray_statemachineviewer_shared_srcs + statemachineviewerinterface.cpp ) +# probe part set(gammaray_statemachineviewer_plugin_srcs - # this part depends on graphviz - gvgraph/gvgraph.cpp - gvgraph/gvgraphitems.cpp - - statemachineview.cpp - statemachineviewer.cpp - statemachinewatcher.cpp - + statemachineviewerserver.cpp transitionmodel.cpp statemodel.cpp + statemachinewatcher.cpp ) -qt4_automoc(${gammaray_statemachineviewer_plugin_srcs}) +gammaray_add_plugin(gammaray_statemachineviewer_plugin + gammaray_statemachineviewer.desktop + ${gammaray_statemachineviewer_shared_srcs} + ${gammaray_statemachineviewer_plugin_srcs} +) + +target_link_libraries(gammaray_statemachineviewer_plugin + ${QT_QTCORE_LIBRARIES} + gammaray_core +) -qt4_wrap_ui(gammaray_statemachineviewer_plugin_srcs statemachineviewer.ui) +############ BEGIN GRAPHVIZ GUI +if(GRAPHVIZ_FOUND AND NOT GAMMARAY_PROBE_ONLY_BUILD) -set(gammaray_statemachineviewer_plugin_libs +set(gammaray_statemachineviewer_ui_plugin_libs ${QT_QTCORE_LIBRARIES} ${QT_QTGUI_LIBRARIES} - ${GRAPHVIZ_GRAPH_LIBRARY} - ${GRAPHVIZ_GVC_LIBRARY} - gammaray_probe + gammaray_common + gammaray_ui ) -gammaray_add_plugin(gammaray_statemachineviewer_plugin - gammaray_statemachineviewer.desktop - ${gammaray_statemachineviewer_plugin_srcs} +set(gammaray_statemachineviewer_ui_plugin_srcs + # gui & client + statemachineviewerclient.cpp + statemachineview.cpp + statemachineviewerwidget.cpp + # this part depends on graphviz + gvgraph/gvgraph.cpp + gvgraph/gvgraphitems.cpp + gvgraph/gvutils.cpp ) -target_link_libraries(gammaray_statemachineviewer_plugin - ${gammaray_statemachineviewer_plugin_libs} +include_directories( + ${GRAPHVIZ_INCLUDE_DIR} + + # TODO: Work-around issue in graphviz/types.h header + # is included there, but it should rather be "cgraph.h" + ${GRAPHVIZ_INCLUDE_DIR}/graphviz ) +list(APPEND gammaray_statemachineviewer_ui_plugin_libs + ${GRAPHVIZ_GVC_LIBRARY} +) + +if(GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_VERSION VERSION_GREATER 2.30.0) + message(STATUS "Enabling use of experimental 'cgraph' library of GraphViz") + # you must add this define when using cgraph from graphviz + # some headers check for this define (see for example graphviz/types.h header) + add_definitions(-DWITH_CGRAPH) + list(APPEND gammaray_statemachineviewer_ui_plugin_libs + ${GRAPHVIZ_CGRAPH_LIBRARY} + ) +else() + list(APPEND gammaray_statemachineviewer_ui_plugin_libs + ${GRAPHVIZ_GRAPH_LIBRARY} + ) +endif() + +qt4_wrap_ui(gammaray_statemachineviewer_ui_plugin_srcs statemachineviewer.ui) + add_executable(statemachineviewer_test gvgraph/gvgraph.cpp gvgraph/gvgraphitems.cpp + gvgraph/gvutils.cpp test_main.cpp ) -target_link_libraries(statemachineviewer_test ${gammaray_statemachineviewer_plugin_libs}) +target_link_libraries(statemachineviewer_test ${gammaray_statemachineviewer_ui_plugin_libs}) + +gammaray_add_plugin(gammaray_statemachineviewer_ui_plugin + gammaray_statemachineviewer_ui.desktop + ${gammaray_statemachineviewer_shared_srcs} + ${gammaray_statemachineviewer_ui_plugin_srcs} +) + +target_link_libraries(gammaray_statemachineviewer_ui_plugin + ${gammaray_statemachineviewer_ui_plugin_libs} +) endif() + +################### END GRAPHVIZ GUI diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gammaray_statemachineviewer.desktop gammaray-2.0.1/plugins/statemachineviewer/gammaray_statemachineviewer.desktop --- gammaray-1.2.2/plugins/statemachineviewer/gammaray_statemachineviewer.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gammaray_statemachineviewer.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,5 @@ [Desktop Entry] Name=State Machines X-GammaRay-Types=QStateMachine; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory Exec=gammaray_statemachineviewer_plugin diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gammaray_statemachineviewer_ui.desktop gammaray-2.0.1/plugins/statemachineviewer/gammaray_statemachineviewer_ui.desktop --- gammaray-1.2.2/plugins/statemachineviewer/gammaray_statemachineviewer_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gammaray_statemachineviewer_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_statemachineviewer +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_statemachineviewer_ui_plugin diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraph.cpp gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraph.cpp --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraph.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraph.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -23,9 +23,12 @@ #include "gvutils.h" -#include #include -#include +#ifdef WITH_CGRAPH +# include +#else +# include +#endif #include #include @@ -34,6 +37,7 @@ #include using namespace GammaRay; +using namespace GammaRay::GVUtils; using namespace std; /*! Dot uses a 72 @@ -51,11 +55,15 @@ void GVGraph::createGraph() { - _graph = _agopen(_name, AGDIGRAPHSTRICT); // Strict directed graph, see libgraph doc - _graphMap.insert(_graph, GVSubGraph("ROOT")); - Q_ASSERT(_context); + +#ifdef WITH_CGRAPH + _graph = _agopen(_name, Agdirected, &AgDefaultDisc); +#else + _graph = _agopen(_name, AGDIGRAPHSTRICT); // Strict directed graph, see libgraph doc +#endif Q_ASSERT(_graph); + _graphMap.insert(_graph, GVSubGraph("ROOT")); _agset(_graph, "overlap", "prism"); _agset(_graph, "splines", "true"); @@ -207,7 +215,7 @@ return 0; } - Agedge_t *edge = agedge(_graph, source, target); + Agedge_t *edge = _agedge(_graph, source, target, 0, true); Q_ASSERT(edge); EdgeId edgeId = id(edge); Q_ASSERT(edge); @@ -294,10 +302,10 @@ QRectF GVGraph::boundingRectForAgraph(Agraph_t *graph) const { const qreal dpi = dpiForGraph(graph); - const qreal left = graph->u.bb.LL.x * (dpi / DotDefaultDPI); - const qreal top = (_graph->u.bb.UR.y - graph->u.bb.LL.y) * (dpi / DotDefaultDPI); - const qreal right = graph->u.bb.UR.x * (dpi / DotDefaultDPI); - const qreal bottom = (_graph->u.bb.UR.y - graph->u.bb.UR.y) * (dpi / DotDefaultDPI); + const qreal left = GD_bb(graph).LL.x * (dpi / DotDefaultDPI); + const qreal top = (GD_bb(_graph).UR.y - GD_bb(graph).LL.y) * (dpi / DotDefaultDPI); + const qreal right = GD_bb(graph).UR.x * (dpi / DotDefaultDPI); + const qreal bottom = (GD_bb(_graph).UR.y - GD_bb(graph).UR.y) * (dpi / DotDefaultDPI); return QRectF(left, top, right - left, bottom - top); } @@ -342,23 +350,23 @@ object.m_name = agget(node, const_cast("label")); //Fetch the X coordinate, apply the DPI conversion rate (actual DPI / 72, used by dot) - qreal x = node->u.coord.x * (dpi / DotDefaultDPI); + qreal x = ND_coord(node).x * (dpi / DotDefaultDPI); //Translate the Y coordinate from bottom-left to top-left corner - qreal y = (_graph->u.bb.UR.y - node->u.coord.y) * (dpi / DotDefaultDPI); - object.m_centerPos=QPoint(x, y); + qreal y = (GD_bb(_graph).UR.y - ND_coord(node).y) * (dpi / DotDefaultDPI); + object.m_centerPos = QPoint(x, y); //Transform the width and height from inches to pixels - object.m_height=node->u.height * dpi; - object.m_width=node->u.width * dpi; + object.m_height = ND_height(node) * dpi; + object.m_width = ND_width(node) * dpi; - if (qstricmp(node->u.shape->name, "rectangle") == 0) { + if (qstricmp(ND_shape(node)->name, "rectangle") == 0) { if (qstricmp(agget(node, const_cast("style")), "rounded") == 0) { object.m_shape = GVNode::RoundedRect; } else { object.m_shape = GVNode::Rect; } - } else if (qstricmp(node->u.shape->name, "doublecircle") == 0) { + } else if (qstricmp(ND_shape(node)->name, "doublecircle") == 0) { object.m_shape = GVNode::DoubleEllipse; } @@ -381,62 +389,63 @@ GVEdge object = _edgeMap[edge]; //Fill the source and target node names - object.m_source=edge->tail->name; - object.m_target=edge->head->name; - - if (edge->u.label) { - object.m_label = QString::fromUtf8(edge->u.label->text); + if (ED_tail_label(edge)) + object.m_source = QString::fromUtf8(ED_tail_label(edge)->text); + if (ED_head_label(edge)) + object.m_target = QString::fromUtf8(ED_head_label(edge)->text); + if (ED_label(edge)) { + object.m_label = QString::fromUtf8(ED_label(edge)->text); // note that the position attributes in graphviz point to the *center* of this element. // we need to subtract half of the width/height to get the top-left position #if GRAPHVIZ_MAJOR_VERSION >= 2 && GRAPHVIZ_MINOR_VERSION > 20 - const double posx = edge->u.label->pos.x; - const double posy = edge->u.label->pos.y; + const double posx = ED_label(edge)->pos.x; + const double posy = ED_label(edge)->pos.y; #else - const double posx = edge->u.label->p.x; - const double posy = edge->u.label->p.y; + const double posx = ED_label(edge)->p.x; + const double posy = ED_label(edge)->p.y; #endif object.m_labelBoundingRect = QRectF( - (posx - edge->u.label->dimen.x / 2.0) * (dpi / DotDefaultDPI), - ((_graph->u.bb.UR.y - posy) - edge->u.label->dimen.y / 2.0) * (dpi / DotDefaultDPI), - edge->u.label->dimen.x * (dpi / DotDefaultDPI), - edge->u.label->dimen.y * (dpi / DotDefaultDPI)); + (posx - ED_label(edge)->dimen.x / 2.0) * (dpi / DotDefaultDPI), + ((GD_bb(_graph).UR.y - posy) - ED_label(edge)->dimen.y / 2.0) * (dpi / DotDefaultDPI), + ED_label(edge)->dimen.x * (dpi / DotDefaultDPI), + ED_label(edge)->dimen.y * (dpi / DotDefaultDPI)); } //Calculate the path from the spline (only one spline, as the graph is strict. //If it wasn't, we would have to iterate over the first list too) //Calculate the path from the spline (only one as the graph is strict) - if ((edge->u.spl->list != 0) && (edge->u.spl->list->size%3 == 1)) { + if ((ED_spl(edge)->list != 0) && (ED_spl(edge)->list->size%3 == 1)) { //If there is a starting point, draw a line from it to the first curve point - if (edge->u.spl->list->sflag) { - object.m_path.moveTo(edge->u.spl->list->sp.x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->sp.y) * (dpi / DotDefaultDPI)); - object.m_path.lineTo(edge->u.spl->list->list[0].x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->list[0].y) * + if (ED_spl(edge)->list->sflag) { + object.m_path.moveTo(ED_spl(edge)->list->sp.x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->sp.y) * (dpi / DotDefaultDPI)); + object.m_path.lineTo(ED_spl(edge)->list->list[0].x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->list[0].y) * (dpi / DotDefaultDPI)); } else { - object.m_path.moveTo(edge->u.spl->list->list[0].x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->list[0].y) * + object.m_path.moveTo(ED_spl(edge)->list->list[0].x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->list[0].y) * (dpi / DotDefaultDPI)); } //Loop over the curve points - for (int i=1; iu.spl->list->size; i+=3) { - object.m_path.cubicTo(edge->u.spl->list->list[i].x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->list[i].y) * + for (int i=1; ilist->size; i+=3) { + object.m_path.cubicTo(ED_spl(edge)->list->list[i].x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->list[i].y) * (dpi / DotDefaultDPI), - edge->u.spl->list->list[i+1].x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->list[i+1].y) * + ED_spl(edge)->list->list[i+1].x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->list[i+1].y) * (dpi / DotDefaultDPI), - edge->u.spl->list->list[i+2].x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->list[i+2].y) * + ED_spl(edge)->list->list[i+2].x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->list[i+2].y) * (dpi / DotDefaultDPI)); } //If there is an ending point, draw a line to it - if(edge->u.spl->list->eflag) { - object.m_path.lineTo(edge->u.spl->list->ep.x * (dpi / DotDefaultDPI), - (_graph->u.bb.UR.y - edge->u.spl->list->ep.y) * (dpi / DotDefaultDPI)); + if(ED_spl(edge)->list->eflag) { + object.m_path.lineTo(ED_spl(edge)->list->ep.x * (dpi / DotDefaultDPI), + (GD_bb(_graph).UR.y - ED_spl(edge)->list->ep.y) * (dpi / DotDefaultDPI)); } } @@ -462,7 +471,7 @@ GVSubGraph object = _graphMap[subGraph]; object.m_path = path; - object.m_name = subGraph->name; + object.m_name = agnameof(subGraph); list.append(GVSubGraphPair(id(subGraph), object)); } diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphelements.h gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphelements.h --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphelements.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphelements.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -34,8 +34,13 @@ public: friend class GVGraph; - GVElement(const QString &name) : m_name(name) {} - GVElement() {} + explicit GVElement(const QString &name) : m_name(name) + { + } + + GVElement() + { + } QString name() const { @@ -52,8 +57,13 @@ friend class GVGraph; public: - GVSubGraph(const QString &name) : GVElement(name) {} - GVSubGraph() {} + explicit GVSubGraph(const QString &name) : GVElement(name) + { + } + + GVSubGraph() + { + } QPainterPath path() const { @@ -77,8 +87,13 @@ RoundedRect }; - GVNode(const QString &name) : GVElement(name), m_height(0), m_width(0), m_shape(Ellipse) {} - GVNode() : m_height(0), m_width(0), m_shape(Ellipse) {} + GVNode(const QString &name) : GVElement(name), m_height(0), m_width(0), m_shape(Ellipse) + { + } + + GVNode() : m_height(0), m_width(0), m_shape(Ellipse) + { + } QPoint centerPos() const { @@ -118,8 +133,13 @@ class GVEdge : public GVElement { public: - GVEdge(const QString &name) : GVElement(name) {} - GVEdge() {} + explicit GVEdge(const QString &name) : GVElement(name) + { + } + + GVEdge() + { + } /// The source and target nodes of the edge QString m_source; diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraph.h gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraph.h --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraph.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraph.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -25,15 +25,12 @@ #include "gvgraphelements.h" #include "gvtypes.h" +#include + #include #include #include -class Agedge_t; -class Agnode_t; -class Agraph_t; -typedef struct GVC_s GVC_t; - namespace GammaRay { typedef QPair GVNodePair; @@ -48,7 +45,7 @@ * \brief Construct a Graphviz graph object * \param name The name of the graph, must be unique in the application */ - GVGraph(const QString &name); + explicit GVGraph(const QString &name); ~GVGraph(); GraphId addGraph(const QString &name); diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphitems.cpp gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphitems.cpp --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphitems.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphitems.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -26,8 +26,8 @@ using namespace GammaRay; -GVNodeItem::GVNodeItem(const GVNode &node, QGraphicsItem *parent, QGraphicsScene *scene) - : QGraphicsItemGroup(parent, scene), +GVNodeItem::GVNodeItem(const GVNode &node, QGraphicsItem *parent) + : QGraphicsItemGroup(parent), m_node(node) { const QSizeF size = node.size(); @@ -109,8 +109,8 @@ m_shapeItem->setBrush(brush); } -GVEdgeItem::GVEdgeItem(const GVEdge &edge, QGraphicsItem *parent, QGraphicsScene *scene) - : QGraphicsItemGroup(parent, scene), +GVEdgeItem::GVEdgeItem(const GVEdge &edge, QGraphicsItem *parent) + : QGraphicsItemGroup(parent), m_edge(edge) { m_pathItem = new QGraphicsPathItem(this); @@ -155,8 +155,8 @@ m_arrowItem->setBrush(arrowPen.color()); } -GVGraphItem::GVGraphItem(const GVSubGraph &graph, QGraphicsItem *parent, QGraphicsScene *scene) - : QGraphicsPathItem(parent, scene), +GVGraphItem::GVGraphItem(const GVSubGraph &graph, QGraphicsItem *parent) + : QGraphicsPathItem(parent), m_graph(graph), m_textItem(0) { diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphitems.h gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphitems.h --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvgraphitems.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvgraphitems.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -32,8 +32,7 @@ class GVNodeItem : public QGraphicsItemGroup { public: - explicit GVNodeItem(const GVNode &node, QGraphicsItem *parent = 0, - QGraphicsScene *scene = 0); + explicit GVNodeItem(const GVNode &node, QGraphicsItem *parent = 0); enum { Type = UserType + 1 @@ -62,8 +61,7 @@ class GVEdgeItem : public QGraphicsItemGroup { public: - explicit GVEdgeItem(const GVEdge &edge, QGraphicsItem *parent = 0, - QGraphicsScene *scene = 0); + explicit GVEdgeItem(const GVEdge &edge, QGraphicsItem *parent = 0); enum { Type = UserType + 2 @@ -90,8 +88,7 @@ class GVGraphItem : public QGraphicsPathItem { public: - explicit GVGraphItem(const GVSubGraph &edge, QGraphicsItem *parent = 0, - QGraphicsScene *scene = 0); + explicit GVGraphItem(const GVSubGraph &edge, QGraphicsItem *parent = 0); enum { Type = UserType + 3 diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvtypes.h gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvtypes.h --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvtypes.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvtypes.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -22,6 +22,8 @@ #ifndef GAMMARAY_GVTYPES_H #define GAMMARAY_GVTYPES_H +#include + namespace GammaRay { typedef quintptr ElementId; diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvutils.cpp gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvutils.cpp --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvutils.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvutils.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,121 @@ +/* + gvutils.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "gvutils.h" + +#include +#ifdef WITH_CGRAPH +# include +#else +# include +#endif + +using namespace GammaRay; + +#ifdef WITH_CGRAPH +Agraph_t *GVUtils::_agopen(const QString &name, Agdesc_t kind, Agdisc_t *disc) +#else +Agraph_t *GVUtils::_agopen(const QString &name, int kind) +#endif +{ +#ifdef WITH_CGRAPH + return agopen(const_cast(qPrintable(name)), kind, disc); +#else + return agopen(const_cast(qPrintable(name)), kind); +#endif +} + +QString GVUtils::_agget(void* object, const QString &attr, const QString &alt) +{ + const QString str = agget(object, const_cast(qPrintable(attr))); + if(str.isEmpty()) { + return alt; + } else { + return str; + } +} + +Agsym_t* GVUtils::_agnodeattr(Agraph_t *object, const QString &attr, const QString &alt) +{ +#ifdef WITH_CGRAPH + return agattr(object, AGNODE, +#else + return agnodeattr(object, +#endif + const_cast(qPrintable(attr)), + const_cast(qPrintable(alt))); +} + +Agsym_t* GVUtils::_agedgeattr(Agraph_t *object, const QString &attr, const QString &alt) +{ +#ifdef WITH_CGRAPH + return agattr(object, AGEDGE, +#else + return agedgeattr(object, +#endif + const_cast(qPrintable(attr)), + const_cast(qPrintable(alt))); +} + +Agnode_t* GVUtils::_agnode(Agraph_t* graph, const QString& attr, bool create) +{ +#ifdef WITH_CGRAPH + return agnode(graph, const_cast(qPrintable(attr)), create); +#else + Q_UNUSED(create); + return agnode(graph, const_cast(qPrintable(attr))); +#endif +} + +Agedge_t* GVUtils::_agedge(Agraph_t *graph, Agnode_t *tail, Agnode_t *head, + const QString &name, bool create) +{ +#ifdef WITH_CGRAPH + return agedge(graph, tail, head, const_cast(qPrintable(name)), create); +#else + Q_UNUSED(name); + Q_UNUSED(create); + return agedge(graph, tail, head); +#endif +} + +Agraph_t* GVUtils::_agsubg(Agraph_t *graph, const QString &attr, bool create) +{ +#ifdef WITH_CGRAPH + return agsubg(graph, const_cast(qPrintable(attr)), create); +#else + Q_UNUSED(create); + return agsubg(graph, const_cast(qPrintable(attr))); +#endif +} + +int GVUtils::_agset(void *object, const QString &attr, const QString &value) +{ + return agsafeset(object, const_cast(qPrintable(attr)), + const_cast(qPrintable(value)), const_cast("")); +} + +int GVUtils::_gvLayout(GVC_t* gvc, graph_t* g, const char* engine) +{ + return gvLayout(gvc, g, const_cast(engine)); +} diff -Nru gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvutils.h gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvutils.h --- gammaray-1.2.2/plugins/statemachineviewer/gvgraph/gvutils.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/gvgraph/gvutils.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -23,65 +23,38 @@ #define GAMMARAY_GVUTILS_H #include -#include -#include #include -#include namespace GammaRay { +namespace GVUtils { + /// The agopen method for opening a graph -static inline Agraph_t *_agopen(QString name, int kind) -{ - return agopen(const_cast(qPrintable(name)), kind); -} +#ifdef WITH_CGRAPH +extern Agraph_t *_agopen(const QString &name, Agdesc_t kind, Agdisc_t *disc); +#else +extern Agraph_t *_agopen(const QString &name, int kind); +#endif /// Add an alternative value parameter to the method for getting an object's attribute -static inline QString _agget(void *object, QString attr, QString alt=QString()) -{ - const QString str = agget(object, const_cast(qPrintable(attr))); - if(str.isEmpty()) { - return alt; - } else { - return str; - } -} +QString _agget(void *object, const QString &attr, const QString& alt = QString()); -static inline Agsym_t *_agnodeattr(Agraph_t *object, QString attr, QString alt=QString()) -{ - return agnodeattr(object, - const_cast(qPrintable(attr)), - const_cast(qPrintable(alt))); -} - -static inline Agsym_t *_agedgeattr(Agraph_t *object, QString attr, QString alt=QString()) -{ - return agedgeattr(object, - const_cast(qPrintable(attr)), - const_cast(qPrintable(alt))); -} - -static inline int _gvLayout(GVC_t *gvc, graph_t *g, const char *engine) -{ - return gvLayout(gvc, g, const_cast(engine)); -} - -static inline Agnode_t *_agnode(Agraph_t *graph, const QString &attr) -{ - return agnode(graph, const_cast(qPrintable(attr))); -} - -static inline Agraph_t *_agsubg(Agraph_t *graph, const QString &attr) -{ - return agsubg(graph, const_cast(qPrintable(attr))); -} +Agsym_t *_agnodeattr(Agraph_t *object, const QString &attr, + const QString &alt = QString()); +Agsym_t *_agedgeattr(Agraph_t *object, const QString &attr, + const QString &alt = QString()); + +int _gvLayout(GVC_t *gvc, graph_t *g, const char *engine); + +Agnode_t *_agnode(Agraph_t *graph, const QString &attr, bool create = true); +Agedge_t *_agedge(Agraph_t *graph, Agnode_t *tail, Agnode_t *head, + const QString &name = QString(), bool create = true); +Agraph_t *_agsubg(Agraph_t *graph, const QString &attr, bool create = true); /// Directly use agsafeset which always works, contrarily to agset -static inline int _agset(void *object, QString attr, QString value) -{ - return agsafeset(object, const_cast(qPrintable(attr)), - const_cast(qPrintable(value)), const_cast("")); +int _agset(void* object, const QString& attr, const QString& value); + } } diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineview.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineview.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineview.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineview.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -47,5 +47,3 @@ zoomBy(zoomFactor); event->accept(); } - -#include "statemachineview.moc" diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerclient.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerclient.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "statemachineviewerclient.h" +#include + +using namespace GammaRay; + +StateMachineViewerClient::StateMachineViewerClient(QObject *parent) + : StateMachineViewerInterface(parent) +{ + +} + +void StateMachineViewerClient::setMaximumDepth(int depth) +{ + Endpoint::instance()->invokeObject(objectName(), "setMaximumDepth", QVariantList() << depth); +} + +void StateMachineViewerClient::toggleRunning() +{ + Endpoint::instance()->invokeObject(objectName(), "toggleRunning"); +} + +void StateMachineViewerClient::repopulateGraph() +{ + Endpoint::instance()->invokeObject(objectName(), "repopulateGraph"); +} diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerclient.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerclient.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STATEMACHINEVIEWERCLIENT_H +#define GAMMARAY_STATEMACHINEVIEWERCLIENT_H + +#include "statemachineviewerinterface.h" + +namespace GammaRay { + +class StateMachineViewerClient : public StateMachineViewerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::StateMachineViewerInterface) + public: + explicit StateMachineViewerClient(QObject *parent = 0); + + void setMaximumDepth(int depth); + void toggleRunning(); + void repopulateGraph(); +}; + +} + +#endif // GAMMARAY_STATEMACHINEVIEWERCLIENT_H diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,554 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "statemachineviewer.h" -#include "statemachineview.h" -#include "statemachinewatcher.h" -#include "statemodel.h" -#include "transitionmodel.h" -#include "ui_statemachineviewer.h" - -#include "gvgraph/gvgraph.h" -#include "gvgraph/gvgraphitems.h" - -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace GammaRay; - -template -static qreal relativePosition(QList list, T t) { - const int index = list.indexOf(t); - Q_ASSERT(index != -1); - return (index+1.0) / list.size(); -} - -static QString uniqueIdentifier(QObject *object) -{ - return Util::addressToUid(object); -} - -StateMachineViewer::StateMachineViewer(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - m_ui(new Ui::StateMachineViewer), - m_graph(new GVGraph("State Machine")), - m_stateModel(new StateModel(this)), - m_transitionModel(new TransitionModel(this)), - m_filteredState(0), - m_maximumDepth(0), - m_font(QFont("Helvetica [Cronxy]", 6)), - m_stateMachineWatcher(new StateMachineWatcher(this)) -{ - m_ui->setupUi(this); - - m_graph->setFont(m_font); - - m_lastConfigurations.resize(5); - - m_ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); - m_ui->graphicsView->setScene(new QGraphicsScene(this)); - m_ui->graphicsView->setRenderHint(QPainter::Antialiasing); - - ObjectTypeFilterProxyModel *stateMachineFilter = - new ObjectTypeFilterProxyModel(this); - stateMachineFilter->setSourceModel(probe->objectListModel()); - m_stateMachineModel = stateMachineFilter; - m_ui->stateMachinesView->setModel(m_stateMachineModel); - m_ui->stateMachinesView->header()->setResizeMode(0, QHeaderView::Stretch); - m_ui->stateMachinesView->header()->setResizeMode(1, QHeaderView::ResizeToContents); - connect(m_ui->stateMachinesView, SIGNAL(clicked(QModelIndex)), - SLOT(handleMachineClicked(QModelIndex))); - - m_ui->singleStateMachineView->setModel(m_stateModel); - connect(m_ui->singleStateMachineView, SIGNAL(clicked(QModelIndex)), - SLOT(handleStateClicked(QModelIndex))); - m_ui->singleStateMachineView->header()->setResizeMode(0, QHeaderView::Stretch); - m_ui->singleStateMachineView->header()->setResizeMode(1, QHeaderView::ResizeToContents); - - connect(m_ui->depthSpinBox, SIGNAL(valueChanged(int)), SLOT(handleDepthChanged(int))); - connect(m_ui->startStopButton, SIGNAL(clicked()), SLOT(startStopClicked())); - connect(m_ui->exportButton, SIGNAL(clicked()), SLOT(exportAsImage())); - - connect(m_stateMachineWatcher, SIGNAL(stateEntered(QAbstractState*)), - SLOT(handleStatesChanged())); - connect(m_stateMachineWatcher, SIGNAL(stateExited(QAbstractState*)), - SLOT(handleStatesChanged())); - connect(m_stateMachineWatcher, SIGNAL(transitionTriggered(QAbstractTransition*)), - SLOT(handleTransitionTriggered(QAbstractTransition*))); - - setMaximumDepth(3); - updateStartStop(); - - // pre-select the first state machine for convenience - if (m_stateMachineModel->rowCount() > 0) { - const QModelIndex firstRow = m_stateMachineModel->index(0, 0); - m_ui->stateMachinesView->selectionModel()->select( - firstRow, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); - handleMachineClicked(firstRow); - } -} - -void StateMachineViewer::clearGraph() -{ - m_graph->clear(); - - m_graphItemMap.clear(); - m_nodeItemMap.clear(); - m_edgeItemMap.clear(); - - m_stateGraphIdMap.clear(); - m_stateNodeIdMap.clear(); - m_transitionEdgeIdMap.clear(); -} - -void StateMachineViewer::repopulateGraph() -{ - clearGraph(); - - for (int i = 0; i < m_stateModel->rowCount(); ++i) { - const QModelIndex index = m_stateModel->index(i, 0); - QObject* stateObject = index.data(StateModel::StateObjectRole).value(); - QAbstractState *state = qobject_cast(stateObject); - if (!state) { - continue; - } - - addState(state); - } -} - -QStateMachine *StateMachineViewer::selectedStateMachine() const -{ - return m_stateModel->stateMachine(); -} - -void StateMachineViewer::selectStateMachine(QStateMachine *machine) -{ - if (!machine) { - qWarning() << Q_FUNC_INFO << "Warning: Null parameter"; - return; - } - - m_stateModel->setStateMachine(machine); - m_ui->singleStateMachineView->expandAll(); - - m_lastConfigurations.clear(); - m_lastTransitions.clear(); - - setFilteredState(machine); - m_stateMachineWatcher->setWatchedStateMachine(machine); - - connect(machine, SIGNAL(started()), SLOT(updateStartStop()), Qt::UniqueConnection); - connect(machine, SIGNAL(stopped()), SLOT(updateStartStop()), Qt::UniqueConnection); - connect(machine, SIGNAL(finished()),SLOT(updateStartStop()), Qt::UniqueConnection); - updateStartStop(); -} - -int treeDepth(QAbstractState *ascendant, QAbstractState *obj) -{ - if (!Util::descendantOf(ascendant, obj)) { - return -1; - } - - int depth = 0; - QAbstractState *parent = obj->parentState(); - while (parent) { - ++depth; - parent = parent->parentState(); - } - return depth; -} - -bool StateMachineViewer::mayAddState(QAbstractState *state) -{ - if (!state) { - return false; - } - - if (m_stateNodeIdMap.contains(state)) { - return false; - } - - if (m_filteredState) { - if (m_filteredState != state && !Util::descendantOf(m_filteredState, state)) { - return false; - } - } - - if (m_maximumDepth > 0) { - if (::treeDepth(m_filteredState, state) > m_maximumDepth) { - return false; - } - } - - return true; -} - -void StateMachineViewer::setFilteredState(QAbstractState *state) -{ - if (m_filteredState == state) { - return; - } - - showMessage(QString("Setting filter on: %1").arg(Util::displayString(state))); - m_filteredState = state; - repopulateGraph(); - repopulateView(); -} - -void StateMachineViewer::setMaximumDepth(int depth) -{ - if (m_maximumDepth == depth) { - return; - } - - showMessage(QString("Showing states until a depth of %1").arg(depth)); - m_maximumDepth = depth; - repopulateGraph(); - repopulateView(); - m_ui->depthSpinBox->setValue(depth); -} - -void StateMachineViewer::handleMachineClicked(const QModelIndex &index) -{ - QObject *stateMachineObject = index.data(ObjectModel::ObjectRole).value(); - QStateMachine *stateMachine = qobject_cast(stateMachineObject); - Q_ASSERT(stateMachine); - - selectStateMachine(stateMachine); -} - -void StateMachineViewer::handleStateClicked(const QModelIndex &index) -{ - QObject *stateObject = index.data(ObjectModel::ObjectRole).value(); - Q_ASSERT(stateObject); - QAbstractState *state = qobject_cast(stateObject); - Q_ASSERT(state); - setFilteredState(state); -} - -void StateMachineViewer::handleDepthChanged(int depth) -{ - setMaximumDepth(depth); -} - -void StateMachineViewer::showMessage(const QString &message) -{ - // update log - QPlainTextEdit *plainTextEdit = m_ui->plainTextEdit; - plainTextEdit->appendPlainText(message); - - // auto-scroll hack - QScrollBar *sb = plainTextEdit->verticalScrollBar(); - sb->setValue(sb->maximum()); -} - -void StateMachineViewer::handleTransitionTriggered(QAbstractTransition *transition) -{ - showMessage(tr("Transition triggered: %1").arg(Util::displayString(transition))); - - m_lastTransitions.enqueue(transition); - updateTransitionItems(); -} - -void StateMachineViewer::updateTransitionItems() -{ - // restore default color - Q_FOREACH (QGraphicsItem *item, m_ui->graphicsView->scene()->items()) { - GVEdgeItem *edgeItem = qgraphicsitem_cast(item); - if (edgeItem) { - edgeItem->setPen(QPen()); - } - } - - // set color based on recent usage - Q_FOREACH (QAbstractTransition *t, m_lastTransitions.entries()) { - EdgeId id = m_transitionEdgeIdMap.value(t); - GVEdgeItem *edgeItem = m_edgeItemMap[id]; - if (!edgeItem) { - continue; - } - - QColor color(Qt::red); - color.setRedF(relativePosition(m_lastTransitions.entries(), t)); - QPen pen(Qt::DashLine); - pen.setWidth(2); - pen.setColor(color); - edgeItem->setPen(pen); - } -} - -void StateMachineViewer::handleStatesChanged() -{ - StateMachineConfiguration config = m_stateModel->stateMachine()->configuration(); - if (m_lastConfigurations.size() > 0 && m_lastConfigurations.tail() == config) { - return; - } - - Q_FOREACH (QAbstractState *state, config) { - showMessage(tr("State entered: %1").arg(Util::displayString(state))); - } - - m_lastConfigurations.enqueue(config); - updateStateItems(); -} - -void StateMachineViewer::updateStateItems() -{ - // initialize - Q_FOREACH (QAbstractState *state, m_stateNodeIdMap.keys()) { - NodeId id = m_stateNodeIdMap.value(state); - GVNodeItem *nodeItem = m_nodeItemMap[id]; - if (qobject_cast(state)) { - nodeItem->setBrush(Qt::black); - } else if (qobject_cast(state)) { - nodeItem->setBrush(Qt::gray); - } else { - nodeItem->setBrush(Qt::white); - } - } - - // color recent configurations based on last usage - // note that each configuration has the same color saturation atm - Q_FOREACH (const StateMachineConfiguration &config, m_lastConfigurations.entries()) { - const qreal alpha = relativePosition(m_lastConfigurations.entries(), config); - Q_FOREACH (QAbstractState *state, config) { - NodeId id = m_stateNodeIdMap.value(state); - GVNodeItem *nodeItem = m_nodeItemMap[id]; - if (!nodeItem) { - continue; - } - - QColor color(Qt::red); - color.setAlphaF(alpha); - QBrush brush = nodeItem->brush(); - brush.setColor(color); - nodeItem->setBrush(brush); - } - } -} - -void StateMachineViewer::addState(QAbstractState *state) -{ - if (!mayAddState(state)) { - return; - } - - QState *parentState = state->parentState(); - if (parentState) { - addState(parentState); // be sure that parent is added first - } - - GraphId parentGraphId = m_stateGraphIdMap.value(parentState); - GraphId graphId = parentGraphId; - if (parentState && parentGraphId) { - if (state->findChild()) { - // only create sub-graphs if we have child states - graphId = m_graph->addGraph(uniqueIdentifier(state), parentGraphId); - m_graph->setGraphAttr(QLatin1String("label"), Util::displayString(state), graphId); - } - } else { - graphId = m_graph->addGraph(uniqueIdentifier(state)); - m_graph->setGraphAttr(QLatin1String("label"), Util::displayString(state), graphId); - } - const NodeId nodeId = m_graph->addNode(uniqueIdentifier(state), graphId); - m_graph->setNodeAttribute(nodeId, QLatin1String("label"), Util::displayString(state)); - Q_ASSERT(graphId); - Q_ASSERT(nodeId); - - if (qobject_cast(state)) { - m_graph->setNodeAttribute(nodeId, "shape", "doublecircle"); - m_graph->setNodeAttribute(nodeId, "label", ""); - m_graph->setNodeAttribute(nodeId, "style", "filled"); - m_graph->setNodeAttribute(nodeId, "fillcolor", "black"); - m_graph->setNodeAttribute(nodeId, "fixedsize", "true"); - m_graph->setNodeAttribute(nodeId, "heigh", "0.15"); - m_graph->setNodeAttribute(nodeId, "width", "0.15"); - } else if (qobject_cast(state)) { - m_graph->setNodeAttribute(nodeId, "label", "H"); - m_graph->setNodeAttribute(nodeId, "shape", "circle"); - } else { - m_graph->setNodeAttribute(nodeId, "shape", "rectangle"); - m_graph->setNodeAttribute(nodeId, "style", "rounded"); - } - - // add a connection from parent state to initial state iff - // parent state is valid and parent state has an initial state - if (parentGraphId && parentState->initialState() == state) { - NodeId initialNode = - m_graph->addNode(QString("initial-%1").arg(uniqueIdentifier(parentState)), parentGraphId); - m_graph->addEdge(initialNode, nodeId, QString()); - m_graph->setNodeAttribute(initialNode, "shape", "circle"); - m_graph->setNodeAttribute(initialNode, "style", "filled"); - m_graph->setNodeAttribute(initialNode, "fillcolor", "black"); - m_graph->setNodeAttribute(initialNode, "fixedsize", "true"); - m_graph->setNodeAttribute(initialNode, "heigh", "0.1"); - m_graph->setNodeAttribute(initialNode, "width", "0.1"); - m_graph->setNodeAttribute(initialNode, "label", ""); - } - - m_stateGraphIdMap.insert(state, graphId); - m_stateNodeIdMap.insert(state, nodeId); - - // add transitions - Q_FOREACH (QAbstractTransition *transition, state->findChildren()) { - addTransition(transition); - } - - // recursive call to add children - Q_FOREACH (QAbstractState* child, state->findChildren()) { - addState(child); - } -} - -void StateMachineViewer::addTransition(QAbstractTransition *transition) -{ - QState *sourceState = transition->sourceState(); - QAbstractState *targetState = transition->targetState(); - addState(sourceState); - addState(targetState); - - NodeId sourceStateId = m_stateNodeIdMap.value(sourceState); - NodeId targetStateId = m_stateNodeIdMap.value(targetState); - if (!sourceStateId || !targetStateId) { - return; - } - - EdgeId id = m_graph->addEdge(sourceStateId, targetStateId, Util::displayString(transition)); - Q_ASSERT(id); - - QSignalTransition *signalTransition = qobject_cast(transition); - if (signalTransition) { - const QString label = - QString::fromLatin1("%1::%2"). - arg(Util::displayString(signalTransition->senderObject())). - arg(QString::fromLatin1(signalTransition->signal().mid(1))); - m_graph->setEdgeAttribute(id, QLatin1String("label"), label); - } - - m_transitionEdgeIdMap.insert(transition, id); -} - -void StateMachineViewer::clearView() -{ - m_ui->graphicsView->scene()->clear(); -} - -void StateMachineViewer::repopulateView() -{ - clearView(); - - m_graph->applyLayout(); - - QGraphicsScene *scene = m_ui->graphicsView->scene(); - Q_FOREACH (const GVNodePair &nodePair, m_graph->gvNodes()) { - const NodeId &id = nodePair.first; - const GVNode &node = nodePair.second; - GVNodeItem *item = new GVNodeItem(node); - scene->addItem(item); - m_nodeItemMap.insert(id, item); - } - - Q_FOREACH (const GVEdgePair &edgePair, m_graph->gvEdges()) { - const EdgeId &id = edgePair.first; - const GVEdge &edge = edgePair.second; - GVEdgeItem *item = new GVEdgeItem(edge); - scene->addItem(item); - m_edgeItemMap.insert(id, item); - } - - Q_FOREACH (const GVSubGraphPair &graphPair, m_graph->gvSubGraphs()) { - const GraphId &id = graphPair.first; - const GVSubGraph &graph = graphPair.second; - GVGraphItem *item = new GVGraphItem(graph); - scene->addItem(item); - m_graphItemMap.insert(id, item); - } - - updateStateItems(); - updateTransitionItems(); - - // correctly set the scene rect - scene->setSceneRect(scene->itemsBoundingRect()); -} - -void StateMachineViewer::updateStartStop() -{ - if (!selectedStateMachine() || !selectedStateMachine()->isRunning()) { - m_ui->startStopButton->setChecked(false); - m_ui->startStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - } else { - m_ui->startStopButton->setChecked(true); - m_ui->startStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); - } - m_ui->startStopButton->setEnabled(selectedStateMachine()); -} - -void StateMachineViewer::startStopClicked() -{ - if (!selectedStateMachine()) { - return; - } - if (selectedStateMachine()->isRunning()) { - selectedStateMachine()->stop(); - } else { - selectedStateMachine()->start(); - } -} - -void StateMachineViewer::exportAsImage() -{ - const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As Image")); - if (fileName.isEmpty()) { - return; - } - - QGraphicsScene *scene = m_ui->graphicsView->scene(); - - QImage image(scene->sceneRect().width(), scene->sceneRect().height(), - QImage::Format_ARGB32_Premultiplied); - image.fill(QColor(Qt::white).rgb()); - - QPainter painter(&image); - painter.setRenderHint(QPainter::Antialiasing); - scene->render(&painter); - - image.save(fileName, "PNG"); -} - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -Q_EXPORT_PLUGIN(StateMachineViewerFactory) -#endif - -#include "statemachineviewer.moc" diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,143 +0,0 @@ -/* - This file is part of GammaRay, the Qt application inspection and - manipulation tool. - - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Kevin Funk - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef GAMMARAY_STATEMACHINEVIEWER_STATEMACHINEVIEWER_H -#define GAMMARAY_STATEMACHINEVIEWER_STATEMACHINEVIEWER_H - -#include "statemachineviewerutil.h" -#include "gvgraph/gvtypes.h" - -#include "include/toolfactory.h" - -#include -#include -#include -#include - -class QAbstractTransition; -class QStateMachine; -class QAbstractState; -class QAbstractItemModel; -class QModelIndex; - -typedef QSet StateMachineConfiguration; - -namespace GammaRay { - -namespace Ui { - class StateMachineViewer; -} - -class GVNodeItem; -class GVEdgeItem; -class GVGraphItem; -class StateModel; -class StateMachineWatcher; -class TransitionModel; - -class GVGraph; - -class StateMachineViewer : public QWidget -{ - Q_OBJECT - public: - explicit StateMachineViewer(ProbeInterface *probe, QWidget *parent = 0); - - void addState(QAbstractState *state); - void addTransition(QAbstractTransition *transition); - - QStateMachine *selectedStateMachine() const; - - private slots: - void handleStatesChanged(); - void handleTransitionTriggered(QAbstractTransition *); - - void handleMachineClicked(const QModelIndex &); - void handleStateClicked(const QModelIndex &); - void handleDepthChanged(int depth); - - void selectStateMachine(QStateMachine *stateMachine); - void setFilteredState(QAbstractState *state); - void setMaximumDepth(int depth); - - void clearView(); - void repopulateView(); - - void showMessage(const QString &message); - - void updateStartStop(); - void startStopClicked(); - void exportAsImage(); - - private: - void clearGraph(); - void repopulateGraph(); - - void updateStateItems(); - void updateTransitionItems(); - - bool mayAddState(QAbstractState *state); - - QScopedPointer m_ui; - - GVGraph *m_graph; - QFont m_font; - - QAbstractItemModel *m_stateMachineModel; - StateModel *m_stateModel; - TransitionModel *m_transitionModel; - - // filters - QAbstractState *m_filteredState; - int m_maximumDepth; - - QHash m_transitionEdgeIdMap; - QHash m_stateGraphIdMap; - QHash m_stateNodeIdMap; - - QHash m_edgeItemMap; - QHash m_graphItemMap; - QHash m_nodeItemMap; - - RingBuffer m_lastConfigurations; - RingBuffer m_lastTransitions; - - StateMachineWatcher *m_stateMachineWatcher; -}; - -class StateMachineViewerFactory : - public QObject, public StandardToolFactory -{ - Q_OBJECT - Q_INTERFACES(GammaRay::ToolFactory) - Q_PLUGIN_METADATA(IID "com.kdab.gammaray.StateMachineViewer") - - public: - explicit StateMachineViewerFactory(QObject *parent = 0) : QObject(parent) {} - inline QString name() const - { - return tr("State Machine Viewer"); - } -}; - -} - -#endif // GAMMARAY_STATEMACHINEVIEWER_H diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerinterface.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerinterface.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "statemachineviewerinterface.h" +#include + +using namespace GammaRay; + +StateMachineViewerInterface::StateMachineViewerInterface(QObject *parent) + : QObject(parent) +{ + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + ObjectBroker::registerObject(this); +} + +StateMachineViewerInterface::~StateMachineViewerInterface() +{ +} diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerinterface.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerinterface.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,151 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STATEMACHINEVIEWERINTERFACE_H +#define GAMMARAY_STATEMACHINEVIEWERINTERFACE_H + +#include +#include +#include + +class QAbstractState; +class QAbstractTransition; + +namespace GammaRay { + +// note: typedef bring major pain, on the client side i.e. it would always look for +// signal/slots with the base type (or actually, the first type which was registered +// to the meta type system)... +struct TransitionId +{ + TransitionId(const TransitionId &id) + : id(id.id) + {} + explicit TransitionId(QAbstractTransition *transition = 0) + : id(reinterpret_cast(transition)) + {} + operator quint64() const + { + return id; + } + quint64 id; +}; + +inline QDataStream &operator<<(QDataStream &out, TransitionId value) +{ + out << value.id; + return out; +} + +inline QDataStream &operator>>(QDataStream &in, TransitionId &value) +{ + in >> value.id; + return in; +} + +struct StateId +{ + StateId(const StateId &id) + : id(id.id) + {} + explicit StateId(QAbstractState *state= 0) + : id(reinterpret_cast(state)) + {} + operator quint64() const + { + return id; + } + quint64 id; +}; + +inline QDataStream &operator<<(QDataStream &out, StateId value) +{ + out << value.id; + return out; +} + +inline QDataStream &operator>>(QDataStream &in, StateId &value) +{ + in >> value.id; + return in; +} + +enum StateType { + OtherState, + FinalState, + HistoryState, + StateMachineState +}; + +inline QDataStream &operator<<(QDataStream &out, StateType value) +{ + out << int(value); + return out; +} + +inline QDataStream &operator>>(QDataStream &in, StateType &value) +{ + int val; + in >> val; + value = static_cast(val); + return in; +} + +typedef QList StateMachineConfiguration; + +class StateMachineViewerInterface : public QObject +{ + Q_OBJECT + public: + explicit StateMachineViewerInterface(QObject *parent = 0); + virtual ~StateMachineViewerInterface(); + + public slots: + virtual void toggleRunning() = 0; + virtual void setMaximumDepth(int depth) = 0; + + virtual void repopulateGraph() = 0; + + signals: + void statusChanged(bool haveStateMachine, bool running); + void message(const QString &message); + void aboutToRepopulateGraph(); + void graphRepopulated(); + void stateConfigurationChanged(const GammaRay::StateMachineConfiguration& config); + void maximumDepthChanged(int depth); + void transitionTriggered(GammaRay::TransitionId transition, const QString &label); + void stateAdded(GammaRay::StateId state, GammaRay::StateId parent, bool hasChildren, + const QString &label, GammaRay::StateType type, bool connectToInitial); + void stateEntered(GammaRay::StateId state); + void stateExited(GammaRay::StateId state); + void transitionAdded(GammaRay::TransitionId state, GammaRay::StateId source, GammaRay::StateId target, + const QString &label); +}; + +} + +Q_DECLARE_METATYPE(GammaRay::StateId) +Q_DECLARE_METATYPE(GammaRay::TransitionId) +Q_DECLARE_METATYPE(GammaRay::StateMachineConfiguration) +Q_DECLARE_METATYPE(GammaRay::StateType) +Q_DECLARE_INTERFACE(GammaRay::StateMachineViewerInterface, "com.kdab.GammaRay.StateMachineViewer") + +#endif // GAMMARAY_STATEMACHINEVIEWERINTERFACE_H diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerserver.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerserver.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerserver.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerserver.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,384 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "statemachineviewerserver.h" + +#include "statemodel.h" +#include "statemachinewatcher.h" +#include "transitionmodel.h" + + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace GammaRay; +using namespace std; + +StateMachineViewerServer::StateMachineViewerServer(ProbeInterface *probe, QObject *parent) + : StateMachineViewerInterface(parent), + m_stateModel(new StateModel(this)), + m_transitionModel(new TransitionModel(this)), + m_maximumDepth(0), + m_stateMachineWatcher(new StateMachineWatcher(this)) +{ + probe->registerModel("com.kdab.GammaRay.StateModel", m_stateModel); + QItemSelectionModel *stateSelectionModel = ObjectBroker::selectionModel(m_stateModel); + connect(stateSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(stateSelectionChanged())); + + ObjectTypeFilterProxyModel *stateMachineFilter = + new ObjectTypeFilterProxyModel(this); + stateMachineFilter->setSourceModel(probe->objectListModel()); + probe->registerModel("com.kdab.GammaRay.StateMachineModel", stateMachineFilter); + QItemSelectionModel *stateMachineSelectionModel = ObjectBroker::selectionModel(stateMachineFilter); + connect(stateMachineSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), + SLOT(handleMachineClicked(QModelIndex))); + + connect(m_stateMachineWatcher, SIGNAL(stateEntered(QAbstractState*)), + SLOT(stateEntered(QAbstractState*))); + connect(m_stateMachineWatcher, SIGNAL(stateExited(QAbstractState*)), + SLOT(stateExited(QAbstractState*))); + connect(m_stateMachineWatcher, SIGNAL(transitionTriggered(QAbstractTransition*)), + SLOT(handleTransitionTriggered(QAbstractTransition*))); + + + + setMaximumDepth(3); + updateStartStop(); +} + +void StateMachineViewerServer::repopulateGraph() +{ + emit aboutToRepopulateGraph(); + + // just to be sure the client has the same setting than we do + emit maximumDepthChanged(m_maximumDepth); + updateStartStop(); + + if (m_filteredStates.isEmpty()) { + addState(m_stateModel->stateMachine()); + } else { + foreach(QAbstractState* state, m_filteredStates) { + addState(state); + } + } + m_recursionGuard.clear(); + + emit graphRepopulated(); +} + +QStateMachine *StateMachineViewerServer::selectedStateMachine() const +{ + return m_stateModel->stateMachine(); +} + +static int treeDepth(QAbstractState *ascendant, QAbstractState *obj) +{ + if (!Util::descendantOf(ascendant, obj)) { + return -1; + } + + int depth = 0; + QAbstractState *parent = obj->parentState(); + while (parent) { + ++depth; + parent = parent->parentState(); + } + return depth; +} + +bool StateMachineViewerServer::mayAddState(QAbstractState *state) +{ + if (!state) { + return false; + } + + if (m_recursionGuard.contains(state)) { + return false; + } + + if (!m_filteredStates.isEmpty()) { + bool isValid = false; + foreach(QAbstractState* filter, m_filteredStates) { + if (filter == state || Util::descendantOf(filter, state)) { + isValid = true; + break; + } + } + if (!isValid) { + return false; + } + } + + if (m_maximumDepth > 0) { + int depth = -1; + if (!m_filteredStates.isEmpty()) { + foreach(QAbstractState* filter, m_filteredStates) { + depth = ::treeDepth(filter, state); + if (depth != -1) { + break; + } + } + } else { + depth = ::treeDepth(m_stateModel->stateMachine(), state); + } + if (depth > m_maximumDepth) { + return false; + } + } + + return true; +} + +void StateMachineViewerServer::setFilteredStates(const QVector& states) +{ + if (m_filteredStates == states) { + return; + } + + if (states.isEmpty()) { + emit message(tr("Clearing filter.")); + } else { + QStringList stateNames; + stateNames.reserve(states.size()); + foreach(QAbstractState* state, states) { + stateNames << Util::displayString(state); + } + emit message(tr("Setting filter on: %1").arg(stateNames.join(", "))); + } + + m_filteredStates = states; +} + +void StateMachineViewerServer::setMaximumDepth(int depth) +{ + if (m_maximumDepth == depth) { + return; + } + + emit message(tr("Showing states until a depth of %1").arg(depth)); + m_maximumDepth = depth; + repopulateGraph(); + + emit maximumDepthChanged(depth); +} + +void StateMachineViewerServer::setSelectedStateMachine(QStateMachine* machine) +{ + QStateMachine* oldMachine = selectedStateMachine(); + if (oldMachine) { + disconnect(oldMachine, SIGNAL(started()), this, SLOT(updateStartStop())); + disconnect(oldMachine, SIGNAL(stopped()), this, SLOT(updateStartStop())); + disconnect(oldMachine, SIGNAL(finished()), this, SLOT(updateStartStop())); + } + + m_stateModel->setStateMachine(machine); + stateConfigurationChanged(); + + setFilteredStates(QVector()); + m_stateMachineWatcher->setWatchedStateMachine(machine); + repopulateGraph(); + + if (machine) { + connect(machine, SIGNAL(started()), this, SLOT(updateStartStop())); + connect(machine, SIGNAL(stopped()), this, SLOT(updateStartStop())); + connect(machine, SIGNAL(finished()), this, SLOT(updateStartStop())); + } + updateStartStop(); +} + +void StateMachineViewerServer::handleMachineClicked(const QModelIndex &index) +{ + if (!index.isValid()) { + setSelectedStateMachine(0); + return; + } + + QObject *stateMachineObject = index.data(ObjectModel::ObjectRole).value(); + QStateMachine *machine = qobject_cast(stateMachineObject); + setSelectedStateMachine(machine); +} + +void StateMachineViewerServer::stateSelectionChanged() +{ + const QModelIndexList& selection = ObjectBroker::selectionModel(m_stateModel)->selectedRows(); + QVector filter; + filter.reserve(selection.size()); + foreach(const QModelIndex &index, selection) { + QObject *stateObject = index.data(ObjectModel::ObjectRole).value(); + Q_ASSERT(stateObject); + QAbstractState *state = qobject_cast(stateObject); + Q_ASSERT(state); + bool addState = true; + /// only pick the top-level items of the selection + // NOTE: this might be slow for large selections, if someone wants to come up with a better + // algorithm, please - go for it! + foreach(QAbstractState *potentialParent, filter) { + if (Util::descendantOf(potentialParent, state)) { + addState = false; + break; + } + } + + if (addState) { + filter << state; + } + } + setFilteredStates(filter); +} + +void StateMachineViewerServer::handleTransitionTriggered(QAbstractTransition *transition) +{ + emit transitionTriggered(TransitionId(transition), Util::displayString(transition)); +} + +void StateMachineViewerServer::stateEntered(QAbstractState *state) +{ + emit message(tr("State entered: %1").arg(Util::displayString(state))); + stateConfigurationChanged(); +} + +void StateMachineViewerServer::stateExited(QAbstractState *state) +{ + emit message(tr("State exited: %1").arg(Util::displayString(state))); + stateConfigurationChanged(); +} + +void StateMachineViewerServer::stateConfigurationChanged() +{ + QSet newConfig; + if (selectedStateMachine()) { + newConfig = selectedStateMachine()->configuration(); + } + + if (newConfig == m_lastStateConfig) { + return; + } + m_lastStateConfig = newConfig; + + StateMachineConfiguration config; + config.reserve(newConfig.size()); + foreach(QAbstractState* state, newConfig) { + config << StateId(state); + } + + emit stateConfigurationChanged(config); +} + +void StateMachineViewerServer::addState(QAbstractState *state) +{ + if (!mayAddState(state)) { + return; + } + + Q_ASSERT(!m_recursionGuard.contains(state)); + m_recursionGuard.insert(state); + + QState *parentState = state->parentState(); + if (parentState) { + addState(parentState); // be sure that parent is added first + } + + const bool hasChildren = state->findChild(); + const QString &label = Util::displayString(state); + // add a connection from parent state to initial state if + // parent state is valid and parent state has an initial state + const bool connectToInitial = parentState && parentState->initialState() == state; + StateType type = OtherState; + if (qobject_cast(state)) { + type = FinalState; + } else if (qobject_cast(state)) { + type = HistoryState; + } else if (qobject_cast(state)) { + type = StateMachineState; + } + + emit stateAdded(StateId(state), StateId(parentState), + hasChildren, label, type, connectToInitial); + + // add transitions + Q_FOREACH (QAbstractTransition *transition, state->findChildren()) { + addTransition(transition); + } + + // recursive call to add children + Q_FOREACH (QAbstractState* child, state->findChildren()) { + addState(child); + } +} + +void StateMachineViewerServer::addTransition(QAbstractTransition *transition) +{ + QState *sourceState = transition->sourceState(); + QAbstractState *targetState = transition->targetState(); + addState(sourceState); + addState(targetState); + + QString label = transition->objectName(); + if (label.isEmpty()) { + // Try to get a label for the transition if it is a QSignalTransition. + QSignalTransition *signalTransition = qobject_cast(transition); + if (signalTransition) { + label = QString::fromLatin1("%1::%2"). + arg(Util::displayString(signalTransition->senderObject())). + arg(QString::fromLatin1(signalTransition->signal().mid(1))); + } else { + label = Util::displayString(transition); + } + } + + emit transitionAdded(TransitionId(transition), StateId(sourceState), + StateId(targetState), label); +} + +void StateMachineViewerServer::updateStartStop() +{ + emit statusChanged(selectedStateMachine() != 0, selectedStateMachine() && selectedStateMachine()->isRunning()); +} + +void StateMachineViewerServer::toggleRunning() +{ + if (!selectedStateMachine()) { + return; + } + if (selectedStateMachine()->isRunning()) { + selectedStateMachine()->stop(); + } else { + selectedStateMachine()->start(); + } +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(StateMachineViewerFactory) +#endif diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerserver.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerserver.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerserver.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerserver.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,120 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STATEMACHINEVIEWER_STATEMACHINEVIEWERSERVER_H +#define GAMMARAY_STATEMACHINEVIEWER_STATEMACHINEVIEWERSERVER_H + +#include "statemachineviewerutil.h" +#include "statemachineviewerinterface.h" + +#include + +#include +#include +#include +#include +#include + +#include + +class QAbstractTransition; +class QStateMachine; +class QAbstractState; +class QAbstractItemModel; +class QModelIndex; + +namespace GammaRay { + +class StateModel; +class StateMachineWatcher; +class TransitionModel; + +class StateMachineViewerServer : public StateMachineViewerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::StateMachineViewerInterface) + public: + explicit StateMachineViewerServer(ProbeInterface *probe, QObject *parent = 0); + + void addState(QAbstractState *state); + void addTransition(QAbstractTransition *transition); + + QStateMachine *selectedStateMachine() const; + + using StateMachineViewerInterface::stateConfigurationChanged; + private slots: + void stateEntered(QAbstractState *state); + void stateExited(QAbstractState *state); + void stateConfigurationChanged(); + void handleTransitionTriggered(QAbstractTransition *); + + void handleMachineClicked(const QModelIndex &); + void stateSelectionChanged(); + + void setFilteredStates(const QVector &states); + void setMaximumDepth(int depth); + void setSelectedStateMachine(QStateMachine* machine); + + void updateStartStop(); + void toggleRunning(); + + void repopulateGraph(); + + private: + + void updateStateItems(); + + bool mayAddState(QAbstractState *state); + + StateModel *m_stateModel; + TransitionModel *m_transitionModel; + + // filters + QVector m_filteredStates; + int m_maximumDepth; + + StateMachineWatcher *m_stateMachineWatcher; + QSet m_recursionGuard; + QSet m_lastStateConfig; +}; + +class StateMachineViewerFactory : +public QObject, public StandardToolFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.StateMachineViewer") + + public: + explicit StateMachineViewerFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("State Machine Viewer"); + } +}; + +} + +#endif // GAMMARAY_STATEMACHINEVIEWERSERVER_H diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.ui gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.ui --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewer.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewer.ui 2014-02-28 19:07:57.000000000 +0000 @@ -33,6 +33,9 @@ Maximum depth of state hierarchy shown: + + depthSpinBox + @@ -59,11 +62,44 @@ - - - Save As Image... - - + + + + + Save As Image... + + + + + + + <qt>Limits the maximum size of the exported image file. Zooming could otherwise make the image extremely large. The number given is in units of mega pixel.</qt> + + + Maximum Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + maxMegaPixelsSpinBox + + + + + + + <qt>Limits the maximum size of the exported image file. Zooming could otherwise make the image extremely large. The number given is in units of mega pixel.</qt> + + + 0 MPx + + + MPx + + + + @@ -74,6 +110,9 @@ Start/Stop State Machine: + + startStopButton + diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerutil.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerutil.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerutil.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerutil.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -28,7 +28,9 @@ class RingBuffer { public: - RingBuffer() : m_size(5) {} + RingBuffer() : m_size(5) + { + } void resize(int size) { diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerwidget.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerwidget.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,456 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "statemachineviewerwidget.h" + +#include "gvgraph/gvgraph.h" +#include "gvgraph/gvgraphitems.h" + +#include "statemachineviewerclient.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +enum { + KEY_STATETYPE +}; + +#include + +using namespace GammaRay; +using namespace std; + +static QObject* createStateMachineViewerClient(const QString &/*name*/, QObject *parent) +{ + return new StateMachineViewerClient(parent); +} + +template +static qreal relativePosition(const QList& list, T t) +{ + const int index = list.indexOf(t); + Q_ASSERT(index != -1); + return (index+1.0) / list.size(); +} + +StateMachineViewerWidget::StateMachineViewerWidget(QWidget *parent, Qt::WindowFlags f) + : QWidget(parent, f) + , m_ui(new Ui::StateMachineViewer) + , m_graph(new GVGraph("State Machine")) + , m_font(QFont("Helvetica [Cronxy]", 6)) + , m_interface(0) +{ + m_lastConfigurations.resize(5); + + ObjectBroker::registerClientObjectFactoryCallback(createStateMachineViewerClient); + m_interface = ObjectBroker::object(); + + m_ui->setupUi(this); + + m_graph->setFont(m_font); + + m_ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); + m_ui->graphicsView->setScene(new QGraphicsScene(this)); + m_ui->graphicsView->setRenderHint(QPainter::Antialiasing); + + QAbstractItemModel *stateMachineModel = ObjectBroker::model("com.kdab.GammaRay.StateMachineModel"); + m_ui->stateMachinesView->setModel(stateMachineModel); + m_ui->stateMachinesView->setSelectionModel(ObjectBroker::selectionModel(stateMachineModel)); + new DeferredResizeModeSetter(m_ui->stateMachinesView->header(), 0, QHeaderView::Stretch); + new DeferredResizeModeSetter(m_ui->stateMachinesView->header(), 1, QHeaderView::ResizeToContents); + new DeferredTreeViewConfiguration(m_ui->stateMachinesView, false); + + QAbstractItemModel *stateModel = ObjectBroker::model("com.kdab.GammaRay.StateModel"); + connect(stateModel, SIGNAL(modelReset()), this, SLOT(stateModelReset())); + + m_ui->singleStateMachineView->setModel(stateModel); + m_ui->singleStateMachineView->setSelectionModel(ObjectBroker::selectionModel(stateModel)); + m_ui->singleStateMachineView->setSelectionMode(QAbstractItemView::ExtendedSelection); + new DeferredResizeModeSetter(m_ui->singleStateMachineView->header(), 0, QHeaderView::Stretch); + new DeferredResizeModeSetter(m_ui->singleStateMachineView->header(), 1, QHeaderView::ResizeToContents); + new DeferredTreeViewConfiguration(m_ui->singleStateMachineView, true, false); + + connect(m_ui->depthSpinBox, SIGNAL(valueChanged(int)), m_interface, SLOT(setMaximumDepth(int))); + connect(m_ui->startStopButton, SIGNAL(clicked()), m_interface, SLOT(toggleRunning())); + connect(m_ui->exportButton, SIGNAL(clicked()), SLOT(exportAsImage())); + + m_ui->maxMegaPixelsSpinBox->setValue(maximumMegaPixels()); + connect(m_ui->maxMegaPixelsSpinBox, SIGNAL(valueChanged(int)), SLOT(setMaximumMegaPixels(int))); + + connect(m_interface, SIGNAL(maximumDepthChanged(int)), m_ui->depthSpinBox, SLOT(setValue(int))); + connect(m_interface, SIGNAL(message(QString)), this, SLOT(showMessage(QString))); + connect(m_interface, SIGNAL(aboutToRepopulateGraph()), this, SLOT(clearGraph())); + connect(m_interface, SIGNAL(graphRepopulated()), this, SLOT(repopulateView())); + connect(m_interface, SIGNAL(stateConfigurationChanged(GammaRay::StateMachineConfiguration)), + this, SLOT(stateConfigurationChanged(GammaRay::StateMachineConfiguration))); + connect(m_interface, SIGNAL(stateAdded(GammaRay::StateId,GammaRay::StateId,bool,QString,GammaRay::StateType,bool)), + this, SLOT(stateAdded(GammaRay::StateId,GammaRay::StateId,bool,QString,GammaRay::StateType,bool))); + connect(m_interface, SIGNAL(transitionAdded(GammaRay::TransitionId,GammaRay::StateId,GammaRay::StateId,QString)), + this, SLOT(transitionAdded(GammaRay::TransitionId,GammaRay::StateId,GammaRay::StateId,QString))); + connect(m_interface, SIGNAL(statusChanged(bool,bool)), this, SLOT(statusChanged(bool,bool))); + connect(m_interface, SIGNAL(transitionTriggered(GammaRay::TransitionId,QString)), + this, SLOT(transitionTriggered(GammaRay::TransitionId,QString))); + + m_interface->repopulateGraph(); +} + +StateMachineViewerWidget::~StateMachineViewerWidget() +{ +} + +void StateMachineViewerWidget::statusChanged(const bool haveStateMachine, const bool running) +{ + if (!running) { + m_ui->startStopButton->setChecked(false); + m_ui->startStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + } else { + m_ui->startStopButton->setChecked(true); + m_ui->startStopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop)); + } + m_ui->startStopButton->setEnabled(haveStateMachine); +} + +void StateMachineViewerWidget::clearView() +{ + m_ui->graphicsView->scene()->clear(); +} + +void StateMachineViewerWidget::repopulateView() +{ + clearView(); + + m_graph->applyLayout(); + + QGraphicsScene *scene = m_ui->graphicsView->scene(); + Q_FOREACH (const GVNodePair &nodePair, m_graph->gvNodes()) { + const NodeId &id = nodePair.first; + const GVNode &node = nodePair.second; + GVNodeItem *item = new GVNodeItem(node); + item->setData(KEY_STATETYPE, QVariant::fromValue(m_nodeTypeMap.value(id, OtherState))); + scene->addItem(item); + m_nodeItemMap.insert(id, item); + } + + Q_FOREACH (const GVEdgePair &edgePair, m_graph->gvEdges()) { + const EdgeId &id = edgePair.first; + const GVEdge &edge = edgePair.second; + GVEdgeItem *item = new GVEdgeItem(edge); + scene->addItem(item); + m_edgeItemMap.insert(id, item); + } + + Q_FOREACH (const GVSubGraphPair &graphPair, m_graph->gvSubGraphs()) { + const GraphId &id = graphPair.first; + const GVSubGraph &graph = graphPair.second; + GVGraphItem *item = new GVGraphItem(graph); + scene->addItem(item); + m_graphItemMap.insert(id, item); + } + + updateStateItems(); + updateTransitionItems(); + + // correctly set the scene rect + scene->setSceneRect(scene->itemsBoundingRect()); +} + +void StateMachineViewerWidget::clearGraph() +{ + m_graph->clear(); + + m_graphItemMap.clear(); + m_nodeItemMap.clear(); + m_edgeItemMap.clear(); + + m_stateGraphIdMap.clear(); + m_stateNodeIdMap.clear(); + m_transitionEdgeIdMap.clear(); + m_nodeTypeMap.clear(); + + m_lastTransitions.clear(); + m_lastConfigurations.clear(); +} + +void StateMachineViewerWidget::transitionTriggered(TransitionId transition, const QString &label) +{ + showMessage(tr("Transition triggered: %1").arg(label)); + + m_lastTransitions.enqueue(transition); + updateTransitionItems(); +} + +void StateMachineViewerWidget::showMessage(const QString &message) +{ + // update log + QPlainTextEdit *plainTextEdit = m_ui->plainTextEdit; + plainTextEdit->appendPlainText(message); + + // auto-scroll hack + QScrollBar *sb = plainTextEdit->verticalScrollBar(); + sb->setValue(sb->maximum()); +} + +void StateMachineViewerWidget::updateTransitionItems() +{ + // restore default color + Q_FOREACH (QGraphicsItem *item, m_ui->graphicsView->scene()->items()) { + GVEdgeItem *edgeItem = qgraphicsitem_cast(item); + if (edgeItem) { + edgeItem->setPen(QPen()); + } + } + + // set color based on recent usage + Q_FOREACH (TransitionId t, m_lastTransitions.entries()) { + EdgeId id = m_transitionEdgeIdMap.value(t); + GVEdgeItem *edgeItem = m_edgeItemMap.value(id); + if (!edgeItem) { + continue; + } + + QColor color(Qt::red); + color.setRedF(relativePosition(m_lastTransitions.entries(), t)); + QPen pen(Qt::DashLine); + pen.setWidth(2); + pen.setColor(color); + edgeItem->setPen(pen); + } +} + +void StateMachineViewerWidget::stateConfigurationChanged(const StateMachineConfiguration &config) +{ + if (m_lastConfigurations.size() > 0 && m_lastConfigurations.tail() == config) { + return; + } + + m_lastConfigurations.enqueue(config); + updateStateItems(); +} + +void StateMachineViewerWidget::updateStateItems() +{ + // initialize + Q_FOREACH (GVNodeItem* item, m_nodeItemMap) { + Q_ASSERT(item); + QColor color; + switch (item->data(KEY_STATETYPE).value()) { + case FinalState: + color = QColor(Qt::black); + break; + case StateMachineState: + color = QColor(Qt::gray); + break; + default: + color = QColor(Qt::white); + break; + } + QBrush brush = item->brush(); + if (brush.style() == Qt::NoBrush) + brush.setStyle(Qt::SolidPattern); + brush.setColor(color); + item->setBrush(brush); + } + + // color recent configurations based on last usage + // note that each configuration has the same color saturation atm + Q_FOREACH (const StateMachineConfiguration &config, m_lastConfigurations.entries()) { + const qreal alpha = relativePosition(m_lastConfigurations.entries(), config); + Q_FOREACH (StateId state, config) { + NodeId id = m_stateNodeIdMap.value(state); + GVNodeItem *nodeItem = m_nodeItemMap.value(id); + if (!nodeItem) { + continue; + } + + QColor color(Qt::red); + color.setAlphaF(alpha); + QBrush brush = nodeItem->brush(); + brush.setColor(color); + nodeItem->setBrush(brush); + } + } +} + +void StateMachineViewerWidget::stateAdded(const StateId state, const StateId parent, const bool hasChildren, + const QString &label, const StateType type, const bool connectToInitial) +{ + if (m_stateNodeIdMap.contains(state)) { + return; + } + + const GraphId parentGraphId = m_stateGraphIdMap.value(parent); + + GraphId graphId = parentGraphId; + + const QString stateId = QString::number(state); + if (parent && parentGraphId) { + if (hasChildren) { + // only create sub-graphs if we have child states + graphId = m_graph->addGraph(stateId, parentGraphId); + m_graph->setGraphAttr(QLatin1String("label"), label, graphId); + } + } else { + graphId = m_graph->addGraph(stateId); + m_graph->setGraphAttr(QLatin1String("label"), label, graphId); + } + Q_ASSERT(graphId); + + const NodeId nodeId = m_graph->addNode(stateId, graphId); + Q_ASSERT(nodeId); + m_graph->setNodeAttribute(nodeId, QLatin1String("label"), label); + m_nodeTypeMap.insert(nodeId, type); + + switch (type) { + case FinalState: + m_graph->setNodeAttribute(nodeId, "GammaRayStateType", "final"); + m_graph->setNodeAttribute(nodeId, "shape", "doublecircle"); + m_graph->setNodeAttribute(nodeId, "label", ""); + m_graph->setNodeAttribute(nodeId, "style", "filled"); + m_graph->setNodeAttribute(nodeId, "fillcolor", "black"); + m_graph->setNodeAttribute(nodeId, "fixedsize", "true"); + m_graph->setNodeAttribute(nodeId, "heigh", "0.15"); + m_graph->setNodeAttribute(nodeId, "width", "0.15"); + break; + case HistoryState: + m_graph->setNodeAttribute(nodeId, "GammaRayStateType", "history"); + m_graph->setNodeAttribute(nodeId, "label", "H"); + m_graph->setNodeAttribute(nodeId, "shape", "circle"); + break; + case StateMachineState: + case OtherState: + m_graph->setNodeAttribute(nodeId, "GammaRayStateType", "other"); + m_graph->setNodeAttribute(nodeId, "shape", "rectangle"); + m_graph->setNodeAttribute(nodeId, "style", "rounded"); + break; + } + + if (connectToInitial && parentGraphId) { + NodeId initialNode = m_graph->addNode(QString("initial-%1").arg(QString::number(parent)), parentGraphId); + m_graph->addEdge(initialNode, nodeId, QString()); + m_graph->setNodeAttribute(initialNode, "shape", "circle"); + m_graph->setNodeAttribute(initialNode, "style", "filled"); + m_graph->setNodeAttribute(initialNode, "fillcolor", "black"); + m_graph->setNodeAttribute(initialNode, "fixedsize", "true"); + m_graph->setNodeAttribute(initialNode, "heigh", "0.1"); + m_graph->setNodeAttribute(initialNode, "width", "0.1"); + m_graph->setNodeAttribute(initialNode, "label", ""); + } + + m_stateGraphIdMap.insert(state, graphId); + m_stateNodeIdMap.insert(state, nodeId); +} + +void StateMachineViewerWidget::transitionAdded(const TransitionId transition, const StateId source, const StateId target, const QString &label) +{ + NodeId sourceStateId = m_stateNodeIdMap.value(source); + NodeId targetStateId = m_stateNodeIdMap.value(target); + if (!sourceStateId || !targetStateId) { + return; + } + + EdgeId id = m_graph->addEdge(sourceStateId, targetStateId, QString::number(transition)); + Q_ASSERT(id); + + if (!label.isEmpty()) { + m_graph->setEdgeAttribute(id, QLatin1String("label"), label); + } + + m_transitionEdgeIdMap.insert(transition, id); +} + +int StateMachineViewerWidget::maximumMegaPixels() const +{ + return QSettings().value("StateMachineViewerServer/maximumMegaPixels", 10).toInt(); +} + +void StateMachineViewerWidget::setMaximumMegaPixels(int megaPixels) +{ + QSettings().setValue("StateMachineViewerServer/maximumMegaPixels", megaPixels); +} + +void StateMachineViewerWidget::exportAsImage() +{ + QSettings settings; + const QString key = QLatin1String("StateMachineViewerServer/imageDir"); + QString lastDir = settings.value(key).toString(); + + const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As Image"), + lastDir, tr("Images (*.png *.jpg *.jpeg)")); + if (fileName.isEmpty()) { + return; + } + + lastDir = QFileInfo(fileName).absolutePath(); + settings.setValue(key, lastDir); + + QGraphicsView* view = m_ui->graphicsView; + const QRectF sceneRect = view->transform().mapRect(view->sceneRect()); + QSizeF size(sceneRect.width(), sceneRect.height()); + + // limit mega pixels + const double maxPixels = maximumMegaPixels() * 1E+6; + const double actualMegaPixels = size.width() * size.height(); + if (actualMegaPixels > maxPixels && actualMegaPixels != 0) { + size *= sqrt(maxPixels / actualMegaPixels); + } + + int quality = -1; + const char* format; + if (fileName.endsWith(QLatin1String("jpg"), Qt::CaseInsensitive) + || fileName.endsWith(QLatin1String("jpeg"), Qt::CaseInsensitive)) { + format = "JPG"; + quality = 90; + } else { + format = "PNG"; + } + + QImage image(size.width() , size.height(), QImage::Format_ARGB32_Premultiplied); + image.fill(QColor(Qt::white).rgb()); + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + view->scene()->render(&painter); + + image.save(fileName, format, quality); +} + +void StateMachineViewerWidget::stateModelReset() +{ + m_ui->singleStateMachineView->expandAll(); + m_lastTransitions.clear(); + m_lastConfigurations.clear(); +} + + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(StateMachineViewerUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerwidget.h gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerwidget.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineviewerwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineviewerwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,108 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STATEMACHINEVIEWERWIDGET_H +#define GAMMARAY_STATEMACHINEVIEWERWIDGET_H + +#include +#include "statemachineviewerinterface.h" + +#include "statemachineviewerutil.h" + +#include "gvgraph/gvtypes.h" + +#include +#include + +class QModelIndex; + +namespace GammaRay { + +class GVGraph; + +namespace Ui { + class StateMachineViewer; +} + +class GVNodeItem; +class GVEdgeItem; +class GVGraphItem; + +class StateMachineViewerWidget : public QWidget +{ + Q_OBJECT + public: + explicit StateMachineViewerWidget(QWidget *parent = 0, Qt::WindowFlags f = 0); + ~StateMachineViewerWidget(); + + private slots: + void clearView(); + void repopulateView(); + void clearGraph(); + void stateAdded(const GammaRay::StateId state, const GammaRay::StateId parent, const bool hasChildren, + const QString &label, const GammaRay::StateType type, const bool connectToInitial); + void stateConfigurationChanged(const GammaRay::StateMachineConfiguration &config); + void transitionAdded(const GammaRay::TransitionId transition, const GammaRay::StateId source, const GammaRay::StateId target, + const QString &label); + void transitionTriggered(GammaRay::TransitionId transition, const QString &label); + void showMessage(const QString &message); + void statusChanged(const bool haveStateMachine, const bool running); + + void exportAsImage(); + void stateModelReset(); + void setMaximumMegaPixels(int); + + private: + void updateStateItems(); + void updateTransitionItems(); + int maximumMegaPixels() const; + + QScopedPointer m_ui; + + GVGraph *m_graph; + QFont m_font; + + QHash m_transitionEdgeIdMap; + QHash m_stateGraphIdMap; + QHash m_stateNodeIdMap; + + QHash m_edgeItemMap; + QHash m_graphItemMap; + QHash m_nodeItemMap; + QHash m_nodeTypeMap; + + RingBuffer m_lastConfigurations; + RingBuffer m_lastTransitions; + + StateMachineViewerInterface *m_interface; +}; + +class StateMachineViewerUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.StateMachineViewerUi") +}; + +} + +#endif // GAMMARAY_STATEMACHINEVIEWERWIDGET_H diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachineview.h gammaray-2.0.1/plugins/statemachineviewer/statemachineview.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachineview.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachineview.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachinewatcher.cpp gammaray-2.0.1/plugins/statemachineviewer/statemachinewatcher.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemachinewatcher.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachinewatcher.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -73,6 +73,8 @@ this, SLOT(handleStateEntered()), Qt::UniqueConnection); connect(state, SIGNAL(exited()), this, SLOT(handleStateExited()), Qt::UniqueConnection); + connect(state, SIGNAL(destroyed(QObject*)), + this, SLOT(handleStateDestroyed()), Qt::UniqueConnection); Q_FOREACH (QAbstractTransition *transition, state->findChildren()) { connect(transition, SIGNAL(triggered()), @@ -86,6 +88,7 @@ Q_FOREACH (QAbstractState *state, m_watchedStates) { disconnect(state, SIGNAL(entered()), this, SLOT(handleStateEntered())); disconnect(state, SIGNAL(exited()), this, SLOT(handleStateExited())); + disconnect(state, SIGNAL(destroyed(QObject*)), this, SLOT(handleStateDestroyed())); Q_FOREACH (QAbstractTransition *transition, state->findChildren()) { disconnect(transition, SIGNAL(triggered()), this, SLOT(handleTransitionTriggered())); @@ -136,4 +139,12 @@ emit stateExited(state); } -#include "statemachinewatcher.moc" +void StateMachineWatcher::handleStateDestroyed() +{ + QAbstractState* state = static_cast(QObject::sender()); + Q_ASSERT(state); + + const int index = m_watchedStates.indexOf(state); + Q_ASSERT(index != -1); + m_watchedStates.remove(index); +} diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemachinewatcher.h gammaray-2.0.1/plugins/statemachineviewer/statemachinewatcher.h --- gammaray-1.2.2/plugins/statemachineviewer/statemachinewatcher.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemachinewatcher.h 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -57,6 +57,7 @@ void handleStateEntered(); void handleStateExited(); + void handleStateDestroyed(); void handleTransitionTriggered(); private: diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemodel.cpp gammaray-2.0.1/plugins/statemachineviewer/statemodel.cpp --- gammaray-1.2.2/plugins/statemachineviewer/statemodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ #include "statemodel.h" #include "statemachinewatcher.h" -#include "include/util.h" +#include #include #include @@ -43,21 +43,26 @@ m_stateMachine(0), m_stateMachineWatcher(new StateMachineWatcher(qq)) { - Q_ASSERT(qq->connect(m_stateMachineWatcher, SIGNAL(transitionTriggered(QAbstractTransition*)), - qq, SLOT(transitionTriggered(QAbstractTransition*)))); + Q_ASSERT(qq->connect(m_stateMachineWatcher, SIGNAL(stateEntered(QAbstractState*)), + qq, SLOT(stateConfigurationChanged()))); + Q_ASSERT(qq->connect(m_stateMachineWatcher, SIGNAL(stateExited(QAbstractState*)), + qq, SLOT(stateConfigurationChanged()))); } Q_DECLARE_PUBLIC(StateModel) StateModel * const q_ptr; StateMachineWatcher * const m_stateMachineWatcher; QStateMachine *m_stateMachine; + QSet m_lastConfiguration; QList children(QObject *parent) const; QObject *mapModelIndex2QObject(const QModelIndex &) const; + QModelIndex indexForState(QAbstractState *state) const; // private slots: - void transitionTriggered(QAbstractTransition*); + void stateConfigurationChanged(); + void handleMachineDestroyed(QObject*); }; } @@ -75,7 +80,7 @@ } foreach (QObject *o, parent->children()) { - if (o->inherits("QState")) { + if (o->inherits("QAbstractState")) { result.append(o); } } @@ -93,13 +98,52 @@ return m_stateMachine; } -void StateModelPrivate::transitionTriggered(QAbstractTransition *transition) +QModelIndex StateModelPrivate::indexForState(QAbstractState *state) const +{ + Q_ASSERT(state); + + if (state == m_stateMachine) { + return QModelIndex(); + } + + Q_ASSERT(state->parentState()); + Q_Q(const StateModel); + int row = children(state->parentState()).indexOf(state); + if (row == -1) { + return QModelIndex(); + } + return q->index(row, 0, indexForState(state->parentState())); +} + +void StateModelPrivate::stateConfigurationChanged() +{ + Q_Q(StateModel); + + QSet newConfig = m_stateMachine->configuration(); + // states which became active + foreach(QAbstractState *state, (newConfig - m_lastConfiguration)) { + const QModelIndex source = indexForState(state); + if (source.isValid()) { + q->dataChanged(source, source); + } + } + // states which became inactive + foreach(QAbstractState *state, (m_lastConfiguration - newConfig)) { + const QModelIndex source = indexForState(state); + if (source.isValid()) { + q->dataChanged(source, source); + } + } + m_lastConfiguration = newConfig; +} + +void StateModelPrivate::handleMachineDestroyed(QObject*) { - Q_UNUSED(transition); Q_Q(StateModel); - // TODO: Make this more efficient? Find out the changed states and update just these indices - q->dataChanged(QModelIndex(), QModelIndex()); + q->beginResetModel(); + m_stateMachine = 0; + q->endResetModel(); } StateModel::StateModel(QObject *parent) @@ -123,10 +167,19 @@ return; } + if (d->m_stateMachine) { + disconnect(d->m_stateMachine, SIGNAL(destroyed(QObject*)), this, SLOT(handleMachineDestroyed(QObject*))); + } + beginResetModel(); d->m_stateMachine = stateMachine; + d->m_lastConfiguration = (stateMachine ? stateMachine->configuration() : QSet()); endResetModel(); + if (d->m_stateMachine) { + connect(d->m_stateMachine, SIGNAL(destroyed(QObject*)), this, SLOT(handleMachineDestroyed(QObject*))); + } + d->m_stateMachineWatcher->setWatchedStateMachine(stateMachine); } @@ -175,7 +228,7 @@ } if (index.column() == 0 && role == Qt::CheckStateRole) { - QState *s = qobject_cast(obj); + QAbstractState *s = qobject_cast(obj); if (s) { return d->m_stateMachine->configuration().contains(s) ? Qt::Checked : Qt::Unchecked; } @@ -234,4 +287,4 @@ return createIndex(row, 0, grandParent); } -#include "statemodel.moc" +#include "moc_statemodel.cpp" diff -Nru gammaray-1.2.2/plugins/statemachineviewer/statemodel.h gammaray-2.0.1/plugins/statemachineviewer/statemodel.h --- gammaray-1.2.2/plugins/statemachineviewer/statemodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/statemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ #ifndef GAMMARAY_STATEMACHINEVIEWER_STATEMODEL_H #define GAMMARAY_STATEMACHINEVIEWER_STATEMODEL_H -#include "include/objectmodelbase.h" +#include class QAbstractTransition; class QStateMachine; @@ -40,7 +40,7 @@ enum Roles { TransitionsRole = ObjectModel::UserRole + 1, IsInitialStateRole, - StateObjectRole = Qt::UserRole + 11 + StateObjectRole = ObjectModel::UserRole + 11 }; explicit StateModel(QObject *parent = 0); ~StateModel(); @@ -58,7 +58,8 @@ StateModelPrivate * const d_ptr; private: - Q_PRIVATE_SLOT(d_func(), void transitionTriggered(QAbstractTransition*)) + Q_PRIVATE_SLOT(d_func(), void stateConfigurationChanged()) + Q_PRIVATE_SLOT(d_func(), void handleMachineDestroyed(QObject*)); }; } diff -Nru gammaray-1.2.2/plugins/statemachineviewer/test_main.cpp gammaray-2.0.1/plugins/statemachineviewer/test_main.cpp --- gammaray-1.2.2/plugins/statemachineviewer/test_main.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/test_main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -2,7 +2,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Kevin Funk This program is free software; you can redistribute it and/or modify @@ -60,15 +60,18 @@ Q_FOREACH (const GVNodePair &pair, graph->gvNodes()) { const GVNode node = pair.second; - new GVNodeItem(node, 0, scene); + QGraphicsItem *item = new GVNodeItem(node, 0); + scene->addItem(item); } Q_FOREACH (const GVEdgePair &pair, graph->gvEdges()) { const GVEdge edge = pair.second; - new GVEdgeItem(edge, 0, scene); + QGraphicsItem *item = new GVEdgeItem(edge, 0); + scene->addItem(item); } Q_FOREACH (const GVSubGraphPair &pair, graph->gvSubGraphs()) { const GVSubGraph graph = pair.second; - new GVGraphItem(graph, 0, scene); + QGraphicsItem *item = new GVGraphItem(graph, 0); + scene->addItem(item); } delete graph; graph = 0; diff -Nru gammaray-1.2.2/plugins/statemachineviewer/transitionmodel.cpp gammaray-2.0.1/plugins/statemachineviewer/transitionmodel.cpp --- gammaray-1.2.2/plugins/statemachineviewer/transitionmodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/transitionmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ #include "transitionmodel.h" -#include "include/util.h" +#include #include #include diff -Nru gammaray-1.2.2/plugins/statemachineviewer/transitionmodel.h gammaray-2.0.1/plugins/statemachineviewer/transitionmodel.h --- gammaray-1.2.2/plugins/statemachineviewer/transitionmodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/statemachineviewer/transitionmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Stephen Kelly This program is free software; you can redistribute it and/or modify @@ -24,7 +24,7 @@ #ifndef GAMMARAY_STATEMACHINEVIEWER_TRANSITIONMODEL_H #define GAMMARAY_STATEMACHINEVIEWER_TRANSITIONMODEL_H -#include "include/objectmodelbase.h" +#include class QAbstractState; @@ -35,7 +35,7 @@ class TransitionModel : public ObjectModelBase { public: - TransitionModel(QObject *parent = 0); + explicit TransitionModel(QObject *parent = 0); ~TransitionModel(); void setState(QAbstractState *state); int columnCount(const QModelIndex &parent = QModelIndex()) const; diff -Nru gammaray-1.2.2/plugins/styleinspector/abstractstyleelementmodel.cpp gammaray-2.0.1/plugins/styleinspector/abstractstyleelementmodel.cpp --- gammaray-1.2.2/plugins/styleinspector/abstractstyleelementmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/abstractstyleelementmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,80 @@ +/* + abstractstyleelementmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "abstractstyleelementmodel.h" + +#include +#include +#include + +using namespace GammaRay; + +AbstractStyleElementModel::AbstractStyleElementModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +void AbstractStyleElementModel::setStyle(QStyle *style) +{ + beginResetModel(); + m_style = QPointer(style); + endResetModel(); +} + +QVariant AbstractStyleElementModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || !m_style) { + return QVariant(); + } + return doData(index.row(), index.column(), role); +} + +int AbstractStyleElementModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return doColumnCount(); +} + +int AbstractStyleElementModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid() || !m_style) { + return 0; + } + return doRowCount(); +} + +bool AbstractStyleElementModel::isMainStyle() const +{ + QStyle *style = qApp->style(); + forever { + if (style == m_style) { + return true; + } + QProxyStyle *proxy = qobject_cast(style); + if (!proxy) { + return false; + } + style = proxy->baseStyle(); + } +} + diff -Nru gammaray-1.2.2/plugins/styleinspector/abstractstyleelementmodel.h gammaray-2.0.1/plugins/styleinspector/abstractstyleelementmodel.h --- gammaray-1.2.2/plugins/styleinspector/abstractstyleelementmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/abstractstyleelementmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,67 @@ +/* + abstractstyleelementmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTMODEL_H +#define GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTMODEL_H + +#include +#include + +class QStyle; + +namespace GammaRay { + +/** + * Base class for all models showing style elements. + */ +class AbstractStyleElementModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit AbstractStyleElementModel(QObject *parent = 0); + + void setStyle(QStyle *style); + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + protected: + virtual QVariant doData(int row, int column, int role) const = 0; + virtual int doColumnCount() const = 0; + virtual int doRowCount() const = 0; + + /** Returns @c true if we are looking at the primary style of the application + * ie. the one set in QApplication. This takes proxy styles into account. + */ + bool isMainStyle() const; + + protected: + QPointer m_style; +}; + +} + +#endif // GAMMARAY_ABSTRACTSTYLEELEMENTMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/abstractstyleelementstatetable.cpp gammaray-2.0.1/plugins/styleinspector/abstractstyleelementstatetable.cpp --- gammaray-1.2.2/plugins/styleinspector/abstractstyleelementstatetable.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/abstractstyleelementstatetable.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,78 @@ +/* + abstractstyleelementstatetable.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "abstractstyleelementstatetable.h" +#include "styleoption.h" +#include "styleinspectorinterface.h" +#include + +#include +#include +#include + +using namespace GammaRay; + +AbstractStyleElementStateTable::AbstractStyleElementStateTable(QObject *parent) + : AbstractStyleElementModel(parent), + m_interface(ObjectBroker::object()) +{ + connect(m_interface, SIGNAL(cellSizeChanged()), SLOT(cellSizeChanged())); +} + +void AbstractStyleElementStateTable::cellSizeChanged() +{ + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} + +int AbstractStyleElementStateTable::doColumnCount() const +{ + return StyleOption::stateCount(); +} + +QVariant AbstractStyleElementStateTable::doData(int row, int column, int role) const +{ + Q_UNUSED(column); + Q_UNUSED(row); + if (role == Qt::SizeHintRole) { + return m_interface->cellSizeHint(); + } + return QVariant(); +} + +QVariant AbstractStyleElementStateTable::headerData(int section, + Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && (role == Qt::DisplayRole || role == Qt::ToolTipRole)) { + return StyleOption::stateDisplayName(section); + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +void AbstractStyleElementStateTable::fillStyleOption(QStyleOption *option, int column) const +{ + option->rect = QRect(0, 0, m_interface->cellWidth(), m_interface->cellHeight()); + option->palette = m_style->standardPalette(); + option->state = StyleOption::prettyState(column); +} + diff -Nru gammaray-1.2.2/plugins/styleinspector/abstractstyleelementstatetable.h gammaray-2.0.1/plugins/styleinspector/abstractstyleelementstatetable.h --- gammaray-1.2.2/plugins/styleinspector/abstractstyleelementstatetable.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/abstractstyleelementstatetable.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,67 @@ +/* + abstractstyleelementstatetable.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTSTATETABLE_H +#define GAMMARAY_STYLEINSPECTOR_ABSTRACTSTYLEELEMENTSTATETABLE_H + +#include "abstractstyleelementmodel.h" +#include + +class QStyleOption; +class QRect; +class QPainter; + +namespace GammaRay { + +class StyleInspectorInterface; + +/** + * Base class for style element x style option state tables. + * Covers the state part, sub-classes need to fill in the corresponding rows. + */ +class AbstractStyleElementStateTable : public GammaRay::AbstractStyleElementModel +{ + Q_OBJECT + public: + explicit AbstractStyleElementStateTable(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + protected: + virtual int doColumnCount() const; + virtual QVariant doData(int row, int column, int role) const; + + /// standard setup for the style option used in a cell in column @p column + void fillStyleOption(QStyleOption *option, int column) const; + + protected: + StyleInspectorInterface *m_interface; + + private slots: + void cellSizeChanged(); +}; + +} + +#endif // GAMMARAY_ABSTRACTSTYLEELEMENTSTATETABLE_H diff -Nru gammaray-1.2.2/plugins/styleinspector/CMakeLists.txt gammaray-2.0.1/plugins/styleinspector/CMakeLists.txt --- gammaray-1.2.2/plugins/styleinspector/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,37 @@ +set(gammaray_styleinspector_plugin_srcs + styleinspector.cpp + styleinspectorwidget.cpp + pixelmetricmodel.cpp + standardiconmodel.cpp + primitivemodel.cpp + controlmodel.cpp + styleoption.cpp + abstractstyleelementmodel.cpp + abstractstyleelementstatetable.cpp + styleelementstatetablepage.cpp + complexcontrolmodel.cpp + dynamicproxystyle.cpp + styleinspectorinterface.cpp + styleinspectorclient.cpp +) + +qt4_wrap_ui(gammaray_styleinspector_plugin_srcs + styleinspectorwidget.ui + styleelementstatetablepage.ui +) + +gammaray_add_plugin(gammaray_styleinspector_plugin + gammaray_styleinspector.desktop + ${gammaray_styleinspector_plugin_srcs} +) + +target_link_libraries(gammaray_styleinspector_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_core + gammaray_ui +) + +if(QNXNTO) + target_link_libraries(gammaray_styleinspector_plugin cpp) +endif() diff -Nru gammaray-1.2.2/plugins/styleinspector/complexcontrolmodel.cpp gammaray-2.0.1/plugins/styleinspector/complexcontrolmodel.cpp --- gammaray-1.2.2/plugins/styleinspector/complexcontrolmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/complexcontrolmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,111 @@ +/* + complexcontrolmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "complexcontrolmodel.h" +#include "styleoption.h" +#include "styleinspectorinterface.h" +#include + +#include +#include +#include + +using namespace GammaRay; + +struct complex_control_element_t { + const char *name; + QStyle::ComplexControl control; + QStyleOption * (*styleOptionFactory)(); + QStyle::SubControls subControls; +}; + +#define MAKE_CC2( control, factory ) { #control, QStyle:: control, &StyleOption:: factory, 0 } +#define MAKE_CC3( control, factory, subControls ) { #control, QStyle:: control, &StyleOption:: factory, subControls } + +static complex_control_element_t complexControlElements[] = { + MAKE_CC3(CC_SpinBox, makeSpinBoxStyleOption, QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown | QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField), + MAKE_CC3(CC_ComboBox, makeComboBoxStyleOption, QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxArrow | QStyle::SC_ComboBoxEditField | QStyle::SC_ComboBoxListBoxPopup), + MAKE_CC3(CC_ScrollBar, makeSliderStyleOption, QStyle::SC_ScrollBarAddLine | QStyle::SC_ScrollBarSubLine | QStyle::SC_ScrollBarAddPage | QStyle::SC_ScrollBarSubPage | QStyle::SC_ScrollBarFirst | QStyle::SC_ScrollBarLast | QStyle::SC_ScrollBarSlider | QStyle::SC_ScrollBarGroove), + MAKE_CC3(CC_Slider, makeSliderStyleOption, QStyle::SC_SliderGroove | QStyle::SC_SliderHandle | QStyle::SC_SliderTickmarks), + MAKE_CC3(CC_ToolButton, makeToolButtonStyleOption, QStyle::SC_ToolButton | QStyle::SC_ToolButtonMenu), + MAKE_CC3(CC_TitleBar, makeTitleBarStyleOption, QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarMinButton | QStyle::SC_TitleBarMaxButton | QStyle::SC_TitleBarCloseButton | QStyle::SC_TitleBarLabel | QStyle::SC_TitleBarNormalButton | QStyle::SC_TitleBarShadeButton | QStyle::SC_TitleBarUnshadeButton | QStyle::SC_TitleBarContextHelpButton), +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + MAKE_CC2(CC_Q3ListView, makeStyleOptionComplex), +#endif + MAKE_CC3(CC_Dial, makeSliderStyleOption, QStyle::SC_DialHandle | QStyle::SC_DialGroove | QStyle::SC_DialTickmarks), + MAKE_CC2(CC_GroupBox, makeStyleOptionComplex), +// MAKE_CC2(CC_GroupBox, makeGroupBoxStyleOption), // TODO: oxygen crashes with that due to widget access + MAKE_CC3(CC_MdiControls, makeStyleOptionComplex, QStyle::SC_MdiNormalButton | QStyle::SC_MdiMinButton | QStyle::SC_MdiCloseButton) +}; + +ComplexControlModel::ComplexControlModel(QObject *parent) : AbstractStyleElementStateTable(parent) +{ +} + +QVariant ComplexControlModel::doData(int row, int column, int role) const +{ + if (role == Qt::DecorationRole) { + QPixmap pixmap(m_interface->cellSizeHint()); + QPainter painter(&pixmap); + Util::drawTransparencyPattern(&painter, pixmap.rect()); + painter.scale(m_interface->cellZoom(), m_interface->cellZoom()); + + QScopedPointer opt( + qstyleoption_cast(complexControlElements[row].styleOptionFactory())); + Q_ASSERT(opt); + fillStyleOption(opt.data(), column); + m_style->drawComplexControl(complexControlElements[row].control, opt.data(), &painter); + + int colorIndex = 7; + for (int i = 0; i < 32; ++i) { + QStyle::SubControl sc = static_cast(1 << i); + if (sc & complexControlElements[row].subControls) { + QRectF scRect = + m_style->subControlRect(complexControlElements[row].control, opt.data(), sc); + scRect.adjust(0, 0, -1.0 / m_interface->cellZoom(), -1.0 / m_interface->cellZoom()); + if (scRect.isValid() && !scRect.isEmpty()) { + // HACK: add some real color mapping + painter.setPen(static_cast(colorIndex++)); + painter.drawRect(scRect); + } + } + } + + return pixmap; + } + + return AbstractStyleElementStateTable::doData(row, column, role); +} + +int ComplexControlModel::doRowCount() const +{ + return sizeof(complexControlElements) / sizeof(complexControlElements[0]); +} + +QVariant ComplexControlModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { + return complexControlElements[section].name; + } + return AbstractStyleElementStateTable::headerData(section, orientation, role); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/complexcontrolmodel.h gammaray-2.0.1/plugins/styleinspector/complexcontrolmodel.h --- gammaray-1.2.2/plugins/styleinspector/complexcontrolmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/complexcontrolmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,47 @@ +/* + complexcontrolmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_COMPLEXCONTROLMODEL_H +#define GAMMARAY_STYLEINSPECTOR_COMPLEXCONTROLMODEL_H + +#include "abstractstyleelementstatetable.h" + +namespace GammaRay { + +class ComplexControlModel : public AbstractStyleElementStateTable +{ + Q_OBJECT + public: + explicit ComplexControlModel(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + protected: + virtual QVariant doData(int row, int column, int role) const; + virtual int doRowCount() const; +}; + +} + +#endif // GAMMARAY_COMPLEXCONTROLMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/controlmodel.cpp gammaray-2.0.1/plugins/styleinspector/controlmodel.cpp --- gammaray-1.2.2/plugins/styleinspector/controlmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/controlmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,130 @@ +/* + controlmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "controlmodel.h" +#include "styleoption.h" +#include "styleinspectorinterface.h" +#include + +#include +#include +#include + +using namespace GammaRay; + +struct control_element_t { + const char *name; + QStyle::ControlElement control; + QStyleOption * (*styleOptionFactory)(); +}; + +#define MAKE_CE( control ) { #control , QStyle:: control, &StyleOption::makeStyleOption } +#define MAKE_CE_X( control, factory ) { #control, QStyle:: control, &StyleOption:: factory } + +static control_element_t controlElements[] = { + MAKE_CE_X(CE_PushButton, makeButtonStyleOption), + MAKE_CE_X(CE_PushButtonBevel, makeButtonStyleOption), + MAKE_CE_X(CE_PushButtonLabel, makeButtonStyleOption), + MAKE_CE_X(CE_CheckBox, makeButtonStyleOption), + MAKE_CE_X(CE_CheckBoxLabel, makeButtonStyleOption), + MAKE_CE_X(CE_RadioButton, makeButtonStyleOption), + MAKE_CE_X(CE_RadioButtonLabel, makeButtonStyleOption), + MAKE_CE_X(CE_TabBarTab, makeTabStyleOption), + MAKE_CE_X(CE_TabBarTabShape, makeTabStyleOption), + MAKE_CE_X(CE_TabBarTabLabel, makeTabStyleOption), + MAKE_CE_X(CE_ProgressBar, makeProgressBarStyleOption), + MAKE_CE_X(CE_ProgressBarGroove, makeProgressBarStyleOption), + MAKE_CE_X(CE_ProgressBarContents, makeProgressBarStyleOption), + MAKE_CE_X(CE_ProgressBarLabel, makeProgressBarStyleOption), + MAKE_CE_X(CE_MenuItem, makeMenuStyleOption), + MAKE_CE(CE_MenuScroller), + MAKE_CE(CE_MenuVMargin), + MAKE_CE(CE_MenuHMargin), + MAKE_CE(CE_MenuTearoff), + MAKE_CE(CE_MenuEmptyArea), + MAKE_CE_X(CE_MenuBarItem, makeMenuStyleOption), + MAKE_CE(CE_MenuBarEmptyArea), + MAKE_CE_X(CE_ToolButtonLabel, makeToolButtonStyleOption), + MAKE_CE_X(CE_Header, makeHeaderStyleOption), + MAKE_CE_X(CE_HeaderSection, makeHeaderStyleOption), + MAKE_CE_X(CE_HeaderLabel, makeHeaderStyleOption), +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + MAKE_CE(CE_Q3DockWindowEmptyArea), +#endif + MAKE_CE_X(CE_ToolBoxTab, makeToolBoxStyleOption), + MAKE_CE(CE_SizeGrip), + MAKE_CE(CE_Splitter), + MAKE_CE(CE_RubberBand), + MAKE_CE(CE_DockWidgetTitle), + MAKE_CE_X(CE_ScrollBarAddLine, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarSubLine, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarAddPage, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarSubPage, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarSlider, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarFirst, makeSliderStyleOption), + MAKE_CE_X(CE_ScrollBarLast, makeSliderStyleOption), + MAKE_CE(CE_FocusFrame), + MAKE_CE_X(CE_ComboBoxLabel, makeComboBoxStyleOption), + MAKE_CE(CE_ToolBar), + MAKE_CE_X(CE_ToolBoxTabShape, makeToolBoxStyleOption), + MAKE_CE_X(CE_ToolBoxTabLabel, makeToolBoxStyleOption), + MAKE_CE_X(CE_HeaderEmptyArea, makeHeaderStyleOption), + MAKE_CE(CE_ColumnViewGrip), + MAKE_CE_X(CE_ItemViewItem, makeItemViewStyleOption), + MAKE_CE_X(CE_ShapedFrame, makeFrameStyleOption) +}; + +ControlModel::ControlModel(QObject *parent) + : AbstractStyleElementStateTable(parent) +{ +} + +QVariant ControlModel::doData(int row, int column, int role) const +{ + if (role == Qt::DecorationRole) { + QPixmap pixmap(m_interface->cellSizeHint()); + QPainter painter(&pixmap); + Util::drawTransparencyPattern(&painter, pixmap.rect()); + painter.scale(m_interface->cellZoom(), m_interface->cellZoom()); + + QScopedPointer opt(controlElements[row].styleOptionFactory()); + fillStyleOption(opt.data(), column); + m_style->drawControl(controlElements[row].control, opt.data(), &painter); + return pixmap; + } + + return AbstractStyleElementStateTable::doData(row, column, role); +} + +int ControlModel::doRowCount() const +{ + return sizeof(controlElements) / sizeof(controlElements[0]); +} + +QVariant ControlModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { + return controlElements[section].name; + } + return AbstractStyleElementStateTable::headerData(section, orientation, role); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/controlmodel.h gammaray-2.0.1/plugins/styleinspector/controlmodel.h --- gammaray-1.2.2/plugins/styleinspector/controlmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/controlmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + controlmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_CONTROLMODEL_H +#define GAMMARAY_STYLEINSPECTOR_CONTROLMODEL_H + +#include "abstractstyleelementstatetable.h" + +namespace GammaRay { + +/** + * Model for listing all controls provided by a QStyle. + */ +class ControlModel : public AbstractStyleElementStateTable +{ + Q_OBJECT + public: + explicit ControlModel(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + protected: + virtual QVariant doData(int row, int column, int role) const; + virtual int doRowCount() const; +}; + +} + +#endif // GAMMARAY_CONTROLMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/dynamicproxystyle.cpp gammaray-2.0.1/plugins/styleinspector/dynamicproxystyle.cpp --- gammaray-1.2.2/plugins/styleinspector/dynamicproxystyle.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/dynamicproxystyle.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,72 @@ +/* + dynamicproxystyle.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "dynamicproxystyle.h" + +#include + +using namespace GammaRay; + +QWeakPointer DynamicProxyStyle::s_instance; + +DynamicProxyStyle::DynamicProxyStyle(QStyle *baseStyle) + : QProxyStyle(baseStyle) +{ + s_instance = QWeakPointer(this); +} + +DynamicProxyStyle *DynamicProxyStyle::instance() +{ + if (!s_instance) { + insertProxyStyle(); + } + return s_instance.data(); +} + +bool DynamicProxyStyle::exists() +{ + return s_instance; +} + +void DynamicProxyStyle::insertProxyStyle() +{ + // TODO: if the current style is a CSS proxy, add us underneath + // to avoid Qt adding yet another CSS proxy on top + qApp->setStyle(new DynamicProxyStyle(qApp->style())); +} + +void DynamicProxyStyle::setPixelMetric(QStyle::PixelMetric metric, int value) +{ + m_pixelMetrics.insert(metric, value); +} + +int DynamicProxyStyle::pixelMetric(QStyle::PixelMetric metric, + const QStyleOption *option, + const QWidget *widget) const +{ + QHash::const_iterator it = m_pixelMetrics.find(metric); + if (it != m_pixelMetrics.end()) { + return it.value(); + } + return QProxyStyle::pixelMetric(metric, option, widget); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/dynamicproxystyle.h gammaray-2.0.1/plugins/styleinspector/dynamicproxystyle.h --- gammaray-1.2.2/plugins/styleinspector/dynamicproxystyle.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/dynamicproxystyle.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + dynamicproxystyle.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_DYNAMICPROXYSTYLE_H +#define GAMMARAY_STYLEINSPECTOR_DYNAMICPROXYSTYLE_H + +#include +#include + +namespace GammaRay { + +/** + * A proxy style that allows runtime-editing of various parameters. + */ +class DynamicProxyStyle : public QProxyStyle +{ + Q_OBJECT + public: + explicit DynamicProxyStyle(QStyle *baseStyle); + + static DynamicProxyStyle *instance(); + static bool exists(); + static void insertProxyStyle(); + + void setPixelMetric(PixelMetric metric, int value); + + virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, + const QWidget *widget = 0) const; + + private: + QHash m_pixelMetrics; + static QWeakPointer s_instance; +}; + +} + +#endif // GAMMARAY_DYNAMICPROXYSTYLE_H diff -Nru gammaray-1.2.2/plugins/styleinspector/gammaray_styleinspector.desktop gammaray-2.0.1/plugins/styleinspector/gammaray_styleinspector.desktop --- gammaray-1.2.2/plugins/styleinspector/gammaray_styleinspector.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/gammaray_styleinspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Style +X-GammaRay-Types=QStyle; +X-GammaRay-ServiceTypes="com.kdab.GammaRay.ToolFactory;com.kdab.GammaRay.ToolUiFactory" +Exec=gammaray_styleinspector_plugin diff -Nru gammaray-1.2.2/plugins/styleinspector/pixelmetricmodel.cpp gammaray-2.0.1/plugins/styleinspector/pixelmetricmodel.cpp --- gammaray-1.2.2/plugins/styleinspector/pixelmetricmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/pixelmetricmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,203 @@ +/* + pixelmetricmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "pixelmetricmodel.h" +#include "dynamicproxystyle.h" + +#include + +using namespace GammaRay; + +struct pixel_metric_t { + const char *name; + QStyle::PixelMetric pixelMetric; +}; + +#define MAKE_PM(metric) { #metric, QStyle:: metric } + +static pixel_metric_t pixelMetrics[] = { + MAKE_PM(PM_ButtonMargin), + MAKE_PM(PM_ButtonDefaultIndicator), + MAKE_PM(PM_MenuButtonIndicator), + MAKE_PM(PM_ButtonShiftHorizontal), + MAKE_PM(PM_ButtonShiftVertical), + MAKE_PM(PM_DefaultFrameWidth), + MAKE_PM(PM_SpinBoxFrameWidth), + MAKE_PM(PM_ComboBoxFrameWidth), + MAKE_PM(PM_MaximumDragDistance), + MAKE_PM(PM_ScrollBarExtent), + MAKE_PM(PM_ScrollBarSliderMin), + MAKE_PM(PM_SliderThickness), + MAKE_PM(PM_SliderControlThickness), + MAKE_PM(PM_SliderLength), + MAKE_PM(PM_SliderTickmarkOffset), + MAKE_PM(PM_SliderSpaceAvailable), + MAKE_PM(PM_DockWidgetSeparatorExtent), + MAKE_PM(PM_DockWidgetHandleExtent), + MAKE_PM(PM_DockWidgetFrameWidth), + MAKE_PM(PM_TabBarTabOverlap), + MAKE_PM(PM_TabBarTabHSpace), + MAKE_PM(PM_TabBarTabVSpace), + MAKE_PM(PM_TabBarBaseHeight), + MAKE_PM(PM_TabBarBaseOverlap), + MAKE_PM(PM_ProgressBarChunkWidth), + MAKE_PM(PM_SplitterWidth), + MAKE_PM(PM_TitleBarHeight), + MAKE_PM(PM_MenuScrollerHeight), + MAKE_PM(PM_MenuHMargin), + MAKE_PM(PM_MenuVMargin), + MAKE_PM(PM_MenuPanelWidth), + MAKE_PM(PM_MenuTearoffHeight), + MAKE_PM(PM_MenuDesktopFrameWidth), + MAKE_PM(PM_MenuBarPanelWidth), + MAKE_PM(PM_MenuBarItemSpacing), + MAKE_PM(PM_MenuBarVMargin), + MAKE_PM(PM_MenuBarHMargin), + MAKE_PM(PM_IndicatorWidth), + MAKE_PM(PM_IndicatorHeight), + MAKE_PM(PM_ExclusiveIndicatorWidth), + MAKE_PM(PM_ExclusiveIndicatorHeight), +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + MAKE_PM(PM_CheckListButtonSize), + MAKE_PM(PM_CheckListControllerSize), +#endif + MAKE_PM(PM_DialogButtonsSeparator), + MAKE_PM(PM_DialogButtonsButtonWidth), + MAKE_PM(PM_DialogButtonsButtonHeight), + MAKE_PM(PM_MdiSubWindowFrameWidth), + MAKE_PM(PM_MdiSubWindowMinimizedWidth), + MAKE_PM(PM_HeaderMargin), + MAKE_PM(PM_HeaderMarkSize), + MAKE_PM(PM_HeaderGripMargin), + MAKE_PM(PM_TabBarTabShiftHorizontal), + MAKE_PM(PM_TabBarTabShiftVertical), + MAKE_PM(PM_TabBarScrollButtonWidth), + MAKE_PM(PM_ToolBarFrameWidth), + MAKE_PM(PM_ToolBarHandleExtent), + MAKE_PM(PM_ToolBarItemSpacing), + MAKE_PM(PM_ToolBarItemMargin), + MAKE_PM(PM_ToolBarSeparatorExtent), + MAKE_PM(PM_ToolBarExtensionExtent), + MAKE_PM(PM_SpinBoxSliderHeight), + MAKE_PM(PM_DefaultTopLevelMargin), + MAKE_PM(PM_DefaultChildMargin), + MAKE_PM(PM_DefaultLayoutSpacing), + MAKE_PM(PM_ToolBarIconSize), + MAKE_PM(PM_ListViewIconSize), + MAKE_PM(PM_IconViewIconSize), + MAKE_PM(PM_SmallIconSize), + MAKE_PM(PM_LargeIconSize), + MAKE_PM(PM_FocusFrameVMargin), + MAKE_PM(PM_FocusFrameHMargin), + MAKE_PM(PM_ToolTipLabelFrameWidth), + MAKE_PM(PM_CheckBoxLabelSpacing), + MAKE_PM(PM_TabBarIconSize), + MAKE_PM(PM_SizeGripSize), + MAKE_PM(PM_DockWidgetTitleMargin), + MAKE_PM(PM_MessageBoxIconSize), + MAKE_PM(PM_ButtonIconSize), + MAKE_PM(PM_DockWidgetTitleBarButtonMargin), + MAKE_PM(PM_RadioButtonLabelSpacing), + MAKE_PM(PM_LayoutLeftMargin), + MAKE_PM(PM_LayoutTopMargin), + MAKE_PM(PM_LayoutRightMargin), + MAKE_PM(PM_LayoutBottomMargin), + MAKE_PM(PM_LayoutHorizontalSpacing), + MAKE_PM(PM_LayoutVerticalSpacing), + MAKE_PM(PM_TabBar_ScrollButtonOverlap), + MAKE_PM(PM_TextCursorWidth), + MAKE_PM(PM_TabCloseIndicatorWidth), + MAKE_PM(PM_TabCloseIndicatorHeight), + MAKE_PM(PM_ScrollView_ScrollBarSpacing), + MAKE_PM(PM_SubMenuOverlap) +}; + +PixelMetricModel::PixelMetricModel(QObject *parent) + : AbstractStyleElementModel(parent) +{ +} + +QVariant PixelMetricModel::doData(int row, int column, int role) const +{ + if (role == Qt::DisplayRole || role == Qt::EditRole) { + switch (column) { + case 0: + return pixelMetrics[row].name; + case 1: + return + (isMainStyle() && DynamicProxyStyle::exists()) ? + DynamicProxyStyle::instance()->pixelMetric(pixelMetrics[row].pixelMetric) : + m_style->pixelMetric(pixelMetrics[row].pixelMetric); + } + } + + return QVariant(); +} + +int PixelMetricModel::doColumnCount() const +{ + return 2; +} + +int PixelMetricModel::doRowCount() const +{ + return QStyle::PM_SubMenuOverlap + 1; +} + +QVariant PixelMetricModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch (section) { + case 0: + return tr("Metric"); + case 1: + return tr("Default Value"); + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +Qt::ItemFlags PixelMetricModel::flags(const QModelIndex &index) const +{ + const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); + if (index.isValid() && index.column() == 1 && isMainStyle()) { + return baseFlags | Qt::ItemIsEditable; + } + return baseFlags; +} + +bool PixelMetricModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid() || + index.column() != 1 || + !value.isValid() || + !value.canConvert(QVariant::Int) || + role != Qt::EditRole) { + return false; + } + + DynamicProxyStyle::instance()->setPixelMetric( + pixelMetrics[index.row()].pixelMetric, value.toInt()); + emit dataChanged(index, index); + return true; +} diff -Nru gammaray-1.2.2/plugins/styleinspector/pixelmetricmodel.h gammaray-2.0.1/plugins/styleinspector/pixelmetricmodel.h --- gammaray-1.2.2/plugins/styleinspector/pixelmetricmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/pixelmetricmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,55 @@ +/* + pixelmetricmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_PIXELMETRICMODEL_H +#define GAMMARAY_STYLEINSPECTOR_PIXELMETRICMODEL_H + +#include "abstractstyleelementmodel.h" + +namespace GammaRay { + +/** + * Lists all pixel metric values of a given QStyle. + */ +class PixelMetricModel : public AbstractStyleElementModel +{ + Q_OBJECT + public: + explicit PixelMetricModel(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + + protected: + virtual QVariant doData(int row, int column, int role) const; + virtual int doColumnCount() const; + virtual int doRowCount() const; +}; + +} + +#endif // GAMMARAY_PIXELMETRICMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/primitivemodel.cpp gammaray-2.0.1/plugins/styleinspector/primitivemodel.cpp --- gammaray-1.2.2/plugins/styleinspector/primitivemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/primitivemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,136 @@ +/* + primitivemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "primitivemodel.h" +#include "styleoption.h" +#include "styleinspectorinterface.h" +#include + +#include +#include +#include + +using namespace GammaRay; + +struct primitive_element_t { + const char *name; + QStyle::PrimitiveElement primitive; + QStyleOption * (*styleOptionFactory)(); +}; + +#define MAKE_PE( primitive ) { #primitive , QStyle:: primitive, &StyleOption::makeStyleOption } +#define MAKE_PE_X( primitive, factory ) { #primitive, QStyle:: primitive, &StyleOption:: factory } + +static primitive_element_t primititveElements[] = { +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + MAKE_PE(PE_Q3CheckListController), + MAKE_PE(PE_Q3CheckListExclusiveIndicator), + MAKE_PE(PE_Q3CheckListIndicator), + MAKE_PE(PE_Q3DockWindowSeparator), + MAKE_PE(PE_Q3Separator), +#endif + MAKE_PE_X(PE_Frame, makeFrameStyleOption), + MAKE_PE(PE_FrameDefaultButton), + MAKE_PE_X(PE_FrameDockWidget, makeFrameStyleOption), + MAKE_PE(PE_FrameFocusRect), + MAKE_PE_X(PE_FrameGroupBox, makeFrameStyleOption), + MAKE_PE_X(PE_FrameLineEdit, makeFrameStyleOption), + MAKE_PE_X(PE_FrameMenu, makeFrameStyleOption), + MAKE_PE(PE_FrameStatusBarItem), + MAKE_PE_X(PE_FrameTabWidget, makeTabWidgetFrameStyleOption), + MAKE_PE_X(PE_FrameWindow, makeFrameStyleOption), + MAKE_PE(PE_FrameButtonBevel), + MAKE_PE(PE_FrameButtonTool), + MAKE_PE_X(PE_FrameTabBarBase, makeTabBarBaseStyleOption), + MAKE_PE_X(PE_PanelButtonCommand, makeButtonStyleOption), + MAKE_PE(PE_PanelButtonBevel), + MAKE_PE(PE_PanelButtonTool), + MAKE_PE(PE_PanelMenuBar), + MAKE_PE(PE_PanelToolBar), + MAKE_PE_X(PE_PanelLineEdit, makeFrameStyleOption), + MAKE_PE(PE_IndicatorArrowDown), + MAKE_PE(PE_IndicatorArrowLeft), + MAKE_PE(PE_IndicatorArrowRight), + MAKE_PE(PE_IndicatorArrowUp), + MAKE_PE(PE_IndicatorBranch), + MAKE_PE(PE_IndicatorButtonDropDown), + MAKE_PE(PE_IndicatorViewItemCheck), + MAKE_PE_X(PE_IndicatorCheckBox, makeButtonStyleOption), + MAKE_PE(PE_IndicatorDockWidgetResizeHandle), + MAKE_PE_X(PE_IndicatorHeaderArrow, makeHeaderStyleOption), + MAKE_PE(PE_IndicatorMenuCheckMark), + MAKE_PE(PE_IndicatorProgressChunk), + MAKE_PE_X(PE_IndicatorRadioButton, makeButtonStyleOption), + MAKE_PE_X(PE_IndicatorSpinDown, makeSpinBoxStyleOption), + MAKE_PE_X(PE_IndicatorSpinMinus, makeSpinBoxStyleOption), + MAKE_PE_X(PE_IndicatorSpinPlus, makeSpinBoxStyleOption), + MAKE_PE_X(PE_IndicatorSpinUp, makeSpinBoxStyleOption), + MAKE_PE(PE_IndicatorToolBarHandle), + MAKE_PE(PE_IndicatorToolBarSeparator), + MAKE_PE(PE_PanelTipLabel), + MAKE_PE_X(PE_IndicatorTabTear, makeTabStyleOption), + MAKE_PE(PE_PanelScrollAreaCorner), + MAKE_PE(PE_Widget), + MAKE_PE(PE_IndicatorColumnViewArrow), + MAKE_PE(PE_IndicatorItemViewItemDrop), + MAKE_PE_X(PE_PanelItemViewItem, makeItemViewStyleOption), + MAKE_PE(PE_PanelItemViewRow), + MAKE_PE(PE_PanelStatusBar), + MAKE_PE(PE_IndicatorTabClose), + MAKE_PE(PE_PanelMenu) +}; + +PrimitiveModel::PrimitiveModel(QObject *parent) + : AbstractStyleElementStateTable(parent) +{ +} + +QVariant PrimitiveModel::doData(int row, int column, int role) const +{ + if (role == Qt::DecorationRole) { + QPixmap pixmap(m_interface->cellSizeHint()); + QPainter painter(&pixmap); + Util::drawTransparencyPattern(&painter, pixmap.rect()); + painter.scale(m_interface->cellZoom(), m_interface->cellZoom()); + + QScopedPointer opt((primititveElements[row].styleOptionFactory)()); + fillStyleOption(opt.data(), column); + m_style->drawPrimitive(primititveElements[row].primitive, opt.data(), &painter); + return pixmap; + } + + return AbstractStyleElementStateTable::doData(row, column, role); +} + +int PrimitiveModel::doRowCount() const +{ + return sizeof(primititveElements) / sizeof(primititveElements[0]) ; +} + +QVariant PrimitiveModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Vertical && role == Qt::DisplayRole) { + return primititveElements[section].name; + } + return AbstractStyleElementStateTable::headerData(section, orientation, role); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/primitivemodel.h gammaray-2.0.1/plugins/styleinspector/primitivemodel.h --- gammaray-1.2.2/plugins/styleinspector/primitivemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/primitivemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + primitivemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_PRIMITIVEMODEL_H +#define GAMMARAY_STYLEINSPECTOR_PRIMITIVEMODEL_H + +#include "abstractstyleelementstatetable.h" + +namespace GammaRay { + +/** + * Model for primitive style elements. + */ +class PrimitiveModel : public AbstractStyleElementStateTable +{ + Q_OBJECT + public: + explicit PrimitiveModel(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + protected: + virtual QVariant doData(int row, int column, int role) const; + virtual int doRowCount() const; +}; + +} + +#endif // GAMMARAY_PRIMITIVEMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/standardiconmodel.cpp gammaray-2.0.1/plugins/styleinspector/standardiconmodel.cpp --- gammaray-1.2.2/plugins/styleinspector/standardiconmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/standardiconmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,152 @@ +/* + standardiconmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "standardiconmodel.h" + +#include + +using namespace GammaRay; + +StandardIconModel::StandardIconModel(QObject *parent) : AbstractStyleElementModel(parent) +{ +} + +QVariant StandardIconModel::dataForStandardIcon(QStyle::StandardPixmap stdPix, + const QString &name, + int column, int role) const +{ + if (column == 0) { + if (role == Qt::DisplayRole) { + return name; + } + } else if (column == 1) { + if (role == Qt::DecorationRole) { + return m_style->standardIcon(stdPix); + } else if (role == Qt::DisplayRole) { + return VariantHandler::displayString(m_style->standardIcon(stdPix)); + } + } + return QVariant(); +} + +#define MAKE_SP(stdPix) \ +if (row == QStyle:: stdPix) \ + return dataForStandardIcon(QStyle:: stdPix, QLatin1String(#stdPix), column, role) + +QVariant StandardIconModel::doData(int row, int column, int role) const +{ + MAKE_SP(SP_TitleBarMenuButton); + MAKE_SP(SP_TitleBarMinButton); + MAKE_SP(SP_TitleBarMaxButton); + MAKE_SP(SP_TitleBarCloseButton); + MAKE_SP(SP_TitleBarNormalButton); + MAKE_SP(SP_TitleBarShadeButton); + MAKE_SP(SP_TitleBarUnshadeButton); + MAKE_SP(SP_TitleBarContextHelpButton); + MAKE_SP(SP_DockWidgetCloseButton); + MAKE_SP(SP_MessageBoxInformation); + MAKE_SP(SP_MessageBoxWarning); + MAKE_SP(SP_MessageBoxCritical); + MAKE_SP(SP_MessageBoxQuestion); + MAKE_SP(SP_DesktopIcon); + MAKE_SP(SP_TrashIcon); + MAKE_SP(SP_ComputerIcon); + MAKE_SP(SP_DriveFDIcon); + MAKE_SP(SP_DriveHDIcon); + MAKE_SP(SP_DriveCDIcon); + MAKE_SP(SP_DriveDVDIcon); + MAKE_SP(SP_DriveNetIcon); + MAKE_SP(SP_DirOpenIcon); + MAKE_SP(SP_DirClosedIcon); + MAKE_SP(SP_DirLinkIcon); + MAKE_SP(SP_FileIcon); + MAKE_SP(SP_FileLinkIcon); + MAKE_SP(SP_ToolBarHorizontalExtensionButton); + MAKE_SP(SP_ToolBarVerticalExtensionButton); + MAKE_SP(SP_FileDialogStart); + MAKE_SP(SP_FileDialogEnd); + MAKE_SP(SP_FileDialogToParent); + MAKE_SP(SP_FileDialogNewFolder); + MAKE_SP(SP_FileDialogDetailedView); + MAKE_SP(SP_FileDialogInfoView); + MAKE_SP(SP_FileDialogContentsView); + MAKE_SP(SP_FileDialogListView); + MAKE_SP(SP_FileDialogBack); + MAKE_SP(SP_DirIcon); + MAKE_SP(SP_DialogOkButton); + MAKE_SP(SP_DialogCancelButton); + MAKE_SP(SP_DialogHelpButton); + MAKE_SP(SP_DialogOpenButton); + MAKE_SP(SP_DialogSaveButton); + MAKE_SP(SP_DialogCloseButton); + MAKE_SP(SP_DialogApplyButton); + MAKE_SP(SP_DialogResetButton); + MAKE_SP(SP_DialogDiscardButton); + MAKE_SP(SP_DialogYesButton); + MAKE_SP(SP_DialogNoButton); + MAKE_SP(SP_ArrowUp); + MAKE_SP(SP_ArrowDown); + MAKE_SP(SP_ArrowLeft); + MAKE_SP(SP_ArrowRight); + MAKE_SP(SP_ArrowBack); + MAKE_SP(SP_ArrowForward); + MAKE_SP(SP_DirHomeIcon); + MAKE_SP(SP_CommandLink); + MAKE_SP(SP_VistaShield); + MAKE_SP(SP_BrowserReload); + MAKE_SP(SP_BrowserStop); + MAKE_SP(SP_MediaPlay); + MAKE_SP(SP_MediaStop); + MAKE_SP(SP_MediaPause); + MAKE_SP(SP_MediaSkipForward); + MAKE_SP(SP_MediaSkipBackward); + MAKE_SP(SP_MediaSeekForward); + MAKE_SP(SP_MediaSeekBackward); + MAKE_SP(SP_MediaVolume); + MAKE_SP(SP_MediaVolumeMuted); + + return QVariant(); +} + +int StandardIconModel::doColumnCount() const +{ + return 2; +} + +int StandardIconModel::doRowCount() const +{ + return QStyle::SP_MediaVolumeMuted + 1; +} + +QVariant StandardIconModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch (section) { + case 0: + return tr("Name"); + case 1: + return tr("Icon"); + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/standardiconmodel.h gammaray-2.0.1/plugins/styleinspector/standardiconmodel.h --- gammaray-1.2.2/plugins/styleinspector/standardiconmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/standardiconmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + standardiconmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_STANDARDICONMODEL_H +#define GAMMARAY_STYLEINSPECTOR_STANDARDICONMODEL_H + +#include "abstractstyleelementmodel.h" + +#include + +namespace GammaRay { + +/** + * Lists all standard icons of a style. + */ +class StandardIconModel : public AbstractStyleElementModel +{ + Q_OBJECT + public: + explicit StandardIconModel(QObject *parent = 0); + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + protected: + virtual QVariant doData(int row, int column, int role) const; + virtual int doColumnCount() const; + virtual int doRowCount() const; + + private: + QVariant dataForStandardIcon(QStyle::StandardPixmap stdPix, + const QString &name, + int column, int role) const; +}; + +} + +#endif // GAMMARAY_STANDARDICONMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleelementproxymodel.cpp gammaray-2.0.1/plugins/styleinspector/styleelementproxymodel.cpp --- gammaray-1.2.2/plugins/styleinspector/styleelementproxymodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleelementproxymodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + styleelementproxymodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleelementproxymodel.h" + +using namespace GammaRay; + +StyleElementProxyModel::StyleModelProxy(QObject *parent) + : QIdentityProxyModel(parent) + , m_sizeHint(64, 64) +{ +} + +void StyleElementProxyModel::setWidth(int width) +{ + m_sizeHint.setWidth(width); +} + +void StyleElementProxyModel::setHeight(int height) +{ + m_sizeHint.setHeight(height); +} + +QVariant StyleElementProxyModel::data(const QModelIndex &proxyIndex, int role) const +{ + if (role == Qt::SizeHintRole) { + return m_sizeHint; + } + + return QAbstractProxyModel::data(proxyIndex, role); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleelementproxymodel.h gammaray-2.0.1/plugins/styleinspector/styleelementproxymodel.h --- gammaray-1.2.2/plugins/styleinspector/styleelementproxymodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleelementproxymodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + styleelementproxymodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEELEMENTPROXYMODEL_H +#define GAMMARAY_STYLEELEMENTPROXYMODEL_H + +#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) +#include +typedef QSortFilterProxyModel QIdentityProxyModel; +#else +#include +#endif + +#include + +namespace GammaRay { + +class StyleElementProxyModel : public QIdentityProxyModel +{ + Q_OBJECT + public: + explicit StyleModelProxy(QObject *parent = 0); + + virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const; + + public slots: + void setWidth(int width); + void setHeight(int height); + void setZoomFactor(int zoom); + + private: + QSize m_sizeHint; +}; + +} + +#endif // GAMMARAY_STYLEELEMENTPROXYMODEL_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.cpp gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.cpp --- gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ +/* + styleelementstatetablepage.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleelementstatetablepage.h" +#include "ui_styleelementstatetablepage.h" +#include "abstractstyleelementstatetable.h" + +#include "styleinspectorclient.h" +#include + +static QObject* createStyleInspectorClient(const QString & /*name*/, QObject *parent) +{ + return new GammaRay::StyleInspectorClient(parent); +} + +using namespace GammaRay; + +StyleElementStateTablePage::StyleElementStateTablePage(QWidget *parent) + : QWidget(parent) + , ui(new Ui::StyleElementStateTablePage) + , m_interface(0) +{ + ObjectBroker::registerClientObjectFactoryCallback(createStyleInspectorClient); + m_interface = ObjectBroker::object(); + + ui->setupUi(this); + ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed); + ui->tableView->verticalHeader()->setResizeMode(QHeaderView::Fixed); + + connect(ui->widthBox, SIGNAL(valueChanged(int)), m_interface, SLOT(setCellWidth(int))); + connect(ui->widthBox, SIGNAL(valueChanged(int)), SLOT(updateCellSize())); + connect(ui->heightBox, SIGNAL(valueChanged(int)), m_interface, SLOT(setCellWidth(int))); + connect(ui->heightBox, SIGNAL(valueChanged(int)), SLOT(updateCellSize())); + connect(ui->zoomSlider, SIGNAL(valueChanged(int)), m_interface, SLOT(setCellZoom(int))); + connect(ui->zoomSlider, SIGNAL(valueChanged(int)), SLOT(updateCellSize())); + + updateCellSize(); +} + +void StyleElementStateTablePage::showEvent(QShowEvent *show) +{ + ui->widthBox->setValue(m_interface->cellWidth()); + ui->heightBox->setValue(m_interface->cellHeight()); + ui->zoomSlider->setValue(m_interface->cellZoom()); + QWidget::showEvent(show); +} + +StyleElementStateTablePage::~StyleElementStateTablePage() +{ + delete ui; +} + +void StyleElementStateTablePage::setModel(QAbstractItemModel *model) +{ + ui->tableView->setModel(model); +} + +void StyleElementStateTablePage::updateCellSize() +{ + ui->tableView->verticalHeader()->setDefaultSectionSize(m_interface->cellSizeHint().height() + 4); + ui->tableView->horizontalHeader()->setDefaultSectionSize(m_interface->cellSizeHint().width() + 4); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.h gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.h --- gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + styleelementstatetablepage.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_STYLEELEMENTSTATETABLEPAGE_H +#define GAMMARAY_STYLEINSPECTOR_STYLEELEMENTSTATETABLEPAGE_H + +#include + +class QAbstractItemModel; + +namespace GammaRay { + +class StyleInspectorInterface; + +namespace Ui { + class StyleElementStateTablePage; +} + +/** + * Tab page for showing a style element x state table and corresponding config UI. + */ +class StyleElementStateTablePage : public QWidget +{ + Q_OBJECT + public: + explicit StyleElementStateTablePage(QWidget *parent = 0); + ~StyleElementStateTablePage(); + void setModel(QAbstractItemModel *model); + + protected: + virtual void showEvent(QShowEvent *show); + + private slots: + void updateCellSize(); + + private: + Ui::StyleElementStateTablePage *ui; + StyleInspectorInterface *m_interface; +}; + +} + +#endif // GAMMARAY_STYLEELEMENTSTATETABLEPAGE_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.ui gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.ui --- gammaray-1.2.2/plugins/styleinspector/styleelementstatetablepage.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleelementstatetablepage.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,114 @@ + + + GammaRay::StyleElementStateTablePage + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + QAbstractItemView::NoSelection + + + false + + + + + + + + + Cell &Width: + + + widthBox + + + + + + + px + + + 999 + + + + + + + Cell &Height: + + + heightBox + + + + + + + px + + + 999 + + + + + + + &Zoom: + + + zoomSlider + + + + + + + 1 + + + 8 + + + 1 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorclient.cpp gammaray-2.0.1/plugins/styleinspector/styleinspectorclient.cpp --- gammaray-1.2.2/plugins/styleinspector/styleinspectorclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,59 @@ +/* + styleinspectorclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleinspectorclient.h" +#include + +using namespace GammaRay; + +StyleInspectorClient::StyleInspectorClient(QObject *parent) + : StyleInspectorInterface(parent) +{ + // make sure the remote server side uses our initial values + setCellHeight(cellHeight()); + setCellWidth(cellWidth()); + setCellZoom(cellZoom()); +} + +StyleInspectorClient::~StyleInspectorClient() +{ + +} + +void StyleInspectorClient::setCellHeight(int height) +{ + StyleInspectorInterface::setCellHeight(height); + Endpoint::instance()->invokeObject(objectName(), "setCellHeight", QVariantList() << height); +} + +void StyleInspectorClient::setCellWidth(int width) +{ + StyleInspectorInterface::setCellWidth(width); + Endpoint::instance()->invokeObject(objectName(), "setCellWidth", QVariantList() << width); +} + +void StyleInspectorClient::setCellZoom(int zoom) +{ + StyleInspectorInterface::setCellZoom(zoom); + Endpoint::instance()->invokeObject(objectName(), "setCellZoom", QVariantList() << zoom); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorclient.h gammaray-2.0.1/plugins/styleinspector/styleinspectorclient.h --- gammaray-1.2.2/plugins/styleinspector/styleinspectorclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + styleinspectorclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTORCLIENT_H +#define GAMMARAY_STYLEINSPECTORCLIENT_H + +#include "styleinspectorinterface.h" + +namespace GammaRay { + +class StyleInspectorClient : public StyleInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::StyleInspectorInterface) + public: + explicit StyleInspectorClient(QObject *parent = 0); + virtual ~StyleInspectorClient(); + + virtual void setCellHeight(int height); + virtual void setCellWidth(int width); + virtual void setCellZoom(int zoom); +}; + +} + +#endif // GAMMARAY_STYLEINSPECTORCLIENT_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspector.cpp gammaray-2.0.1/plugins/styleinspector/styleinspector.cpp --- gammaray-1.2.2/plugins/styleinspector/styleinspector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,91 @@ +/* + styleinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleinspector.h" +#include "complexcontrolmodel.h" +#include "controlmodel.h" +#include "pixelmetricmodel.h" +#include "primitivemodel.h" +#include "standardiconmodel.h" + +#include +#include +#include + +#include +#include + +#include +#include + +using namespace GammaRay; + +StyleInspector::StyleInspector(ProbeInterface *probe, QObject *parent) + : StyleInspectorInterface(parent), + m_primitiveModel(new PrimitiveModel(this)), + m_controlModel(new ControlModel(this)), + m_complexControlModel(new ComplexControlModel(this)), + m_pixelMetricModel(new PixelMetricModel(this)), + m_standardIconModel(new StandardIconModel(this)), + m_standardPaletteModel(new PaletteModel(this)) +{ + ObjectTypeFilterProxyModel *styleFilter = new ObjectTypeFilterProxyModel(this); + styleFilter->setSourceModel(probe->objectListModel()); + SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); + singleColumnProxy->setSourceModel(styleFilter); + probe->registerModel("com.kdab.GammaRay.StyleList", singleColumnProxy); + + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(singleColumnProxy); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(styleSelected(QItemSelection))); + + probe->registerModel("com.kdab.GammaRay.StyleInspector.PrimitiveModel", m_primitiveModel); + probe->registerModel("com.kdab.GammaRay.StyleInspector.ControlModel", m_controlModel); + probe->registerModel("com.kdab.GammaRay.StyleInspector.ComplexControlModel", m_complexControlModel); + probe->registerModel("com.kdab.GammaRay.StyleInspector.PixelMetricModel", m_pixelMetricModel); + probe->registerModel("com.kdab.GammaRay.StyleInspector.StandardIconModel", m_standardIconModel); + probe->registerModel("com.kdab.GammaRay.StyleInspector.PaletteModel", m_standardPaletteModel); +} + +StyleInspector::~StyleInspector() +{ +} + +void StyleInspector::styleSelected(const QItemSelection &selection) +{ + if (selection.isEmpty()) + return; + const QModelIndex index = selection.first().topLeft(); + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + QStyle *style = qobject_cast(obj); + m_primitiveModel->setStyle(style); + m_controlModel->setStyle(style); + m_complexControlModel->setStyle(style); + m_pixelMetricModel->setStyle(style); + m_standardIconModel->setStyle(style); + m_standardPaletteModel->setPalette(style ? style->standardPalette() : qApp->palette()); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(StyleInspectorFactory) +#endif diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspector.h gammaray-2.0.1/plugins/styleinspector/styleinspector.h --- gammaray-1.2.2/plugins/styleinspector/styleinspector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,84 @@ +/* + styleinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_STYLEINSPECTOR_H +#define GAMMARAY_STYLEINSPECTOR_STYLEINSPECTOR_H + +#include +#include "styleinspectorwidget.h" +#include "styleinspectorinterface.h" + +#include +#include + +class QItemSelection; + +namespace GammaRay { + +class ComplexControlModel; +class ControlModel; +class PaletteModel; +class PixelMetricModel; +class PrimitiveModel; +class StandardIconModel; + +class StyleInspector : public StyleInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::StyleInspectorInterface) + public: + explicit StyleInspector(ProbeInterface *probe, QObject *parent = 0); + virtual ~StyleInspector(); + + private slots: + void styleSelected(const QItemSelection &selection); + + private: + PrimitiveModel *m_primitiveModel; + ControlModel *m_controlModel; + ComplexControlModel *m_complexControlModel; + PixelMetricModel *m_pixelMetricModel; + StandardIconModel *m_standardIconModel; + PaletteModel *m_standardPaletteModel; +}; + +class StyleInspectorFactory : public QObject, public StandardToolFactory2 +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.StyleInspector") + + public: + explicit StyleInspectorFactory(QObject *parent = 0) : QObject(parent) + { + } + + virtual QString name() const + { + return tr("Style"); + } +}; + +} + +#endif // GAMMARAY_STYLEINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorinterface.cpp gammaray-2.0.1/plugins/styleinspector/styleinspectorinterface.cpp --- gammaray-1.2.2/plugins/styleinspector/styleinspectorinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,80 @@ +/* + styleinspectorinterface.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleinspectorinterface.h" +#include +#include + +using namespace GammaRay; + +StyleInspectorInterface::StyleInspectorInterface(QObject *parent) + : QObject(parent) + , m_cellHeight(64) + , m_cellWidth(64) + , m_cellZoom(1) +{ + ObjectBroker::registerObject(this); +} + +StyleInspectorInterface::~StyleInspectorInterface() +{ + +} + +int StyleInspectorInterface::cellHeight() const +{ + return m_cellHeight; +} + +int StyleInspectorInterface::cellWidth() const +{ + return m_cellWidth; +} + +int StyleInspectorInterface::cellZoom() const +{ + return m_cellZoom; +} + +QSize StyleInspectorInterface::cellSizeHint() const +{ + return QSize(m_cellWidth * m_cellZoom, m_cellHeight * m_cellZoom); +} + +void StyleInspectorInterface::setCellHeight(int height) +{ + m_cellHeight = height; + emit cellSizeChanged(); +} + +void StyleInspectorInterface::setCellWidth(int width) +{ + m_cellWidth = width; + emit cellSizeChanged(); +} + +void StyleInspectorInterface::setCellZoom(int zoom) +{ + m_cellZoom = zoom; + emit cellSizeChanged(); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorinterface.h gammaray-2.0.1/plugins/styleinspector/styleinspectorinterface.h --- gammaray-1.2.2/plugins/styleinspector/styleinspectorinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + styleinspectorinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTORINTERFACE_H +#define GAMMARAY_STYLEINSPECTORINTERFACE_H + +#include + +class QSize; + +namespace GammaRay { + +class StyleInspectorInterface : public QObject +{ + Q_OBJECT + public: + explicit StyleInspectorInterface(QObject *parent = 0); + virtual ~StyleInspectorInterface(); + + int cellHeight() const; + int cellWidth() const; + int cellZoom() const; + QSize cellSizeHint() const; + + signals: + void cellSizeChanged(); + + public slots: + virtual void setCellHeight(int height); + virtual void setCellWidth(int width); + virtual void setCellZoom(int zoom); + + private: + int m_cellHeight; + int m_cellWidth; + int m_cellZoom; +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::StyleInspectorInterface, "com.kdab.GammaRay.StyleInspectorInterface") + +#endif // GAMMARAY_STYLEINSPECTORINTERFACE_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.cpp gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.cpp --- gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ +/* + styleinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleinspectorwidget.h" +#include "ui_styleinspectorwidget.h" + +#include + +using namespace GammaRay; + +StyleInspectorWidget::StyleInspectorWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::StyleInspectorWidget) +{ + ui->setupUi(this); + + ui->styleSelector->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleList")); + connect(ui->styleSelector, SIGNAL(currentIndexChanged(int)), SLOT(styleSelected(int))); + + ui->primitivePage->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.PrimitiveModel")); + ui->controlPage->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.ControlModel")); + ui->complexControlPage->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.ComplexControlModel")); + + ui->pixelMetricView->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.PixelMetricModel")); + ui->pixelMetricView->header()->setResizeMode(QHeaderView::ResizeToContents); + + ui->standardIconView->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.StandardIconModel")); + ui->standardIconView->header()->setResizeMode(QHeaderView::ResizeToContents); + + ui->standardPaletteView->setModel(ObjectBroker::model("com.kdab.GammaRay.StyleInspector.PaletteModel")); + ui->standardIconView->header()->setResizeMode(QHeaderView::ResizeToContents); + + // TODO this will fail due to lazy model population + if (ui->styleSelector->count()) { + styleSelected(0); + } +} + +StyleInspectorWidget::~StyleInspectorWidget() +{ + delete ui; +} + +void StyleInspectorWidget::styleSelected(int index) +{ + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(ui->styleSelector->model()); + selectionModel->select(ui->styleSelector->model()->index(index, 0), QItemSelectionModel::ClearAndSelect); +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.h gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.h --- gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + styleinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_STYLEINSPECTORWIDGET_H +#define GAMMARAY_STYLEINSPECTOR_STYLEINSPECTORWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class StyleInspectorWidget; +} + +class StyleInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit StyleInspectorWidget(QWidget *parent = 0); + virtual ~StyleInspectorWidget(); + + private slots: + void styleSelected(int index); + + private: + Ui::StyleInspectorWidget *ui; +}; + +} + +#endif // GAMMARAY_STYLEINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.ui gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.ui --- gammaray-1.2.2/plugins/styleinspector/styleinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,137 @@ + + + GammaRay::StyleInspectorWidget + + + + 0 + 0 + 400 + 300 + + + + + + + + + + 0 + 0 + + + + &Style: + + + styleSelector + + + + + + + + + + + + 0 + + + + Primitives + + + + + + + + + + Controls + + + + + + + + + + Complex Controls + + + + + + + + + + Pixel Metric + + + + + + false + + + true + + + + + + + + Standard Icons + + + + + + false + + + true + + + + + + + + Standard Palette + + + + + + false + + + true + + + + + + + + + + + + GammaRay::StyleElementStateTablePage + QWidget +
styleelementstatetablepage.h
+ 1 +
+
+ + +
diff -Nru gammaray-1.2.2/plugins/styleinspector/styleoption.cpp gammaray-2.0.1/plugins/styleinspector/styleoption.cpp --- gammaray-1.2.2/plugins/styleinspector/styleoption.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleoption.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,223 @@ +/* + styleoption.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "styleoption.h" + +#include + +using namespace GammaRay; + +struct style_state_t { + const char *name; + QStyle::State state; +}; + +#define MAKE_STATE( state ) { #state, QStyle:: state } + +static style_state_t styleStates[] = { + MAKE_STATE(State_None), + MAKE_STATE(State_Enabled), + MAKE_STATE(State_Raised), + MAKE_STATE(State_Sunken), + MAKE_STATE(State_Off), + MAKE_STATE(State_NoChange), + MAKE_STATE(State_On), + MAKE_STATE(State_DownArrow), + MAKE_STATE(State_Horizontal), + MAKE_STATE(State_HasFocus), + MAKE_STATE(State_Top), + MAKE_STATE(State_Bottom), + MAKE_STATE(State_FocusAtBorder), + MAKE_STATE(State_AutoRaise), + MAKE_STATE(State_MouseOver), + MAKE_STATE(State_UpArrow), + MAKE_STATE(State_Selected), + MAKE_STATE(State_Active), + MAKE_STATE(State_Window), + MAKE_STATE(State_Open), + MAKE_STATE(State_Children), + MAKE_STATE(State_Item), + MAKE_STATE(State_Sibling), + MAKE_STATE(State_Editing), + MAKE_STATE(State_KeyboardFocusChange), + MAKE_STATE(State_ReadOnly), + MAKE_STATE(State_Small), + MAKE_STATE(State_Mini) +}; + +int StyleOption::stateCount() +{ + return sizeof(styleStates) / sizeof(style_state_t); +} + +QString StyleOption::stateDisplayName(int index) +{ + return QString::fromLatin1(styleStates[index].name).mid(6); // remove the State_ prefix +} + +QStyle::State StyleOption::prettyState(int index) +{ + QStyle::State s = styleStates[index].state; + if (s == QStyle::State_None) { + return s; + } + return s | QStyle::State_Enabled; // enable by default, else we usually see disabled stuff only +} + +QStyleOption *StyleOption::makeStyleOption() +{ + return new QStyleOption; +} + +QStyleOption *StyleOption::makeStyleOptionComplex() +{ + return new QStyleOptionComplex; +} + +QStyleOption *StyleOption::makeButtonStyleOption() +{ + QStyleOptionButton *opt = new QStyleOptionButton; + opt->features = QStyleOptionButton::None; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption *StyleOption::makeComboBoxStyleOption() +{ + QStyleOptionComboBox *opt = new QStyleOptionComboBox; + opt->frame = true; + opt->currentText = QLatin1String("Current Text"); + return opt; +} + +QStyleOption *StyleOption::makeFrameStyleOption() +{ + QStyleOptionFrameV3 *opt = new QStyleOptionFrameV3; + opt->lineWidth = 1; + opt->midLineWidth = 0; + opt->frameShape = QFrame::StyledPanel; + return opt; +} + +QStyleOption *StyleOption::makeGroupBoxStyleOption() +{ + QStyleOptionGroupBox *opt = new QStyleOptionGroupBox; + opt->lineWidth = 1; + opt->midLineWidth = 0; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption *StyleOption::makeHeaderStyleOption() +{ + QStyleOptionHeader *opt = new QStyleOptionHeader; + opt->orientation = Qt::Horizontal; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption *StyleOption::makeItemViewStyleOption() +{ + QStyleOptionViewItemV4 *opt = new QStyleOptionViewItemV4; + opt->text = QLatin1String("Text"); + opt->features = QStyleOptionViewItemV2::HasDisplay; + return opt; +} + +QStyleOption *StyleOption::makeMenuStyleOption() +{ + QStyleOptionMenuItem *opt = new QStyleOptionMenuItem; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption *StyleOption::makeProgressBarStyleOption() +{ + QStyleOptionProgressBarV2 *opt = new QStyleOptionProgressBarV2; + opt->minimum = 0; + opt->maximum = 100; + opt->progress = 42; + return opt; +} + +QStyleOption *StyleOption::makeSliderStyleOption() +{ + QStyleOptionSlider *opt = new QStyleOptionSlider; + opt->minimum = 0; + opt->maximum = 100; + opt->sliderValue = 42; + opt->tickInterval = 5; + return opt; +} + +QStyleOption *StyleOption::makeSpinBoxStyleOption() +{ + QStyleOptionSpinBox *opt = new QStyleOptionSpinBox; + opt->frame = true; + return opt; +} + +QStyleOption *StyleOption::makeTabStyleOption() +{ + QStyleOptionTabV3 *opt = new QStyleOptionTabV3; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption *StyleOption::makeTabBarBaseStyleOption() +{ + return new QStyleOptionTabBarBaseV2; +} + +QStyleOption *StyleOption::makeTabWidgetFrameStyleOption() +{ + QStyleOptionTabWidgetFrameV2 *opt = new QStyleOptionTabWidgetFrameV2; + opt->lineWidth = 1; + return opt; +} + +QStyleOption *StyleOption::makeTitleBarStyleOption() +{ + QStyleOptionTitleBar *opt = new QStyleOptionTitleBar; + opt->text = QLatin1String("Title"); + opt->titleBarFlags = Qt::WindowMinMaxButtonsHint | + Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | + Qt::WindowCloseButtonHint; + return opt; +} + +QStyleOption *StyleOption::makeToolBoxStyleOption() +{ + QStyleOptionToolBoxV2 *opt = new QStyleOptionToolBoxV2; + opt->text = QLatin1String("Label"); + return opt; +} + +QStyleOption * StyleOption::makeToolButtonStyleOption() +{ + QStyleOptionToolButton *opt = new QStyleOptionToolButton; + opt->text = QLatin1String("Label"); + opt->toolButtonStyle = Qt::ToolButtonFollowStyle; + return opt; +} diff -Nru gammaray-1.2.2/plugins/styleinspector/styleoption.h gammaray-2.0.1/plugins/styleinspector/styleoption.h --- gammaray-1.2.2/plugins/styleinspector/styleoption.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/styleinspector/styleoption.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,66 @@ +/* + styleoption.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STYLEINSPECTOR_STYLEOPTION_H +#define GAMMARAY_STYLEINSPECTOR_STYLEOPTION_H + +#include + +class QStyleOption; +class QString; + +namespace GammaRay { + +/** + * Various helper methods for dealing with QStyleOption. + */ +namespace StyleOption { + + int stateCount(); + QString stateDisplayName(int index); + QStyle::State prettyState(int index); + + QStyleOption *makeStyleOption(); + QStyleOption *makeStyleOptionComplex(); + + QStyleOption *makeButtonStyleOption(); + QStyleOption *makeComboBoxStyleOption(); + QStyleOption *makeFrameStyleOption(); + QStyleOption *makeGroupBoxStyleOption(); + QStyleOption *makeHeaderStyleOption(); + QStyleOption *makeItemViewStyleOption(); + QStyleOption *makeMenuStyleOption(); + QStyleOption *makeProgressBarStyleOption(); + QStyleOption *makeSliderStyleOption(); + QStyleOption *makeSpinBoxStyleOption(); + QStyleOption *makeTabStyleOption(); + QStyleOption *makeTabBarBaseStyleOption(); + QStyleOption *makeTabWidgetFrameStyleOption(); + QStyleOption *makeTitleBarStyleOption(); + QStyleOption *makeToolBoxStyleOption(); + QStyleOption *makeToolButtonStyleOption(); +} + +} + +#endif // GAMMARAY_STYLEOPTION_H diff -Nru gammaray-1.2.2/plugins/timertop/CMakeLists.txt gammaray-2.0.1/plugins/timertop/CMakeLists.txt --- gammaray-1.2.2/plugins/timertop/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,10 +1,6 @@ +# probe part if(BUILD_TIMER_PLUGIN) -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} -) - set(gammaray_timertop_plugin_srcs timertop.cpp timermodel.cpp @@ -12,12 +8,6 @@ functioncalltimer.cpp ) -qt4_automoc(${gammaray_timertop_plugin_srcs}) - -qt4_wrap_ui(gammaray_timertop_plugin_srcs - timertop.ui -) - gammaray_add_plugin(gammaray_timertop_plugin gammaray_timertop.desktop ${gammaray_timertop_plugin_srcs} @@ -25,8 +15,7 @@ target_link_libraries(gammaray_timertop_plugin ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} - gammaray_probe + gammaray_core ) if(NOT WIN32 AND NOT APPLE) @@ -34,3 +23,27 @@ endif() endif() + +# ui part +if((Qt5Widgets_FOUND OR QT_QTGUI_FOUND) AND NOT GAMMARAY_PROBE_ONLY_BUILD) + + set(gammaray_timertop_plugin_ui_srcs + timertopwidget.cpp + ) + + qt4_wrap_ui(gammaray_timertop_plugin_ui_srcs + timertopwidget.ui + ) + + gammaray_add_plugin(gammaray_timertop_ui_plugin + gammaray_timertop_ui.desktop + ${gammaray_timertop_plugin_ui_srcs} + ) + + target_link_libraries(gammaray_timertop_ui_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common + ) + +endif() diff -Nru gammaray-1.2.2/plugins/timertop/functioncalltimer.cpp gammaray-2.0.1/plugins/timertop/functioncalltimer.cpp --- gammaray-1.2.2/plugins/timertop/functioncalltimer.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/functioncalltimer.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/timertop/functioncalltimer.h gammaray-2.0.1/plugins/timertop/functioncalltimer.h --- gammaray-1.2.2/plugins/timertop/functioncalltimer.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/functioncalltimer.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/timertop/gammaray_timertop.desktop gammaray-2.0.1/plugins/timertop/gammaray_timertop.desktop --- gammaray-1.2.2/plugins/timertop/gammaray_timertop.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/gammaray_timertop.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,5 @@ [Desktop Entry] Name=Timers X-GammaRay-Types=QTimer; +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory Exec=gammaray_timertop_plugin diff -Nru gammaray-1.2.2/plugins/timertop/gammaray_timertop_ui.desktop gammaray-2.0.1/plugins/timertop/gammaray_timertop_ui.desktop --- gammaray-1.2.2/plugins/timertop/gammaray_timertop_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/gammaray_timertop_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_timertop +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_timertop_ui_plugin diff -Nru gammaray-1.2.2/plugins/timertop/timerinfo.cpp gammaray-2.0.1/plugins/timertop/timerinfo.cpp --- gammaray-1.2.2/plugins/timertop/timerinfo.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timerinfo.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify @@ -22,7 +22,7 @@ */ #include "timerinfo.h" -#include "include/util.h" +#include #include diff -Nru gammaray-1.2.2/plugins/timertop/timerinfo.h gammaray-2.0.1/plugins/timertop/timerinfo.h --- gammaray-1.2.2/plugins/timertop/timerinfo.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timerinfo.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/plugins/timertop/timermodel.cpp gammaray-2.0.1/plugins/timertop/timermodel.cpp --- gammaray-1.2.2/plugins/timertop/timermodel.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify @@ -22,13 +22,14 @@ */ #include "timermodel.h" -#include "include/probeinterface.h" +#include #include //krazy:exclude=camelcase #include #include #include +#include #include @@ -39,47 +40,56 @@ static TimerModel *s_timerModel = 0; -static QTimer *timer_from_callback(QObject *caller, int method_index) +static bool processCallback() { - QTimer * const timer = qobject_cast(caller); - if (timer) { - QMetaMethod method = timer->metaObject()->method(method_index); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - if (method.signature() == QLatin1String("timeout()")) { -#else - if (method.methodSignature() == QByteArray("timeout()")) { -#endif - if (timer->objectName().toLower().startsWith(QLatin1String("gammaray"))) { - return 0; - } - return timer; - } + ///TODO: multi-threading support + if (!TimerModel::isInitialized() || QThread::currentThread() != qApp->thread()) { + return false; } - return 0; + return true; } static void signal_begin_callback(QObject *caller, int method_index, void **argv) { Q_UNUSED(argv); - QTimer * const timer = timer_from_callback(caller, method_index); - if (timer) { - TimerModel::instance()->preSignalActivate(timer); + if (!processCallback()) { + return; + } + + ///TODO: support threads living in other threads + if (caller->thread() != qApp->thread()) { + return; } + + TimerModel::instance()->preSignalActivate(caller, method_index); } static void signal_end_callback(QObject *caller, int method_index) { - QTimer * const timer = timer_from_callback(caller, method_index); - if (timer) { - TimerModel::instance()->postSignalActivate(timer); + // NOTE: here and below the caller may be invalid, e.g. if it was deleted from a slot + if (!processCallback()) { + return; } + + TimerModel::instance()->postSignalActivate(caller, method_index); } TimerModel::TimerModel(QObject *parent) : QAbstractTableModel(parent), m_sourceModel(0), - m_probe(0) + m_probe(0), + m_timeoutIndex(QTimer::staticMetaObject.indexOfSignal("timeout()")) +{ +} + +TimerModel::~TimerModel() +{ + s_timerModel = 0; +} + +bool TimerModel::isInitialized() { + return s_timerModel != 0; } TimerModel *TimerModel::instance() @@ -117,7 +127,8 @@ QVariant timerInfoVariant = timer->property(timerInfoPropertyName); if (!timerInfoVariant.isValid()) { timerInfoVariant.setValue(TimerInfoPtr(new TimerInfo(timer))); - timer->setProperty(timerInfoPropertyName, timerInfoVariant); + if (timer->thread() == QThread::currentThread()) // ### FIXME: we shouldn't use setProperty() in the first place... + timer->setProperty(timerInfoPropertyName, timerInfoVariant); } const TimerInfoPtr timerInfo = timerInfoVariant.value(); @@ -159,49 +170,81 @@ { for (int i = 0; i < rowCount(); i++) { const TimerInfoPtr timerInfo = findOrCreateTimerInfo(index(i, 0)); - if (timerInfo->timer() == timer) { + if (timerInfo && timerInfo->timer() == timer) { return i; } } return -1; } -void TimerModel::preSignalActivate(QTimer *timer) +void TimerModel::preSignalActivate(QObject *caller, int methodIndex) { + if (methodIndex != m_timeoutIndex) { + return; + } + + QTimer *timer = qobject_cast(caller); + if (!timer || timer->objectName().toLower().startsWith(QLatin1String("gammaray"))) { + return; + } + const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(timer); - if (timerInfo) { - if (!timerInfo->functionCallTimer()->start()) { - cout << "TimerModel::preSignalActivate(): Recursive timeout for timer " - << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; - } - } else { + + if (!timerInfo) { // Ok, likely a GammaRay timer //cout << "TimerModel::preSignalActivate(): Unable to find timer " // << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; + return; } + + if (!timerInfo->functionCallTimer()->start()) { + cout << "TimerModel::preSignalActivate(): Recursive timeout for timer " + << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; + return; + } + + Q_ASSERT(!m_currentSignals.contains(caller)); + m_currentSignals[caller] = timerInfo; } -void TimerModel::postSignalActivate(QTimer *timer) +void TimerModel::postSignalActivate(QObject *caller, int methodIndex) { - const TimerInfoPtr timerInfo = findOrCreateQTimerTimerInfo(timer); - if (timerInfo) { - if (!timerInfo->functionCallTimer()->active()) { - cout << "TimerModel::postSignalActivate(): Timer not active: " - << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; - } else { - TimerInfo::TimeoutEvent event; - event.timeStamp = QTime::currentTime(); - event.executionTime = timerInfo->functionCallTimer()->stop(); - timerInfo->addEvent(event); - const int row = rowFor(timer); - if (row != -1) { - emit dataChanged(index(row, 0), index(row, columnCount() - 1)); - } - } - } else { + if (methodIndex != m_timeoutIndex) { + return; + } + QHash::iterator it = m_currentSignals.find(caller); + if (it == m_currentSignals.end()) { // Ok, likely a GammaRay timer //cout << "TimerModel::postSignalActivate(): Unable to find timer " // << (void*)timer << " (" << timer->objectName().toStdString() << ")!" << endl; + return; + } + + const TimerInfoPtr timerInfo = *it; + Q_ASSERT(timerInfo); + + m_currentSignals.erase(it); + + if (!timerInfo->timer()) { + // timer got killed in a slot + return; + } + + Q_ASSERT(static_cast(caller) == timerInfo->timer()); + + if (!timerInfo->functionCallTimer()->active()) { + cout << "TimerModel::postSignalActivate(): Timer not active: " + << (void*)caller << " (" << caller->objectName().toStdString() << ")!" << endl; + return; + } + + TimerInfo::TimeoutEvent event; + event.timeStamp = QTime::currentTime(); + event.executionTime = timerInfo->functionCallTimer()->stop(); + timerInfo->addEvent(event); + const int row = rowFor(timerInfo->timer()); + if (row != -1) { + emit dataChanged(index(row, 0), index(row, columnCount() - 1)); } } @@ -362,5 +405,3 @@ { endResetModel(); } - -#include "timermodel.moc" diff -Nru gammaray-1.2.2/plugins/timertop/timermodel.h gammaray-2.0.1/plugins/timertop/timermodel.h --- gammaray-1.2.2/plugins/timertop/timermodel.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify @@ -25,7 +25,8 @@ #include "timerinfo.h" -#include "include/objecttypefilterproxymodel.h" +#include +#include #include @@ -39,15 +40,19 @@ { Q_OBJECT public: - TimerModel(QObject *parent = 0); + virtual ~TimerModel(); + + /// @return True in case instance() would return a valid pointer, else false + static bool isInitialized(); + static TimerModel *instance(); // For the spy callbacks - void preSignalActivate(QTimer *timer); - void postSignalActivate(QTimer *timer); + void preSignalActivate(QObject *caller, int methodIndex); + void postSignalActivate(QObject *caller, int methodIndex); enum Roles { - FirstRole = Qt::UserRole + 1, + FirstRole = UserRole + 1, ObjectNameRole, StateRole, TotalWakeupsRole, @@ -87,6 +92,7 @@ void slotEndReset(); private: + explicit TimerModel(QObject *parent = 0); // Finds only QTimers based on the timer ID, not free timers. TimerInfoPtr findOrCreateQTimerTimerInfo(int timerId); @@ -105,6 +111,10 @@ ObjectTypeFilterProxyModel *m_sourceModel; QList m_freeTimers; ProbeInterface *m_probe; + // current timer signals that are being processed + QHash m_currentSignals; + // the method index of the timeout() signal of a QTimer + const int m_timeoutIndex; }; } diff -Nru gammaray-1.2.2/plugins/timertop/timertop.cpp gammaray-2.0.1/plugins/timertop/timertop.cpp --- gammaray-1.2.2/plugins/timertop/timertop.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertop.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify @@ -23,9 +23,8 @@ #include "timertop.h" #include "timermodel.h" -#include "ui_timertop.h" -#include "include/probeinterface.h" +#include #include @@ -58,14 +57,12 @@ // Flash delegate when timer triggered // Color cell in view redish, depending on how active the timer is -TimerTop::TimerTop(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), - ui(new Ui::TimerTop), +TimerTop::TimerTop(ProbeInterface *probe, QObject *parent) + : QObject(parent), m_updateTimer(new QTimer(this)) { Q_ASSERT(probe); - ui->setupUi(this); ObjectTypeFilterProxyModel * const filterModel = new ObjectTypeFilterProxyModel(this); filterModel->setDynamicSortFilter(true); @@ -73,23 +70,8 @@ TimerModel::instance()->setParent(this); // otherwise it's not filtered out TimerModel::instance()->setProbe(probe); TimerModel::instance()->setSourceModel(filterModel); - QSortFilterProxyModel * const sortModel = new QSortFilterProxyModel(this); - sortModel->setSourceModel(TimerModel::instance()); - sortModel->setDynamicSortFilter(true); - ui->timerView->setModel(sortModel); - ui->timerView->sortByColumn(TimerModel::WakeupsPerSecRole - TimerModel::FirstRole - 1, - Qt::DescendingOrder); - - m_updateTimer->setObjectName("GammaRay update timer"); - m_updateTimer->setSingleShot(false); - m_updateTimer->setInterval(500); - m_updateTimer->start(); - connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(slotUpdateView())); -} -void TimerTop::slotUpdateView() -{ - ui->timerView->viewport()->update(); + probe->registerModel("com.kdab.GammaRay.TimerModel", TimerModel::instance()); } QStringList TimerTopFactory::supportedTypes() const @@ -100,5 +82,3 @@ #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) Q_EXPORT_PLUGIN(TimerTopFactory) #endif - -#include "timertop.moc" diff -Nru gammaray-1.2.2/plugins/timertop/timertop.h gammaray-2.0.1/plugins/timertop/timertop.h --- gammaray-1.2.2/plugins/timertop/timertop.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertop.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Thomas McGuire This program is free software; you can redistribute it and/or modify @@ -23,10 +23,9 @@ #ifndef GAMMARAY_TIMERTOP_TIMERTOP_H #define GAMMARAY_TIMERTOP_TIMERTOP_H -#include "include/toolfactory.h" +#include #include -#include namespace GammaRay { @@ -34,17 +33,13 @@ class TimerTop; } -class TimerTop : public QWidget +class TimerTop : public QObject { Q_OBJECT public: - explicit TimerTop(ProbeInterface *probe, QWidget *parent = 0); - - private slots: - void slotUpdateView(); + explicit TimerTop(ProbeInterface *probe, QObject *parent = 0); private: - QScopedPointer ui; QTimer *m_updateTimer; }; @@ -54,9 +49,16 @@ Q_OBJECT Q_INTERFACES(GammaRay::ToolFactory) Q_PLUGIN_METADATA(IID "com.kdab.gammaray.TimerTop") + public: - explicit TimerTopFactory(QObject *parent = 0) : QObject(parent) {} - inline QString name() const { return tr("Timers"); } + explicit TimerTopFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("Timers"); + } /* reimp */ QStringList supportedTypes() const; diff -Nru gammaray-1.2.2/plugins/timertop/timertop.ui gammaray-2.0.1/plugins/timertop/timertop.ui --- gammaray-1.2.2/plugins/timertop/timertop.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertop.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ - - - GammaRay::TimerTop - - - - 0 - 0 - 400 - 300 - - - - - 0 - - - - - true - - - false - - - true - - - true - - - - - - - - diff -Nru gammaray-1.2.2/plugins/timertop/timertopwidget.cpp gammaray-2.0.1/plugins/timertop/timertopwidget.cpp --- gammaray-1.2.2/plugins/timertop/timertopwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertopwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,67 @@ +/* + timertopwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Thomas McGuire + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "timertopwidget.h" +#include "ui_timertopwidget.h" +#include "timermodel.h" + +#include + +#include +#include + +using namespace GammaRay; + +TimerTopWidget::TimerTopWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::TimerTopWidget), + m_updateTimer(new QTimer(this)) +{ + ui->setupUi(this); + QSortFilterProxyModel * const sortModel = new QSortFilterProxyModel(this); + sortModel->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.TimerModel")); + sortModel->setDynamicSortFilter(true); + ui->timerView->setModel(sortModel); + ui->timerView->sortByColumn(TimerModel::WakeupsPerSecRole - TimerModel::FirstRole - 1, + Qt::DescendingOrder); + + // TODO is this even necessary? for sure it wont work remotely since model data is cached, would need to be put into the model itself in that case + m_updateTimer->setObjectName("GammaRay update timer"); + m_updateTimer->setSingleShot(false); + m_updateTimer->setInterval(500); + m_updateTimer->start(); + connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(slotUpdateView())); +} + +TimerTopWidget::~TimerTopWidget() +{ +} + +void TimerTopWidget::slotUpdateView() +{ + ui->timerView->viewport()->update(); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(TimerTopUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/timertop/timertopwidget.h gammaray-2.0.1/plugins/timertop/timertopwidget.h --- gammaray-1.2.2/plugins/timertop/timertopwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertopwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + timertopwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Thomas McGuire + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef GAMMARAY_TIMERTOPWIDGET_H +#define GAMMARAY_TIMERTOPWIDGET_H + +#include + +#include + +class QTimer; + +namespace GammaRay { + +namespace Ui { + class TimerTopWidget; +} + +class TimerTopWidget : public QWidget +{ + Q_OBJECT + public: + explicit TimerTopWidget(QWidget *parent = 0); + ~TimerTopWidget(); + + private slots: + void slotUpdateView(); + + private: + QScopedPointer ui; + QTimer *m_updateTimer; +}; + +class TimerTopUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.TimerTopUi") +}; + +} + +#endif // GAMMARAY_TIMERTOPWIDGET_H diff -Nru gammaray-1.2.2/plugins/timertop/timertopwidget.ui gammaray-2.0.1/plugins/timertop/timertopwidget.ui --- gammaray-1.2.2/plugins/timertop/timertopwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/timertop/timertopwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,37 @@ + + + GammaRay::TimerTopWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + true + + + false + + + true + + + true + + + + + + + + diff -Nru gammaray-1.2.2/plugins/webinspector/CMakeLists.txt gammaray-2.0.1/plugins/webinspector/CMakeLists.txt --- gammaray-1.2.2/plugins/webinspector/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,15 +1,9 @@ -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} -) - +# probe part set(gammaray_webinspector_plugin_srcs webinspector.cpp + webviewmodel.cpp ) -qt4_automoc(${gammaray_webinspector_plugin_srcs}) - -qt4_wrap_ui(gammaray_webinspector_plugin_srcs webinspector.ui) - gammaray_add_plugin(gammaray_webinspector_plugin gammaray_webinspector.desktop ${gammaray_webinspector_plugin_srcs} @@ -17,7 +11,33 @@ target_link_libraries(gammaray_webinspector_plugin ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} - ${QT_QTWEBKIT_LIBRARIES} - gammaray_probe + gammaray_core ) + +if(HAVE_QT_WEBKIT1) + target_link_libraries(gammaray_webinspector_plugin + ${QT_QTWEBKIT_LIBRARIES} + ${Qt5WebKitWidgets_LIBRARIES} + ) + + # ui part + set(gammaray_webinspector_ui_plugin_srcs + webinspectorwidget.cpp + ) + + qt4_wrap_ui(gammaray_webinspector_ui_plugin_srcs webinspectorwidget.ui) + + gammaray_add_plugin(gammaray_webinspector_ui_plugin + gammaray_webinspector_ui.desktop + ${gammaray_webinspector_ui_plugin_srcs} + ) + + target_link_libraries(gammaray_webinspector_ui_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTWEBKIT_LIBRARIES} + ${Qt5WebKitWidgets_LIBRARIES} + gammaray_common + ) + +endif() diff -Nru gammaray-1.2.2/plugins/webinspector/gammaray_webinspector.desktop gammaray-2.0.1/plugins/webinspector/gammaray_webinspector.desktop --- gammaray-1.2.2/plugins/webinspector/gammaray_webinspector.desktop 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/gammaray_webinspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -1,4 +1,5 @@ [Desktop Entry] Name=Web Inspector -X-GammaRay-Types=QWebPage; +X-GammaRay-Types="QWebPage;QQuickWebView" +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolFactory Exec=gammaray_webinspector_plugin diff -Nru gammaray-1.2.2/plugins/webinspector/gammaray_webinspector_ui.desktop gammaray-2.0.1/plugins/webinspector/gammaray_webinspector_ui.desktop --- gammaray-1.2.2/plugins/webinspector/gammaray_webinspector_ui.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/gammaray_webinspector_ui.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,4 @@ +[Desktop Entry] +X-GammaRay-Id=gammaray_webinspector +X-GammaRay-ServiceTypes=com.kdab.GammaRay.ToolUiFactory +Exec=gammaray_webinspector_ui_plugin diff -Nru gammaray-1.2.2/plugins/webinspector/webinspector.cpp gammaray-2.0.1/plugins/webinspector/webinspector.cpp --- gammaray-1.2.2/plugins/webinspector/webinspector.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -22,42 +22,83 @@ */ #include "webinspector.h" -#include "ui_webinspector.h" +#include "webviewmodel.h" -#include "include/objectmodel.h" -#include "include/objecttypefilterproxymodel.h" -#include "include/probeinterface.h" -#include "include/singlecolumnobjectproxymodel.h" +#include +#include +#include +#include +#include #include using namespace GammaRay; -WebInspector::WebInspector(ProbeInterface *probe, QWidget *parent) - : QWidget(parent), ui(new Ui::WebInspector) +WebInspector::WebInspector(ProbeInterface *probe, QObject *parent) + : QObject(parent) { - ui->setupUi(this); + WebViewModel *webViewModel = new WebViewModel(this); + webViewModel->setSourceModel(probe->objectListModel()); + probe->registerModel("com.kdab.GammaRay.WebPages", webViewModel); - ObjectTypeFilterProxyModel *webPageFilter = - new ObjectTypeFilterProxyModel(this); - webPageFilter->setSourceModel(probe->objectListModel()); - SingleColumnObjectProxyModel *singleColumnProxy = new SingleColumnObjectProxyModel(this); - singleColumnProxy->setSourceModel(webPageFilter); - ui->webPageComboBox->setModel(singleColumnProxy); - connect(ui->webPageComboBox, SIGNAL(activated(int)), SLOT(webPageSelected(int))); -} - -void WebInspector::webPageSelected(int index) -{ - QObject *obj = - ui->webPageComboBox->itemData(index, ObjectModel::ObjectRole).value(); - QWebPage *page = qobject_cast(obj); - if (page) { - page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); - ui->webInspector->setPage(page); + connect(probe->probe(), SIGNAL(objectCreated(QObject*)), SLOT(objectAdded(QObject*))); + + const QString serverAddress = ProbeSettings::value("TCPServer", QLatin1String("0.0.0.0")).toString(); + qputenv("QTWEBKIT_INSPECTOR_SERVER", serverAddress.toLocal8Bit() + ':' + QByteArray::number(Endpoint::defaultPort() + 1)); +} + +void WebInspector::objectAdded(QObject* obj) +{ + // both of the following cases seem to be needed, the web view object changes depending on + // you have "import QtWebKit.experimental 1.0" or not... + QObject *experimental = 0; + if (obj->inherits("QQuickWebView")) { + experimental = obj->property("experimental").value(); } + if (obj->inherits("QQuickWebViewExperimental")) + experimental = obj; + + if (!experimental) + return; + + // FIXME: this conversion fails with "QMetaProperty::read: Unable to handle unregistered datatype 'QWebPreferences*' for property 'QQuickWebViewExperimental::preferences'" + // if we don't have "import QtWebKit.experimental 1.0" + QObject *prefs = experimental->property("preferences").value(); + if (!prefs) + return; + prefs->setProperty("developerExtrasEnabled", true); } -Q_EXPORT_PLUGIN(WebInspectorFactory) -#include "webinspector.moc" +WebInspectorFactory::WebInspectorFactory(QObject* parent): QObject(parent) +{ +} + +QString WebInspectorFactory::id() const +{ + return WebInspector::staticMetaObject.className(); +} + +void WebInspectorFactory::init(ProbeInterface* probe) +{ + new WebInspector(probe, probe->probe()); +} + +QStringList WebInspectorFactory::supportedTypes() const +{ + QStringList types; +#ifdef HAVE_QT_WEBKIT1 + types.push_back(QWebPage::staticMetaObject.className(); +#endif + types.push_back("QQuickWebView"); + return types; +} + +QString WebInspectorFactory::name() const +{ + return tr("Web Pages"); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(WebInspectorFactory) +#endif diff -Nru gammaray-1.2.2/plugins/webinspector/webinspector.h gammaray-2.0.1/plugins/webinspector/webinspector.h --- gammaray-1.2.2/plugins/webinspector/webinspector.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Volker Krause This program is free software; you can redistribute it and/or modify @@ -24,40 +24,32 @@ #ifndef GAMMARAY_WEBINSPECTOR_WEBINSPECTOR_H #define GAMMARAY_WEBINSPECTOR_WEBINSPECTOR_H -#include "include/toolfactory.h" - -#include -#include +#include namespace GammaRay { -namespace Ui { - class WebInspector; -} - -class WebInspector : public QWidget +class WebInspector : public QObject { Q_OBJECT - Q_PLUGIN_METADATA(IID "com.kdab.gammaray.WebInspector") public: - explicit WebInspector(GammaRay::ProbeInterface *probe, QWidget *parent = 0); + explicit WebInspector(GammaRay::ProbeInterface *probe, QObject *parent = 0); private slots: - void webPageSelected(int index); - - private: - QScopedPointer ui; + void objectAdded(QObject *obj); }; -class WebInspectorFactory - : public QObject, public StandardToolFactory +class WebInspectorFactory : public QObject, public ToolFactory { Q_OBJECT Q_INTERFACES(GammaRay::ToolFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.WebInspector") public: - explicit WebInspectorFactory(QObject *parent = 0) : QObject(parent) {} - inline QString name() const { return tr("Web Pages"); } + explicit WebInspectorFactory(QObject *parent = 0); + QString id() const; + QString name() const; + void init(ProbeInterface* probe); + QStringList supportedTypes() const; }; } diff -Nru gammaray-1.2.2/plugins/webinspector/webinspector.ui gammaray-2.0.1/plugins/webinspector/webinspector.ui --- gammaray-1.2.2/plugins/webinspector/webinspector.ui 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspector.ui 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ - - - GammaRay::WebInspector - - - - 0 - 0 - 727 - 530 - - - - - - - - - - - - - - diff -Nru gammaray-1.2.2/plugins/webinspector/webinspectorwidget.cpp gammaray-2.0.1/plugins/webinspector/webinspectorwidget.cpp --- gammaray-1.2.2/plugins/webinspector/webinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,78 @@ +/* + webinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "webinspectorwidget.h" +#include "webviewmodel.h" +#include "ui_webinspectorwidget.h" + +#include +#include +#include + +using namespace GammaRay; + +WebInspectorWidget::WebInspectorWidget(QWidget* parent) + : QWidget(parent), ui(new Ui::WebInspectorWidget) +{ + ui->setupUi(this); + ui->webPageComboBox->setModel(ObjectBroker::model("com.kdab.GammaRay.WebPages")); + connect(ui->webPageComboBox, SIGNAL(activated(int)), SLOT(webPageSelected(int))); +} + +WebInspectorWidget::~WebInspectorWidget() +{ +} + +void WebInspectorWidget::webPageSelected(int index) +{ + QObject *obj = ui->webPageComboBox->itemData(index, ObjectModel::ObjectRole).value(); + + // Wk 1, local + if (QWebPage *page = qobject_cast(obj)) { + page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); + ui->webInspector->setPage(page); + // webinspector needs a show event to actually show anything, just setting the page is not enough... + ui->webInspector->hide(); + ui->webInspector->show(); + + ui->stack->setCurrentWidget(ui->wk1LocalPage); + } + + else if (ui->webPageComboBox->itemData(index, WebViewModel::WebKitVersionRole).toInt() == 2) { + QUrl url; + url.setScheme("http"); + url.setHost(Endpoint::instance()->serverAddress()); + url.setPort(Endpoint::defaultPort() + 1); + ui->webView->setUrl(url); + ui->stack->setCurrentWidget(ui->wk2Page); + } + + // WK1, remote + else { + ui->stack->setCurrentWidget(ui->wk1RemotePage); + } +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(WebInspectorUiFactory) +#endif diff -Nru gammaray-1.2.2/plugins/webinspector/webinspectorwidget.h gammaray-2.0.1/plugins/webinspector/webinspectorwidget.h --- gammaray-1.2.2/plugins/webinspector/webinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + webinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WEBINSPECTOR_WEBINSPECTORWIDGET_H +#define GAMMARAY_WEBINSPECTOR_WEBINSPECTORWIDGET_H + +#include + +#include +#include + +namespace GammaRay { + +namespace Ui { + class WebInspectorWidget; +} + +class WebInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit WebInspectorWidget(QWidget *parent = 0); + ~WebInspectorWidget(); + + private slots: + void webPageSelected(int index); + + private: + QScopedPointer ui; +}; + +class WebInspectorUiFactory : public QObject, public StandardToolUiFactory +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.WebInspectorUi") +}; + +} + +#endif diff -Nru gammaray-1.2.2/plugins/webinspector/webinspectorwidget.ui gammaray-2.0.1/plugins/webinspector/webinspectorwidget.ui --- gammaray-1.2.2/plugins/webinspector/webinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,71 @@ + + + GammaRay::WebInspectorWidget + + + + 0 + 0 + 727 + 530 + + + + + + + + + + + + + + + + + + + + + Sorry, WebKit1 introspection is not available remotely/out-of-process. + + + Qt::AlignCenter + + + + + + + + + + + + about:blank + + + + + + + + + + + + + QWebView + QWidget +
QtWebKitWidgets/QWebView
+
+ + QWebInspector + QWidget +
qwebinspector.h
+
+
+ + +
diff -Nru gammaray-1.2.2/plugins/webinspector/webviewmodel.cpp gammaray-2.0.1/plugins/webinspector/webviewmodel.cpp --- gammaray-1.2.2/plugins/webinspector/webviewmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webviewmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,81 @@ +/* + webviewmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#include "webviewmodel.h" + +#include + +#ifdef HAVE_QT_WEBKIT1 +#include +#endif + +using namespace GammaRay; + +WebViewModel::WebViewModel(QObject* parent): ObjectFilterProxyModelBase(parent) +{ +} + +WebViewModel::~WebViewModel() +{ +} + +QVariant WebViewModel::data(const QModelIndex& index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if ((role != Qt::DisplayRole && role != WebKitVersionRole) || index.column() != 0) + return QSortFilterProxyModel::data(index, role); + + const QObject *obj = index.data(ObjectModel::ObjectRole).value(); +#ifdef HAVE_QT_WEBKIT1 + const bool isWk1 = qobject_cast(obj); +#else + const bool isWk1 = false; +#endif + + if (role == Qt::DisplayRole) + return QString(Util::displayString(obj) + (isWk1 ? " [WebKit1]" : " [WebKit2]")); + if (role == WebKitVersionRole) + return isWk1 ? 1 : 2; + + Q_ASSERT(!"WTF?"); + return QVariant(); +} + +QMap< int, QVariant > WebViewModel::itemData(const QModelIndex& index) const +{ + QMap d = ObjectFilterProxyModelBase::itemData(index); + d.insert(WebKitVersionRole, data(index, WebKitVersionRole)); + return d; +} + +bool WebViewModel::filterAcceptsObject(QObject* object) const +{ + return +#ifdef HAVE_QT_WEBKIT1 + qobject_cast(object) || +#endif + object->inherits("QQuickWebView"); +} diff -Nru gammaray-1.2.2/plugins/webinspector/webviewmodel.h gammaray-2.0.1/plugins/webinspector/webviewmodel.h --- gammaray-1.2.2/plugins/webinspector/webviewmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/webinspector/webviewmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + webviewmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WEBVIEWMODEL_H +#define GAMMARAY_WEBVIEWMODEL_H + +#include + +namespace GammaRay { + +class WebViewModel : public ObjectFilterProxyModelBase +{ + Q_OBJECT +public: + explicit WebViewModel(QObject *parent = 0); + ~WebViewModel(); + + enum Role { + WebKitVersionRole = ObjectModel::UserRole + }; + + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + QMap< int, QVariant > itemData(const QModelIndex& index) const; + bool filterAcceptsObject(QObject* object) const; +}; + +} + +#endif // GAMMARAY_WEBVIEWMODEL_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/CMakeLists.txt gammaray-2.0.1/plugins/widgetinspector/CMakeLists.txt --- gammaray-1.2.2/plugins/widgetinspector/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +set(gammaray_widgetinspector_plugin_srcs + widgetinspector.cpp + widgetinspectorinterface.cpp + widgetinspectorserver.cpp + widgetinspectorclient.cpp + widgetinspectorwidget.cpp + overlaywidget.cpp + widgettreemodel.cpp + widgetpreviewwidget.cpp + paintbufferviewer.cpp + paintbufferreplaywidget.cpp +) + +if(HAVE_PRIVATE_QT_HEADERS) + set(gammaray_widgetinspector_plugin_srcs + ${gammaray_widgetinspector_plugin_srcs} + paintbuffermodel.cpp + ) +endif() + +qt4_wrap_ui(gammaray_widgetinspector_plugin_srcs + widgetinspectorwidget.ui + paintbufferviewer.ui +) + +gammaray_add_plugin(gammaray_widgetinspector_plugin + gammaray_widgetinspector.desktop + ${gammaray_widgetinspector_plugin_srcs} +) + +target_link_libraries(gammaray_widgetinspector_plugin + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_core + gammaray_ui +) + +add_library(gammaray_widget_export_actions SHARED + widgetinspector_export_actions.cpp + uiextractor.cpp +) + +set_target_properties(gammaray_widget_export_actions PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}" +) + +set(EXTRA_LIBS) +if(HAVE_QT_DESIGNER) + list(APPEND EXTRA_LIBS ${QT_QTDESIGNER_LIBRARIES}) +endif() + +target_link_libraries(gammaray_widget_export_actions + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTSVG_LIBRARIES} + ${Qt5PrintSupport_LIBRARIES} + + ${EXTRA_LIBS} +) + +install(TARGETS gammaray_widget_export_actions DESTINATION ${PLUGIN_INSTALL_DIR}/${GAMMARAY_PLUGIN_VERSION}/${GAMMARAY_PROBE_ABI}) diff -Nru gammaray-1.2.2/plugins/widgetinspector/gammaray_widgetinspector.desktop gammaray-2.0.1/plugins/widgetinspector/gammaray_widgetinspector.desktop --- gammaray-1.2.2/plugins/widgetinspector/gammaray_widgetinspector.desktop 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/gammaray_widgetinspector.desktop 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Widgets +X-GammaRay-Types="QWidget;QApplication" +X-GammaRay-ServiceTypes="com.kdab.GammaRay.ToolFactory;com.kdab.GammaRay.ToolUiFactory" +Exec=gammaray_widgetinspector_plugin diff -Nru gammaray-1.2.2/plugins/widgetinspector/overlaywidget.cpp gammaray-2.0.1/plugins/widgetinspector/overlaywidget.cpp --- gammaray-1.2.2/plugins/widgetinspector/overlaywidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/overlaywidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,198 @@ +/* + overlaywidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Tobias Koenig + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "overlaywidget.h" + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +static QWidget *toplevelWidget(QWidget *widget) +{ + QWidget *parent = widget; + while (parent->parentWidget() && + (qobject_cast(parent->parentWidget()) == 0) && + (qobject_cast(parent) == 0)) { + parent = parent->parentWidget(); + } + + return parent; +} + +OverlayWidget::OverlayWidget() + : m_currentToplevelWidget(0), + m_currentWidget(0) +{ + setAttribute(Qt::WA_TransparentForMouseEvents); + setFocusPolicy(Qt::NoFocus); +} + +void OverlayWidget::placeOn(QWidget *widget) +{ + if (widget == 0) { + if (m_currentWidget) { + m_currentWidget->removeEventFilter(this); + } + + if (m_currentToplevelWidget) { + m_currentToplevelWidget->removeEventFilter(this); + } + + m_currentToplevelWidget = 0; + m_currentWidget = 0; + m_widgetRect = QRect(); + m_layoutPath = QPainterPath(); + + update(); + return; + } + + QWidget *toplevel = toplevelWidget(widget); + Q_ASSERT(toplevel); + + if (m_currentWidget) { + m_currentWidget->removeEventFilter(this); + } + + m_currentWidget = widget; + + if (toplevel != m_currentToplevelWidget) { + if (m_currentToplevelWidget) { + m_currentToplevelWidget->removeEventFilter(this); + } + + m_currentToplevelWidget = toplevel; + + setParent(toplevel); + move(0, 0); + resize(toplevel->size()); + + m_currentToplevelWidget->installEventFilter(this); + + show(); + } + + m_currentWidget->installEventFilter(this); + + updatePositions(); +} + +bool OverlayWidget::eventFilter(QObject *receiver, QEvent *event) +{ + if (receiver == m_currentToplevelWidget) { + if (event->type() == QEvent::Resize) { + resizeOverlay(); + updatePositions(); + } + } else if (receiver == m_currentWidget) { + if (event->type() == QEvent::Resize || event->type() == QEvent::Move) { + resizeOverlay(); + updatePositions(); + } + } + + return false; +} + +void OverlayWidget::updatePositions() +{ + if (!m_currentWidget || !m_currentToplevelWidget) { + return; + } + + if (!m_currentWidget->isVisible() || m_currentWidget->isHidden()) { + m_widgetColor = Qt::green; + } else { + m_widgetColor = Qt::red; + } + + const QPoint parentPos = m_currentWidget->mapTo(m_currentToplevelWidget, QPoint(0, 0)); + m_widgetRect = QRect(parentPos.x(), parentPos.y(), + m_currentWidget->width(), + m_currentWidget->height()).adjusted(0, 0, -1, -1); + + m_layoutPath = QPainterPath(); + + if (m_currentWidget->layout() && + qstrcmp(m_currentWidget->layout()->metaObject()->className(), "QMainWindowLayout") != 0) { + const QRect layoutGeometry = m_currentWidget->layout()->geometry(); + + const QRect mappedOuterRect = + QRect(m_currentWidget->mapTo(m_currentToplevelWidget, + layoutGeometry.topLeft()), layoutGeometry.size()); + + QPainterPath outerPath; + outerPath.addRect(mappedOuterRect.adjusted(1, 1, -2, -2)); + + QPainterPath innerPath; + for (int i = 0; i < m_currentWidget->layout()->count(); ++i) { + QLayoutItem *item = m_currentWidget->layout()->itemAt(i); + const QRect mappedInnerRect = + QRect(m_currentWidget->mapTo(m_currentToplevelWidget, + item->geometry().topLeft()), item->geometry().size()); + innerPath.addRect(mappedInnerRect); + } + + m_layoutPath.setFillRule(Qt::OddEvenFill); + m_layoutPath = outerPath.subtracted(innerPath); + + if (m_layoutPath.isEmpty()) { + m_layoutPath = outerPath; + m_layoutPath.addPath(innerPath); + m_drawLayoutOutlineOnly = true; + } else { + m_drawLayoutOutlineOnly = false; + } + } + + update(); +} + +void OverlayWidget::resizeOverlay() +{ + if (m_currentToplevelWidget) { + move(0, 0); + resize(m_currentToplevelWidget->size()); + } +} + +void OverlayWidget::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.setPen(m_widgetColor); + p.drawRect(m_widgetRect); + + QBrush brush(Qt::BDiagPattern); + brush.setColor(Qt::blue); + + if (!m_drawLayoutOutlineOnly) { + p.fillPath(m_layoutPath, brush); + } + + p.setPen(Qt::blue); + p.drawPath(m_layoutPath); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/overlaywidget.h gammaray-2.0.1/plugins/widgetinspector/overlaywidget.h --- gammaray-1.2.2/plugins/widgetinspector/overlaywidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/overlaywidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + overlaywidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Tobias Koenig + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_OVERLAYWIDGET_H +#define GAMMARAY_WIDGETINSPECTOR_OVERLAYWIDGET_H + +#include + +namespace GammaRay { + +class OverlayWidget : public QWidget +{ + Q_OBJECT + + public: + OverlayWidget(); + + void placeOn(QWidget *widget); + + virtual bool eventFilter(QObject *receiver, QEvent *event); + + protected: + virtual void paintEvent(QPaintEvent *event); + + private: + void resizeOverlay(); + void updatePositions(); + + QWidget *m_currentToplevelWidget; + QWidget *m_currentWidget; + QRect m_widgetRect; + QColor m_widgetColor; + + QPainterPath m_layoutPath; + bool m_drawLayoutOutlineOnly; +}; + +} + +#endif diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbuffermodel.cpp gammaray-2.0.1/plugins/widgetinspector/paintbuffermodel.cpp --- gammaray-1.2.2/plugins/widgetinspector/paintbuffermodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbuffermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,175 @@ +/* + paintbuffermodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray.h" +#ifdef HAVE_PRIVATE_QT_HEADERS +#include "paintbuffermodel.h" + +using namespace GammaRay; + +struct cmd_t { + QPaintBufferPrivate::Command cmd; + const char *name; +}; + +#define CMD(cmd) { QPaintBufferPrivate::Cmd_ ## cmd, #cmd } + +static cmd_t cmdTypes[] = { + CMD(Save), + CMD(Restore), + CMD(SetBrush), + CMD(SetBrushOrigin), + CMD(SetClipEnabled), + CMD(SetCompositionMode), + CMD(SetOpacity), + CMD(SetPen), + CMD(SetRenderHints), + CMD(SetTransform), + CMD(SetBackgroundMode), + CMD(ClipPath), + CMD(ClipRect), + CMD(ClipRegion), + CMD(ClipVectorPath), + CMD(DrawVectorPath), + CMD(FillVectorPath), + CMD(StrokeVectorPath), + CMD(DrawConvexPolygonF), + CMD(DrawConvexPolygonI), + CMD(DrawEllipseF), + CMD(DrawEllipseI), + CMD(DrawLineF), + CMD(DrawLineI), + CMD(DrawPath), + CMD(DrawPointsF), + CMD(DrawPointsI), + CMD(DrawPolygonF), + CMD(DrawPolygonI), + CMD(DrawPolylineF), + CMD(DrawPolylineI), + CMD(DrawRectF), + CMD(DrawRectI), + CMD(FillRectBrush), + CMD(FillRectColor), + CMD(DrawText), + CMD(DrawTextItem), + CMD(DrawImagePos), + CMD(DrawImageRect), + CMD(DrawPixmapPos), + CMD(DrawPixmapRect), + CMD(DrawTiledPixmap), + CMD(SystemStateChanged), + CMD(Translate), + CMD(DrawStaticText) +}; + +class PaintBufferPrivacyViolater : public QPainterReplayer +{ + public: + QPaintBufferPrivate *extract() const { return d; } +}; + +PaintBufferModel::PaintBufferModel(QObject *parent) + : QAbstractTableModel(parent), m_privateBuffer(0) +{ +} + +void PaintBufferModel::setPaintBuffer(const QPaintBuffer &buffer) +{ + beginResetModel(); + m_buffer = buffer; + PaintBufferPrivacyViolater p; + p.processCommands(buffer, 0, 0, -1); // end < begin -> no processing + m_privateBuffer = p.extract(); + endResetModel(); +} + +QPaintBuffer PaintBufferModel::buffer() const +{ + return m_buffer; +} + +QVariant PaintBufferModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || !m_privateBuffer) { + return QVariant(); + } + + if (role == Qt::DisplayRole) { + const QPaintBufferCommand cmd = m_privateBuffer->commands.at(index.row()); + switch (index.column()) { + case 0: + return cmdTypes[cmd.id].name; + case 1: + { +#ifndef QT_NO_DEBUG_STREAM + QString desc = m_buffer.commandDescription(index.row()); + const QString prefix = QLatin1String("Cmd_") + QLatin1String(cmdTypes[cmd.id].name); + + if (desc.startsWith(prefix)) { + desc = desc.mid(prefix.length()); + } + + if (desc.startsWith(QLatin1String(": ")) || desc.startsWith(QLatin1String(", "))) { + desc = desc.mid(2); + } + return desc; +#endif + } + } + } + + return QVariant(); +} + +int PaintBufferModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); +#ifndef QT_NO_DEBUG_STREAM + return 2; +#else + return 1; +#endif +} + +int PaintBufferModel::rowCount(const QModelIndex &parent) const +{ + if (!m_privateBuffer || parent.isValid()) { + return 0; + } + return m_privateBuffer->commands.size(); +} + +QVariant PaintBufferModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch (section) { + case 0: + return tr("Command"); + case 1: + return tr("Arguments"); + } + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +#endif diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbuffermodel.h gammaray-2.0.1/plugins/widgetinspector/paintbuffermodel.h --- gammaray-1.2.2/plugins/widgetinspector/paintbuffermodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbuffermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ +/* + paintbuffermodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PAINTBUFFERMODEL_H +#define GAMMARAY_PAINTBUFFERMODEL_H + +#include "config-gammaray.h" + +#ifdef HAVE_PRIVATE_QT_HEADERS +#include + +#include //krazy:exclude=camelcase + +class QPaintBuffer; + +namespace GammaRay { + +/** + * Model that shows commands stored in a QPaintBuffer. + */ +class PaintBufferModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit PaintBufferModel(QObject *parent = 0); + + void setPaintBuffer(const QPaintBuffer &buffer); + QPaintBuffer buffer() const; + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + private: + QPaintBuffer m_buffer; + QPaintBufferPrivate *m_privateBuffer; +}; + +} + +#endif + +#endif // GAMMARAY_PAINTBUFFERMODEL_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbufferreplaywidget.cpp gammaray-2.0.1/plugins/widgetinspector/paintbufferreplaywidget.cpp --- gammaray-1.2.2/plugins/widgetinspector/paintbufferreplaywidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbufferreplaywidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +/* + paintbufferreplaywidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "paintbufferreplaywidget.h" +#include + +using namespace GammaRay; + +PaintBufferReplayWidget::PaintBufferReplayWidget(QWidget *parent) + : QWidget(parent), + m_zoomFactor(1) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); +} + +void PaintBufferReplayWidget::setZoomFactor(int zoom) +{ + m_zoomFactor = zoom; + resize(sizeHint()); + update(); +} + +void PaintBufferReplayWidget::setPixmap(const QPixmap &pixmap) +{ + m_pixmap = pixmap; + resize(sizeHint()); + update(); +} + +QSize PaintBufferReplayWidget::sizeHint() const +{ + const QSize size = m_pixmap.size(); + return QSize(size.width() * m_zoomFactor, + size.height() * m_zoomFactor); +} + +void PaintBufferReplayWidget::paintEvent(QPaintEvent * /*event*/) +{ + QPainter p(this); + p.setRenderHint(QPainter::SmoothPixmapTransform, false); + p.scale(m_zoomFactor, m_zoomFactor); + p.drawPixmap(QPoint(0, 0), m_pixmap); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbufferreplaywidget.h gammaray-2.0.1/plugins/widgetinspector/paintbufferreplaywidget.h --- gammaray-1.2.2/plugins/widgetinspector/paintbufferreplaywidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbufferreplaywidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + paintbufferreplaywidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PAINTBUFFERREPLAYWIDGET_H +#define GAMMARAY_PAINTBUFFERREPLAYWIDGET_H + +#include "config-gammaray.h" + +#include + +namespace GammaRay { + +/** + * A widget painting a certain sub-set of a QPaintBuffer. + */ +class PaintBufferReplayWidget : public QWidget +{ + Q_OBJECT + public: + explicit PaintBufferReplayWidget(QWidget *parent = 0); + + virtual QSize sizeHint() const; + + public slots: + void setZoomFactor(int zoom); + void setPixmap(const QPixmap &pixmap); + + protected: + virtual void paintEvent(QPaintEvent *event); + + private: + QPixmap m_pixmap; + int m_zoomFactor; +}; + +} + +#endif // GAMMARAY_PAINTBUFFERREPLAYWIDGET_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.cpp gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.cpp --- gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ +/* + paintbufferviewer.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "paintbufferviewer.h" + +#include "ui_paintbufferviewer.h" + +#include "widgetinspectorinterface.h" +#include + +using namespace GammaRay; + +PaintBufferViewer::PaintBufferViewer(QWidget *parent) + : QDialog(parent) + , ui(new Ui::PaintBufferViewer) +{ + ui->setupUi(this); + + ui->commandView->setModel(ObjectBroker::model("com.kdab.GammaRay.PaintBufferModel")); + ui->commandView->setSelectionModel(ObjectBroker::selectionModel(ui->commandView->model())); + + ui->splitter->setStretchFactor(0, 0); + ui->splitter->setStretchFactor(1, 1); + + connect(ObjectBroker::object(), SIGNAL(paintAnalyzed(QPixmap)), + ui->replayWidget, SLOT(setPixmap(QPixmap))); + connect(ui->zoomSlider, SIGNAL(valueChanged(int)), ui->replayWidget, SLOT(setZoomFactor(int))); +} + +PaintBufferViewer::~PaintBufferViewer() +{ +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.h gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.h --- gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + paintbufferviewer.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PAINTBUFFERVIEWER_H +#define GAMMARAY_PAINTBUFFERVIEWER_H + +#include "config-gammaray.h" + +#include + +class QAbstractItemModel; + +namespace GammaRay { + +class WidgetInspectorInterface; + +namespace Ui { + class PaintBufferViewer; +} + +/** + * A widget to look at the command list in a QPaintBuffer. + */ +class PaintBufferViewer : public QDialog +{ + Q_OBJECT + public: + explicit PaintBufferViewer(QWidget *parent = 0); + virtual ~PaintBufferViewer(); + + private: + QScopedPointer ui; +}; + +} + +#endif diff -Nru gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.ui gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.ui --- gammaray-1.2.2/plugins/widgetinspector/paintbufferviewer.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/paintbufferviewer.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,108 @@ + + + GammaRay::PaintBufferViewer + + + + 0 + 0 + 591 + 378 + + + + + 0 + + + + + Qt::Horizontal + + + + false + + + + + + + + + + &Zoom: + + + zoomSlider + + + + + + + 1 + + + 8 + + + 1 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + Qt::AlignCenter + + + + + 0 + 0 + 227 + 341 + + + + + + + + + + + + + + GammaRay::PaintBufferReplayWidget + QWidget +
paintbufferreplaywidget.h
+ 1 +
+
+ + +
diff -Nru gammaray-1.2.2/plugins/widgetinspector/uiextractor.cpp gammaray-2.0.1/plugins/widgetinspector/uiextractor.cpp --- gammaray-1.2.2/plugins/widgetinspector/uiextractor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/uiextractor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,70 @@ +/* + uiextractor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "uiextractor.h" + +#ifdef HAVE_QT_DESIGNER +#include +#include +#include +#include + +using namespace GammaRay; + +bool UiExtractor::checkProperty(QObject *obj, const QString &prop) const +{ + const QMetaObject *mo = obj->metaObject(); + const QMetaProperty mp = mo->property(mo->indexOfProperty(prop.toLatin1())); + + // TODO come up with some more aggressive filtering + if (mp.isValid() && mp.isDesignable(obj) && mp.isStored(obj) && mp.isWritable()) { + const QVariant value = mp.read(obj); + + // try to figure out the default by resetting to it + if (mp.isResettable()) { + mp.reset(obj); + if (mp.read(obj) == value) { + return false; + } + mp.write(obj, value); + return true; + } + + // some guessing for non-resettable properties + if (value.isNull() || !value.isValid()) { + return false; + } + + if (value.type() == QVariant::String) { + return !value.toString().isEmpty(); + } else if (value.type() == QVariant::Locale) { + return value.value() != QLocale::system(); + } + + return true; + } + + return false; +} + +#endif diff -Nru gammaray-1.2.2/plugins/widgetinspector/uiextractor.h gammaray-2.0.1/plugins/widgetinspector/uiextractor.h --- gammaray-1.2.2/plugins/widgetinspector/uiextractor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/uiextractor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + uiextractor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_UIEXTRACTOR_H +#define GAMMARAY_WIDGETINSPECTOR_UIEXTRACTOR_H + +#include "config-gammaray.h" + +#ifdef HAVE_QT_DESIGNER +#include + +namespace GammaRay { + +class UiExtractor : public QFormBuilder +{ + protected: + virtual bool checkProperty(QObject *obj, const QString &prop) const; +}; + +} + +#endif + +#endif // GAMMARAY_UIEXTRACTOR_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorclient.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspectorclient.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + * widgetinspectorclient.cpp + * + * This file is part of GammaRay, the Qt application inspection and + * manipulation tool. + * + * Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + * Author: Milian Wolff + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "widgetinspectorclient.h" +#include + +using namespace GammaRay; + +WidgetInspectorClient::WidgetInspectorClient(QObject *parent) + : WidgetInspectorInterface(parent) +{ +} + +WidgetInspectorClient::~WidgetInspectorClient() +{ +} + +#define WRAP_REMOTE(func, type) \ +void WidgetInspectorClient::func(type arg) \ +{ \ + Endpoint::instance()->invokeObject(objectName(), #func, QVariantList() << arg); \ +} + +WRAP_REMOTE(saveAsImage, const QString &) +WRAP_REMOTE(saveAsPdf, const QString &) +WRAP_REMOTE(saveAsSvg, const QString &) +WRAP_REMOTE(saveAsUiFile, const QString &) + +void WidgetInspectorClient::analyzePainting() +{ + Endpoint::instance()->invokeObject(objectName(), "analyzePainting"); +} + +void WidgetInspectorClient::checkFeatures() +{ + Endpoint::instance()->invokeObject(objectName(), "checkFeatures"); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorclient.h gammaray-2.0.1/plugins/widgetinspector/widgetinspectorclient.h --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + * widgetinspectorclient.h + * + * This file is part of GammaRay, the Qt application inspection and + * manipulation tool. + * + * Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + * Author: Milian Wolff + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef GAMMARAY_WIDGETINSPECTORCLIENT_H +#define GAMMARAY_WIDGETINSPECTORCLIENT_H + +#include + +namespace GammaRay { + +class WidgetInspectorClient : public WidgetInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::WidgetInspectorInterface) + + public: + explicit WidgetInspectorClient(QObject *parent); + ~WidgetInspectorClient(); + + private: + virtual void saveAsImage(const QString &fileName); + virtual void saveAsSvg(const QString &fileName); + virtual void saveAsPdf(const QString &fileName); + virtual void saveAsUiFile(const QString &fileName); + virtual void analyzePainting(); + virtual void checkFeatures(); +}; +} + +#endif // GAMMARAY_WIDGETINSPECTORCLIENT_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspector.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspector.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,32 @@ +/* + widgetinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgetinspector.h" + +#include + +using namespace GammaRay; + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN(WidgetInspectorFactory) +#endif diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspector_export_actions.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspector_export_actions.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspector_export_actions.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspector_export_actions.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,83 @@ +/* + widgetinspector_export_actions.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file widgetinspector_export_actions.cpp + * dlopen hack to avoid dependencies on QtSvg and QtDesigner in the main probe. + */ + +#include "config-gammaray.h" +#include "uiextractor.h" + +#ifdef HAVE_QT_SVG +#include +#endif + +#ifdef HAVE_QT_PRINTSUPPORT +#include +#endif + +#include +#include +#include + +extern "C" { + +#ifdef HAVE_QT_SVG +Q_DECL_EXPORT void gammaray_save_widget_to_svg(QWidget *widget, const QString &fileName) +{ + QSvgGenerator svg; + svg.setFileName(fileName); + svg.setSize(widget->size()); + svg.setViewBox(QRect(QPoint(0, 0), widget->size())); + QPainter painter(&svg); + widget->render(&painter); + painter.end(); +} +#endif + +#ifdef HAVE_QT_DESIGNER +Q_DECL_EXPORT void gammaray_save_widget_to_ui(QWidget *widget, const QString &fileName) +{ + QFile file(fileName); + if (file.open(QFile::WriteOnly)) { + GammaRay::UiExtractor formBuilder; + formBuilder.save(&file, widget); + } +} +#endif + +#ifdef HAVE_QT_PRINTSUPPORT +Q_DECL_EXPORT void gammaray_save_widget_to_pdf(QWidget *widget, const QString &fileName) +{ + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFileName(fileName); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel); + printer.setPaperSize(widget->size(), QPrinter::DevicePixel); + + widget->render(&printer); +} +#endif + +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspector.h gammaray-2.0.1/plugins/widgetinspector/widgetinspector.h --- gammaray-1.2.2/plugins/widgetinspector/widgetinspector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + widgetinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTOR_H +#define GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTOR_H + +#include + +#include "widgetinspectorwidget.h" +#include "widgetinspectorserver.h" + +namespace GammaRay { + +class WidgetInspectorFactory + : public QObject, public StandardToolFactory2 +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ToolFactory GammaRay::ToolUiFactory) + Q_PLUGIN_METADATA(IID "com.kdab.gammaray.WidgetInspector") + public: + explicit WidgetInspectorFactory(QObject *parent = 0) : QObject(parent) + { + } + + inline QString name() const + { + return tr("Widgets"); + } +}; + +} + +#endif // GAMMARAY_WIDGETINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorinterface.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspectorinterface.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorinterface.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorinterface.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,39 @@ +/* + widgetinspectorinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgetinspectorinterface.h" + +#include + +using namespace GammaRay; + +WidgetInspectorInterface::WidgetInspectorInterface(QObject *parent) + : QObject(parent) +{ + ObjectBroker::registerObject(this); +} + +WidgetInspectorInterface::~WidgetInspectorInterface() +{ + +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorinterface.h gammaray-2.0.1/plugins/widgetinspector/widgetinspectorinterface.h --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorinterface.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorinterface.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,59 @@ +/* + widgetinspectorinterface.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTORINTERFACE_H +#define GAMMARAY_WIDGETINSPECTORINTERFACE_H + +#include + +class QPixmap; + +namespace GammaRay { + +class WidgetInspectorInterface : public QObject +{ + Q_OBJECT + public: + explicit WidgetInspectorInterface(QObject *parent = 0); + virtual ~WidgetInspectorInterface(); + + public slots: + virtual void checkFeatures() = 0; + virtual void saveAsImage(const QString &fileName) = 0; + virtual void saveAsSvg(const QString &fileName) = 0; + virtual void saveAsPdf(const QString &fileName) = 0; + virtual void saveAsUiFile(const QString &fileName) = 0; + + virtual void analyzePainting() = 0; + + signals: + void widgetPreviewAvailable(const QPixmap &pixmap); + void paintAnalyzed(const QPixmap &pixmap); + void features(bool svg, bool print, bool designer, bool privateHeaders); +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::WidgetInspectorInterface, "com.kdab.GammaRay.WidgetInspector") + +#endif // GAMMARAY_WIDGETINSPECTORINTERFACE_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorserver.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspectorserver.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorserver.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorserver.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,461 @@ +/* + widgetinspectorserver.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgetinspectorserver.h" + +#include "config-gammaray.h" +#include "overlaywidget.h" +#include "paintbufferviewer.h" +#include "widgettreemodel.h" +#include "paintbuffermodel.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "other/modelutils.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef HAVE_PRIVATE_QT_HEADERS +#include //krazy:exclude=camelcase +#endif + +Q_DECLARE_METATYPE(const QStyle *) + +using namespace GammaRay; +using namespace std; + +WidgetInspectorServer::WidgetInspectorServer(ProbeInterface *probe, QObject *parent) + : WidgetInspectorInterface(parent) + , m_overlayWidget(new OverlayWidget) + , m_propertyController(new PropertyController(objectName(), this)) + , m_updatePreviewTimer(new QTimer(this)) + , m_paintBufferModel(0) + , m_paintAnalyzerTimer(new QTimer(this)) + , m_probe(probe) +{ + registerWidgetMetaTypes(); + registerVariantHandlers(); + probe->installGlobalEventFilter(this); + + m_updatePreviewTimer->setSingleShot(true); + m_updatePreviewTimer->setInterval(100); + connect(m_updatePreviewTimer, SIGNAL(timeout()), SLOT(updateWidgetPreview())); + + m_paintAnalyzerTimer->setSingleShot(true); + m_paintAnalyzerTimer->setInterval(100); + connect(m_paintAnalyzerTimer, SIGNAL(timeout()), SLOT(updatePaintAnalyzer())); + + m_overlayWidget->hide(); + connect(m_overlayWidget, SIGNAL(destroyed(QObject*)), + SLOT(handleOverlayWidgetDestroyed(QObject*))); + + WidgetTreeModel *widgetFilterProxy = new WidgetTreeModel(this); + widgetFilterProxy->setSourceModel(probe->objectTreeModel()); + probe->registerModel("com.kdab.GammaRay.WidgetTree", widgetFilterProxy); + + m_widgetSelectionModel = ObjectBroker::selectionModel(widgetFilterProxy); + connect(m_widgetSelectionModel, + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(widgetSelected(QItemSelection))); + +#ifdef HAVE_PRIVATE_QT_HEADERS + m_paintBufferModel = new PaintBufferModel(this); + probe->registerModel("com.kdab.GammaRay.PaintBufferModel", m_paintBufferModel); + connect(ObjectBroker::selectionModel(m_paintBufferModel), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(eventuallyUpdatePaintAnalyzer())); +#endif + + // TODO this needs to be delayed until there actually is something to select + selectDefaultItem(); + + if (!m_probe->hasReliableObjectTracking()) { + connect(m_probe->probe(), SIGNAL(objectCreated(QObject*)), SLOT(objectCreated(QObject*))); + discoverObjects(); + } +} + +static bool isMainWindowSubclassAcceptor(const QVariant &v) +{ + return qobject_cast(v.value()); +} + +void WidgetInspectorServer::selectDefaultItem() +{ + const QAbstractItemModel *viewModel = m_widgetSelectionModel->model(); + const QModelIndexList matches = + ModelUtils::match( + viewModel, viewModel->index(0, 0), + ObjectModel::ObjectRole, isMainWindowSubclassAcceptor); + + if (!matches.isEmpty()) { + m_widgetSelectionModel->select(matches.first(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + } +} + +void WidgetInspectorServer::widgetSelected(const QItemSelection &selection) +{ + m_propertyController->setObject(0); + + if (selection.isEmpty()) + return; + const QModelIndex index = selection.first().topLeft(); + + QWidget *widget = 0; + if (index.isValid()) { + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + m_propertyController->setObject(obj); + widget = qobject_cast(obj); + QLayout *layout = qobject_cast(obj); + if (!widget && layout) { + widget = layout->parentWidget(); + } + } + + if (m_selectedWidget == widget) { + return; + } + + m_selectedWidget = widget; + + if (m_selectedWidget && + (qobject_cast(m_selectedWidget) || + m_selectedWidget->inherits("QDesktopScreenWidget"))) { + m_overlayWidget->placeOn(0); + return; + } + + m_overlayWidget->placeOn(m_selectedWidget); + + if (!m_selectedWidget) { + return; + } + + updateWidgetPreview(); +} + +bool WidgetInspectorServer::eventFilter(QObject *object, QEvent *event) +{ + if (object == m_selectedWidget && event->type() == QEvent::Paint) { + // delay pixmap grabbing such that the object can update itself beforehand + // also use a timer to prevent aggregation of previews + if (!m_updatePreviewTimer->isActive()) { + m_updatePreviewTimer->start(); + } + } + + // make modal dialogs non-modal so that the gammaray window is still reachable + // TODO: should only be done in in-process mode + if (event->type() == QEvent::Show) { + QDialog *dlg = qobject_cast(object); + if (dlg) { + dlg->setWindowModality(Qt::NonModal); + } + } + + if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *mouseEv = static_cast(event); + if (mouseEv->button() == Qt::LeftButton && + mouseEv->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { + QWidget *widget = QApplication::widgetAt(mouseEv->globalPos()); + if (widget) { + // also select the corresponding model if a view was selected + if (QAbstractItemView *view = Util::findParentOfType(object)) { + m_probe->selectObject(view->model()); + } else if (QComboBox *box = Util::findParentOfType(object)) { + m_probe->selectObject(box->model()); + } + + m_probe->selectObject(widget, widget->mapFromGlobal(mouseEv->globalPos())); + widgetSelected(widget); + } + } + } + + return QObject::eventFilter(object, event); +} + +void WidgetInspectorServer::updateWidgetPreview() +{ + if (!m_selectedWidget) { + return; + } + + emit widgetPreviewAvailable(pixmapForWidget(m_selectedWidget)); +} + +QPixmap WidgetInspectorServer::pixmapForWidget(QWidget *widget) +{ + // prevent "recursion", i.e. infinite update loop, in our eventFilter + Util::SetTempValue > guard(m_selectedWidget, 0); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + return QPixmap::grabWidget(widget); +#else + return widget->grab(); +#endif +} + +void WidgetInspectorServer::handleOverlayWidgetDestroyed(QObject *) +{ + // the target application might have destroyed the overlay widget + // (e.g. because the parent of the overlay got destroyed). + // just recreate a new one in this case + m_overlayWidget = new OverlayWidget; + m_overlayWidget->hide(); +} + +void WidgetInspectorServer::widgetSelected(QWidget *widget) +{ + const QAbstractItemModel *model = m_widgetSelectionModel->model(); + const QModelIndexList indexList = + model->match(model->index(0, 0), + ObjectModel::ObjectRole, + QVariant::fromValue(widget), 1, + Qt::MatchExactly | Qt::MatchRecursive); + if (indexList.isEmpty()) { + return; + } + const QModelIndex index = indexList.first(); + m_widgetSelectionModel->select( + index, + QItemSelectionModel::Select | QItemSelectionModel::Clear | + QItemSelectionModel::Rows | QItemSelectionModel::Current); +} + +// TODO the following actions should actually store the file on the client! + +void WidgetInspectorServer::saveAsImage(const QString& fileName) +{ + if (fileName.isEmpty() || !m_selectedWidget) { + return; + } + + m_overlayWidget->hide(); + QPixmap pixmap = pixmapForWidget(m_selectedWidget); + m_overlayWidget->show(); + pixmap.save(fileName); +} + +void WidgetInspectorServer::saveAsSvg(const QString &fileName) +{ + if (fileName.isEmpty() || !m_selectedWidget) { + return; + } + + m_overlayWidget->hide(); + callExternalExportAction("gammaray_save_widget_to_svg", m_selectedWidget, fileName); + m_overlayWidget->show(); +} + +void WidgetInspectorServer::saveAsPdf(const QString &fileName) +{ + if (fileName.isEmpty() || !m_selectedWidget) { + return; + } + + m_overlayWidget->hide(); + callExternalExportAction("gammaray_save_widget_to_pdf", m_selectedWidget, fileName); + m_overlayWidget->show(); +} + +void WidgetInspectorServer::saveAsUiFile(const QString &fileName) +{ + if (fileName.isEmpty() || !m_selectedWidget) { + return; + } + + callExternalExportAction("gammaray_save_widget_to_ui", m_selectedWidget, fileName); +} + +void WidgetInspectorServer::callExternalExportAction(const char *name, + QWidget *widget, + const QString &fileName) +{ + if (!m_externalExportActions.isLoaded()) { + m_externalExportActions.setFileName( + Paths::currentProbePath() + QLatin1String("/libgammaray_widget_export_actions")); + + m_externalExportActions.load(); + } + + void(*function)(QWidget *, const QString &) = + reinterpret_cast(m_externalExportActions.resolve(name)); + + if (!function) { + cerr << Q_FUNC_INFO << ' ' << qPrintable(m_externalExportActions.errorString()) << endl; + return; + } + function(widget, fileName); +} + +void WidgetInspectorServer::analyzePainting() +{ + if (!m_selectedWidget) { + return; + } +#ifdef HAVE_PRIVATE_QT_HEADERS + QPaintBuffer buffer; + m_overlayWidget->hide(); + buffer.setBoundingRect(m_selectedWidget->rect()); + m_selectedWidget->render(&buffer); + m_overlayWidget->show(); + m_paintBufferModel->setPaintBuffer(buffer); + eventuallyUpdatePaintAnalyzer(); +#endif +} + +void WidgetInspectorServer::eventuallyUpdatePaintAnalyzer() +{ +#ifdef HAVE_PRIVATE_QT_HEADERS + m_paintAnalyzerTimer->start(); +#endif +} + +void WidgetInspectorServer::updatePaintAnalyzer() +{ +#ifdef HAVE_PRIVATE_QT_HEADERS + // didn't manage painting on the widget directly, even with the correct + // translation it is always clipping as if the widget was at 0,0 of its parent + const QSize sourceSize = m_paintBufferModel->buffer().boundingRect().size().toSize(); + QPixmap pixmap(sourceSize); + QPainter painter(&pixmap); + Util::drawTransparencyPattern(&painter, QRect(QPoint(0, 0), sourceSize)); + int start = m_paintBufferModel->buffer().frameStartIndex(0); + // include selected row or paint all if nothing is selected + const QModelIndex index = ObjectBroker::selectionModel(m_paintBufferModel)->currentIndex(); + int end = index.isValid() ? index.row() + 1 : m_paintBufferModel->rowCount(); + int depth = m_paintBufferModel->buffer().processCommands(&painter, start, start + end); + for (; depth > 0; --depth) { + painter.restore(); + } + painter.end(); + emit paintAnalyzed(pixmap); +#endif +} + +void WidgetInspectorServer::checkFeatures() +{ + emit features( +#ifdef HAVE_QT_SVG + true, +#else + false, +#endif +#ifdef HAVE_QT_PRINTSUPPORT + true, +#else + false, +#endif +#ifdef HAVE_QT_DESIGNER + true, +#else + false, +#endif +#ifdef HAVE_PRIVATE_QT_HEADERS + true +#else + false +#endif + ); +} + +void WidgetInspectorServer::registerWidgetMetaTypes() +{ + MetaObject *mo = 0; + MO_ADD_METAOBJECT2(QWidget, QObject, QPaintDevice); + MO_ADD_PROPERTY_RO(QWidget, QWidget*, focusProxy); + + MO_ADD_METAOBJECT1(QStyle, QObject); + MO_ADD_PROPERTY_RO(QStyle, const QStyle*, proxy); + MO_ADD_PROPERTY_RO(QStyle, QPalette, standardPalette); +} + +static QString sizePolicyPolicyToString(QSizePolicy::Policy policy) +{ + const int index = QSizePolicy::staticMetaObject.indexOfEnumerator("Policy"); + const QMetaEnum metaEnum = QSizePolicy::staticMetaObject.enumerator(index); + return QString::fromLatin1(metaEnum.valueToKey(policy)); +} + +static QString sizePolicyToString(const QSizePolicy &policy) +{ + return QString::fromLatin1("%1 x %2"). + arg(sizePolicyPolicyToString(policy.horizontalPolicy())). + arg(sizePolicyPolicyToString(policy.verticalPolicy())); + +} + +void WidgetInspectorServer::registerVariantHandlers() +{ + VariantHandler::registerStringConverter(sizePolicyToString); + +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) + VariantHandler::registerStringConverter(Util::displayString); + VariantHandler::registerStringConverter(Util::displayString); +#endif +} + +void WidgetInspectorServer::discoverObjects() +{ + if (qApp) { + foreach (QWidget *widget, qApp->topLevelWidgets()) + m_probe->discoverObject(widget); + } +} + +void WidgetInspectorServer::objectCreated(QObject* object) +{ + if (!object) + return; + + if (qobject_cast(object)) + discoverObjects(); + if (QAbstractItemView* view = qobject_cast(object)) + m_probe->discoverObject(view->model()); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorserver.h gammaray-2.0.1/plugins/widgetinspector/widgetinspectorserver.h --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorserver.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorserver.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,98 @@ +/* + widgetinspectorserver.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTORSERVER_H +#define GAMMARAY_WIDGETINSPECTORSERVER_H + +#include + +#include +#include + +class QModelIndex; +class QItemSelection; +class QItemSelectionModel; +class QTimer; + +namespace GammaRay { + +class ProbeInterface; +class PropertyController; +class OverlayWidget; +class PaintBufferModel; + +class WidgetInspectorServer : public WidgetInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::WidgetInspectorInterface) + public: + explicit WidgetInspectorServer(ProbeInterface *probe, QObject *parent = 0); + + void selectDefaultItem(); + + protected: + bool eventFilter(QObject *object, QEvent *event); + + private: + void callExternalExportAction(const char *name, QWidget *widget, const QString &fileName); + QPixmap pixmapForWidget(QWidget *widget); + void registerWidgetMetaTypes(); + void registerVariantHandlers(); + void discoverObjects(); + + private slots: + void widgetSelected(const QItemSelection &selection); + void widgetSelected(QWidget *widget); + void objectCreated(QObject *object); + + void handleOverlayWidgetDestroyed(QObject*); + + void saveAsImage(const QString &fileName); + void saveAsSvg(const QString &fileName); + void saveAsPdf(const QString &fileName); + void saveAsUiFile(const QString &fileName); + + void analyzePainting(); + void eventuallyUpdatePaintAnalyzer(); + void updatePaintAnalyzer(); + + void updateWidgetPreview(); + + void checkFeatures(); + + private: + OverlayWidget *m_overlayWidget; + QLibrary m_externalExportActions; + PropertyController *m_propertyController; + QItemSelectionModel *m_widgetSelectionModel; + QPointer m_selectedWidget; + QTimer *m_updatePreviewTimer; + PaintBufferModel *m_paintBufferModel; + QTimer *m_paintAnalyzerTimer; + ProbeInterface *m_probe; +}; + +} + +#endif // GAMMARAY_WIDGETINSPECTORSERVER_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.cpp gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,215 @@ +/* + widgetinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgetinspectorwidget.h" +#include "config-gammaray.h" +#include "paintbufferviewer.h" +#include "ui_widgetinspectorwidget.h" +#include "widgetinspectorinterface.h" +#include "widgetinspectorclient.h" + +#include +#include + +#include "kde/krecursivefilterproxymodel.h" +#include "other/modelutils.h" +#include + +#include +#include +#include + +using namespace GammaRay; + +static QObject* createWidgetInspectorClient(const QString &/*name*/, QObject *parent) +{ + return new WidgetInspectorClient(parent); +} + +WidgetInspectorWidget::WidgetInspectorWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::WidgetInspectorWidget) + , m_inspector(0) +{ + ObjectBroker::registerClientObjectFactoryCallback(createWidgetInspectorClient); + m_inspector = ObjectBroker::object(); + + ui->setupUi(this); + ui->widgetPropertyWidget->setObjectBaseName(m_inspector->objectName()); + + KRecursiveFilterProxyModel *widgetSearchProxy = new KRecursiveFilterProxyModel(this); + widgetSearchProxy->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.WidgetTree")); + ui->widgetTreeView->setModel(widgetSearchProxy); + ui->widgetTreeView->setSelectionModel(ObjectBroker::selectionModel(widgetSearchProxy)); + new DeferredResizeModeSetter(ui->widgetTreeView->header(), 0, QHeaderView::Stretch); + new DeferredResizeModeSetter(ui->widgetTreeView->header(), 1, QHeaderView::Interactive); + ui->widgetSearchLine->setProxy(widgetSearchProxy); + connect(ui->widgetTreeView->selectionModel(), + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(widgetSelected(QItemSelection))); + + connect(ui->actionSaveAsImage, SIGNAL(triggered()), SLOT(saveAsImage())); + connect(ui->actionSaveAsSvg, SIGNAL(triggered()), SLOT(saveAsSvg())); + connect(ui->actionSaveAsPdf, SIGNAL(triggered()), SLOT(saveAsPdf())); + connect(ui->actionSaveAsUiFile, SIGNAL(triggered()), SLOT(saveAsUiFile())); + connect(ui->actionAnalyzePainting, SIGNAL(triggered()), SLOT(analyzePainting())); + connect(m_inspector, SIGNAL(widgetPreviewAvailable(QPixmap)), SLOT(widgetPreviewAvailable(QPixmap))); + + connect(m_inspector, SIGNAL(features(bool,bool,bool,bool)), + this, SLOT(setFeatures(bool,bool,bool,bool))); + + // NOTE: we must add actions in the ctor... + addAction(ui->actionSaveAsImage); + addAction(ui->actionSaveAsSvg); + addAction(ui->actionSaveAsPdf); + addAction(ui->actionSaveAsUiFile); + addAction(ui->actionAnalyzePainting); + setActionsEnabled(false); + + m_inspector->checkFeatures(); +} + +WidgetInspectorWidget::~WidgetInspectorWidget() +{ +} + +void WidgetInspectorWidget::setFeatures(bool svg, bool print, bool designer, bool privateHeaders) +{ + if (!svg) { + delete ui->actionSaveAsSvg; + ui->actionSaveAsSvg = 0; + } + if (!print) { + delete ui->actionSaveAsPdf; + ui->actionSaveAsPdf = 0; + } + if (!designer) { + delete ui->actionSaveAsUiFile; + ui->actionSaveAsUiFile = 0; + } + if (!privateHeaders) { + delete ui->actionAnalyzePainting; + ui->actionAnalyzePainting = 0; + } + + setActionsEnabled(ui->widgetTreeView->selectionModel()->hasSelection()); +} + +void WidgetInspectorWidget::widgetSelected(const QItemSelection& selection) +{ + QModelIndex index; + if (selection.size() > 0) + index = selection.first().topLeft(); + + if (index.isValid()) { + setActionsEnabled(true); + + // in case selection was triggered remotely + ui->widgetTreeView->scrollTo(index); + } else { + setActionsEnabled(false); + } +} + +void WidgetInspectorWidget::widgetPreviewAvailable(const QPixmap &preview) +{ + ui->widgetPreviewWidget->setPixmap(preview); +} + +void WidgetInspectorWidget::setActionsEnabled(bool enabled) +{ + foreach (QAction *action, actions()) { + action->setEnabled(enabled); + } +} + +void WidgetInspectorWidget::saveAsImage() +{ + const QString fileName = + QFileDialog::getSaveFileName( + this, + tr("Save As Image"), + QString(), + tr("Image Files (*.png *.jpg)")); + + if (fileName.isEmpty()) + return; + + m_inspector->saveAsImage(fileName); +} + +void WidgetInspectorWidget::saveAsSvg() +{ + const QString fileName = + QFileDialog::getSaveFileName( + this, + tr("Save As SVG"), + QString(), + tr("Scalable Vector Graphics (*.svg)")); + + if (fileName.isEmpty()) + return; + + m_inspector->saveAsSvg(fileName); +} + +void WidgetInspectorWidget::saveAsPdf() +{ + const QString fileName = + QFileDialog::getSaveFileName( + this, + tr("Save As PDF"), + QString(), + tr("PDF (*.pdf)")); + + if (fileName.isEmpty()) + return; + + m_inspector->saveAsPdf(fileName); +} + +void WidgetInspectorWidget::saveAsUiFile() +{ + const QString fileName = + QFileDialog::getSaveFileName( + this, + tr("Save As Qt Designer UI File"), + QString(), + tr("Qt Designer UI File (*.ui)")); + + if (fileName.isEmpty()) + return; + + m_inspector->saveAsUiFile(fileName); +} + +void WidgetInspectorWidget::analyzePainting() +{ + m_inspector->analyzePainting(); + + PaintBufferViewer *viewer = new PaintBufferViewer(this); + viewer->setWindowTitle(tr("Analyze Painting")); + viewer->setAttribute(Qt::WA_DeleteOnClose); + viewer->setModal(true); + viewer->show(); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.h gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.h --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,68 @@ +/* + widgetinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTORWIDGET_H +#define GAMMARAY_WIDGETINSPECTOR_WIDGETINSPECTORWIDGET_H + +#include + +class QItemSelection; +class QModelIndex; + +namespace GammaRay { + +class WidgetInspectorInterface; + +namespace Ui { + class WidgetInspectorWidget; +} + +class WidgetInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit WidgetInspectorWidget(QWidget *parent = 0); + ~WidgetInspectorWidget(); + + private: + void setActionsEnabled(bool enabled); + + private slots: + void widgetSelected(const QItemSelection &selection); + + void saveAsImage(); + void saveAsSvg(); + void saveAsPdf(); + void saveAsUiFile(); + void widgetPreviewAvailable(const QPixmap &preview); + void analyzePainting(); + void setFeatures(bool svg, bool print, bool designer, bool privateHeaders); + + private: + QScopedPointer ui; + WidgetInspectorInterface *m_inspector; +}; + +} + +#endif // GAMMARAY_WIDGETINSPECTOR_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.ui gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.ui --- gammaray-1.2.2/plugins/widgetinspector/widgetinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,107 @@ + + + GammaRay::WidgetInspectorWidget + + + + 0 + 0 + 732 + 528 + + + + + + + Qt::Horizontal + + + + Qt::Vertical + + + + + + + + + + + + + + Preview + + + + + + + + + + + + + + + Save as &Image... + + + Save currently selected widget as image. + + + + + Save as &SVG... + + + Renders the currently selected image as SVG vector graphic. + + + + + Save as &PDF... + + + Renders the currently selected widget in to a PDF file. + + + + + Save as &UI file... + + + Saves the currently selected widget as a Qt designer UI file. + + + + + &Analyze Painting... + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+ + GammaRay::PropertyWidget + QWidget +
ui/propertywidget.h
+ 1 +
+ + GammaRay::WidgetPreviewWidget + QWidget +
widgetpreviewwidget.h
+ 1 +
+
+ + +
diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetpreviewwidget.cpp gammaray-2.0.1/plugins/widgetinspector/widgetpreviewwidget.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgetpreviewwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetpreviewwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + widgetpreviewwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgetpreviewwidget.h" + +#include +#include + +using namespace GammaRay; + +WidgetPreviewWidget::WidgetPreviewWidget(QWidget *parent) + : QWidget(parent) +{ +} + +void WidgetPreviewWidget::setPixmap(const QPixmap &pixmap) +{ + m_pixmap = pixmap; + update(); +} + +void WidgetPreviewWidget::paintEvent(QPaintEvent * /*event*/) +{ + QPainter painter(this); + const qreal scale = qMin(1.0, qMin((qreal)width() / (qreal)m_pixmap.width(), + (qreal)height() / (qreal)m_pixmap.height())); + const qreal targetWidth = m_pixmap.width() * scale; + const qreal targetHeight = m_pixmap.height() * scale; + painter.drawPixmap((width() - targetWidth) / 2, + (height() - targetHeight) / 2, + targetWidth, targetHeight, + m_pixmap); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgetpreviewwidget.h gammaray-2.0.1/plugins/widgetinspector/widgetpreviewwidget.h --- gammaray-1.2.2/plugins/widgetinspector/widgetpreviewwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgetpreviewwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + widgetpreviewwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETPREVIEWWIDGET_H +#define GAMMARAY_WIDGETINSPECTOR_WIDGETPREVIEWWIDGET_H + +#include +#include + +namespace GammaRay { + +class WidgetPreviewWidget : public QWidget +{ + Q_OBJECT + public: + explicit WidgetPreviewWidget(QWidget *parent = 0); + void setPixmap(const QPixmap &pixmap); + + protected: + virtual void paintEvent(QPaintEvent *event); + + private: + QPixmap m_pixmap; +}; + +} + +#endif // GAMMARAY_WIDGETPREVIEWWIDGET_H diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgettreemodel.cpp gammaray-2.0.1/plugins/widgetinspector/widgettreemodel.cpp --- gammaray-1.2.2/plugins/widgetinspector/widgettreemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgettreemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,59 @@ +/* + widgettreemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "widgettreemodel.h" + +#include +#include +#include +#include + +using namespace GammaRay; + +WidgetTreeModel::WidgetTreeModel(QObject *parent) + : ObjectFilterProxyModelBase(parent) +{ +} + +QVariant WidgetTreeModel::data(const QModelIndex &index, int role) const +{ + if (index.isValid() && role == Qt::ForegroundRole) { + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + QWidget *widget = qobject_cast(obj); + if (!widget) { + QLayout *layout = qobject_cast(obj); + if (layout) { + widget = layout->parentWidget(); + } + } + if (widget && !widget->isVisible()) { + return qApp->palette().color(QPalette::Disabled, QPalette::Text); + } + } + return QSortFilterProxyModel::data(index, role); +} + +bool WidgetTreeModel::filterAcceptsObject(QObject *object) const +{ + return object->isWidgetType() || qobject_cast(object); +} diff -Nru gammaray-1.2.2/plugins/widgetinspector/widgettreemodel.h gammaray-2.0.1/plugins/widgetinspector/widgettreemodel.h --- gammaray-1.2.2/plugins/widgetinspector/widgettreemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/plugins/widgetinspector/widgettreemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,47 @@ +/* + widgettreemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_WIDGETINSPECTOR_WIDGETTREEMODEL_H +#define GAMMARAY_WIDGETINSPECTOR_WIDGETTREEMODEL_H + +#include + +namespace GammaRay { + +/** Widget tree model. + * @todo Show layout hierarchy instead of object hierarchy. + */ +class WidgetTreeModel : public ObjectFilterProxyModelBase +{ + Q_OBJECT + public: + explicit WidgetTreeModel(QObject *parent = 0); + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + protected: + virtual bool filterAcceptsObject(QObject *object) const; +}; + +} + +#endif // GAMMARAY_WIDGETTREEMODEL_H diff -Nru gammaray-1.2.2/ReadMe.md gammaray-2.0.1/ReadMe.md --- gammaray-1.2.2/ReadMe.md 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/ReadMe.md 2014-02-28 19:07:57.000000000 +0000 @@ -24,7 +24,7 @@ debugging a proxy model chain for example. * Browse the QAbstractProxyModel (QAPM) hierarchy. - + * Browse the QGraphicsView (QGV) item tree of any QGV scene. * Show a live preview of QGV items, including showing their coordinate system, @@ -53,9 +53,20 @@ Head Engineer for GammaRay is Volker Krause +Contact +======= + +* Feel free to visit us on IRC: Channel is #gammaray on Freenode (irc://irc.freenode.net/gammaray) +* Or send a mail to our mailing list: https://mail.kdab.com/mailman/listinfo/gammaray-interest + +Get Involved +================= + +If you want to contribute, please check out: https://github.com/KDAB/GammaRay/wiki/Get-Involved + License ======= -Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, +Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff -Nru gammaray-1.2.2/ReadMe.txt gammaray-2.0.1/ReadMe.txt --- gammaray-1.2.2/ReadMe.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/ReadMe.txt 2014-02-28 19:07:57.000000000 +0000 @@ -24,7 +24,7 @@ debugging a proxy model chain for example. * Browse the QAbstractProxyModel (QAPM) hierarchy. - + * Browse the QGraphicsView (QGV) item tree of any QGV scene. * Show a live preview of QGV items, including showing their coordinate system, @@ -53,9 +53,20 @@ Head Engineer for GammaRay is Volker Krause +Contact +======= + +* Feel free to visit us on IRC: Channel is #gammaray on Freenode (irc://irc.freenode.net/gammaray) +* Or send a mail to our mailing list: https://mail.kdab.com/mailman/listinfo/gammaray-interest + +Get Involved +================= + +If you want to contribute, please check out: https://github.com/KDAB/GammaRay/wiki/Get-Involved + License ======= -Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, +Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff -Nru gammaray-1.2.2/resources/gammaray.qrc gammaray-2.0.1/resources/gammaray.qrc --- gammaray-1.2.2/resources/gammaray.qrc 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/resources/gammaray.qrc 2014-02-28 19:07:57.000000000 +0000 @@ -9,7 +9,7 @@ kdabproducts.png kdablogo160.png splashscreen.png - kdab-gammary-logo.png + kdab-gammaray-logo.png classes/datetimeedit.png @@ -24,7 +24,7 @@ classes/combobox.png - classes/hsplit.png + classes/commandlinkbutton.png classes/wizard.png classes/widget.png Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/resources/kdab-gammaray-logo.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/resources/kdab-gammaray-logo.png differ Binary files /tmp/wFvWh2Ks4j/gammaray-1.2.2/resources/kdab-gammary-logo.png and /tmp/0_oq0dn_5A/gammaray-2.0.1/resources/kdab-gammary-logo.png differ diff -Nru gammaray-1.2.2/tests/attachhelper.cpp gammaray-2.0.1/tests/attachhelper.cpp --- gammaray-1.2.2/tests/attachhelper.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/attachhelper.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -24,6 +24,11 @@ #include "attachhelper.h" #ifdef Q_OS_WIN32 +#ifndef NOMINMAX +// compile fix for Qt5+VS2010+QDateTime, see: http://qt-project.org/forums/viewthread/22133 +#define NOMINMAX +#endif + #include #endif @@ -72,10 +77,11 @@ qDebug() << "attaching gammaray"; QProcess gammaray; QStringList args; + args << "--inprocess" << "-i" << m_injector; #ifdef Q_OS_WIN32 - args << "-i" << m_injector << "-p" << QString::number(m_proc->pid()->dwProcessId); + args << "-p" << QString::number(m_proc->pid()->dwProcessId); #else - args << "-i" << m_injector << "-p" << QString::number(m_proc->pid()); + args << "-p" << QString::number(m_proc->pid()); #endif args << "-nodialogs"; const int ret = gammaray.execute(m_gammaray, args); @@ -109,4 +115,3 @@ return app.exec(); } -#include "attachhelper.moc" diff -Nru gammaray-1.2.2/tests/attachhelper.h gammaray-2.0.1/tests/attachhelper.h --- gammaray-1.2.2/tests/attachhelper.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/attachhelper.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/tests/benchsuite.cpp gammaray-2.0.1/tests/benchsuite.cpp --- gammaray-1.2.2/tests/benchsuite.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/benchsuite.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,167 @@ +/* + benchsuite.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "benchsuite.h" +#include "core/connectionmodel.h" +#include "core/probe.h" +#include "core/util.h" + +#include + +#include +#include + +QTEST_MAIN(GammaRay::BenchSuite) + +using namespace GammaRay; + +void BenchSuite::iconForObject() +{ + QWidget widget; + QLabel label; + QTreeView treeView; + QBENCHMARK { + Util::iconForObject(this); + Util::iconForObject(&widget); + Util::iconForObject(&label); + Util::iconForObject(&treeView); + } +} + +void BenchSuite::connectionModel_connectionAdded() +{ + Probe::createProbe(false); + + ConnectionModel model; + static const int NUM_OBJECTS = 10000; + QVector objects; + objects.reserve(NUM_OBJECTS + 1); + // fill it + objects << new QObject; + for (int i = 1; i <= NUM_OBJECTS; ++i) { + QObject *obj = new QObject; + objects << obj; + Probe::objectAdded(obj); + } + + QBENCHMARK { + for (int i = 1; i <= NUM_OBJECTS; ++i) { + model.connectionAdded(objects.at(i), SIGNAL(destroyed()), + objects.at(i-1), SLOT(deleteLater()), Qt::AutoConnection); + model.connectionAdded(objects.at(i-1), SIGNAL(destroyed()), + objects.at(i), SLOT(deleteLater()), Qt::AutoConnection); + } + } + + qDeleteAll(objects); + delete Probe::instance(); +} + +void BenchSuite::connectionModel_connectionRemoved() +{ + Probe::createProbe(false); + + ConnectionModel model; + static const int NUM_OBJECTS = 1000; + QVector objects; + objects.reserve(NUM_OBJECTS + 1); + // fill it + objects << new QObject; + for (int i = 1; i <= NUM_OBJECTS; ++i) { + QObject *obj = new QObject; + objects << obj; + Probe::objectAdded(obj); + model.connectionAdded(obj, SIGNAL(destroyed()), + objects.at(i-1), SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(objects.at(i-1), SIGNAL(destroyed()), + obj, SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(obj, SIGNAL(destroyed()), + objects.at(i-1), SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(objects.at(i-1), SIGNAL(destroyed()), + obj, SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(obj, SIGNAL(invalid()), + objects.at(i-1), SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(objects.at(i-1), SIGNAL(destroyed()), + obj, SLOT(invalid()), Qt::AutoConnection); + +//krazy:cond=normalized,style + // non-normalized + model.connectionAdded(obj, SIGNAL( destroyed( ) ), + objects.at(i-1), SLOT(deleteLater()), Qt::AutoConnection); + + model.connectionAdded(objects.at(i-1), SIGNAL(destroyed()), + obj, SLOT( deleteLater( ) ), Qt::AutoConnection); +//krazy:endcond=normalized,style + } + + QBENCHMARK_ONCE { + for (int i = 1; i <= NUM_OBJECTS; ++i) { + model.connectionRemoved(objects.at(i), SIGNAL(destroyed()), + objects.at(i-1), SLOT(deleteLater())); + + model.connectionRemoved(objects.at(i-1), SIGNAL(destroyed()), + objects.at(i), SLOT(deleteLater())); + + model.connectionRemoved(objects.at(i), SIGNAL(destroyed()), + objects.at(i-1), SLOT(invalid())); + + model.connectionRemoved(objects.at(i-1), SIGNAL(invalid()), + objects.at(i), SLOT(deleteLater())); + } + } + + qDeleteAll(objects); + delete Probe::instance(); +} + +void BenchSuite::probe_objectAdded() +{ + Probe::createProbe(false); + + static const int NUM_OBJECTS = 10000; + QVector objects; + objects.reserve(NUM_OBJECTS + 1); + // fill it + for (int i = 0; i < NUM_OBJECTS; ++i) { + QObject *obj = new QObject; + objects << obj; + } + + QVector::const_iterator it = objects.constBegin(); + QVector::const_iterator end = objects.constEnd(); + QBENCHMARK_ONCE { + while (it != end) { + Probe::objectAdded(*it); + ++it; + } + } + + qDeleteAll(objects); + delete Probe::instance(); +} + diff -Nru gammaray-1.2.2/tests/benchsuite.h gammaray-2.0.1/tests/benchsuite.h --- gammaray-1.2.2/tests/benchsuite.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/benchsuite.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + benchsuite.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_BENCHSUITE_H +#define GAMMARAY_BENCHSUITE_H + +#include + +namespace GammaRay { + +class BenchSuite : public QObject +{ + Q_OBJECT + + private slots: + void iconForObject(); + void connectionModel_connectionAdded(); + void connectionModel_connectionRemoved(); + void probe_objectAdded(); +}; + +} + +#endif // GAMMARAY_BENCHSUITE_H diff -Nru gammaray-1.2.2/tests/CMakeLists.txt gammaray-2.0.1/tests/CMakeLists.txt --- gammaray-1.2.2/tests/CMakeLists.txt 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -1,28 +1,50 @@ -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +### BENCH SUITE -qt4_automoc(test_connections.cpp) +if(Qt5Widgets_FOUND OR QT_QTGUI_FOUND) + add_executable(benchsuite benchsuite.cpp) -add_executable(connectiontest test_connections.cpp) + target_link_libraries(benchsuite + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTTEST_LIBRARIES} + gammaray_common + gammaray_core + ) + + if(QNXNTO) + target_link_libraries(benchsuite cpp) + endif() -target_link_libraries(connectiontest - ${QT_QTCORE_LIBRARIES} - ${QT_QTGUI_LIBRARIES} - ${QT_QTTEST_LIBRARIES} -) +### CONNECTIONTEST -qt4_automoc(attachhelper.cpp) + add_executable(connectiontest test_connections.cpp) + + target_link_libraries(connectiontest + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTTEST_LIBRARIES} + ) + + if(QNXNTO) + target_link_libraries(connectiontest cpp) + endif() +endif() add_executable(attachhelper attachhelper.cpp) target_link_libraries(attachhelper ${QT_QTCORE_LIBRARIES}) +if(QNXNTO) + target_link_libraries(attachhelper cpp) +endif() + if(UNIX AND NOT APPLE) add_test(connectiontest-preload - ${PROJECT_BINARY_DIR}/bin/gammaray -unittest -i preload + ${PROJECT_BINARY_DIR}/bin/gammaray --inprocess -unittest -i preload ${PROJECT_BINARY_DIR}/bin/connectiontest ) add_test(connectiontest-style - ${PROJECT_BINARY_DIR}/bin/gammaray -unittest -i style + ${PROJECT_BINARY_DIR}/bin/gammaray --inprocess -unittest -i style ${PROJECT_BINARY_DIR}/bin/connectiontest ) @@ -47,7 +69,7 @@ find_program(GDB_EXECUTABLE gdb) if(GDB_EXECUTABLE) add_test(connectiontest-gdb - ${PROJECT_BINARY_DIR}/bin/gammaray -unittest -i gdb + ${PROJECT_BINARY_DIR}/bin/gammaray --inprocess -unittest -i gdb ${PROJECT_BINARY_DIR}/bin/connectiontest ) add_test(attachtest-gdb @@ -56,9 +78,11 @@ ) if(RUN_FILTER_TESTS) add_test(connectiontest-gdb-filter - ${PROJECT_BINARY_DIR}/bin/gammaray -unittest -filtertest -i gdb + ${PROJECT_BINARY_DIR}/bin/gammaray --inprocess -unittest -filtertest -i gdb ${PROJECT_BINARY_DIR}/bin/connectiontest ) endif() endif() endif() + +add_subdirectory(manual) diff -Nru gammaray-1.2.2/tests/hooktest/main.cpp gammaray-2.0.1/tests/hooktest/main.cpp --- gammaray-1.2.2/tests/hooktest/main.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/hooktest/main.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Andreas Holzammer This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/tests/hooktest/mainwindow.cpp gammaray-2.0.1/tests/hooktest/mainwindow.cpp --- gammaray-1.2.2/tests/hooktest/mainwindow.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/hooktest/mainwindow.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Andreas Holzammer This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/tests/hooktest/mainwindow.h gammaray-2.0.1/tests/hooktest/mainwindow.h --- gammaray-1.2.2/tests/hooktest/mainwindow.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/hooktest/mainwindow.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Andreas Holzammer This program is free software; you can redistribute it and/or modify diff -Nru gammaray-1.2.2/tests/manual/CMakeLists.txt gammaray-2.0.1/tests/manual/CMakeLists.txt --- gammaray-1.2.2/tests/manual/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,63 @@ +if(Qt5Widgets_FOUND OR QT_QTGUI_FOUND) + add_executable(propertywidgettest + propertywidgettest.cpp + ) + + target_link_libraries(propertywidgettest + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_ui + gammaray_core + gammaray_common + ) + + set(gammaray_messagemodeltest_srcs + messagemodeltest.cpp + ) + + add_executable(messagemodeltest + ${gammaray_messagemodeltest_srcs} + ) + + target_link_libraries(messagemodeltest + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ) +endif() + +add_executable(minimalcoreapplication minimalcoreapplication.cpp) +target_link_libraries(minimalcoreapplication ${QT_QTCORE_LIBRARIES}) + +add_executable(propertytest propertytest.cpp) +target_link_libraries(propertytest ${QT_QTCORE_LIBRARIES}) + +if(QT_QTWEBKIT_FOUND) + add_executable(wk1application wk1application.cpp) + target_link_libraries(wk1application + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + ${QT_QTWEBKIT_LIBRARIES} + ${QT_QTWEBKITWIDGETS_LIBRARIES} + ) +endif() + +if(Qt5WebKit_FOUND) + set(wk2application_srcs wk2application.cpp) + qt4_add_resources(wk2application_srcs wk2application.qrc) + add_executable(wk2application ${wk2application_srcs}) + target_link_libraries(wk2application Qt5::Quick) +endif() + +if(QNXNTO) + target_link_libraries(propertywidgettest cpp) + target_link_libraries(messagemodeltest cpp) +endif() + +if(Qt5Widgets_FOUND AND NOT Qt5Widgets_VERSION VERSION_LESS 5.2.0) + add_executable(variantinspectortest + variantinspector.cpp + variantinspectorapplication.cpp + ) + set_property(TARGET variantinspectortest PROPERTY AUTOMOC TRUE) + target_link_libraries(variantinspectortest Qt5::Widgets) +endif() diff -Nru gammaray-1.2.2/tests/manual/keyhandlingtest.qml gammaray-2.0.1/tests/manual/keyhandlingtest.qml --- gammaray-1.2.2/tests/manual/keyhandlingtest.qml 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/keyhandlingtest.qml 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,41 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtQuick 2.0 + +Rectangle { + color: "lightsteelblue" + width: 640 + height: 480 + focus: true + + Text { + id: label + anchors.centerIn: parent + text: "press a key" + } + + // always works + Keys.onLeftPressed: { label.text = "left pressed"; } + + // breaks with signal spy callbacks installed + Keys.onPressed: { label.text = "key pressed"; console.log("xxx"); } +} diff -Nru gammaray-1.2.2/tests/manual/messagemodeltest.cpp gammaray-2.0.1/tests/manual/messagemodeltest.cpp --- gammaray-1.2.2/tests/manual/messagemodeltest.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/messagemodeltest.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,85 @@ +/* + messagemodeltest.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "messagemodeltest.h" + +#include +#include +#include +#include + +using namespace GammaRay; + +MessageGenerator::MessageGenerator() +{ + QVBoxLayout *layout = new QVBoxLayout; + + QPushButton *button = new QPushButton("debug"); + connect(button, SIGNAL(clicked(bool)), SLOT(generateDebug())); + layout->addWidget(button); + + button = new QPushButton("warning"); + connect(button, SIGNAL(clicked(bool)), SLOT(generateWarning())); + layout->addWidget(button); + + button = new QPushButton("critical"); + connect(button, SIGNAL(clicked(bool)), SLOT(generateCritical())); + layout->addWidget(button); + + button = new QPushButton("fatal"); + connect(button, SIGNAL(clicked(bool)), SLOT(generateFatal())); + layout->addWidget(button); + + setLayout(layout); +} + +void MessageGenerator::generateDebug() +{ + qDebug() << "A debug message"; +} + +void MessageGenerator::generateWarning() +{ + qWarning() << "A warning message" << "split into two parts"; +} + +void MessageGenerator::generateCritical() +{ + qCritical() << "A critical message"; +} + +void MessageGenerator::generateFatal() +{ + qFatal("A fatal message"); +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + MessageGenerator generator; + generator.show(); + + return app.exec(); +} + diff -Nru gammaray-1.2.2/tests/manual/messagemodeltest.h gammaray-2.0.1/tests/manual/messagemodeltest.h --- gammaray-1.2.2/tests/manual/messagemodeltest.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/messagemodeltest.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + messagemodeltest.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MESSAGEMODELTEST_H +#define GAMMARAY_MESSAGEMODELTEST_H + +#include + +#ifndef Q_NORETURN +#define Q_NORETURN +#endif + +namespace GammaRay { + +class MessageGenerator : public QWidget +{ + Q_OBJECT + + public: + MessageGenerator(); + + private slots: + void generateDebug(); + void generateWarning(); + void generateCritical(); + Q_NORETURN void generateFatal(); +}; + +} + +#endif // GAMMARAY_MESSAGEMODELTEST_H diff -Nru gammaray-1.2.2/tests/manual/minimalcoreapplication.cpp gammaray-2.0.1/tests/manual/minimalcoreapplication.cpp --- gammaray-1.2.2/tests/manual/minimalcoreapplication.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/minimalcoreapplication.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,32 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + QObject obj; + obj.setObjectName("myTestObject"); + + return app.exec(); +} diff -Nru gammaray-1.2.2/tests/manual/propertytest.cpp gammaray-2.0.1/tests/manual/propertytest.cpp --- gammaray-1.2.2/tests/manual/propertytest.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/propertytest.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,66 @@ +/* + propertytest.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include + +class MyTestObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int staticChangingProperty READ staticChangingProperty NOTIFY staticChangingPropertyChanged) +public: + explicit MyTestObject(QObject *parent = 0) : QObject(parent), m_count(0) + { + setObjectName("propertyTestObject"); + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer->start(5000); + } + + int staticChangingProperty() { return m_count; } + +signals: + void staticChangingPropertyChanged(); + +private slots: + void timeout() + { + ++m_count; + setProperty("dynamicChangingProperty", m_count); + emit staticChangingPropertyChanged(); + } + +private: + int m_count; + +}; + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + MyTestObject obj; + return app.exec(); +} + +#include "propertytest.moc" diff -Nru gammaray-1.2.2/tests/manual/propertywidgettest.cpp gammaray-2.0.1/tests/manual/propertywidgettest.cpp --- gammaray-1.2.2/tests/manual/propertywidgettest.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/propertywidgettest.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertywidgettest.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "ui/propertywidget.h" + +#include +#include +#include + +using namespace GammaRay; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + PropertyWidget widget; + //widget.setMetaObject((new QTreeView())->metaObject()); + //widget.setObject(new QTreeView()); + //widget.setObject(new QGraphicsRectItem, "QGraphicsRectItem"); + widget.show(); + + return app.exec(); +} diff -Nru gammaray-1.2.2/tests/manual/variantinspectorapplication.cpp gammaray-2.0.1/tests/manual/variantinspectorapplication.cpp --- gammaray-1.2.2/tests/manual/variantinspectorapplication.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/variantinspectorapplication.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + variantinspectorapplication.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include + +#include "variantinspector.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + VariantInspector vi; + + QHash mapping; + mapping.insert("One", 1); + mapping.insert("Two", 2); + + vi.setProperty("dynamicProperty", QVariant::fromValue(mapping)); + + return app.exec(); +} diff -Nru gammaray-1.2.2/tests/manual/variantinspector.cpp gammaray-2.0.1/tests/manual/variantinspector.cpp --- gammaray-1.2.2/tests/manual/variantinspector.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/variantinspector.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + variantinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include "variantinspector.h" + +#include + +VariantInspector::VariantInspector(QObject *parent) + : QObject(parent) +{ + m_widget.reset(new QWidget); +} + +QSharedPointer VariantInspector::sharedWidget() const +{ + return m_widget; +} + +QPointer VariantInspector::trackingWidget() const +{ + return m_widget.data(); +} + +QVector VariantInspector::widgetVector() const +{ + QVector vec; + vec << 5; + vec << 6; + vec << 7; + vec << 8; + return vec; +} diff -Nru gammaray-1.2.2/tests/manual/variantinspector.h gammaray-2.0.1/tests/manual/variantinspector.h --- gammaray-1.2.2/tests/manual/variantinspector.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/variantinspector.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + variantinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#ifndef VARIANTINSPECTOR_H +#define VARIANTINSPECTOR_H + +#include +#include + +class VariantInspector : public QObject +{ + Q_OBJECT + Q_PROPERTY(QSharedPointer sharedWidget READ sharedWidget CONSTANT) + Q_PROPERTY(QPointer trackingWidget READ trackingWidget CONSTANT) + Q_PROPERTY(QVector widgetVector READ widgetVector CONSTANT) +public: + explicit VariantInspector(QObject *parent = 0); + + QSharedPointer sharedWidget() const; + QPointer trackingWidget() const; + QVector widgetVector() const; + +private: + QSharedPointer m_widget; +}; + +#endif diff -Nru gammaray-1.2.2/tests/manual/wk1application.cpp gammaray-2.0.1/tests/manual/wk1application.cpp --- gammaray-1.2.2/tests/manual/wk1application.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/wk1application.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,34 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include + +int main(int argc, char** argv) +{ + QApplication app(argc, argv); + + QWebView view; + view.setUrl(QUrl("http://www.kdab.com/gammaray")); + view.show(); + + return app.exec(); +} diff -Nru gammaray-1.2.2/tests/manual/wk2application.cpp gammaray-2.0.1/tests/manual/wk2application.cpp --- gammaray-1.2.2/tests/manual/wk2application.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/wk2application.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,34 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include + +int main(int argc, char** argv) +{ + QGuiApplication app(argc, argv); + + QQuickView view; + view.setSource(QUrl("qrc:/wk2application.qml")); + view.show(); + + return app.exec(); +} diff -Nru gammaray-1.2.2/tests/manual/wk2application.qml gammaray-2.0.1/tests/manual/wk2application.qml --- gammaray-1.2.2/tests/manual/wk2application.qml 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/wk2application.qml 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,30 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtQuick 2.0 +import QtWebKit 3.0 +import QtWebKit.experimental 1.0 + +WebView { + width: 800 + height: 600 + url: "http://www.kdab.com/gammaray" +} diff -Nru gammaray-1.2.2/tests/manual/wk2application.qrc gammaray-2.0.1/tests/manual/wk2application.qrc --- gammaray-1.2.2/tests/manual/wk2application.qrc 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/manual/wk2application.qrc 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,5 @@ + + + wk2application.qml + + \ No newline at end of file diff -Nru gammaray-1.2.2/tests/modeltest.cpp gammaray-2.0.1/tests/modeltest.cpp --- gammaray-1.2.2/tests/modeltest.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/modeltest.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,752 @@ +/**************************************************************************** +** +** Copyright (C) 2007 Trolltech ASA. All rights reserved. +** +** This file is part of the Qt Concurrent project on Trolltech Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.trolltech.com/products/qt/opensource.html +** +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://www.trolltech.com/products/qt/licensing.html or contact the +** sales department at sales@trolltech.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include +#include +#include + +#include "modeltest.h" + +Q_DECLARE_METATYPE ( QModelIndex ) + +/*! + Connect to all of the models signals. Whenever anything happens recheck everything. +*/ +ModelTest::ModelTest ( QAbstractItemModel *_model, Mode testType, QObject *parent ) + : QObject ( parent ), + model ( _model ), + fetchingMore ( false ), + pedantic(testType == Pedantic) +{ + init(); + if (pedantic) { + refreshStatus(); + // This is almost certainly not needed. +// connect(QAbstractEventDispatcher::instance(), SIGNAL(awake()), SLOT(ensureSteady())); + } +} + +ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) + : QObject ( parent ), + model ( _model ), + fetchingMore ( false ), + pedantic( false ) +{ + init(); +} + +void ModelTest::init() +{ + Q_ASSERT ( model ); + + connect ( model, SIGNAL (columnsAboutToBeInserted(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (columnsAboutToBeRemoved(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (columnsInserted(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (columnsRemoved(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (dataChanged(QModelIndex,QModelIndex)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (headerDataChanged(Qt::Orientation,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (layoutAboutToBeChanged()), this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (layoutChanged()), this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (modelReset()), this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (modelAboutToBeReset()), this, SLOT (modelAboutToBeReset()) ); + connect ( model, SIGNAL (modelReset()), this, SLOT (modelReset()) ); + connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), + this, SLOT (runAllTests()) ); + + // Special checks for inserting/removing + connect ( model, SIGNAL (layoutAboutToBeChanged()), + this, SLOT (layoutAboutToBeChanged()) ); + connect ( model, SIGNAL (layoutChanged()), + this, SLOT (layoutChanged()) ); + + connect ( model, SIGNAL (rowsAboutToBeInserted(QModelIndex,int,int)), + this, SLOT (rowsAboutToBeInserted(QModelIndex,int,int)) ); + connect ( model, SIGNAL (rowsAboutToBeRemoved(QModelIndex,int,int)), + this, SLOT (rowsAboutToBeRemoved(QModelIndex,int,int)) ); + connect ( model, SIGNAL (rowsInserted(QModelIndex,int,int)), + this, SLOT (rowsInserted(QModelIndex,int,int)) ); + connect ( model, SIGNAL (rowsRemoved(QModelIndex,int,int)), + this, SLOT (rowsRemoved(QModelIndex,int,int)) ); + + connect ( model, SIGNAL (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), + this, SLOT (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) ); + connect ( model, SIGNAL (rowsMoved(QModelIndex,int,int,QModelIndex,int)), + this, SLOT (rowsMoved(QModelIndex,int,int,QModelIndex,int)) ); + + runAllTests(); +} + +void ModelTest::runAllTests() +{ + +// qDebug() << "rats"; + if ( fetchingMore ) + return; + nonDestructiveBasicTest(); + rowCount(); + columnCount(); + hasIndex(); + index(); + parent(); + data(); +} + +/*! + nonDestructiveBasicTest tries to call a number of the basic functions (not all) + to make sure the model doesn't outright segfault, testing the functions that makes sense. +*/ +void ModelTest::nonDestructiveBasicTest() +{ + Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() ); + model->canFetchMore ( QModelIndex() ); + Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 ); + Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() ); + fetchingMore = true; + model->fetchMore ( QModelIndex() ); + fetchingMore = false; + Qt::ItemFlags flags = model->flags ( QModelIndex() ); + Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 ); + model->hasChildren ( QModelIndex() ); + model->hasIndex ( 0, 0 ); + model->headerData ( 0, Qt::Horizontal ); + model->index ( 0, 0 ); + model->itemData ( QModelIndex() ); + QVariant cache; + model->match ( QModelIndex(), -1, cache ); + model->mimeTypes(); + Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); + Q_ASSERT ( model->rowCount() >= 0 ); + QVariant variant; + model->setData ( QModelIndex(), variant, -1 ); + model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); + model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); + QMap roles; + model->sibling ( 0, 0, QModelIndex() ); + model->span ( QModelIndex() ); + model->supportedDropActions(); +} + +/*! + Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren() + + Models that are dynamically populated are not as fully tested here. + */ +void ModelTest::rowCount() +{ +// qDebug() << "rc"; + // check top row + QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); + int rows = model->rowCount ( topIndex ); + Q_ASSERT ( rows >= 0 ); + + Q_ASSERT ( model->hasChildren ( topIndex ) == ( rows > 0 ) ); + + QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); + if ( secondLevelIndex.isValid() ) { // not the top level + // check a row count where parent is valid + rows = model->rowCount ( secondLevelIndex ); + Q_ASSERT ( rows >= 0 ); + if ( rows > 0 ) + Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true ); + } + + // The models rowCount() is tested more extensively in checkChildren(), + // but this catches the big mistakes +} + +/*! + Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren() + */ +void ModelTest::columnCount() +{ + // check top row + QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); + Q_ASSERT ( model->columnCount ( topIndex ) >= 0 ); + + // check a column count where parent is valid + QModelIndex childIndex = model->index ( 0, 0, topIndex ); + if ( childIndex.isValid() ) + Q_ASSERT ( model->columnCount ( childIndex ) >= 0 ); + + // columnCount() is tested more extensively in checkChildren(), + // but this catches the big mistakes +} + +/*! + Tests model's implementation of QAbstractItemModel::hasIndex() + */ +void ModelTest::hasIndex() +{ +// qDebug() << "hi"; + // Make sure that invalid values returns an invalid index + Q_ASSERT ( model->hasIndex ( -2, -2 ) == false ); + Q_ASSERT ( model->hasIndex ( -2, 0 ) == false ); + Q_ASSERT ( model->hasIndex ( 0, -2 ) == false ); + + int rows = model->rowCount(); + int columns = model->columnCount(); + + // check out of bounds + Q_ASSERT ( model->hasIndex ( rows, columns ) == false ); + Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false ); + + Q_ASSERT ( model->hasIndex ( 0, 0 ) == ( rows > 0 ) ); + + // hasIndex() is tested more extensively in checkChildren(), + // but this catches the big mistakes +} + +/*! + Tests model's implementation of QAbstractItemModel::index() + */ +void ModelTest::index() +{ +// qDebug() << "i"; + // Make sure that invalid values returns an invalid index + Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() ); + Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() ); + Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() ); + + int rows = model->rowCount(); + int columns = model->columnCount(); + + if ( rows == 0 ) + return; + + // Catch off by one errors + Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() ); + Q_ASSERT ( model->index ( 0, 0 ).isValid() == true ); + + // Make sure that the same index is *always* returned + QModelIndex a = model->index ( 0, 0 ); + QModelIndex b = model->index ( 0, 0 ); + Q_ASSERT ( a == b ); + + // index() is tested more extensively in checkChildren(), + // but this catches the big mistakes +} + +/*! + Tests model's implementation of QAbstractItemModel::parent() + */ +void ModelTest::parent() +{ +// qDebug() << "p"; + // Make sure the model wont crash and will return an invalid QModelIndex + // when asked for the parent of an invalid index. + Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); + + if ( model->rowCount() == 0 ) + return; + + // Column 0 | Column 1 | + // QModelIndex() | | + // \- topIndex | topIndex1 | + // \- childIndex | childIndex1 | + + // Common error test #1, make sure that a top level index has a parent + // that is a invalid QModelIndex. + QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); + Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() ); + + // Common error test #2, make sure that a second level index has a parent + // that is the first level index. + if ( model->rowCount ( topIndex ) > 0 ) { + QModelIndex childIndex = model->index ( 0, 0, topIndex ); + if ( model->parent ( childIndex ) != topIndex ) + qDebug() << model->parent ( childIndex ) << topIndex << topIndex.data(); + Q_ASSERT ( model->parent ( childIndex ) == topIndex ); + } + + // Common error test #3, the second column should NOT have the same children + // as the first column in a row. + // Usually the second column shouldn't have children. + QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() ); + if ( model->rowCount ( topIndex1 ) > 0 ) { + QModelIndex childIndex = model->index ( 0, 0, topIndex ); + QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); + Q_ASSERT ( childIndex != childIndex1 ); + } + + // Full test, walk n levels deep through the model making sure that all + // parent's children correctly specify their parent. + checkChildren ( QModelIndex() ); +} + +/*! + Called from the parent() test. + + A model that returns an index of parent X should also return X when asking + for the parent of the index. + + This recursive function does pretty extensive testing on the whole model in an + effort to catch edge cases. + + This function assumes that rowCount(), columnCount() and index() already work. + If they have a bug it will point it out, but the above tests should have already + found the basic bugs because it is easier to figure out the problem in + those tests then this one. + */ +void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) +{ + // First just try walking back up the tree. + QModelIndex p = parent; + while ( p.isValid() ) + p = p.parent(); + + // For models that are dynamically populated + if ( model->canFetchMore ( parent ) ) { + fetchingMore = true; + model->fetchMore ( parent ); + fetchingMore = false; + } + + int rows = model->rowCount ( parent ); + int columns = model->columnCount ( parent ); + + // Some further testing against rows(), columns(), and hasChildren() + Q_ASSERT ( rows >= 0 ); + Q_ASSERT ( columns >= 0 ); + Q_ASSERT ( model->hasChildren ( parent ) == ( rows > 0 ) ); + + qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows + << "columns:" << columns << "parent column:" << parent.column(); + + Q_ASSERT ( model->hasIndex ( rows, 0, parent ) == false ); + Q_ASSERT ( model->index(rows, 0, parent).isValid() == false ); + for ( int r = 0; r < rows; ++r ) { + if ( model->canFetchMore ( parent ) ) { + fetchingMore = true; + model->fetchMore ( parent ); + fetchingMore = false; + } + Q_ASSERT ( model->hasIndex ( r, columns, parent ) == false ); + Q_ASSERT ( model->index(r, columns, parent).isValid() == false ); +// qDebug() << "Cols" << columns; + for ( int c = 0; c < columns; ++c ) { +// qDebug() << "has" << r << c << parent; + Q_ASSERT ( model->hasIndex ( r, c, parent ) == true ); + QModelIndex index = model->index ( r, c, parent ); + // rowCount() and columnCount() said that it existed... + Q_ASSERT ( index.isValid() == true ); + + // index() should always return the same index when called twice in a row + QModelIndex modifiedIndex = model->index ( r, c, parent ); + Q_ASSERT ( index == modifiedIndex ); + + // Make sure we get the same index if we request it twice in a row + QModelIndex a = model->index ( r, c, parent ); + QModelIndex b = model->index ( r, c, parent ); + Q_ASSERT ( a == b ); + + // Some basic checking on the index that is returned + Q_ASSERT ( index.model() == model ); +// qDebug() << index.row() << r; + Q_ASSERT ( index.row() == r ); + Q_ASSERT ( index.column() == c ); + // While you can technically return a QVariant usually this is a sign + // of an bug in data() Disable if this really is ok in your model. + if ( !model->data ( index, Qt::DisplayRole ).isValid() ) + qDebug() << index << index.data() << index.parent(); + Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true ); + + // If the next test fails here is some somewhat useful debug you play with. + /* + if (model->parent(index) != parent) { + qDebug() << r << c << currentDepth << model->data(index).toString() + << model->data(parent).toString(); + qDebug() << index << parent << model->parent(index); + // And a view that you can even use to show the model. + //QTreeView view; + //view.setModel(model); + //view.show(); + }*/ + + // Check that we can get back our real parent. +// qDebug() << index.data() << parent << model->parent ( index ) << parent.data() << model->parent ( index ).data() << r << rows << c << columns; + Q_ASSERT ( model->parent ( index ) == parent ); + + // recursively go down the children + if ( model->hasChildren ( index ) && currentDepth < 10 ) { +// qDebug() << r << c << "has children" << model->rowCount(index); + checkChildren ( index, ++currentDepth ); + }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/ + + // make sure that after testing the children that the index doesn't change. + QModelIndex newerIndex = model->index ( r, c, parent ); + Q_ASSERT ( index == newerIndex ); + } + } +} + +/*! + Tests model's implementation of QAbstractItemModel::data() + */ +void ModelTest::data() +{ + // Invalid index should return an invalid qvariant + Q_ASSERT ( !model->data ( QModelIndex() ).isValid() ); + + if ( model->rowCount() == 0 ) + return; + + // A valid index should have a valid QVariant data + Q_ASSERT ( model->index ( 0, 0 ).isValid() ); + + // shouldn't be able to set data on an invalid index + Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) == false ); + + // General Purpose roles that should return a QString + QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); + if ( variant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( variant ) ); + } + variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); + if ( variant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( variant ) ); + } + variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); + if ( variant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( variant ) ); + } + + // General Purpose roles that should return a QSize + variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); + if ( variant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( variant ) ); + } + + // General Purpose roles that should return a QFont + QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); + if ( fontVariant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( fontVariant ) ); + } + + // Check that the alignment is one we know about + QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); + if ( textAlignmentVariant.isValid() ) { + int alignment = textAlignmentVariant.toInt(); + Q_ASSERT ( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) ); + } + + // General Purpose roles that should return a QColor + QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); + if ( colorVariant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); + } + + colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); + if ( colorVariant.isValid() ) { + Q_ASSERT ( qVariantCanConvert ( colorVariant ) ); + } + + // Check that the "check state" is one we know about. + QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); + if ( checkStateVariant.isValid() ) { + int state = checkStateVariant.toInt(); + Q_ASSERT ( state == Qt::Unchecked || + state == Qt::PartiallyChecked || + state == Qt::Checked ); + } +} + +/*! + Store what is about to be inserted to make sure it actually happens + + \sa rowsInserted() + */ +void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end ) +{ +// Q_UNUSED(end); + qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).value() + << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) ); +// qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); + Changing c; + c.parent = parent; + c.oldSize = model->rowCount ( parent ); + c.last = model->data ( model->index ( start - 1, 0, parent ) ); + c.next = model->data ( model->index ( start, 0, parent ) ); + qDebug() << "last=" << c.last << c.next; + insert.push ( c ); + if (pedantic) { + ensureConsistent(); + status.type = Status::InsertingRows; + } +} + +/*! + Confirm that what was said was going to happen actually did + + \sa rowsAboutToBeInserted() + */ +void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) +{ + Changing c = insert.pop(); + Q_ASSERT ( c.parent == parent ); + qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize + << "parent=" << model->data ( parent ).value() << "current rowcount=" << model->rowCount ( parent ); + + for (int ii=start; ii <= end; ii++) + { + qDebug() << "itemWasInserted:" << model->data ( model->index ( ii, 0, parent )); + } + + + Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); + Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); + /* + if (c.next != model->data(model->index(end + 1, 0, c.parent))) { + qDebug() << start << end; + for (int i=0; i < model->rowCount(); ++i) + qDebug() << model->index(i, 0).data().toString(); + qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); + } + */ + qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); + Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) ); + + if (pedantic) { + Q_ASSERT(status.type == Status::InsertingRows); + refreshStatus(); + } +} + + +void ModelTest::modelAboutToBeReset() +{ + qDebug() << "@@@@@@@@@@@" << "modelAboutToBeReset"; + + if (pedantic) { + ensureConsistent(); + status.type = Status::Resetting; + } +} + +void ModelTest::modelReset() +{ + qDebug() << "@@@@@@@@@@@" << "modelReset"; + if (pedantic) { + Q_ASSERT(status.type == Status::Resetting); + refreshStatus(); + } +} + +void ModelTest::layoutAboutToBeChanged() +{ + qDebug() << "@@@@@@@@@@@" << "layoutAboutToBeChanged"; + + if (pedantic) { + ensureConsistent(); + status.type = Status::ChangingLayout; + } + for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) + { +// qDebug() << "persisting" << model->index ( i, 0 ) << model->index ( i, 0 ).data(); + changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) ); + } +} + +void ModelTest::layoutChanged() +{ + qDebug() << "@@@@@@@@@@@" << "layoutAboutToBeChanged"; +// qDebug() << "B"; + for ( int i = 0; i < changing.count(); ++i ) { + QPersistentModelIndex p = changing[i]; +// qDebug() << "Bp" << p; +// qDebug() << "p" << p << p.data(); +// qDebug() << "Ap"; + Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) ); + } + changing.clear(); + + if (pedantic) { + Q_ASSERT(status.type == Status::ChangingLayout); + refreshStatus(); + } + +// qDebug() << "A"; +} + +void ModelTest::rowsAboutToBeMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ) +{ + qDebug() << "rowsAboutToBeMoved" << srcParent << start << end << destParent << destinationRow; + + for (int row = start, dr = destinationRow; row <= end; ++row, ++dr) + qDebug() << "row" << model->index ( row, 0, srcParent ).data() << "in " << srcParent << "will be moved to " << destParent << dr; + + Changing cs; + cs.parent = srcParent; + cs.oldSize = model->rowCount ( srcParent ); + cs.last = model->data ( model->index ( start - 1, 0, srcParent ) ); + cs.next = model->data ( model->index ( end + 1, 0, srcParent ) ); + remove.push ( cs ); + Changing cd; + cd.parent = destParent; + cd.oldSize = model->rowCount ( destParent ); + cd.last = model->data ( model->index ( destinationRow - 1, 0, destParent ) ); + cd.next = model->data ( model->index ( destinationRow, 0, destParent ) ); + insert.push ( cd ); +} + +void ModelTest::rowsMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow ) +{ + qDebug() << "rowsMoved" << srcParent << start << end << destParent << destinationRow; + + Changing cd = insert.pop(); + Q_ASSERT ( cd.parent == destParent ); + if (srcParent == destParent) + { + Q_ASSERT ( cd.oldSize == model->rowCount ( destParent ) ); + + // TODO: Find out what I can assert here about last and next. +// Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); +// Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); + + + } + else + { + qDebug() << cd.oldSize << end << start << model->rowCount ( destParent ) << destParent.data() << "#########"; + Q_ASSERT ( cd.oldSize + ( end - start + 1 ) == model->rowCount ( destParent ) ); + + Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) ); + Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) ); + } + Changing cs = remove.pop(); + + Q_ASSERT ( cs.parent == srcParent ); + if (srcParent == destParent) + { + Q_ASSERT ( cs.oldSize == model->rowCount ( srcParent ) ); + } + else + { + Q_ASSERT ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) ); + + Q_ASSERT ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) ); +// qDebug() << cs.next << model->data ( model->index ( start, 0, srcParent ) ); + Q_ASSERT ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) ); + } + +} + +/*! + Store what is about to be inserted to make sure it actually happens + + \sa rowsRemoved() + */ +void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end ) +{ + qDebug() << "ratbr" << parent << start << end; + for (int ii=start; ii <= end; ii++) + { + qDebug() << "itemwillbe removed:" << model->data ( model->index ( ii, 0, parent )); + } + + if (pedantic) { + ensureConsistent(); + status.type = Status::RemovingRows; + } + + Changing c; + c.parent = parent; + c.oldSize = model->rowCount ( parent ); + c.last = model->data ( model->index ( start - 1, 0, parent ) ); + c.next = model->data ( model->index ( end + 1, 0, parent ) ); + remove.push ( c ); +} + +/*! + Confirm that what was said was going to happen actually did + + \sa rowsAboutToBeRemoved() + */ +void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) +{ + qDebug() << "rr" << parent << start << end; + Changing c = remove.pop(); + Q_ASSERT ( c.parent == parent ); + qDebug() << (c.oldSize - ( end - start + 1 ) ) << model->rowCount ( parent ); + Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) ); + Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); + Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); + + if (pedantic) { + Q_ASSERT(status.type == Status::RemovingRows); + refreshStatus(); + } +} + +void ModelTest::refreshStatus() +{ + status.type = Status::Idle; + status.nonPersistent.clear(); + status.persistent.clear(); + + persistStatus(QModelIndex()); +} + +void ModelTest::persistStatus(const QModelIndex& index) +{ + const int rowCount = model->rowCount(index); + for (int row = 0; row < rowCount; ++row) + { + // TODO: Test multi columns + static const int column = 0; + QPersistentModelIndex idx = model->index(row, column, index); + status.persistent.append(idx); + status.nonPersistent.append(idx); + persistStatus(idx); + } +} + +void ModelTest::ensureSteady() +{ + Q_ASSERT(insert.isEmpty()); + Q_ASSERT(remove.isEmpty()); + Q_ASSERT(changing.isEmpty()); + ensureConsistent(); +} + +void ModelTest::ensureConsistent() +{ + Q_ASSERT(status.type == Status::Idle); + + Q_ASSERT(status.nonPersistent.size() == status.persistent.size()); + for (int i = 0; i < status.nonPersistent.size(); ++i) { + Q_ASSERT(status.nonPersistent.at(i) == status.persistent.at(i)); + } +} + diff -Nru gammaray-1.2.2/tests/modeltest.h gammaray-2.0.1/tests/modeltest.h --- gammaray-1.2.2/tests/modeltest.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/tests/modeltest.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2007 Trolltech ASA. All rights reserved. +** +** This file is part of the Qt Concurrent project on Trolltech Labs. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of +** this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** http://www.trolltech.com/products/qt/opensource.html +** +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://www.trolltech.com/products/qt/licensing.html or contact the +** sales department at sales@trolltech.com. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef MODELTEST_H +#define MODELTEST_H + +#include +#include +#include + +class ModelTest : public QObject +{ + Q_OBJECT + +public: + enum Mode { + Normal, + Pedantic + }; + + ModelTest( QAbstractItemModel *model, QObject *parent = 0 ); + ModelTest( QAbstractItemModel *model, Mode testType, QObject *parent = 0 ); + +private Q_SLOTS: + void nonDestructiveBasicTest(); + void rowCount(); + void columnCount(); + void hasIndex(); + void index(); + void parent(); + void data(); + +protected Q_SLOTS: + void runAllTests(); + void layoutAboutToBeChanged(); + void layoutChanged(); + void modelAboutToBeReset(); + void modelReset(); + void rowsAboutToBeInserted( const QModelIndex &parent, int start, int end ); + void rowsInserted( const QModelIndex & parent, int start, int end ); + void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); + void rowsRemoved( const QModelIndex & parent, int start, int end ); + void rowsAboutToBeMoved ( const QModelIndex &, int, int, const QModelIndex &, int); + void rowsMoved ( const QModelIndex &, int, int, const QModelIndex &, int ); + + void ensureConsistent(); + void ensureSteady(); + +private: + void checkChildren( const QModelIndex &parent, int currentDepth = 0 ); + void refreshStatus(); + void persistStatus(const QModelIndex &index); + void init(); + + QAbstractItemModel * const model; + + struct Status { + enum Type { + Idle, + InsertingRows, + RemovingRows, + MovingRows, + ChangingLayout, + Resetting + }; + + Type type; + + QList persistent; + QList nonPersistent; + } status; + + struct Changing { + QPersistentModelIndex parent; + int oldSize; + QVariant last; + QVariant next; + }; + QStack insert; + QStack remove; + + bool fetchingMore; + const bool pedantic; + + QList changing; +}; + +#endif diff -Nru gammaray-1.2.2/tests/test_connections.cpp gammaray-2.0.1/tests/test_connections.cpp --- gammaray-1.2.2/tests/test_connections.cpp 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/test_connections.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -277,4 +277,3 @@ TestMain tc(argc, argv); return app.exec(); } -#include "test_connections.moc" diff -Nru gammaray-1.2.2/tests/test_connections.h gammaray-2.0.1/tests/test_connections.h --- gammaray-1.2.2/tests/test_connections.h 2012-12-21 21:38:15.000000000 +0000 +++ gammaray-2.0.1/tests/test_connections.h 2014-02-28 19:07:57.000000000 +0000 @@ -4,7 +4,7 @@ This file is part of GammaRay, the Qt application inspection and manipulation tool. - Copyright (C) 2010-2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Milian Wolff This program is free software; you can redistribute it and/or modify @@ -38,7 +38,9 @@ virtual ~TestObject(); private slots: - void dummySlot() {} + void dummySlot() + { + } public: QObject *child; @@ -63,7 +65,9 @@ void timeout(); private slots: - void dummySlot(){} + void dummySlot() + { + } signals: void done(); diff -Nru gammaray-1.2.2/ui/aboutdialog.cpp gammaray-2.0.1/ui/aboutdialog.cpp --- gammaray-1.2.2/ui/aboutdialog.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/aboutdialog.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + aboutdialog.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "aboutdialog.h" +#include "ui_aboutdialog.h" + +using namespace GammaRay; + +AboutDialog::AboutDialog(QWidget* parent): QDialog(parent), + ui(new Ui::AboutDialog) +{ + ui->setupUi(this); +} + +AboutDialog::~AboutDialog() +{ +} + +void AboutDialog::setTitle(const QString& title) +{ + ui->titleLabel->setText(title); +} + +void AboutDialog::setText(const QString& text) +{ + ui->textLabel->setText(text); +} + +void AboutDialog::setLogo(const QString& iconFileName) +{ + ui->logoLabel->setPixmap(iconFileName); +} + diff -Nru gammaray-1.2.2/ui/aboutdialog.h gammaray-2.0.1/ui/aboutdialog.h --- gammaray-1.2.2/ui/aboutdialog.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/aboutdialog.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ +/* + aboutdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ABOUTDIALOG_H +#define GAMMARAY_ABOUTDIALOG_H + +#include + +namespace GammaRay { + +namespace Ui +{ +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT +public: + explicit AboutDialog(QWidget* parent = 0); + ~AboutDialog(); + + void setTitle(const QString &title); + void setText(const QString &text); + void setLogo(const QString &iconFileName); + +private: + QScopedPointer ui; +}; +} + +#endif // GAMMARAY_ABOUTDIALOG_H diff -Nru gammaray-1.2.2/ui/aboutdialog.ui gammaray-2.0.1/ui/aboutdialog.ui --- gammaray-1.2.2/ui/aboutdialog.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/aboutdialog.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,82 @@ + + + GammaRay::AboutDialog + + + + + + + 75 + true + + + + + + + + + + + + 0 + 0 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + Qt::TextBrowserInteraction + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + rejected() + GammaRay::AboutDialog + close() + + + 261 + 302 + + + 310 + 98 + + + + + diff -Nru gammaray-1.2.2/ui/aboutpluginsdialog.cpp gammaray-2.0.1/ui/aboutpluginsdialog.cpp --- gammaray-1.2.2/ui/aboutpluginsdialog.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/aboutpluginsdialog.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,72 @@ +/* + aboutpluginsdialog.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "aboutpluginsdialog.h" +#include +#include + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +AboutPluginsDialog::AboutPluginsDialog(QWidget *parent, Qt::WindowFlags f) + : QDialog(parent, f) +{ + QLayout *layout = 0; + QVBoxLayout *vbox = new QVBoxLayout(this); + + { + QTableView *toolView = new QTableView(this); + toolView->setShowGrid(false); + toolView->setSelectionBehavior(QAbstractItemView::SelectRows); + toolView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + toolView->verticalHeader()->hide(); + toolView->setModel(ObjectBroker::model("com.kdab.GammaRay.ToolPluginModel")); + + QGroupBox *toolBox = new QGroupBox(tr("Loaded Plugins"), this); + layout = new QHBoxLayout(toolBox); + layout->addWidget(toolView); + vbox->addWidget(toolBox); + } + + { + QTableView *errorView = new QTableView(this); + errorView->setShowGrid(false); + errorView->setSelectionBehavior(QAbstractItemView::SelectRows); + errorView->setModel(ObjectBroker::model("com.kdab.GammaRay.ToolPluginErrorModel")); + errorView->verticalHeader()->hide(); + errorView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + + QGroupBox *errorBox = new QGroupBox(tr("Failed Plugins"), this); + layout = new QHBoxLayout(errorBox); + layout->addWidget(errorView); + vbox->addWidget(errorBox); + } + + setWindowTitle(tr("GammaRay: Plugin Info")); +} + diff -Nru gammaray-1.2.2/ui/aboutpluginsdialog.h gammaray-2.0.1/ui/aboutpluginsdialog.h --- gammaray-1.2.2/ui/aboutpluginsdialog.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/aboutpluginsdialog.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,41 @@ +/* + aboutpluginsdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_ABOUTPLUGINSDIALOG_H +#define GAMMARAY_ABOUTPLUGINSDIALOG_H + +#include + +namespace GammaRay { + +class AboutPluginsDialog : public QDialog +{ + Q_OBJECT + + public: + explicit AboutPluginsDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); +}; + +} + +#endif // GAMMARAY_ABOUTPLUGINSDIALOG_H diff -Nru gammaray-1.2.2/ui/clienttoolmodel.cpp gammaray-2.0.1/ui/clienttoolmodel.cpp --- gammaray-1.2.2/ui/clienttoolmodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/clienttoolmodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,156 @@ +/* + clienttoolmodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "clienttoolmodel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +using namespace GammaRay; + + +#define MAKE_FACTORY(type, remote) \ +class type ## Factory : public ToolUiFactory { \ +public: \ + virtual inline QString id() const { return "GammaRay::" #type; } \ + virtual inline QWidget *createWidget(QWidget *parentWidget) { return new type ## Widget(parentWidget); } \ + virtual inline bool remotingSupported() const { return remote; } \ +} + +MAKE_FACTORY(ConnectionInspector, true); +MAKE_FACTORY(LocaleInspector, true); +MAKE_FACTORY(MessageHandler, true); +MAKE_FACTORY(MetaObjectBrowser, true); +MAKE_FACTORY(MetaTypeBrowser, true); +MAKE_FACTORY(MimeTypes, true); +MAKE_FACTORY(ModelInspector, true); +MAKE_FACTORY(ObjectInspector, true); +MAKE_FACTORY(ResourceBrowser, true); +MAKE_FACTORY(StandardPaths, true); +MAKE_FACTORY(TextDocumentInspector, false); + +ClientToolModel::ClientToolModel(QObject* parent) : QSortFilterProxyModel(parent) +{ + insertFactory(new ConnectionInspectorFactory); + insertFactory(new LocaleInspectorFactory); + insertFactory(new MessageHandlerFactory); + insertFactory(new MetaObjectBrowserFactory); + insertFactory(new MetaTypeBrowserFactory); + insertFactory(new MimeTypesFactory); + insertFactory(new ModelInspectorFactory); + insertFactory(new ObjectInspectorFactory); + insertFactory(new ResourceBrowserFactory); + insertFactory(new StandardPathsFactory); + insertFactory(new TextDocumentInspectorFactory); + + PluginManager pm; + foreach(ToolUiFactory* factory, pm.plugins()) + insertFactory(factory); +} + +ClientToolModel::~ClientToolModel() +{ + qDeleteAll(m_factories.values()); +} + +QVariant ClientToolModel::data(const QModelIndex& index, int role) const +{ + if (role == ToolModelRole::ToolFactory || role == ToolModelRole::ToolWidget || role == Qt::ToolTipRole) { + const QString toolId = QSortFilterProxyModel::data(index, ToolModelRole::ToolId).toString(); + if (toolId.isEmpty()) + return QVariant(); + + if (role == ToolModelRole::ToolFactory) + return QVariant::fromValue(m_factories.value(toolId)); + if (role == ToolModelRole::ToolWidget) { + const QHash::const_iterator it = m_widgets.constFind(toolId); + if (it != m_widgets.constEnd()) + return QVariant::fromValue(it.value()); + ToolUiFactory *factory = m_factories.value(toolId); + if (!factory) + return QVariant(); + QWidget *widget = factory->createWidget(m_parentWidget); + m_widgets.insert(toolId, widget); + return QVariant::fromValue(widget); + } + if (role == Qt::ToolTipRole) { + ToolUiFactory *factory = m_factories.value(toolId); + if (factory && (!factory->remotingSupported() && Endpoint::instance()->isRemoteClient())) + return tr("This tool does not work in out-of-process mode."); + } + } + + return QSortFilterProxyModel::data(index, role); +} + +bool ClientToolModel::setData(const QModelIndex& index, const QVariant& value, int role) +{ + if (index.isValid() && role == ToolModelRole::ToolWidget) { + const QString toolId = QSortFilterProxyModel::data(index, ToolModelRole::ToolId).toString(); + Q_ASSERT(!toolId.isEmpty()); + Q_ASSERT(!m_widgets.contains(toolId)); + m_widgets.insert(toolId, value.value()); + return true; + } else if (role == ToolModelRole::ToolWidgetParent) { + m_parentWidget = value.value(); + return true; + } + + return QSortFilterProxyModel::setData(index, value, role); +} + +Qt::ItemFlags ClientToolModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags ret = QSortFilterProxyModel::flags(index); + const QString toolId = QSortFilterProxyModel::data(index, ToolModelRole::ToolId).toString(); + ToolUiFactory *factory = m_factories.value(toolId); + if (!factory || (!factory->remotingSupported() && Endpoint::instance()->isRemoteClient())) { + ret &= ~Qt::ItemIsEnabled; + } + return ret; +} + +void ClientToolModel::insertFactory(ToolUiFactory* factory) +{ + m_factories.insert(factory->id(), factory); +} + + diff -Nru gammaray-1.2.2/ui/clienttoolmodel.h gammaray-2.0.1/ui/clienttoolmodel.h --- gammaray-1.2.2/ui/clienttoolmodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/clienttoolmodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + clienttoolmodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CLIENTTOOLMODEL_H +#define GAMMARAY_CLIENTTOOLMODEL_H + +#include +#include +#include + +class QWidget; + +namespace GammaRay { + +class ToolUiFactory; + +/** Tool model for the client that implements the custom roles that return widget/factory pointers. */ +class ClientToolModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + explicit ClientToolModel(QObject* parent = 0); + ~ClientToolModel(); + + virtual QVariant data(const QModelIndex& index, int role) const; + virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + +private: + void insertFactory(ToolUiFactory* factory); + +private: + QHash m_factories; // ToolId -> ToolUiFactory + mutable QHash m_widgets; // ToolId -> Widget + QPointer m_parentWidget; +}; + +} + +#endif // GAMMARAY_CLIENTTOOLMODEL_H diff -Nru gammaray-1.2.2/ui/CMakeLists.txt gammaray-2.0.1/ui/CMakeLists.txt --- gammaray-1.2.2/ui/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/CMakeLists.txt 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,128 @@ +# +# Shared code between in-process and out-of-process UI +# +set(gammaray_ui_srcs + ${CMAKE_SOURCE_DIR}/3rdparty/kde/krecursivefilterproxymodel.cpp + ${CMAKE_SOURCE_DIR}/3rdparty/kde/kfilterproxysearchline.cpp + + ${CMAKE_SOURCE_DIR}/3rdparty/other/modelutils.cpp + + palettemodel.cpp + methodinvocationdialog.cpp + propertywidget.cpp + deferredresizemodesetter.cpp + deferredtreeviewconfiguration.cpp + splashscreen.cpp + + propertyeditor/propertycoloreditor.cpp + propertyeditor/propertydoublepaireditor.cpp + propertyeditor/propertyeditorfactory.cpp + propertyeditor/propertyextendededitor.cpp + propertyeditor/propertyfonteditor.cpp + propertyeditor/propertyintpaireditor.cpp + propertyeditor/propertypaletteeditor.cpp + propertyeditor/palettedialog.cpp + propertyeditor/propertyeditordelegate.cpp +) + +if(NOT Qt5Core_VERSION VERSION_LESS 5.2.0) + list(APPEND gammaray_ui_srcs + variantcontainermodel.cpp + ) +endif() + +qt4_wrap_ui(gammaray_ui_srcs + methodinvocationdialog.ui + propertywidget.ui + + propertyeditor/propertydoublepaireditor.ui + propertyeditor/propertyextendededitor.ui + propertyeditor/propertyintpaireditor.ui + propertyeditor/palettedialog.ui +) + +add_library(gammaray_ui SHARED ${gammaray_ui_srcs}) +set_target_properties(gammaray_ui PROPERTIES + DEFINE_SYMBOL MAKE_GAMMARAY_UI_LIB + SOVERSION ${GAMMARAY_SOVERSION} + VERSION ${GAMMARAY_SOVERSION} + OUTPUT_NAME gammaray_ui-${GAMMARAY_PROBE_ABI} +) + +target_link_libraries(gammaray_ui + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common_internal +) + +target_link_libraries(gammaray_ui LINK_INTERFACE_LIBRARIES + gammaray_common + ${QT_QTGUI_LIBRARIES} +) + +install(TARGETS gammaray_ui EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) + +set(gammaray_ui_internal_srcs + sidepane.cpp + aboutpluginsdialog.cpp + mainwindow.cpp + aboutdialog.cpp + proxytooluifactory.cpp + clienttoolmodel.cpp + + tools/connectioninspector/connectioninspectorwidget.cpp + tools/localeinspector/localeinspectorwidget.cpp + tools/messagehandler/messagehandlerwidget.cpp + tools/messagehandler/messagehandlerclient.cpp + ../core/tools/messagehandler/messagehandlerinterface.cpp + tools/metaobjectbrowser/metaobjectbrowserwidget.cpp + tools/metatypebrowser/metatypebrowserwidget.cpp + tools/mimetypes/mimetypeswidget.cpp + tools/modelinspector/modelinspectorwidget.cpp + tools/modelinspector/modelinspectorclient.cpp + tools/objectinspector/objectinspectorwidget.cpp + tools/resourcebrowser/clientresourcemodel.cpp + tools/resourcebrowser/resourcebrowserwidget.cpp + tools/resourcebrowser/resourcebrowserclient.cpp + tools/standardpaths/standardpathswidget.cpp + tools/textdocumentinspector/textdocumentinspectorwidget.cpp + tools/textdocumentinspector/textdocumentcontentview.cpp +) + +qt4_wrap_ui(gammaray_ui_internal_srcs + mainwindow.ui + aboutdialog.ui + + tools/connectioninspector/connectioninspectorwidget.ui + tools/localeinspector/localeinspectorwidget.ui + tools/messagehandler/messagehandlerwidget.ui + tools/metatypebrowser/metatypebrowserwidget.ui + tools/mimetypes/mimetypeswidget.ui + tools/modelinspector/modelinspectorwidget.ui + tools/objectinspector/objectinspectorwidget.ui + tools/resourcebrowser/resourcebrowserwidget.ui + tools/standardpaths/standardpathswidget.ui + tools/textdocumentinspector/textdocumentinspectorwidget.ui +) + +if(NOT WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +endif() + +add_library(gammaray_ui_internal STATIC ${gammaray_ui_internal_srcs}) + +target_link_libraries(gammaray_ui_internal + ${QT_QTCORE_LIBRARIES} + ${QT_QTGUI_LIBRARIES} + gammaray_common_internal + gammaray_ui +) + +gammaray_install_headers( + gammaray_ui_export.h + deferredresizemodesetter.h + deferredtreeviewconfiguration.h + palettemodel.h + propertywidget.h + tooluifactory.h +) diff -Nru gammaray-1.2.2/ui/deferredresizemodesetter.cpp gammaray-2.0.1/ui/deferredresizemodesetter.cpp --- gammaray-1.2.2/ui/deferredresizemodesetter.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/deferredresizemodesetter.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + deferredresizemodesetter.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "deferredresizemodesetter.h" + +using namespace GammaRay; + +DeferredResizeModeSetter::DeferredResizeModeSetter(QHeaderView* headerView, int section, QHeaderView::ResizeMode resizeMode): + QObject(headerView), + m_view(headerView), + m_section(section), + m_resizeMode(resizeMode) +{ + connect(m_view, SIGNAL(sectionCountChanged(int,int)), SLOT(setSectionResizeMode())); + setSectionResizeMode(); +} + +DeferredResizeModeSetter::~DeferredResizeModeSetter() +{ +} + +void DeferredResizeModeSetter::setSectionResizeMode() +{ + if (m_view->count() <= m_section) + return; // section not loaded yet + + m_view->setResizeMode(m_section, m_resizeMode); +} + diff -Nru gammaray-1.2.2/ui/deferredresizemodesetter.h gammaray-2.0.1/ui/deferredresizemodesetter.h --- gammaray-1.2.2/ui/deferredresizemodesetter.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/deferredresizemodesetter.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + deferredresizemodesetter.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_DEFERREDRESIZEMODESETTER_H +#define GAMMARAY_DEFERREDRESIZEMODESETTER_H + +#include "gammaray_ui_export.h" + +#include +#include + +namespace GammaRay { + +/** @brief Sets the resize mode on a QHeaderView section once that section is actually available. + * + * This is a workaround for QHeaderView asserting when manipulating if the corresponding section + * hasn't been loaded yet by the corresponding model, as well as forgetting the setting if the + * model reports a columnCount of 0 again inbetween. + */ +class GAMMARAY_UI_EXPORT DeferredResizeModeSetter : public QObject +{ + Q_OBJECT +public: + DeferredResizeModeSetter(QHeaderView *headerView, int section, QHeaderView::ResizeMode resizeMode); + ~DeferredResizeModeSetter(); + +private slots: + void setSectionResizeMode(); + +private: + QHeaderView *m_view; + int m_section; + QHeaderView::ResizeMode m_resizeMode; +}; + +} + +#endif // GAMMARAY_DEFERREDRESIZEMODESETTER_H diff -Nru gammaray-1.2.2/ui/deferredtreeviewconfiguration.cpp gammaray-2.0.1/ui/deferredtreeviewconfiguration.cpp --- gammaray-1.2.2/ui/deferredtreeviewconfiguration.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/deferredtreeviewconfiguration.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,86 @@ +/* + deferredtreeviewconfiguration.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "deferredtreeviewconfiguration.h" + +#include +#include + +using namespace GammaRay; +using namespace std; + +DeferredTreeViewConfiguration::DeferredTreeViewConfiguration(QTreeView *view, bool expandNewContent, bool selectNewContent, QObject *parent) + : QObject(parent ? parent : view) + , m_view(view) + , m_expand(expandNewContent) + , m_select(selectNewContent) +{ + Q_ASSERT(view); + Q_ASSERT(view->model()); + Q_ASSERT(view->selectionModel()); + + connect(view->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), + SLOT(rowsInserted(QModelIndex))); + connect(view->model(), SIGNAL(columnsInserted(QModelIndex,int,int)), + SLOT(columnsInserted(QModelIndex))); + + if (view->model()->rowCount() > 0) { + rowsInserted(QModelIndex()); + if (m_expand) { + view->expandAll(); + } + } + columnsInserted(QModelIndex()); +} + +void DeferredTreeViewConfiguration::hideColumn(int column) +{ + m_hiddenColumns << column; + + columnsInserted(QModelIndex()); +} + +void DeferredTreeViewConfiguration::rowsInserted(const QModelIndex &parent) +{ + if (m_expand) { + m_view->expand(parent); + } + if (m_select && !m_view->currentIndex().isValid()) { + m_view->selectionModel()->setCurrentIndex(m_view->model()->index(0, 0), QItemSelectionModel::ClearAndSelect); + } +} + +void DeferredTreeViewConfiguration::columnsInserted(const QModelIndex &parent) +{ + if (m_hiddenColumns.isEmpty() || parent.isValid()) { + return; + } + + const int columns = m_view->model()->columnCount(parent); + foreach(int column, m_hiddenColumns) { + if (column < columns) { + m_view->hideColumn(column); + } + } +} + diff -Nru gammaray-1.2.2/ui/deferredtreeviewconfiguration.h gammaray-2.0.1/ui/deferredtreeviewconfiguration.h --- gammaray-1.2.2/ui/deferredtreeviewconfiguration.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/deferredtreeviewconfiguration.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,72 @@ +/* + deferredtreeviewconfiguration.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_DEFERREDTREEVIEWCONFIGURATION_H +#define GAMMARAY_DEFERREDTREEVIEWCONFIGURATION_H + +#include "gammaray_ui_export.h" + +#include +#include + +class QModelIndex; +class QTreeView; + +namespace GammaRay { + +/** + * @brief A utility helper to configure views for remote content. + * + * When @p expandNewContent is set to true, the tree view will stay expanded + * when new content is added to the model. + * + * When @p selectNewContent is set to true, the tree view will select new content, + * if no selection is already present. + * + * @note The tree view's model and selectionModel must be set beforehand and not + * be changed afterwards! + */ +class GAMMARAY_UI_EXPORT DeferredTreeViewConfiguration : public QObject +{ + Q_OBJECT + public: + explicit DeferredTreeViewConfiguration(QTreeView *view, + bool expandNewContent = true, bool selectNewContent = true, + QObject *parent = 0); + + void hideColumn(int column); + + private slots: + void rowsInserted(const QModelIndex &parent); + void columnsInserted(const QModelIndex &parent); + + private: + QTreeView *m_view; + bool m_expand; + bool m_select; + QVector m_hiddenColumns; +}; + +} + +#endif // GAMMARAY_DEFERREDTREEVIEWCONFIGURATION_H diff -Nru gammaray-1.2.2/ui/gammaray_ui_export.h gammaray-2.0.1/ui/gammaray_ui_export.h --- gammaray-1.2.2/ui/gammaray_ui_export.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/gammaray_ui_export.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,40 @@ +/* + gammaray_ui_export.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_UI_EXPORT_H +#define GAMMARAY_UI_EXPORT_H + +#include + +#ifdef GAMMARAY_UI_STATICLIB +# undef GAMMARAY_UI_SHAREDLIB +# define GAMMARAY_UI_EXPORT +#else +# ifdef MAKE_GAMMARAY_UI_LIB +# define GAMMARAY_UI_EXPORT Q_DECL_EXPORT +# else +# define GAMMARAY_UI_EXPORT Q_DECL_IMPORT +# endif +#endif + +#endif /* GAMMARAY_UI_EXPORT_H */ diff -Nru gammaray-1.2.2/ui/mainwindow.cpp gammaray-2.0.1/ui/mainwindow.cpp --- gammaray-1.2.2/ui/mainwindow.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/mainwindow.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,270 @@ +/* + mainwindow.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "config-gammaray-version.h" +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "aboutpluginsdialog.h" +#include "aboutdialog.h" +#include "clienttoolmodel.h" + +#include +#include +#include +#include + +#include "kde/krecursivefilterproxymodel.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#include //krazy:exclude=camelcase +#else +#include //krazy:exclude=camelcase +#include //krazy:exclude=camelcase +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +static const char progName[] = PROGRAM_NAME; +static const char progVersion[] = GAMMARAY_VERSION_STRING; +static const char progDesc[] = "The Qt application inspection and manipulation tool"; +static const char progURL[] = "http://www.kdab.com/gammaray"; + +MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) +{ + if (!Endpoint::instance()->isRemoteClient()) { + // we don't want application styles to propagate to the GammaRay window, + // so set the platform default one. + // unfortunately, that's not recursive by default, unless we have a style sheet set + setStyleSheet(QLatin1String("I_DONT_EXIST {}")); + + QStyle *defaultStyle = 0; +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + QGuiPlatformPlugin defaultGuiPlatform; + defaultStyle = QStyleFactory::create(defaultGuiPlatform.styleName()); +#else + foreach (const QString &styleName, QGuiApplicationPrivate::platform_theme->themeHint(QPlatformTheme::StyleNames).toStringList()) { + if ((defaultStyle = QStyleFactory::create(styleName))) { + break; + } + } +#endif + if (defaultStyle) { + // do not set parent of default style + // this will cause the style being deleted too early through ~QObject() + // other objects (e.g. the script engine debugger) still might have a + // reference on the style during destruction + setStyle(defaultStyle); + } + } + + ui->setupUi(this); + + connect(ui->actionRetractProbe, SIGNAL(triggered(bool)), SLOT(detachProbe())); + + connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(close())); + connect(ui->actionQuit, SIGNAL(triggered(bool)), this, SLOT(quitHost())); + ui->actionQuit->setIcon(QIcon::fromTheme("application-exit")); + + connect(ui->actionPlugins, SIGNAL(triggered(bool)), + this, SLOT(aboutPlugins())); + connect(ui->actionAboutQt, SIGNAL(triggered(bool)), + QApplication::instance(), SLOT(aboutQt())); + connect(ui->actionAboutGammaRay, SIGNAL(triggered(bool)), SLOT(about())); + connect(ui->actionAboutKDAB, SIGNAL(triggered(bool)), SLOT(aboutKDAB())); + + setWindowIcon(QIcon(":gammaray/GammaRay-128x128.png")); + + QAbstractItemModel *model = ObjectBroker::model("com.kdab.GammaRay.ToolModel"); + ClientToolModel *proxyModel = new ClientToolModel(this); + proxyModel->setData(QModelIndex(), QVariant::fromValue(this), ToolModelRole::ToolWidgetParent); + proxyModel->setDynamicSortFilter(true); + proxyModel->setSourceModel(model); + proxyModel->sort(0); + ui->toolSelector->setModel(proxyModel); + ui->toolSelector->resize(ui->toolSelector->minimumSize()); + connect(ui->toolSelector->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + SLOT(toolSelected())); + + // hide unused tool bar for now + ui->mainToolBar->setHidden(true); + + setWindowTitle(tr("%1 (%2)").arg(progName).arg(Endpoint::instance()->label())); + + selectInitialTool(); + connect(ui->toolSelector->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(selectInitialTool())); + connect(ui->toolSelector->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(selectInitialTool())); + +#ifdef Q_OS_MAC + ui->groupBox->setFlat(true); + ui->horizontalLayout->setContentsMargins(0, 0, 0, 0); +#endif + + // get some sane size on startup + resize(1024, 768); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::about() +{ + AboutDialog dialog(this); + dialog.setWindowTitle(tr("About %1").arg(progName)); + dialog.setTitle(tr("%1 %2

%3").arg(progName).arg(progVersion).arg(progDesc)); + dialog.setText( + trUtf8("" + "

Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, " + "a KDAB Group company, info@kdab.com

" + "

Authors:
" + "Allen Winter <allen.winter@kdab.com>
" + "Andreas Holzammer <andreas.holzammer@kdab.com>
" + "David Faure <david.faure@kdab.com>
" + "Kevin Funk <kevin.funk@kdab.com>
" + "Laurent Montel <laurent.montel@kdab.com>
" + "Milian Wolff <milian.wolff@kdab.com>
" + "Patrick Spendrin <patrick.spendrin@kdab.com>
" + "Stephen Kelly <stephen.kelly@kdab.com>
" + "Till Adam <till@kdab.com>
" + "Thomas McGuire <thomas.mcguire@kdab.com>
" + "Tobias Koenig <tobias.koenig@kdab.com>
" + "Volker Krause <volker.krause@kdab.com>

" + "

StackWalker code Copyright (c) 2005-2009, Jochen Kalmbach, All rights reserved

" + "")); + dialog.setLogo(":gammaray/GammaRay-128x128.png"); + dialog.setWindowIcon(QPixmap(":gammaray/GammaRay-128x128.png")); + dialog.exec(); +} + +void MainWindow::aboutPlugins() +{ + AboutPluginsDialog dlg(this); + dlg.setFixedSize(800, 600); + dlg.exec(); +} + +void MainWindow::aboutKDAB() +{ + AboutDialog dialog(this); + dialog.setWindowTitle(tr("About KDAB")); + dialog.setTitle(trUtf8("Klarälvdalens Datakonsult AB (KDAB)")); + dialog.setText( + tr("

%1 is supported and maintained by KDAB

" + "KDAB, the Qt experts, provide consulting and mentoring for developing " + "Qt applications from scratch and in porting from all popular and legacy " + "frameworks to Qt. Our software products increase Qt productivity and our " + "Qt trainers have trained 50% of commercial Qt developers globally.

" + "

Please visit http://www.kdab.com " + "to meet the people who write code like this. " + "We also offer Qt training courses." + "

").arg(progName)); + dialog.setLogo(":gammaray/kdablogo160.png"); + dialog.setWindowIcon(QPixmap(":gammaray/kdablogo160.png")); + dialog.exec(); +} + +void MainWindow::selectInitialTool() +{ + static const QString initialTool("GammaRay::ObjectInspector"); + + QAbstractItemModel *model = ui->toolSelector->model(); + QModelIndexList matches = + model->match(model->index(0, 0), ToolModelRole::ToolId, initialTool); + if (matches.isEmpty()) { + return; + } + + disconnect(ui->toolSelector->model(), 0, this, SLOT(selectInitialTool())); + ui->toolSelector->setCurrentIndex(matches.first()); + toolSelected(); +} + +void MainWindow::toolSelected() +{ + ui->actionsMenu->clear(); + const int row = ui->toolSelector->currentIndex().row(); + if (row == -1) { + return; + } + + const QModelIndex mi = ui->toolSelector->model()->index(row, 0); + QWidget *toolWidget = mi.data(ToolModelRole::ToolWidget).value(); + if (!toolWidget) { + toolWidget = createErrorPage(mi); + ui->toolSelector->model()->setData(mi, QVariant::fromValue(toolWidget), ToolModelRole::ToolWidget); + } + + Q_ASSERT(toolWidget); + if (ui->toolStack->indexOf(toolWidget) < 0) { // newly created + if (toolWidget->layout()) { +#ifndef Q_OS_MAC + toolWidget->layout()->setContentsMargins(11, 0, 0, 0); +#else + QMargins margins = toolWidget->layout()->contentsMargins(); + margins.setLeft(0); + toolWidget->layout()->setContentsMargins(margins); +#endif + } + ui->toolStack->addWidget(toolWidget); + } + + ui->toolStack->setCurrentIndex(ui->toolStack->indexOf(toolWidget)); + + foreach (QAction *action, toolWidget->actions()) { + ui->actionsMenu->addAction(action); + } + ui->actionsMenu->setEnabled(!ui->actionsMenu->isEmpty()); +} + +QWidget* MainWindow::createErrorPage(const QModelIndex& index) +{ + QLabel *page = new QLabel(this); + page->setAlignment(Qt::AlignCenter); + // TODO show the actual plugin error message as well as any other useful information (eg. file name) we have, once the tool model has those + page->setText(tr("Tool %1 failed to load.").arg(index.data(ToolModelRole::ToolId).toString())); + return page; +} + +void MainWindow::quitHost() +{ + ObjectBroker::object()->quitHost(); +} + +void MainWindow::detachProbe() +{ + ObjectBroker::object()->detachProbe(); +} + diff -Nru gammaray-1.2.2/ui/mainwindow.h gammaray-2.0.1/ui/mainwindow.h --- gammaray-1.2.2/ui/mainwindow.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/mainwindow.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + mainwindow.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MAINWINDOW_H +#define GAMMARAY_MAINWINDOW_H + +#include + +class QModelIndex; + +namespace GammaRay { + +namespace Ui { class MainWindow; } + +class MainWindow : public QMainWindow +{ + Q_OBJECT + public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + private slots: + void about(); + void aboutPlugins(); + void aboutKDAB(); + + void toolSelected(); + void selectInitialTool(); + + void quitHost(); + void detachProbe(); + + private: + QWidget* createErrorPage(const QModelIndex &index); + + QScopedPointer ui; +}; + +} + +#endif // MAINWINDOW_H diff -Nru gammaray-1.2.2/ui/mainwindow.ui gammaray-2.0.1/ui/mainwindow.ui --- gammaray-1.2.2/ui/mainwindow.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/mainwindow.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,203 @@ + + + GammaRay::MainWindow + + + + 0 + 0 + 829 + 600 + + + + + + 0 + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 180 + 0 + + + + background-image: url(:/gammaray/kdab-gammaray-logo.png); +background-repeat: no-repeat; +background-attachment:fixed; +background-position:bottom right; + + + + QFrame::NoFrame + + + QFrame::Plain + + + Qt::ElideRight + + + QListView::TopToBottom + + + false + + + QListView::Fixed + + + QListView::ListMode + + + true + + + false + + + true + + + + + + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + 829 + 21 + + + + + &GammaRay + + + + + + + + &Help + + + + + + + + + + &Actions + + + + + + + + + Main Toolbar + + + false + + + Qt::BottomToolBarArea|Qt::TopToolBarArea + + + false + + + TopToolBarArea + + + false + + + + + &Detach + + + Retract probe from application. + + + + + &Quit + + + Quit probed application. + + + + + + :/gammaray/GammaRay-32x32.png:/gammaray/GammaRay-32x32.png + + + About &GammaRay + + + + + About &Qt + + + + + About &KDAB + + + + + Plugins... + + + + + + SidePane + QListView +
sidepane.h
+
+
+ + + + +
diff -Nru gammaray-1.2.2/ui/methodinvocationdialog.cpp gammaray-2.0.1/ui/methodinvocationdialog.cpp --- gammaray-1.2.2/ui/methodinvocationdialog.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/methodinvocationdialog.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + methodinvocationdialog.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "methodinvocationdialog.h" +#include "ui_methodinvocationdialog.h" + +#include + +#include + +using namespace GammaRay; + +MethodInvocationDialog::MethodInvocationDialog(QWidget *parent) + : QDialog(parent), + ui(new Ui::MethodInvocationDialog) +{ + ui->setupUi(this); + + ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Invoke")); + connect(ui->buttonBox, SIGNAL(accepted()), SLOT(accept())); + connect(ui->buttonBox, SIGNAL(rejected()), SLOT(reject())); + + ui->connectionTypeComboBox->addItem(tr("Auto"), QVariant::fromValue(Qt::AutoConnection)); + ui->connectionTypeComboBox->addItem(tr("Direct"), QVariant::fromValue(Qt::DirectConnection)); + ui->connectionTypeComboBox->addItem(tr("Queued"), QVariant::fromValue(Qt::QueuedConnection)); +} + +MethodInvocationDialog::~MethodInvocationDialog() +{ +} + +Qt::ConnectionType MethodInvocationDialog::connectionType() const +{ + return ui->connectionTypeComboBox->itemData(ui->connectionTypeComboBox->currentIndex()).value(); +} + +void MethodInvocationDialog::setArgumentModel(QAbstractItemModel* model) +{ + ui->argumentView->setModel(model); +} + diff -Nru gammaray-1.2.2/ui/methodinvocationdialog.h gammaray-2.0.1/ui/methodinvocationdialog.h --- gammaray-1.2.2/ui/methodinvocationdialog.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/methodinvocationdialog.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + methodinvocationdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METHODINVOCATIONDIALOG_H +#define GAMMARAY_METHODINVOCATIONDIALOG_H + +#include + +class QAbstractItemModel; + +namespace GammaRay { + +namespace Ui { class MethodInvocationDialog; } + +class MethodInvocationDialog : public QDialog +{ + Q_OBJECT + public: + explicit MethodInvocationDialog(QWidget *parent = 0); + ~MethodInvocationDialog(); + + Qt::ConnectionType connectionType() const; + void setArgumentModel(QAbstractItemModel *model); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_METHODINVOCATIONDIALOG_H diff -Nru gammaray-1.2.2/ui/methodinvocationdialog.ui gammaray-2.0.1/ui/methodinvocationdialog.ui --- gammaray-1.2.2/ui/methodinvocationdialog.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/methodinvocationdialog.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ + + + GammaRay::MethodInvocationDialog + + + + 0 + 0 + 400 + 300 + + + + + + + + + &Connection type: + + + connectionTypeComboBox + + + + + + + + + + + + false + + + true + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff -Nru gammaray-1.2.2/ui/palettemodel.cpp gammaray-2.0.1/ui/palettemodel.cpp --- gammaray-1.2.2/ui/palettemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/palettemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,176 @@ +/* + palettemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010 Ariya Hidayat + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "palettemodel.h" + +#include +#include + +using namespace GammaRay; + +struct role_t { + const char *name; + QPalette::ColorRole role; +}; + +static role_t paletteRoles[] = { + { "Window", QPalette::Window }, + { "WindowText", QPalette::WindowText }, + { "Base", QPalette::Base }, + { "AlternateBase", QPalette::AlternateBase }, + { "Text", QPalette::Text }, + { "ToolTipBase", QPalette::ToolTipBase }, + { "ToolTipText", QPalette::ToolTipText }, + { "Button", QPalette::Button }, + { "ButtonText", QPalette::ButtonText }, + { "BrightText", QPalette::BrightText }, + { "Light", QPalette::Light }, + { "Midlight", QPalette::Midlight }, + { "Dark", QPalette::Dark }, + { "Mid", QPalette::Mid }, + { "Shadow", QPalette::Shadow }, + { "Highlight", QPalette::Highlight }, + { "HighlightedText", QPalette::HighlightedText }, + { "Link", QPalette::Link }, + { "LinkVisited", QPalette::LinkVisited } +}; + +struct group_t { + const char *name; + QPalette::ColorGroup group; +}; + +static group_t paletteGroups[] = { + { "Active", QPalette::Active }, + { "Inactive", QPalette::Inactive }, + { "Disabled", QPalette::Disabled }, +}; + +PaletteModel::PaletteModel(QObject *parent) + : QAbstractTableModel(parent), m_editable(false) +{ +} + +QPalette PaletteModel::palette() const +{ + return m_palette; +} + +void PaletteModel::setPalette(const QPalette &palette) +{ + beginResetModel(); + m_palette = palette; + endResetModel(); +} + +void PaletteModel::setEditable(bool editable) +{ + m_editable = editable; +} + +QVariant PaletteModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) { + return QVariant(); + } + + if (role == Qt::DisplayRole) { + if (index.column() == 0) { + return paletteRoles[index.row()].name; + } + + return + m_palette.color(paletteGroups[index.column()-1].group, + paletteRoles[index.row()].role).name(); + + } else if (role == Qt::EditRole) { + // TODO return QBrush once we have an editor for that + return + m_palette.color(paletteGroups[index.column()-1].group, + paletteRoles[index.row()].role); + } else if (role == Qt::DecorationRole && index.column() != 0) { + const QBrush brush = m_palette.brush(paletteGroups[index.column()-1].group, + paletteRoles[index.row()].role); + QPixmap pixmap(32, 32); + QPainter painter(&pixmap); + painter.fillRect(pixmap.rect(), Qt::black); + painter.fillRect(pixmap.rect().adjusted(1, 1, -1, -1), brush); + return QIcon(pixmap); + } + + return QVariant(); +} + +bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!m_editable) { + return false; + } + + if (index.isValid() && role == Qt::EditRole) { + if (value.type() == QVariant::Color) { + m_palette.setColor(paletteGroups[index.column()-1].group, + paletteRoles[index.row()].role, value.value()); + } else if (value.type() == QVariant::Brush) { + m_palette.setBrush(paletteGroups[index.column()-1].group, + paletteRoles[index.row()].role, value.value()); + } + } + return QAbstractItemModel::setData(index, value, role); +} + +int PaletteModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return 1 + sizeof(paletteGroups) / sizeof(paletteGroups[0]); +} + +int PaletteModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) { + return 0; + } + return sizeof(paletteRoles) / sizeof(paletteRoles[0]); +} + +QVariant PaletteModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + if (section == 0) { + return tr("Role"); + } + return paletteGroups[section-1].name; + } + return QAbstractItemModel::headerData(section, orientation, role); +} + +Qt::ItemFlags PaletteModel::flags(const QModelIndex &index) const +{ + const Qt::ItemFlags baseFlags = QAbstractItemModel::flags(index); + if (m_editable && index.column() > 0) { + return baseFlags | Qt::ItemIsEditable; + } + return baseFlags; +} + diff -Nru gammaray-1.2.2/ui/palettemodel.h gammaray-2.0.1/ui/palettemodel.h --- gammaray-1.2.2/ui/palettemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/palettemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + palettemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PALETTEMODEL_H +#define GAMMARAY_PALETTEMODEL_H + +#include "gammaray_ui_export.h" + +#include +#include + +namespace GammaRay { + +/** + * @brief Model showing the content of a QPalette. + */ +class GAMMARAY_UI_EXPORT PaletteModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit PaletteModel(QObject *parent = 0); + + QPalette palette() const; + void setPalette(const QPalette &palette); + void setEditable(bool editable); + + ///@cond override + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + ///@endcond + + private: + QPalette m_palette; + bool m_editable; +}; + +} + +#endif // GAMMARAY_PALETTEMODEL_H diff -Nru gammaray-1.2.2/ui/propertyeditor/palettedialog.cpp gammaray-2.0.1/ui/propertyeditor/palettedialog.cpp --- gammaray-1.2.2/ui/propertyeditor/palettedialog.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/palettedialog.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + palettedialog.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "palettedialog.h" + +#include "ui_palettedialog.h" +#include "palettemodel.h" +#include "propertyeditor/propertyeditordelegate.h" + +#include +#include + +using namespace GammaRay; + +PaletteDialog::PaletteDialog(const QPalette &palette, QWidget *parent) + : QDialog(parent), + ui(new Ui::PaletteDialog), + m_model(new PaletteModel(this)) +{ + ui->setupUi(this); + m_model->setPalette(palette); + m_model->setEditable(true); + ui->paletteView->setModel(m_model); + ui->paletteView->setItemDelegate(new PropertyEditorDelegate(this)); +} + +PaletteDialog::~PaletteDialog() +{ + delete ui; +} + +QPalette PaletteDialog::editedPalette() const +{ + return m_model->palette(); +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/palettedialog.h gammaray-2.0.1/ui/propertyeditor/palettedialog.h --- gammaray-1.2.2/ui/propertyeditor/palettedialog.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/palettedialog.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,55 @@ +/* + palettedialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PALETTEDIALOG_H +#define GAMMARAY_PALETTEDIALOG_H + +#include + +namespace GammaRay { + +class PropertyEditorFactory; + +class PaletteModel; + +namespace Ui { + class PaletteDialog; +} + +class PaletteDialog : public QDialog +{ + Q_OBJECT + public: + explicit PaletteDialog(const QPalette &palette, QWidget *parent = 0); + virtual ~PaletteDialog(); + + QPalette editedPalette() const; + + private: + Ui::PaletteDialog *ui; + PaletteModel *m_model; +}; + +} + +#endif // GAMMARAY_PALETTEDIALOG_H diff -Nru gammaray-1.2.2/ui/propertyeditor/palettedialog.ui gammaray-2.0.1/ui/propertyeditor/palettedialog.ui --- gammaray-1.2.2/ui/propertyeditor/palettedialog.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/palettedialog.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,74 @@ + + + GammaRay::PaletteDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + false + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Save + + + + + + + + + buttonBox + accepted() + GammaRay::PaletteDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GammaRay::PaletteDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertycoloreditor.cpp gammaray-2.0.1/ui/propertyeditor/propertycoloreditor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertycoloreditor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertycoloreditor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + propertycoloreditor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertycoloreditor.h" + +#include + +using namespace GammaRay; + +PropertyColorEditor::PropertyColorEditor(QWidget *parent) + : PropertyExtendedEditor(parent) +{ +} + +void PropertyColorEditor::edit() +{ + const QColor color = QColorDialog::getColor(value().value(), this); + if (color.isValid()) { + setValue(QVariant::fromValue(color)); + } +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertycoloreditor.h gammaray-2.0.1/ui/propertyeditor/propertycoloreditor.h --- gammaray-1.2.2/ui/propertyeditor/propertycoloreditor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertycoloreditor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + propertycoloreditor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYCOLOREDITOR_H +#define GAMMARAY_PROPERTYCOLOREDITOR_H + +#include "propertyextendededitor.h" + +namespace GammaRay { + +/** Property editor for QColor. */ +class PropertyColorEditor : public PropertyExtendedEditor +{ + Q_OBJECT + public: + explicit PropertyColorEditor(QWidget *parent = 0); + + protected: + virtual void edit(); +}; + +} + +#endif // GAMMARAY_PROPERTYCOLOREDITOR_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.cpp gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,70 @@ +/* + propertydoublepaireditor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertydoublepaireditor.h" + +#include "ui_propertydoublepaireditor.h" + +using namespace GammaRay; + +PropertyDoublePairEditor::PropertyDoublePairEditor(QWidget *parent) + : QWidget(parent), ui(new Ui::PropertyDoublePairEditor) +{ + ui->setupUi(this); +} + +PropertyDoublePairEditor::~PropertyDoublePairEditor() +{ +} + +PropertyPointFEditor::PropertyPointFEditor(QWidget *parent) + : PropertyDoublePairEditor(parent) +{ +} + +QPointF PropertyPointFEditor::pointF() const +{ + return QPointF(ui->xBox->value(), ui->yBox->value()); +} + +void PropertyPointFEditor::setPointF(const QPointF &point) +{ + ui->xBox->setValue(point.x()); + ui->yBox->setValue(point.y()); +} + +PropertySizeFEditor::PropertySizeFEditor(QWidget *parent) : PropertyDoublePairEditor(parent) +{ +} + +QSizeF PropertySizeFEditor::sizeF() const +{ + return QSizeF(ui->xBox->value(), ui->yBox->value()); +} + +void PropertySizeFEditor::setSizeF(const QSizeF &size) +{ + ui->xBox->setValue(size.width()); + ui->yBox->setValue(size.height()); +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.h gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.h --- gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ +/* + propertydoublepaireditor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H +#define GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H + +#include + +namespace GammaRay { + +namespace Ui { + class PropertyDoublePairEditor; +} + +/** Property editor for pairs of doubles, such as PointF and SizeF. */ +class PropertyDoublePairEditor : public QWidget +{ + Q_OBJECT + public: + explicit PropertyDoublePairEditor(QWidget *parent = 0); + ~PropertyDoublePairEditor(); + + protected: + QScopedPointer ui; +}; + +class PropertyPointFEditor : public PropertyDoublePairEditor +{ + Q_OBJECT + Q_PROPERTY(QPointF pointF READ pointF WRITE setPointF USER true) + public: + explicit PropertyPointFEditor(QWidget *parent = 0); + QPointF pointF() const; + void setPointF(const QPointF &point); +}; + +class PropertySizeFEditor : public PropertyDoublePairEditor +{ + Q_OBJECT + Q_PROPERTY(QSizeF sizeF READ sizeF WRITE setSizeF USER true) + public: + explicit PropertySizeFEditor(QWidget *parent = 0); + QSizeF sizeF() const; + void setSizeF(const QSizeF &size); +}; + +} + +#endif // GAMMARAY_PROPERTYDOUBLEPAIREDITOR_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.ui gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.ui --- gammaray-1.2.2/ui/propertyeditor/propertydoublepaireditor.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertydoublepaireditor.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,45 @@ + + + GammaRay::PropertyDoublePairEditor + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + false + + + + + + + x + + + Qt::AlignCenter + + + + + + + false + + + + + + + + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyeditordelegate.cpp gammaray-2.0.1/ui/propertyeditor/propertyeditordelegate.cpp --- gammaray-1.2.2/ui/propertyeditor/propertyeditordelegate.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyeditordelegate.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertyeditordelegate.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertyeditordelegate.h" +#include "propertyeditorfactory.h" + +using namespace GammaRay; + +PropertyEditorDelegate::PropertyEditorDelegate(QObject* parent): QStyledItemDelegate(parent) +{ + setItemEditorFactory(PropertyEditorFactory::instance()); +} + +PropertyEditorDelegate::~PropertyEditorDelegate() +{ +} + +void PropertyEditorDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const +{ + editor->setProperty("displayString", index.data(Qt::DisplayRole)); + QStyledItemDelegate::setEditorData(editor, index); +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyeditordelegate.h gammaray-2.0.1/ui/propertyeditor/propertyeditordelegate.h --- gammaray-1.2.2/ui/propertyeditor/propertyeditordelegate.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyeditordelegate.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertyeditordelegate.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYEDITORDELEGATE_H +#define GAMMARAY_PROPERTYEDITORDELEGATE_H + +#include + +namespace GammaRay { + +class PropertyEditorDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit PropertyEditorDelegate(QObject *parent); + ~PropertyEditorDelegate(); + + /*override*/ void setEditorData(QWidget* editor, const QModelIndex& index) const; +}; + +} + +#endif // GAMMARAY_PROPERTYEDITORDELEGATE_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyeditorfactory.cpp gammaray-2.0.1/ui/propertyeditor/propertyeditorfactory.cpp --- gammaray-1.2.2/ui/propertyeditor/propertyeditorfactory.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyeditorfactory.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,67 @@ +/* + propertyeditorfactory.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertyeditorfactory.h" +#include "propertycoloreditor.h" +#include "propertyfonteditor.h" +#include "propertyintpaireditor.h" +#include "propertydoublepaireditor.h" +#include "propertypaletteeditor.h" + +#include + +using namespace GammaRay; + +PropertyEditorFactory::PropertyEditorFactory() +{ + registerEditor(QVariant::Color, new QStandardItemEditorCreator()); + registerEditor(QVariant::Font, new QStandardItemEditorCreator()); + registerEditor(QVariant::Palette, new QStandardItemEditorCreator()); + registerEditor(QVariant::Point, new QStandardItemEditorCreator()); + registerEditor(QVariant::PointF, new QStandardItemEditorCreator()); + registerEditor(QVariant::Size, new QStandardItemEditorCreator()); + registerEditor(QVariant::SizeF, new QStandardItemEditorCreator()); +} + +PropertyEditorFactory* PropertyEditorFactory::instance() +{ + static PropertyEditorFactory *s_instance = new PropertyEditorFactory; + return s_instance; +} + + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +QWidget *PropertyEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const +#else +QWidget *PropertyEditorFactory::createEditor(int type, QWidget *parent) const +#endif +{ + QWidget *w = QItemEditorFactory::createEditor(type, parent); + if (!w) { + return 0; + } + + // the read-only view is still in the background usually, so transparency is not a good choice here + w->setAutoFillBackground(true); + return w; +} diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyeditorfactory.h gammaray-2.0.1/ui/propertyeditor/propertyeditorfactory.h --- gammaray-1.2.2/ui/propertyeditor/propertyeditorfactory.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyeditorfactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + propertyeditorfactory.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYEDITORFACTORY_H +#define GAMMARAY_PROPERTYEDITORFACTORY_H + +#include + +namespace GammaRay { + +/** Item editor factory with support for extra types while keeping support for the built-in ones. */ +class PropertyEditorFactory : public QItemEditorFactory +{ + public: + static PropertyEditorFactory *instance(); + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + virtual QWidget *createEditor(QVariant::Type type, QWidget *parent) const; +#else + virtual QWidget *createEditor(int type, QWidget *parent) const; +#endif + + protected: + PropertyEditorFactory(); +}; + +} + +#endif // GAMMARAY_PROPERTYEDITORFACTORY_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.cpp gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + propertyextendededitor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertyextendededitor.h" +#include "ui_propertyextendededitor.h" + +#include +using namespace GammaRay; + +PropertyExtendedEditor::PropertyExtendedEditor(QWidget *parent) + : QWidget(parent), ui(new Ui::PropertyExtendedEditor) +{ + ui->setupUi(this); + // TODO: make button content smaller by using a tiny icon + connect(ui->editButton, SIGNAL(clicked()),SLOT(edit())); +} + +PropertyExtendedEditor::~PropertyExtendedEditor() +{ + delete ui; +} + +QVariant PropertyExtendedEditor::value() const +{ + return m_value; +} + +void PropertyExtendedEditor::setValue(const QVariant &value) +{ + m_value = value; + const QString displayValue = property("displayString").toString(); + ui->valueLabel->setText(displayValue.isEmpty() ? value.toString() : displayValue); +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.h gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.h --- gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,58 @@ +/* + propertyextendededitor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYEXTENDEDEDITOR_H +#define GAMMARAY_PROPERTYEXTENDEDEDITOR_H + +#include +#include + +namespace GammaRay { + +namespace Ui { + class PropertyExtendedEditor; +} + +/** Base class for property editors that open a separate dialog. */ +class PropertyExtendedEditor : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QVariant value READ value WRITE setValue USER true) + public: + explicit PropertyExtendedEditor(QWidget *parent = 0); + virtual ~PropertyExtendedEditor(); + + QVariant value() const; + void setValue(const QVariant &value); + + protected slots: + virtual void edit() = 0; + + private: + Ui::PropertyExtendedEditor *ui; + QVariant m_value; +}; + +} + +#endif // GAMMARAY_PROPERTYEXTENDEDEDITOR_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.ui gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.ui --- gammaray-1.2.2/ui/propertyeditor/propertyextendededitor.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyextendededitor.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,34 @@ + + + GammaRay::PropertyExtendedEditor + + + + 0 + 0 + 392 + 23 + + + + + 0 + + + 0 + + + + + + + + ... + + + + + + + + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyfonteditor.cpp gammaray-2.0.1/ui/propertyeditor/propertyfonteditor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertyfonteditor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyfonteditor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertyfonteditor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertyfonteditor.h" + +#include + +using namespace GammaRay; + +PropertyFontEditor::PropertyFontEditor(QWidget *parent) + : PropertyExtendedEditor(parent) +{ +} + +void PropertyFontEditor::edit() +{ + bool ok = false; + const QFont font = QFontDialog::getFont(&ok, value().value(), this); + if (ok) { + setValue(font); + } +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyfonteditor.h gammaray-2.0.1/ui/propertyeditor/propertyfonteditor.h --- gammaray-1.2.2/ui/propertyeditor/propertyfonteditor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyfonteditor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertyfonteditor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYFONTEDITOR_H +#define GAMMARAY_PROPERTYFONTEDITOR_H + +#include "propertyextendededitor.h" + +namespace GammaRay { + +class PropertyFontEditor : public PropertyExtendedEditor +{ + Q_OBJECT + public: + explicit PropertyFontEditor(QWidget *parent = 0); + + protected: + virtual void edit(); +}; + +} + +#endif // GAMMARAY_PROPERTYFONTEDITOR_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.cpp gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,78 @@ +/* + propertyintpaireditor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertyintpaireditor.h" +#include "ui_propertyintpaireditor.h" + +#include + +#include + +using namespace GammaRay; + +PropertyIntPairEditor::PropertyIntPairEditor(QWidget *parent) + : QWidget(parent), ui(new Ui::PropertyIntPairEditor) +{ + ui->setupUi(this); + ui->xBox->setMinimum(std::numeric_limits::min()); + ui->xBox->setMaximum(std::numeric_limits::max()); + ui->yBox->setMinimum(std::numeric_limits::min()); + ui->yBox->setMaximum(std::numeric_limits::max()); +} + +PropertyIntPairEditor::~PropertyIntPairEditor() +{ +} + +PropertyPointEditor::PropertyPointEditor(QWidget *parent) + : PropertyIntPairEditor(parent) +{ +} + +QPoint PropertyPointEditor::point() const +{ + return QPoint(ui->xBox->value(), ui->yBox->value()); +} + +void PropertyPointEditor::setPoint(const QPoint &point) +{ + ui->xBox->setValue(point.x()); + ui->yBox->setValue(point.y()); +} + +PropertySizeEditor::PropertySizeEditor(QWidget *parent) + : PropertyIntPairEditor(parent) +{ +} + +QSize PropertySizeEditor::sizeValue() const +{ + return QSize(ui->xBox->value(), ui->yBox->value()); +} + +void PropertySizeEditor::setSizeValue(const QSize &size) +{ + ui->xBox->setValue(size.width()); + ui->yBox->setValue(size.height()); +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.h gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.h --- gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,77 @@ +/* + propertyintpaireditor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYINTPAIREDITOR_H +#define GAMMARAY_PROPERTYINTPAIREDITOR_H + +#include + +class QPoint; + +namespace GammaRay { + +namespace Ui { + class PropertyIntPairEditor; +} + +/** Property editor for QPoint, QSize and anything else consisting of two integer values. */ +class PropertyIntPairEditor : public QWidget +{ + Q_OBJECT + public: + explicit PropertyIntPairEditor(QWidget *parent = 0); + ~PropertyIntPairEditor(); + + protected: + QScopedPointer ui; +}; + +/** Property editor for points. Since QStyledItemDelegate ignore valuePropertyName and insists on + * USER properties we need one class per type here... + */ +class PropertyPointEditor : public PropertyIntPairEditor +{ + Q_OBJECT + Q_PROPERTY(QPoint point READ point WRITE setPoint USER true) + public: + explicit PropertyPointEditor(QWidget *parent = 0); + + QPoint point() const; + void setPoint(const QPoint &point); +}; + +/** Same again for size. */ +class PropertySizeEditor : public PropertyIntPairEditor +{ + Q_OBJECT + Q_PROPERTY(QSize sizeValue READ sizeValue WRITE setSizeValue USER true) + public: + explicit PropertySizeEditor(QWidget *parent = 0); + + QSize sizeValue() const; + void setSizeValue(const QSize &size); +}; + +} + +#endif // GAMMARAY_PROPERTYINTPAIREDITOR_H diff -Nru gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.ui gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.ui --- gammaray-1.2.2/ui/propertyeditor/propertyintpaireditor.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertyintpaireditor.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ + + + GammaRay::PropertyIntPairEditor + + + + 0 + 0 + 145 + 22 + + + + + 0 + + + + + false + + + -99999 + + + 99999 + + + + + + + x + + + Qt::AlignCenter + + + + + + + false + + + + + + + + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertypaletteeditor.cpp gammaray-2.0.1/ui/propertyeditor/propertypaletteeditor.cpp --- gammaray-1.2.2/ui/propertyeditor/propertypaletteeditor.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertypaletteeditor.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,41 @@ +/* + propertypaletteeditor.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertypaletteeditor.h" +#include "palettedialog.h" + +using namespace GammaRay; + +PropertyPaletteEditor::PropertyPaletteEditor(QWidget *parent) + : PropertyExtendedEditor(parent) +{ +} + +void PropertyPaletteEditor::edit() +{ + PaletteDialog dlg(value().value(), this); + if (dlg.exec() == QDialog::Accepted) { + setValue(dlg.editedPalette()); + } +} + diff -Nru gammaray-1.2.2/ui/propertyeditor/propertypaletteeditor.h gammaray-2.0.1/ui/propertyeditor/propertypaletteeditor.h --- gammaray-1.2.2/ui/propertyeditor/propertypaletteeditor.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertyeditor/propertypaletteeditor.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + propertypaletteeditor.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYPALETTEEDITOR_H +#define GAMMARAY_PROPERTYPALETTEEDITOR_H + +#include "propertyextendededitor.h" + +namespace GammaRay { + +class PropertyPaletteEditor : public PropertyExtendedEditor +{ + Q_OBJECT + public: + explicit PropertyPaletteEditor(QWidget *parent = 0); + + protected: + virtual void edit(); +}; + +} + +#endif // GAMMARAY_PROPERTYPALETTEEDITOR_H diff -Nru gammaray-1.2.2/ui/propertywidget.cpp gammaray-2.0.1/ui/propertywidget.cpp --- gammaray-1.2.2/ui/propertywidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertywidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,289 @@ +/* + propertywidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "propertywidget.h" +#include "ui_propertywidget.h" + +#include "ui/methodinvocationdialog.h" +#include "ui/propertyeditor/propertyeditordelegate.h" +#include "ui/deferredresizemodesetter.h" + +#include "variantcontainermodel.h" + +#include "common/objectbroker.h" +#include "common/modelroles.h" +#include "common/metatypedeclarations.h" +#include "common/propertycontrollerinterface.h" + +#include "kde/krecursivefilterproxymodel.h" + +#include +#include +#include +#include +#include + +using namespace GammaRay; + +static bool removePage(QTabWidget *tabWidget, QWidget *widget) +{ + const int index = tabWidget->indexOf(widget); + if (index == -1) { + return false; + } + + tabWidget->removeTab(index); + return true; +} + +PropertyWidget::PropertyWidget(QWidget *parent) + : QWidget(parent), + m_ui(new Ui_PropertyWidget), + m_displayState(PropertyWidgetDisplayState::QObject), + m_controller(0) +{ + m_ui->setupUi(this); +} + +PropertyWidget::~PropertyWidget() +{ +} + +void PropertyWidget::setObjectBaseName(const QString &baseName) +{ + m_objectBaseName = baseName; + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("staticProperties")); + m_ui->staticPropertyView->setModel(proxy); + m_ui->staticPropertyView->sortByColumn(0, Qt::AscendingOrder); + new DeferredResizeModeSetter( + m_ui->staticPropertyView->header(), 0, QHeaderView::ResizeToContents); + m_ui->staticPropertySearchLine->setProxy(proxy); + m_ui->staticPropertyView->setItemDelegate(new PropertyEditorDelegate(this)); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + connect(m_ui->staticPropertyView, SIGNAL(doubleClicked(QModelIndex)), + SLOT(onDoubleClick(QModelIndex))); +#endif + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("dynamicProperties")); + m_ui->dynamicPropertyView->setModel(proxy); + m_ui->dynamicPropertyView->sortByColumn(0, Qt::AscendingOrder); + new DeferredResizeModeSetter( + m_ui->dynamicPropertyView->header(), 0, QHeaderView::ResizeToContents); + m_ui->dynamicPropertyView->setItemDelegate(new PropertyEditorDelegate(this)); + m_ui->dynamicPropertySearchLine->setProxy(proxy); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + connect(m_ui->dynamicPropertyView, SIGNAL(doubleClicked(QModelIndex)), + SLOT(onDoubleClick(QModelIndex))); +#endif + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("methods")); + m_ui->methodView->setModel(proxy); + m_ui->methodView->sortByColumn(0, Qt::AscendingOrder); + m_ui->methodView->setSelectionModel(ObjectBroker::selectionModel(proxy)); + m_ui->methodView->header()->setResizeMode(QHeaderView::ResizeToContents); + m_ui->methodSearchLine->setProxy(proxy); + connect(m_ui->methodView, SIGNAL(doubleClicked(QModelIndex)), + SLOT(methodActivated(QModelIndex))); + connect(m_ui->methodView, SIGNAL(customContextMenuRequested(QPoint)), + SLOT(methodConextMenu(QPoint))); + m_ui->methodLog->setModel(model("methodLog")); + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("classInfo")); + m_ui->classInfoView->setModel(proxy); + m_ui->classInfoView->sortByColumn(0, Qt::AscendingOrder); + m_ui->classInfoView->header()->setResizeMode(QHeaderView::ResizeToContents); + m_ui->classInfoSearchLine->setProxy(proxy); + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("inboundConnections")); + m_ui->inboundConnectionView->setModel(proxy); + m_ui->inboundConnectionView->sortByColumn(0, Qt::AscendingOrder); + m_ui->inboundConnectionSearchLine->setProxy(proxy); + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("outboundConnections")); + m_ui->outboundConnectionView->setModel(proxy); + m_ui->outboundConnectionView->sortByColumn(0, Qt::AscendingOrder); + m_ui->outboundConnectionSearchLine->setProxy(proxy); + + proxy = new KRecursiveFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("enums")); + m_ui->enumView->setModel(proxy); + m_ui->enumView->sortByColumn(0, Qt::AscendingOrder); + m_ui->enumView->header()->setResizeMode(QHeaderView::ResizeToContents); + m_ui->enumSearchLine->setProxy(proxy); + + // save back initial tab widgets + for (int i = 0; i < m_ui->tabWidget->count(); ++i) { + m_tabWidgets.push_back(qMakePair(m_ui->tabWidget->widget(i), m_ui->tabWidget->tabText(i))); + } + + proxy = new QSortFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(model("nonQProperties")); + m_ui->metaPropertyView->setModel(proxy); + m_ui->metaPropertyView->sortByColumn(0, Qt::AscendingOrder); + m_ui->metaPropertySearchLine->setProxy(proxy); + m_ui->metaPropertyView->setItemDelegate(new PropertyEditorDelegate(this)); + + if (m_controller) { + disconnect(m_controller, + SIGNAL(displayStateChanged(GammaRay::PropertyWidgetDisplayState::State)), + this, SLOT(setDisplayState(GammaRay::PropertyWidgetDisplayState::State))); + } + m_controller = + ObjectBroker::object(m_objectBaseName + ".controller"); + connect(m_controller, SIGNAL(displayStateChanged(GammaRay::PropertyWidgetDisplayState::State)), + this, SLOT(setDisplayState(GammaRay::PropertyWidgetDisplayState::State))); +} + +QAbstractItemModel *PropertyWidget::model(const QString &nameSuffix) +{ + return ObjectBroker::model(m_objectBaseName + '.' + nameSuffix); +} + +void GammaRay::PropertyWidget::methodActivated(const QModelIndex &index) +{ + if (!index.isValid() || m_displayState != PropertyWidgetDisplayState::QObject) { + return; + } + m_controller->activateMethod(); + + const QMetaMethod::MethodType methodType = + index.data(ObjectMethodModelRole::MetaMethodType).value(); + if (methodType == QMetaMethod::Slot) { + MethodInvocationDialog dlg(this); + dlg.setArgumentModel(model("methodArguments")); + if (dlg.exec()) { + m_controller->invokeMethod(dlg.connectionType()); + } + } +} + +void PropertyWidget::methodConextMenu(const QPoint &pos) +{ + const QModelIndex index = m_ui->methodView->indexAt(pos); + if (!index.isValid() || m_displayState != PropertyWidgetDisplayState::QObject) { + return; + } + + const QMetaMethod::MethodType methodType = + index.data(ObjectMethodModelRole::MetaMethodType).value(); + QMenu contextMenu; + if (methodType == QMetaMethod::Slot) { + contextMenu.addAction(tr("Invoke")); + } else if (methodType == QMetaMethod::Signal) { + contextMenu.addAction(tr("Connect to")); + } + + if (contextMenu.exec(m_ui->methodView->viewport()->mapToGlobal(pos))) { + methodActivated(index); + } +} + +bool PropertyWidget::showTab(const QWidget *widget, PropertyWidgetDisplayState::State state) const +{ + // TODO: this check needs to consider the server-side Qt version! +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + if (widget == m_ui->inboundConnectionTab || + widget == m_ui->outboundConnectionTab) { + return false; + } +#endif + switch(state) { + case PropertyWidgetDisplayState::QObject: + return true; // show all + case PropertyWidgetDisplayState::Object: + if (widget == m_ui->metaPropertyTab) { + return true; + } + break; + case PropertyWidgetDisplayState::MetaObject: + if (widget == m_ui->enumTab || widget == m_ui->classInfoTab || widget == m_ui->methodTab) { + return true; + } + break; + } + return false; +} + +void PropertyWidget::setDisplayState(PropertyWidgetDisplayState::State state) +{ + m_displayState = state; + QWidget *currentWidget = m_ui->tabWidget->currentWidget(); + + // iterate through all tabs, decide for each tab if it gets hidden or not + typedef QPair WidgetStringPair; + Q_FOREACH (const WidgetStringPair &tab, m_tabWidgets) { + const bool show = showTab(tab.first, state); + if (show) { + m_ui->tabWidget->addTab(tab.first, tab.second); + } else { + removePage(m_ui->tabWidget, tab.first); + } + } + + if (m_ui->tabWidget->indexOf(currentWidget) >= 0) { + m_ui->tabWidget->setCurrentWidget(currentWidget); + } + + m_ui->methodLog->setVisible(m_displayState == PropertyWidgetDisplayState::QObject); +} + +void PropertyWidget::onDoubleClick(const QModelIndex &index) +{ + if (index.column() != 0) { + return; + } + +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + QVariant var = index.sibling(index.row(), 1).data(Qt::EditRole); + + if (!var.canConvert() && !var.canConvert()) { + return; + } + + QTreeView *v = new QTreeView; + + VariantContainerModel *m = new VariantContainerModel(v); + m->setVariant(var); + + v->setModel(m); + v->show(); +#endif +} + diff -Nru gammaray-1.2.2/ui/propertywidget.h gammaray-2.0.1/ui/propertywidget.h --- gammaray-1.2.2/ui/propertywidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertywidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,79 @@ +/* + propertywidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROPERTYWIDGET_H +#define GAMMARAY_PROPERTYWIDGET_H + +#include +#include +#include + +#include "gammaray_ui_export.h" +#include + +class QAbstractItemModel; +class QAbstractItemView; +class QModelIndex; + +namespace GammaRay { + +class Ui_PropertyWidget; +class PropertyControllerInterface; + +/** @brief Client-side counter-part GammaRay::PropertyController. */ +class GAMMARAY_UI_EXPORT PropertyWidget : public QWidget +{ + Q_OBJECT + public: + explicit PropertyWidget(QWidget *parent = 0); + virtual ~PropertyWidget(); + + void setObjectBaseName(const QString &baseName); + + private slots: + void setDisplayState(GammaRay::PropertyWidgetDisplayState::State state); + void methodActivated(const QModelIndex &index); + void methodConextMenu(const QPoint &pos); + + void onDoubleClick(const QModelIndex &index); + + private: + /// Decides if widget is supposed to be shown at this display state + bool showTab(const QWidget *widget, PropertyWidgetDisplayState::State state) const; + + QAbstractItemModel* model(const QString &nameSuffix); + + Ui_PropertyWidget *m_ui; + + QString m_objectBaseName; + + // Contains initially added tab widgets (Tab widget/Label) + QVector< QPair > m_tabWidgets; + + PropertyWidgetDisplayState::State m_displayState; + PropertyControllerInterface *m_controller; +}; + +} + +#endif // GAMMARAY_PROPERTYWIDGET_H diff -Nru gammaray-1.2.2/ui/propertywidget.ui gammaray-2.0.1/ui/propertywidget.ui --- gammaray-1.2.2/ui/propertywidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/propertywidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,229 @@ + + + GammaRay::PropertyWidget + + + + 0 + 0 + 816 + 605 + + + + + 0 + + + + + 0 + + + + Static Properties + + + + + + + + + false + + + true + + + true + + + + + + + + Dynamic Properties + + + + + + + + + false + + + true + + + true + + + + + + + + Methods + + + + + + + + + Qt::CustomContextMenu + + + false + + + true + + + true + + + + + + + false + + + true + + + false + + + + + + + + Inbound Connections + + + + + + + + + false + + + true + + + true + + + + + + + + Outbound Connections + + + + + + + + + false + + + true + + + true + + + + + + + + Enums + + + + + + + + + true + + + + + + + + Class Info + + + + + + + + + false + + + true + + + true + + + + + + + + Non-QObject Properties + + + + + + + + + false + + + true + + + true + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/proxytooluifactory.cpp gammaray-2.0.1/ui/proxytooluifactory.cpp --- gammaray-1.2.2/ui/proxytooluifactory.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/proxytooluifactory.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,56 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "proxytooluifactory.h" + +#include + +using namespace GammaRay; + +ProxyToolUiFactory::ProxyToolUiFactory(const QString &path, QObject *parent) + : ProxyFactory(path, parent) + , m_remotingSupported(false) +{ + m_remotingSupported = value(QLatin1String("X-GammaRay-Remote"), true).toBool(); +} + +bool ProxyToolUiFactory::isValid() const +{ + return + !id().isEmpty() && + !m_pluginPath.isEmpty(); +} + +bool ProxyToolUiFactory::remotingSupported() const +{ + return m_remotingSupported; +} + +QWidget *ProxyToolUiFactory::createWidget(QWidget *parentWidget) +{ + loadPlugin(); + ToolUiFactory *fac = factory(); + if (!fac) { + return new QLabel(tr("Plugin '%1' could not be loaded.").arg(m_pluginPath), parentWidget); + } + Q_ASSERT(fac); + return fac->createWidget(parentWidget); +} diff -Nru gammaray-1.2.2/ui/proxytooluifactory.h gammaray-2.0.1/ui/proxytooluifactory.h --- gammaray-1.2.2/ui/proxytooluifactory.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/proxytooluifactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,54 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_PROXYTOOLUIFACTORY_H +#define GAMMARAY_PROXYTOOLUIFACTORY_H + +#include +#include + +namespace GammaRay { + +/** + * A wrapper around a plugin ToolUiFactory that only loads the actual plugin once really needed. + * Until then, meta-data is provided based on a plugin spec file. + */ +class ProxyToolUiFactory : public ProxyFactory +{ + public: + /** + * @param path Path to the plugin spec file + */ + explicit ProxyToolUiFactory(const QString &path, QObject *parent = 0); + + /** Returns @c true if the plugin seems valid from all the information we have so far. */ + bool isValid() const; + + /*override*/ bool remotingSupported() const; + /*override*/ QWidget *createWidget(QWidget *parentWidget); + +private: + bool m_remotingSupported; +}; + +} + +#endif // GAMMARAY_PROXYTOOLUIFACTORY_H diff -Nru gammaray-1.2.2/ui/sidepane.cpp gammaray-2.0.1/ui/sidepane.cpp --- gammaray-1.2.2/ui/sidepane.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/sidepane.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,96 @@ +/* + sidepane.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "sidepane.h" + +#include +#include + +using namespace GammaRay; + +class Delegate : public QStyledItemDelegate +{ + public: + explicit Delegate(QObject *parent = 0) + : QStyledItemDelegate(parent) + { + } + + virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const + { + static const int heightMargin = 10; + + QSize size = QStyledItemDelegate::sizeHint(option, index); + size.setHeight(size.height() + heightMargin); + return size; + } +}; + +SidePane::SidePane(QWidget *parent) + : QListView(parent) +{ + viewport()->setAutoFillBackground(false); + setAttribute(Qt::WA_MacShowFocusRect, false); + + setItemDelegate(new Delegate(this)); +} + +SidePane::~SidePane() +{ +} + +QSize SidePane::sizeHint() const +{ + static const int widthMargin = 10; + + if (!model()) { + return QSize(0, 0); + } + + const int width = sizeHintForColumn(0) + widthMargin; + const int height = QListView::sizeHint().height(); + + return QSize(width, height); +} + +void SidePane::setModel(QAbstractItemModel *model) +{ + if (model) { + connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(updateSizeHint())); + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(updateSizeHint())); + } + QAbstractItemView::setModel(model); +} + +void SidePane::resizeEvent(QResizeEvent *e) +{ + updateSizeHint(); + + QListView::resizeEvent(e); +} + +void SidePane::updateSizeHint() +{ + setMinimumWidth(sizeHint().width()); +} + diff -Nru gammaray-1.2.2/ui/sidepane.h gammaray-2.0.1/ui/sidepane.h --- gammaray-1.2.2/ui/sidepane.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/sidepane.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,50 @@ +/* + sidepane.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SIDEPANE_H +#define GAMMARAY_SIDEPANE_H + +#include + +namespace GammaRay { + +class SidePane : public QListView +{ + Q_OBJECT + public: + explicit SidePane(QWidget *parent = 0); + virtual ~SidePane(); + + virtual QSize sizeHint() const; + virtual void setModel(QAbstractItemModel* model); + + protected: + virtual void resizeEvent(QResizeEvent *e); + + private slots: + void updateSizeHint(); +}; + +} + +#endif // GAMMARAY_SIDEPANE_H diff -Nru gammaray-1.2.2/ui/splashscreen.cpp gammaray-2.0.1/ui/splashscreen.cpp --- gammaray-1.2.2/ui/splashscreen.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/splashscreen.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + attachdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "splashscreen.h" + +#include +#include + +QSplashScreen *splash = 0; + +namespace GammaRay { + +void showSplashScreen() +{ + if (!splash) { + QPixmap pixmap(QLatin1String(":gammaray/splashscreen.png")); + splash = new QSplashScreen(pixmap); + splash->setMask(pixmap.mask()); + } + + splash->show(); +} + +void hideSplashScreen() +{ + if (splash) { + splash->hide(); + } +} + +} diff -Nru gammaray-1.2.2/ui/splashscreen.h gammaray-2.0.1/ui/splashscreen.h --- gammaray-1.2.2/ui/splashscreen.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/splashscreen.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,36 @@ +/* + attachdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_SPLASHSCREEN_H +#define GAMMARAY_SPLASHSCREEN_H + +#include "gammaray_ui_export.h" + +namespace GammaRay { + +GAMMARAY_UI_EXPORT void showSplashScreen(); +GAMMARAY_UI_EXPORT void hideSplashScreen(); + +} + +#endif // SPLASHSCREEN_H diff -Nru gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.cpp gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.cpp --- gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,55 @@ +/* + connectioninspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "connectioninspectorwidget.h" +#include "ui_connectioninspectorwidget.h" + +#include + +#include +#include + +using namespace GammaRay; + +ConnectionInspectorWidget::ConnectionInspectorWidget(QWidget* parent) + : QWidget(parent), + ui(new Ui::ConnectionInspectorWidget) +{ + ui->setupUi(this); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + // TODO: 1.3 had a proxy detacher here, to improve performance + proxy->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.ConnectionModel")); + ui->connectionSearchLine->setProxy(proxy); + ui->connectionView->setModel(proxy); + + if (qgetenv("GAMMARAY_TEST_FILTER") == "1") { + QMetaObject::invokeMethod(ui->connectionSearchLine->lineEdit(), "setText", + Qt::QueuedConnection, + Q_ARG(QString, QLatin1String("destroyed"))); + } +} + +ConnectionInspectorWidget::~ConnectionInspectorWidget() +{ +} diff -Nru gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.h gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.h --- gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + connectioninspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CONNECTIONINSPECTORWIDGET_H +#define GAMMARAY_CONNECTIONINSPECTORWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class ConnectionInspectorWidget; +} + +class ConnectionInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit ConnectionInspectorWidget(QWidget *parent = 0); + ~ConnectionInspectorWidget(); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_CONNECTIONINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.ui gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.ui --- gammaray-1.2.2/ui/tools/connectioninspector/connectioninspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/connectioninspector/connectioninspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,35 @@ + + + GammaRay::ConnectionInspectorWidget + + + + 0 + 0 + 400 + 300 + + + + + + + + + + true + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.cpp gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.cpp --- gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,66 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "localeinspectorwidget.h" +#include "ui_localeinspectorwidget.h" + +#include + +#include + +using namespace GammaRay; + +LocaleInspectorWidget::LocaleInspectorWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::LocaleInspectorWidget) +{ + QAbstractItemModel *localeModel = ObjectBroker::model("com.kdab.GammaRay.LocaleModel"); + QAbstractItemModel *accessorModel = ObjectBroker::model("com.kdab.GammaRay.LocaleAccessorModel"); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + proxy->setSourceModel(localeModel); + + ui->setupUi(this); + + ui->localeTable->setModel(proxy); + ui->accessorTable->setModel(accessorModel); + ui->localeSearchLine->setProxy(proxy); + + ui->accessorTable->resizeColumnsToContents(); + ui->localeTable->resizeColumnsToContents(); + connect(localeModel, SIGNAL(modelReset()), ui->localeTable, SLOT(resizeColumnsToContents())); + connect(accessorModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), ui->accessorTable, SLOT(resizeColumnsToContents())); + + QMetaObject::invokeMethod(this, "initSplitterPosition", Qt::QueuedConnection); + connect(accessorModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(initSplitterPosition())); +} + +LocaleInspectorWidget::~LocaleInspectorWidget() +{ +} + +void LocaleInspectorWidget::initSplitterPosition() +{ + const int accessorHeight = ui->accessorTable->model()->rowCount() * (ui->accessorTable->rowHeight(0) + 1) // + grid line + + 2 * ui->accessorTable->frameWidth(); + ui->splitter->setSizes(QList() << accessorHeight << height() - accessorHeight); +} + diff -Nru gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.h gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.h --- gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2011-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_LOCALEINSPECTOR_LOCALEINSPECTORWIDGET_H +#define GAMMARAY_LOCALEINSPECTOR_LOCALEINSPECTORWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class LocaleInspectorWidget; +} + +class LocaleInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit LocaleInspectorWidget(QWidget *parent = 0); + ~LocaleInspectorWidget(); + + private slots: + void initSplitterPosition(); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_LOCALEINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.ui gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.ui --- gammaray-1.2.2/ui/tools/localeinspector/localeinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/localeinspector/localeinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,69 @@ + + + GammaRay::LocaleInspectorWidget + + + + 0 + 0 + 654 + 506 + + + + + 0 + + + + + Qt::Vertical + + + + QAbstractItemView::NoSelection + + + false + + + false + + + false + + + + + + 0 + + + + + + + + true + + + false + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/messagehandler/messagehandlerclient.cpp gammaray-2.0.1/ui/tools/messagehandler/messagehandlerclient.cpp --- gammaray-1.2.2/ui/tools/messagehandler/messagehandlerclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/messagehandler/messagehandlerclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,33 @@ +/* + messagehandlerclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "messagehandlerclient.h" + +using namespace GammaRay; + +MessageHandlerClient::MessageHandlerClient(QObject *parent) + : MessageHandlerInterface(parent) +{ + +} + diff -Nru gammaray-1.2.2/ui/tools/messagehandler/messagehandlerclient.h gammaray-2.0.1/ui/tools/messagehandler/messagehandlerclient.h --- gammaray-1.2.2/ui/tools/messagehandler/messagehandlerclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/messagehandler/messagehandlerclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,41 @@ +/* + messagehandlerclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MESSAGEHANDLERCLIENT_H +#define GAMMARAY_MESSAGEHANDLERCLIENT_H + +#include + +namespace GammaRay { + +class MessageHandlerClient : public MessageHandlerInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::MessageHandlerInterface) + public: + explicit MessageHandlerClient(QObject *parent = 0); +}; + +} + +#endif // GAMMARAY_MESSAGEHANDLERCLIENT_H diff -Nru gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.cpp gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.cpp --- gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,117 @@ +/* + messagehandlerwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "messagehandlerwidget.h" +#include "ui_messagehandlerwidget.h" + +#include +#include +#include "messagehandlerclient.h" + +#include +#include +#include +#include +#include +#include + +using namespace GammaRay; + +static QObject *createClientMessageHandler(const QString &/*name*/, QObject *parent) +{ + return new MessageHandlerClient(parent); +} + +MessageHandlerWidget::MessageHandlerWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::MessageHandlerWidget) +{ + ObjectBroker::registerClientObjectFactoryCallback(createClientMessageHandler); + MessageHandlerInterface *handler = ObjectBroker::object(); + + connect(handler, SIGNAL(fatalMessageReceived(QString,QString,QTime,QStringList)), + this, SLOT(fatalMessageReceived(QString,QString,QTime,QStringList))); + + ui->setupUi(this); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + proxy->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.MessageModel")); + ui->messageSearchLine->setProxy(proxy); + ui->messageView->setModel(proxy); + ui->messageView->setIndentation(0); + ui->messageView->setSortingEnabled(true); + + ///FIXME: implement this + ui->backtraceView->hide(); +} + +MessageHandlerWidget::~MessageHandlerWidget() +{ +} + +void MessageHandlerWidget::fatalMessageReceived(const QString &app, const QString &message, + const QTime &time, const QStringList &backtrace) +{ + if (Endpoint::isConnected() && !qobject_cast(ObjectBroker::object())) { + // only show on remote side + return; + } + QDialog dlg; + dlg.setWindowTitle(QObject::tr("QFatal in %1 at %2").arg(app).arg(time.toString())); + + QGridLayout *layout = new QGridLayout; + + QLabel *iconLabel = new QLabel; + QIcon icon = dlg.style()->standardIcon(QStyle::SP_MessageBoxCritical, 0, &dlg); + int iconSize = dlg.style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, &dlg); + iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); + iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + layout->addWidget(iconLabel, 0, 0); + + QLabel *errorLabel = new QLabel; + errorLabel->setTextFormat(Qt::PlainText); + errorLabel->setWordWrap(true); + errorLabel->setText(message); + layout->addWidget(errorLabel, 0, 1); + + if (!backtrace.isEmpty()) { + QListWidget *backtraceWidget = new QListWidget; + foreach (const QString &frame, backtrace) { + backtraceWidget->addItem(frame); + } + layout->addWidget(backtraceWidget, 1, 0, 1, 2); + } + + QDialogButtonBox *buttons = new QDialogButtonBox; + buttons->addButton(QDialogButtonBox::Close); + QObject::connect(buttons, SIGNAL(accepted()), + &dlg, SLOT(accept())); + QObject::connect(buttons, SIGNAL(rejected()), + &dlg, SLOT(reject())); + layout->addWidget(buttons, 2, 0, 1, 2); + + dlg.setLayout(layout); + dlg.adjustSize(); + dlg.exec(); +} + diff -Nru gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.h gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.h --- gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + messagehandlerwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef GAMMARAY_MESSAGEHANDLERWIDGET_H +#define GAMMARAY_MESSAGEHANDLERWIDGET_H + +#include + +class QTime; + +namespace GammaRay { + +namespace Ui { + class MessageHandlerWidget; +} + +class MessageHandlerWidget : public QWidget +{ + Q_OBJECT + public: + explicit MessageHandlerWidget(QWidget *parent = 0); + ~MessageHandlerWidget(); + + private slots: + void fatalMessageReceived(const QString &app, const QString &message, + const QTime &time, const QStringList &backtrace); + + private: + QScopedPointer ui; +}; + +} + +#endif // MESSAGEHANDLERWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.ui gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.ui --- gammaray-1.2.2/ui/tools/messagehandler/messagehandlerwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/messagehandler/messagehandlerwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ + + + GammaRay::MessageHandlerWidget + + + + 0 + 0 + 400 + 300 + + + + + + + Qt::Horizontal + + + + + + + + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+ 1 +
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.cpp gammaray-2.0.1/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.cpp --- gammaray-1.2.2/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,76 @@ +/* + metaobjectbrowserwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "metaobjectbrowserwidget.h" +#include "propertywidget.h" +#include "deferredresizemodesetter.h" +#include + +#include "kde/kfilterproxysearchline.h" +#include "kde/krecursivefilterproxymodel.h" + +#include + +#include +#include +#include +#include + +using namespace GammaRay; + +MetaObjectBrowserWidget::MetaObjectBrowserWidget(QWidget *parent) + : QWidget(parent) +{ + QAbstractItemModel *model = ObjectBroker::model("com.kdab.GammaRay.MetaObjectModel"); + + QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this); + objectFilter->setSourceModel(model); + objectFilter->setDynamicSortFilter(true); + + QTreeView *treeView = new QTreeView(this); + treeView->setUniformRowHeights(true); + treeView->setModel(objectFilter); + new DeferredResizeModeSetter(treeView->header(), 0, QHeaderView::Stretch); + treeView->setSortingEnabled(true); + treeView->setSelectionModel(ObjectBroker::selectionModel(objectFilter)); + + KFilterProxySearchLine *objectSearchLine = new KFilterProxySearchLine(this); + objectSearchLine->setProxy(objectFilter); + + PropertyWidget *propertyWidget = new PropertyWidget(this); + m_propertyWidget = propertyWidget; + m_propertyWidget->setObjectBaseName("com.kdab.GammaRay.MetaObjectBrowser"); + + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(objectSearchLine); + vbox->addWidget(treeView); + + QHBoxLayout *hbox = new QHBoxLayout(this); + hbox->addLayout(vbox); + hbox->addWidget(propertyWidget); + + // init widget + new DeferredTreeViewConfiguration(treeView); + treeView->sortByColumn(0, Qt::AscendingOrder); +} + diff -Nru gammaray-1.2.2/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.h gammaray-2.0.1/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.h --- gammaray-1.2.2/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/metaobjectbrowser/metaobjectbrowserwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,46 @@ +/* + metaobjectbrowserwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Funk + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METAOBJECTBROWSERWIDGET_H +#define GAMMARAY_METAOBJECTBROWSERWIDGET_H + +#include + +namespace GammaRay { + +class PropertyWidget; + +class MetaObjectBrowserWidget : public QWidget +{ + Q_OBJECT + + public: + explicit MetaObjectBrowserWidget(QWidget *parent = 0); + + private: + PropertyWidget *m_propertyWidget; +}; + +} + +#endif // GAMMARAY_METAOBJECTBROWSERWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.cpp gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.cpp --- gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + metatypebrowserwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "metatypebrowserwidget.h" +#include +#include "ui_metatypebrowserwidget.h" + +#include + +#include + +using namespace GammaRay; + +MetaTypeBrowserWidget::MetaTypeBrowserWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::MetaTypeBrowserWidget) +{ + ui->setupUi(this); + + QAbstractItemModel *mtm = ObjectBroker::model("com.kdab.GammaRay.MetaTypeModel"); + Q_ASSERT(mtm); + + QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); + proxy->setSourceModel(mtm); + ui->metaTypeView->setModel(proxy); + new DeferredResizeModeSetter(ui->metaTypeView->header(), 0, QHeaderView::ResizeToContents); + ui->metaTypeSearchLine->setProxy(proxy); + ui->metaTypeView->header()->setSortIndicator(1, Qt::AscendingOrder); // sort by type id +} + +MetaTypeBrowserWidget::~MetaTypeBrowserWidget() +{ +} diff -Nru gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.h gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.h --- gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + metatypebrowserwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_METATYPEBROWSERWIDGET_H +#define GAMMARAY_METATYPEBROWSERWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class MetaTypeBrowserWidget; +} + +class MetaTypeBrowserWidget : public QWidget +{ + Q_OBJECT + public: + explicit MetaTypeBrowserWidget(QWidget *parent = 0); + ~MetaTypeBrowserWidget(); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_METATYPEBROWSERWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.ui gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.ui --- gammaray-1.2.2/ui/tools/metatypebrowser/metatypebrowserwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/metatypebrowser/metatypebrowserwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ + + + GammaRay::MetaTypeBrowserWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + + + + false + + + true + + + true + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.cpp gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.cpp --- gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,52 @@ +/* + mimetypeswidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "mimetypeswidget.h" +#include "ui_mimetypeswidget.h" + +#include +#include + +#include + +using namespace GammaRay; + +MimeTypesWidget::MimeTypesWidget(QWidget *parent) + : QWidget(parent), ui(new Ui::MimeTypesWidget) +{ + ui->setupUi(this); + + QSortFilterProxyModel *proxy = new KRecursiveFilterProxyModel(this); + proxy->setDynamicSortFilter(true); + proxy->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.MimeTypeModel")); + ui->mimeTypeView->setModel(proxy); + new DeferredResizeModeSetter(ui->mimeTypeView->header(), 0, QHeaderView::ResizeToContents); + new DeferredResizeModeSetter(ui->mimeTypeView->header(), 1, QHeaderView::ResizeToContents); + ui->mimeTypeView->sortByColumn(0, Qt::AscendingOrder); + ui->searchLine->setProxy(proxy); +} + +MimeTypesWidget::~MimeTypesWidget() +{ +} + diff -Nru gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.h gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.h --- gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + mimetypeswidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MIMETYPESWIDGET_H +#define GAMMARAY_MIMETYPESWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class MimeTypesWidget; +} + +class MimeTypesWidget : public QWidget +{ + Q_OBJECT + public: + explicit MimeTypesWidget(QWidget *parent = 0); + ~MimeTypesWidget(); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_MIMETYPESWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.ui gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.ui --- gammaray-1.2.2/ui/tools/mimetypes/mimetypeswidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/mimetypes/mimetypeswidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ + + + GammaRay::MimeTypesWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + + + + true + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/modelinspector/modelinspectorclient.cpp gammaray-2.0.1/ui/tools/modelinspector/modelinspectorclient.cpp --- gammaray-1.2.2/ui/tools/modelinspector/modelinspectorclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/modelinspector/modelinspectorclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ +/* + modelinspectorclient.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "modelinspectorclient.h" + +using namespace GammaRay; + +ModelInspectorClient::ModelInspectorClient(QObject *parent) +: ModelInspectorInterface(parent) +{ + +} + +ModelInspectorClient::~ModelInspectorClient() +{ + +} + diff -Nru gammaray-1.2.2/ui/tools/modelinspector/modelinspectorclient.h gammaray-2.0.1/ui/tools/modelinspector/modelinspectorclient.h --- gammaray-1.2.2/ui/tools/modelinspector/modelinspectorclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/modelinspector/modelinspectorclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,42 @@ +/* + modelinspectorclient.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Milian Wolff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MODELINSPECTORCLIENT_H +#define GAMMARAY_MODELINSPECTORCLIENT_H + +#include + +namespace GammaRay { + +class ModelInspectorClient : public ModelInspectorInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ModelInspectorInterface) + public: + explicit ModelInspectorClient(QObject *parent = 0); + virtual ~ModelInspectorClient(); +}; + +} + +#endif // GAMMARAY_MODELINSPECTORCLIENT_H diff -Nru gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.cpp gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.cpp --- gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,129 @@ +/* + modelinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "modelinspectorwidget.h" +#include "ui_modelinspectorwidget.h" + +#include "modelinspectorclient.h" + +#include +#include +#include + +#include +#include + +using namespace GammaRay; + +static QObject* createModelInspectorClient(const QString & /*name*/, QObject *parent) +{ + return new ModelInspectorClient(parent); +} + +ModelInspectorWidget::ModelInspectorWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ModelInspectorWidget) + , m_interface(0) +{ + ui->setupUi(this); + + ObjectBroker::registerClientObjectFactoryCallback(createModelInspectorClient); + m_interface = ObjectBroker::object(); + connect(m_interface, SIGNAL(cellSelected(int,int,QString,QString)), + SLOT(cellSelected(int,int,QString,QString))); + + KRecursiveFilterProxyModel *modelFilterProxy = new KRecursiveFilterProxyModel(this); + modelFilterProxy->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.ModelModel")); + ui->modelView->setModel(modelFilterProxy); + ui->modelView->setSelectionModel(ObjectBroker::selectionModel(modelFilterProxy)); + ui->modelSearchLine->setProxy(modelFilterProxy); + connect(ui->modelView->selectionModel(), + SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(modelSelected(QItemSelection))); + + ui->modelCellView->setModel(ObjectBroker::model("com.kdab.GammaRay.ModelCellModel")); + + cellSelected(-1, -1, QString(), QString()); +} + +ModelInspectorWidget::~ModelInspectorWidget() +{ +} + +void ModelInspectorWidget::modelSelected(const QItemSelection& selected) +{ + QModelIndex index; + if (selected.size() >= 1) + index = selected.first().topLeft(); + + if (index.isValid()) { + QObject *obj = index.data(ObjectModel::ObjectRole).value(); + QAbstractItemModel *model = qobject_cast(obj); + if (model) { + // we are on the server side + ui->modelContentView->setModel(model); + if (ObjectBroker::hasSelectionModel(ui->modelContentView->model())) + setupModelContentSelectionModel(); + connect(Endpoint::instance(), SIGNAL(objectRegistered(QString,Protocol::ObjectAddress)), + this, SLOT(objectRegistered(QString)), Qt::UniqueConnection); + } else { + // we are on the client side + model = ObjectBroker::model("com.kdab.GammaRay.ModelContent"); + ui->modelContentView->setModel(model); + setupModelContentSelectionModel(); + } + + // in case selection is not directly triggered by the user + ui->modelView->scrollTo(index, QAbstractItemView::EnsureVisible); + } else { + ui->modelContentView->setModel(0); + } + + // clear the cell info box + cellSelected(-1, -1, QString(), QString()); +} + +void ModelInspectorWidget::cellSelected(int row, int column, const QString &internalId, const QString &internalPtr) +{ + ui->indexLabel->setText(row != -1 ? + tr("Row: %1 Column: %2").arg(row).arg(column) : + tr("Invalid")); + ui->internalIdLabel->setText(internalId); + ui->internalPtrLabel->setText(internalPtr); +} + +void ModelInspectorWidget::objectRegistered(const QString& objectName) +{ + if (objectName == "com.kdab.GammaRay.ModelContent.selection") + // delay, since it's not registered yet when the signal is emitted + QMetaObject::invokeMethod(this, "setupModelContentSelectionModel", Qt::QueuedConnection); +} + +void ModelInspectorWidget::setupModelContentSelectionModel() +{ + if (!ui->modelContentView->model()) + return; + + ui->modelContentView->setSelectionModel(ObjectBroker::selectionModel(ui->modelContentView->model())); +} + diff -Nru gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.h gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.h --- gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,60 @@ +/* + modelinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_MODELINSPECTOR_MODELINSPECTORWIDGET_H +#define GAMMARAY_MODELINSPECTOR_MODELINSPECTORWIDGET_H + +#include + +class QItemSelection; +class QModelIndex; + +namespace GammaRay { + +class ModelInspectorInterface; + +namespace Ui { + class ModelInspectorWidget; +} + +class ModelInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit ModelInspectorWidget(QWidget *parent = 0); + ~ModelInspectorWidget(); + + private slots: + void cellSelected(int row, int column, const QString &internalId, const QString &internalPtr); + void objectRegistered(const QString &objectName); + void modelSelected(const QItemSelection& selected); + void setupModelContentSelectionModel(); + + private: + QScopedPointer ui; + ModelInspectorInterface *m_interface; +}; + +} + +#endif // GAMMARAY_MODELINSPECTORWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.ui gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.ui --- gammaray-1.2.2/ui/tools/modelinspector/modelinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/modelinspector/modelinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,129 @@ + + + GammaRay::ModelInspectorWidget + + + + 0 + 0 + 788 + 479 + + + + + + + Qt::Horizontal + + + + + + + + + + true + + + true + + + + + + + + Model Content + + + + + + true + + + + + + + + Cell Info + + + + + + + + Model Index: + + + + + + + Invalid + + + + + + + Internal Id: + + + + + + + + + + + + + + Internal Pointer: + + + + + + + + + + + + + + + + false + + + true + + + true + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.cpp gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.cpp --- gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,75 @@ +/* + objectinspector.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "objectinspectorwidget.h" +#include "ui_objectinspectorwidget.h" + +#include + +#include + +#include + +#include +#include + +using namespace GammaRay; + +ObjectInspectorWidget::ObjectInspectorWidget(QWidget *parent) + : QWidget(parent), + ui(new Ui::ObjectInspectorWidget) +{ + ui->setupUi(this); + ui->objectPropertyWidget->setObjectBaseName("com.kdab.GammaRay.ObjectInspector"); + + QSortFilterProxyModel *objectFilter = new KRecursiveFilterProxyModel(this); + objectFilter->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.ObjectTree")); + objectFilter->setDynamicSortFilter(true); + ui->objectTreeView->setModel(objectFilter); + new DeferredResizeModeSetter(ui->objectTreeView->header(), 0, QHeaderView::Stretch); + new DeferredResizeModeSetter(ui->objectTreeView->header(), 1, QHeaderView::Interactive); + ui->objectSearchLine->setProxy(objectFilter); + + QItemSelectionModel* selectionModel = ObjectBroker::selectionModel(ui->objectTreeView->model()); + ui->objectTreeView->setSelectionModel(selectionModel); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(objectSelectionChanged(QItemSelection))); + + if (qgetenv("GAMMARAY_TEST_FILTER") == "1") { + QMetaObject::invokeMethod(ui->objectSearchLine->lineEdit(), "setText", + Qt::QueuedConnection, + Q_ARG(QString, QLatin1String("Object"))); + } +} + +ObjectInspectorWidget::~ObjectInspectorWidget() +{ +} + +void ObjectInspectorWidget::objectSelectionChanged(const QItemSelection& selection) +{ + if (selection.isEmpty()) + return; + const QModelIndex index = selection.first().topLeft(); + ui->objectTreeView->scrollTo(index); +} diff -Nru gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.h gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.h --- gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,53 @@ +/* + objectinspector.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_OBJECTINSPECTOR_OBJECTINSPECTORWIDGET_H +#define GAMMARAY_OBJECTINSPECTOR_OBJECTINSPECTORWIDGET_H + +#include + +class QItemSelection; + +namespace GammaRay { + +namespace Ui { + class ObjectInspectorWidget; +} + +class ObjectInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit ObjectInspectorWidget(QWidget *parent = 0); + ~ObjectInspectorWidget(); + + private slots: + void objectSelectionChanged(const QItemSelection &selection); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_OBJECTINSPECTOR_H diff -Nru gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.ui gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.ui --- gammaray-1.2.2/ui/tools/objectinspector/objectinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/objectinspector/objectinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,59 @@ + + + GammaRay::ObjectInspectorWidget + + + + 0 + 0 + 400 + 300 + + + + + + + Qt::Horizontal + + + + + + + + + + true + + + true + + + true + + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+ + GammaRay::PropertyWidget + QWidget +
propertywidget.h
+ 1 +
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/clientresourcemodel.cpp gammaray-2.0.1/ui/tools/resourcebrowser/clientresourcemodel.cpp --- gammaray-1.2.2/ui/tools/resourcebrowser/clientresourcemodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/clientresourcemodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + clientresourcemodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "clientresourcemodel.h" + +#include + +using namespace GammaRay; + +ClientResourceModel::ClientResourceModel(QObject* parent): KRecursiveFilterProxyModel(parent) +{ +} + +ClientResourceModel::~ClientResourceModel() +{ + +} + +QVariant ClientResourceModel::data(const QModelIndex& index, int role) const +{ + if (role == Qt::DecorationRole && index.column() == 0) { + if (!index.parent().isValid()) + return m_iconProvider.icon(QFileIconProvider::Drive); + if (hasChildren(index)) + return m_iconProvider.icon(QFileIconProvider::Folder); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QList types = m_mimeDb.mimeTypesForFileName(index.data(Qt::DisplayRole).toString()); + foreach( const QMimeType &mt, types) { + QIcon icon = QIcon::fromTheme(mt.iconName()); + if (!icon.isNull()) + return icon; + icon = QIcon::fromTheme(mt.genericIconName()); + if (!icon.isNull()) + return icon; + } +#endif + return m_iconProvider.icon(QFileIconProvider::File); + } + return QSortFilterProxyModel::data(index, role); +} + diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/clientresourcemodel.h gammaray-2.0.1/ui/tools/resourcebrowser/clientresourcemodel.h --- gammaray-1.2.2/ui/tools/resourcebrowser/clientresourcemodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/clientresourcemodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,57 @@ +/* + clientresourcemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_CLIENTRESOURCEMODEL_H +#define GAMMARAY_CLIENTRESOURCEMODEL_H + +#include "kde/krecursivefilterproxymodel.h" +#include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0 ,0) +#include +#endif + +namespace GammaRay { + +/** + * Adds file icons for the resource model. + * This can't be done server-side since the icon stuff might not exist in a pure QtCore application. + */ +class ClientResourceModel : public KRecursiveFilterProxyModel +{ + Q_OBJECT +public: + explicit ClientResourceModel(QObject *parent = 0); + ~ClientResourceModel(); + + /*override*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + +private: + QFileIconProvider m_iconProvider; +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QMimeDatabase m_mimeDb; +#endif +}; +} + +#endif // GAMMARAY_CLIENTRESOURCEMODEL_H diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserclient.cpp gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserclient.cpp --- gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserclient.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserclient.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,38 @@ +/* + * + * + * This file is part of GammaRay, the Qt application inspection and + * manipulation tool. + * + * Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + * Author: Milian Wolff + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "resourcebrowserclient.h" + +using namespace GammaRay; + +ResourceBrowserClient::ResourceBrowserClient(QObject *parent) + : ResourceBrowserInterface(parent) +{ +} + +ResourceBrowserClient::~ResourceBrowserClient() +{ + +} + diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserclient.h gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserclient.h --- gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserclient.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserclient.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,43 @@ +/* + * + * + * This file is part of GammaRay, the Qt application inspection and + * manipulation tool. + * + * Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + * Author: Milian Wolff + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef RESOURCEBROWSERCLIENT_H +#define RESOURCEBROWSERCLIENT_H + +#include + +namespace GammaRay { + +class ResourceBrowserClient : public ResourceBrowserInterface +{ + Q_OBJECT + Q_INTERFACES(GammaRay::ResourceBrowserInterface) + public: + explicit ResourceBrowserClient(QObject *parent); + virtual ~ResourceBrowserClient(); +}; + +} + +#endif // RESOURCEBROWSERCLIENT_H diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.cpp gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.cpp --- gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,128 @@ +/* + resourcebrowserwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "resourcebrowserwidget.h" + +#include "ui_resourcebrowserwidget.h" +#include "resourcebrowserclient.h" +#include "clientresourcemodel.h" + +#include +#include <3rdparty/qt/resourcemodel.h> +#include + +#include +#include +#include + +using namespace GammaRay; + +static QObject* createResourceBrowserClient(const QString & /*name*/, QObject *parent) +{ + return new ResourceBrowserClient(parent); +} + +ResourceBrowserWidget::ResourceBrowserWidget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::ResourceBrowserWidget) + , m_timer(new QTimer(this)) + , m_interface(0) +{ + ObjectBroker::registerClientObjectFactoryCallback(createResourceBrowserClient); + m_interface = ObjectBroker::object(); + connect(m_interface, SIGNAL(resourceDeselected()), this, SLOT(resourceDeselected())); + connect(m_interface, SIGNAL(resourceSelected(QPixmap)), this, SLOT(resourceSelected(QPixmap))); + connect(m_interface, SIGNAL(resourceSelected(QByteArray)), this, SLOT(resourceSelected(QByteArray))); + + ui->setupUi(this); + ClientResourceModel* model = new ClientResourceModel(this); + model->setSourceModel(ObjectBroker::model("com.kdab.GammaRay.ResourceModel")); + ui->treeView->setModel(model); + ui->treeView->setSelectionModel(ObjectBroker::selectionModel(ui->treeView->model())); + ui->searchLine->setProxy(model); + + DeferredTreeViewConfiguration *config = new DeferredTreeViewConfiguration(ui->treeView); + config->hideColumn(3); + connect(ui->treeView->model(), SIGNAL(rowsInserted(QModelIndex,int,int)), + SLOT(rowsInserted())); + + ui->resourceLabel->setText(tr("Select a Resource to Preview")); + ui->stackedWidget->setCurrentWidget(ui->contentLabelPage); + + m_timer->setInterval(100); + m_timer->setSingleShot(true); + connect(m_timer, SIGNAL(timeout()), SLOT(setupLayout())); + m_timer->start(); +} + +ResourceBrowserWidget::~ResourceBrowserWidget() +{ +} + +void ResourceBrowserWidget::rowsInserted() +{ + m_timer->start(); +} + +void ResourceBrowserWidget::setupLayout() +{ + // now we can assume the model is filled properly and can adjust the tree view column sizes + for(int i = 0; i < 3; ++i) { + ui->treeView->resizeColumnToContents(i); + } + + // now the view was setup properly and we can mess with the splitter to resize + // the widgets for nicer display + + int viewWidth = ui->treeView->columnWidth(0) + + ui->treeView->columnWidth(1) + + ui->treeView->columnWidth(2) + + ui->treeView->contentsMargins().left() + + ui->treeView->contentsMargins().right() + 25; + const int totalWidth = ui->splitter->width(); + const int minPreviewWidth = 150; + if (totalWidth > viewWidth + minPreviewWidth) { + ui->splitter->setSizes(QList() << viewWidth << (totalWidth - viewWidth)); + ui->splitter->setStretchFactor(1, 3); + } +} + +void ResourceBrowserWidget::resourceDeselected() +{ + ui->resourceLabel->setText(tr("Select a Resource to Preview")); + ui->stackedWidget->setCurrentWidget(ui->contentLabelPage); +} + +void ResourceBrowserWidget::resourceSelected(const QPixmap &pixmap) +{ + ui->resourceLabel->setPixmap(pixmap); + ui->stackedWidget->setCurrentWidget(ui->contentLabelPage); +} + +void ResourceBrowserWidget::resourceSelected(const QByteArray &contents) +{ + //TODO: make encoding configurable + ui->textBrowser->setText(contents); + ui->stackedWidget->setCurrentWidget(ui->contentTextPage); +} + diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.h gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.h --- gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,62 @@ +/* + resourcebrowserwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_RESOURCEBROWSER_RESOURCEBROWSERWIDGET_H +#define GAMMARAY_RESOURCEBROWSER_RESOURCEBROWSERWIDGET_H + +#include + +class QTimer; +class QItemSelection; + +namespace GammaRay { + +class ResourceBrowserInterface; + +namespace Ui { + class ResourceBrowserWidget; +} + +class ResourceBrowserWidget : public QWidget +{ + Q_OBJECT + public: + explicit ResourceBrowserWidget(QWidget *parent = 0); + ~ResourceBrowserWidget(); + + private slots: + void rowsInserted(); + void setupLayout(); + void resourceDeselected(); + void resourceSelected(const QPixmap &pixmap); + void resourceSelected(const QByteArray &contents); + + private: + QScopedPointer ui; + QTimer *m_timer; + ResourceBrowserInterface *m_interface; +}; + +} + +#endif // GAMMARAY_RESOURCEBROWSER_H diff -Nru gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.ui gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.ui --- gammaray-1.2.2/ui/tools/resourcebrowser/resourcebrowserwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/resourcebrowser/resourcebrowserwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,91 @@ + + + GammaRay::ResourceBrowserWidget + + + + 0 + 0 + 400 + 300 + + + + + + + Qt::Horizontal + + + + + + + + + + + + + + 1 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + KFilterProxySearchLine + QWidget +
kde/kfilterproxysearchline.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.cpp gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.cpp --- gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,44 @@ +/* + standardpathswidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "standardpathswidget.h" +#include "ui_standardpathswidget.h" + +#include + +using namespace GammaRay; + +StandardPathsWidget::StandardPathsWidget(QWidget *parent) + : QWidget(parent), ui(new Ui::StandardPathsWidget) +{ + ui->setupUi(this); + + ui->pathView->setModel(ObjectBroker::model("com.kdab.GammaRay.StandardPathsModel")); + + ui->pathView->header()->setResizeMode(QHeaderView::ResizeToContents); +} + +StandardPathsWidget::~StandardPathsWidget() +{ +} + diff -Nru gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.h gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.h --- gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + standardpathswidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_STANDARDPATHSWIDGET_H +#define GAMMARAY_STANDARDPATHSWIDGET_H + +#include + +namespace GammaRay { + +namespace Ui { + class StandardPathsWidget; +} + +class StandardPathsWidget : public QWidget +{ + Q_OBJECT + public: + explicit StandardPathsWidget(QWidget *parent = 0); + ~StandardPathsWidget(); + + private: + QScopedPointer ui; +}; + +} + +#endif // GAMMARAY_STANDARDPATHSWIDGET_H diff -Nru gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.ui gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.ui --- gammaray-1.2.2/ui/tools/standardpaths/standardpathswidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/standardpaths/standardpathswidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,31 @@ + + + GammaRay::StandardPathsWidget + + + + 0 + 0 + 400 + 300 + + + + + 0 + + + + + false + + + true + + + + + + + + diff -Nru gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentcontentview.cpp gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentcontentview.cpp --- gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentcontentview.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentcontentview.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,49 @@ +/* + textdocumentcontentview.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "textdocumentcontentview.h" + +#include + +using namespace GammaRay; + +TextDocumentContentView::TextDocumentContentView(QWidget *parent): QTextEdit(parent) +{ +} + +void TextDocumentContentView::setShowBoundingBox(const QRectF &boundingBox) +{ + m_boundingBox = boundingBox; + viewport()->update(); +} + +void TextDocumentContentView::paintEvent(QPaintEvent *e) +{ + QTextEdit::paintEvent(e); + if (!m_boundingBox.isEmpty()) { + QPainter painter(viewport()); + painter.setPen(Qt::red); + painter.drawRect(m_boundingBox); + } +} + diff -Nru gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentcontentview.h gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentcontentview.h --- gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentcontentview.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentcontentview.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,48 @@ +/* + textdocumentcontentview.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTCONTENTVIEW_H +#define GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTCONTENTVIEW_H + +#include + +namespace GammaRay { + +class TextDocumentContentView : public QTextEdit +{ + Q_OBJECT + public: + explicit TextDocumentContentView(QWidget *parent = 0); + + void setShowBoundingBox(const QRectF &boundingBox); + + protected: + virtual void paintEvent(QPaintEvent *e); + + private: + QRectF m_boundingBox; +}; + +} + +#endif // GAMMARAY_TEXTDOCUMENTCONTENTVIEW_H diff -Nru gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.cpp gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.cpp --- gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,94 @@ +/* + textdocumentinspectorwidget.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "textdocumentinspectorwidget.h" +#include "ui_textdocumentinspectorwidget.h" +#include "core/tools/textdocumentinspector/textdocumentmodel.h" + +#include +#include + +#include + +using namespace GammaRay; + +TextDocumentInspectorWidget::TextDocumentInspectorWidget(QWidget *parent): + QWidget(parent), + ui(new Ui::TextDocumentInspectorWidget) +{ + ui->setupUi(this); + + ui->documentList->setModel(ObjectBroker::model("com.kdab.GammaRay.TextDocumentsModel")); + QItemSelectionModel *selectionModel = ObjectBroker::selectionModel(ui->documentList->model()); + ui->documentList->setSelectionModel(selectionModel); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(documentSelected(QItemSelection,QItemSelection))); + + ui->documentTree->setModel(ObjectBroker::model("com.kdab.GammaRay.TextDocumentModel")); + selectionModel = ObjectBroker::selectionModel(ui->documentTree->model()); + ui->documentTree->setSelectionModel(selectionModel); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + SLOT(documentElementSelected(QItemSelection,QItemSelection))); + ui->documentFormatView->setModel(ObjectBroker::model("com.kdab.GammaRay.TextDocumentFormatModel")); +} + +TextDocumentInspectorWidget::~TextDocumentInspectorWidget() +{ +} + +void TextDocumentInspectorWidget::documentSelected(const QItemSelection &selected, + const QItemSelection &deselected) +{ + Q_UNUSED(deselected); + const QModelIndex selectedRow = selected.first().topLeft(); + QObject *selectedObj = selectedRow.data(ObjectModel::ObjectRole).value(); + QTextDocument *doc = qobject_cast(selectedObj); + + if (m_currentDocument) { + disconnect(m_currentDocument, SIGNAL(contentsChanged()), + this, SLOT(documentContentChanged())); + } + m_currentDocument = QPointer(doc); + + if (doc) { + ui->documentView->setDocument(doc); + connect(doc, SIGNAL(contentsChanged()), SLOT(documentContentChanged())); + documentContentChanged(); + } +} + +void TextDocumentInspectorWidget::documentElementSelected(const QItemSelection &selected, + const QItemSelection &deselected) +{ + Q_UNUSED(deselected); + const QModelIndex selectedRow = selected.first().topLeft(); + + const QRectF boundingBox = selectedRow.data(TextDocumentModel::BoundingBoxRole).toRectF(); + ui->documentView->setShowBoundingBox(boundingBox); +} + +void TextDocumentInspectorWidget::documentContentChanged() +{ + ui->htmlView->setPlainText(m_currentDocument->toHtml()); +} + diff -Nru gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.h gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.h --- gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,61 @@ +/* + textdocumentinspectorwidget.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTINSPECTORWIDGET_H +#define GAMMARAY_TEXTDOCUMENTINSPECTOR_TEXTDOCUMENTINSPECTORWIDGET_H + +#include +#include +#include + +class QItemSelection; + +namespace GammaRay { + +class TextDocumentModel; +class TextDocumentFormatModel; + +namespace Ui { + class TextDocumentInspectorWidget; +} + +class TextDocumentInspectorWidget : public QWidget +{ + Q_OBJECT + public: + explicit TextDocumentInspectorWidget(QWidget *parent = 0); + ~TextDocumentInspectorWidget(); + + private slots: + void documentSelected(const QItemSelection &selected, const QItemSelection &deselected); + void documentElementSelected(const QItemSelection &selected, const QItemSelection &deselected); + void documentContentChanged(); + + private: + QScopedPointer ui; + QPointer m_currentDocument; +}; + +} + +#endif // GAMMARAY_TEXTDOCUMENTINSPECTOR_H diff -Nru gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.ui gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.ui --- gammaray-1.2.2/ui/tools/textdocumentinspector/textdocumentinspectorwidget.ui 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tools/textdocumentinspector/textdocumentinspectorwidget.ui 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,131 @@ + + + GammaRay::TextDocumentInspectorWidget + + + + 0 + 0 + 762 + 631 + + + + + + + Qt::Horizontal + + + + + + + All documents: + + + + + + + false + + + true + + + true + + + + + + + + Qt::Vertical + + + + + + + Document structure: + + + + + + + true + + + true + + + + + + + + + + + Element format: + + + + + + + false + + + true + + + true + + + + + + + + + 0 + + + + Content + + + + + + + + + + HTML + + + + + + + + + + + + + + + GammaRay::TextDocumentContentView + QTextEdit +
tools/textdocumentinspector/textdocumentcontentview.h
+
+
+ + +
diff -Nru gammaray-1.2.2/ui/tooluifactory.h gammaray-2.0.1/ui/tooluifactory.h --- gammaray-1.2.2/ui/tooluifactory.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/tooluifactory.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,96 @@ +/* + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2010-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Volker Krause + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_TOOLUIFACTORY_H +#define GAMMARAY_TOOLUIFACTORY_H + +#include +#include +#include + +namespace GammaRay { + +/** + * @brief An abstract interface for creating the UI parts of probe tools. + * + * The ToolUiFactory class is an abstract base class for creating UIs for probe tools + * for GammaRay. The unique identifier used for the UI must match the one of the corresponding + * probe tool. + */ +class ToolUiFactory +{ + public: + virtual inline ~ToolUiFactory() + { + } + + /** + * Unique id of this tool, must match the id of a the corresponding probe tool. + * @return a QString containing the tool id. + */ + virtual QString id() const = 0; + + /** + * Return true if this tool supports remoting, false otherwise. + */ + virtual bool remotingSupported() const = 0; + + /** + * Create the UI part of this tool. + * @param parentWidget The parent widget for the visual elements of this tool. + * @return a pointer to the created QwWidget. + */ + virtual QWidget *createWidget(QWidget *parentWidget) = 0; +}; + +/** + * @brief A templated convenience ToolUiFactory applicable for most use-cases. + */ +template +class StandardToolUiFactory : public ToolUiFactory +{ +public: + virtual inline QString id() const + { + return QString(); // TODO is this a problem?? + } + + virtual inline QWidget *createWidget(QWidget *parentWidget) + { + return new ToolUi(parentWidget); + } + + virtual bool remotingSupported() const + { + return true; + } +}; + +} + +Q_DECLARE_INTERFACE(GammaRay::ToolUiFactory, "com.kdab.GammaRay.ToolUiFactory/1.0") +Q_DECLARE_METATYPE(GammaRay::ToolUiFactory *) + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#define Q_PLUGIN_METADATA(x) +#endif + +#endif diff -Nru gammaray-1.2.2/ui/variantcontainermodel.cpp gammaray-2.0.1/ui/variantcontainermodel.cpp --- gammaray-1.2.2/ui/variantcontainermodel.cpp 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/variantcontainermodel.cpp 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,97 @@ +/* + variantcontainermodel.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "variantcontainermodel.h" + +using namespace GammaRay; + +VariantContainerModel::VariantContainerModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +void VariantContainerModel::setVariant(const QVariant &variant) +{ + beginResetModel(); + m_variant = variant; + endResetModel(); +} + +int VariantContainerModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid() || (!m_variant.canConvert() + && !m_variant.canConvert())) { + return 0; + } + if (m_variant.canConvert()) { + QSequentialIterable iter = m_variant.value(); + return iter.size(); + } + QAssociativeIterable iter = m_variant.value(); + return iter.size(); +} + +int VariantContainerModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid() || (!m_variant.canConvert() + && !m_variant.canConvert())) { + return 0; + } + if (m_variant.canConvert()) { + return 1; + } + if (m_variant.canConvert()) { + return 2; + } + return 0; +} + +QVariant VariantContainerModel::data(const QModelIndex &index, int role) const +{ + if ((!m_variant.canConvert() + && !m_variant.canConvert()) || !index.isValid()) { + return QVariant(); + } + + if (m_variant.canConvert()) { + QSequentialIterable iter = m_variant.value(); + + if (role == Qt::DisplayRole) { + return iter.at(index.row()); + } + } + if (m_variant.canConvert()) { + QAssociativeIterable iter = m_variant.value(); + + QAssociativeIterable::const_iterator it = iter.begin() + index.row(); + + if (role == Qt::DisplayRole) { + if (index.column() == 0) + return it.key(); + if (index.column() == 1) + return it.value(); + } + } + return QVariant(); +} + diff -Nru gammaray-1.2.2/ui/variantcontainermodel.h gammaray-2.0.1/ui/variantcontainermodel.h --- gammaray-1.2.2/ui/variantcontainermodel.h 1970-01-01 00:00:00.000000000 +0000 +++ gammaray-2.0.1/ui/variantcontainermodel.h 2014-02-28 19:07:57.000000000 +0000 @@ -0,0 +1,51 @@ +/* + variantsequencemodel.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2013-2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Stephen Kelly + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef GAMMARAY_VARIANTCONTAINERMODEL_H +#define GAMMARAY_VARIANTCONTAINERMODEL_H + +#include + +namespace GammaRay { + +/** Model showing sequence inside a QVariant instance.. + */ +class VariantContainerModel : public QAbstractTableModel +{ + Q_OBJECT + public: + explicit VariantContainerModel(QObject *parent = 0); + + void setVariant(const QVariant &variant); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + private: + QVariant m_variant; +}; + +} + +#endif // GAMMARAY_VARIANTCONTAINERMODEL_H