Commit ecdecd4e authored by Aurindam Jana's avatar Aurindam Jana Committed by hjk
Browse files

DebuggerTreeView: Move base class to utils



Change-Id: I3313789be5f835d218cad5ed5f3143aee18e9f5f
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 68471c21
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@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 qt-info@nokia.com.
**
**************************************************************************/
#include "basetreeview.h"
#include <QHeaderView>
#include <QMenu>
#include <QMouseEvent>
namespace Utils {
BaseTreeView::BaseTreeView(QWidget *parent)
: QTreeView(parent)
{
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setSelectionMode(QAbstractItemView::ExtendedSelection);
setUniformRowHeights(true);
header()->setDefaultAlignment(Qt::AlignLeft);
header()->setClickable(true);
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex)));
connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(int)));
m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0);
m_alwaysAdjustColumnsAction = 0;
}
void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action)
{
m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
}
void BaseTreeView::addBaseContextActions(QMenu *menu)
{
menu->addSeparator();
if (m_alwaysAdjustColumnsAction)
menu->addAction(m_alwaysAdjustColumnsAction);
menu->addAction(m_adjustColumnsAction);
menu->addSeparator();
}
bool BaseTreeView::handleBaseContextAction(QAction *act)
{
if (act == 0)
return true;
if (act == m_adjustColumnsAction) {
resizeColumnsToContents();
return true;
}
if (act == m_alwaysAdjustColumnsAction) {
if (act->isChecked())
resizeColumnsToContents();
// Action triggered automatically.
return true;
}
return false;
}
void BaseTreeView::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
}
void BaseTreeView::mousePressEvent(QMouseEvent *ev)
{
QTreeView::mousePressEvent(ev);
if (!indexAt(ev->pos()).isValid())
resizeColumnsToContents();
}
void BaseTreeView::resizeColumnsToContents()
{
const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c);
}
void BaseTreeView::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
}
void BaseTreeView::headerSectionClicked(int logicalIndex)
{
resizeColumnToContents(logicalIndex);
}
void BaseTreeView::reset()
{
QTreeView::reset();
if (header() && m_alwaysAdjustColumnsAction
&& m_alwaysAdjustColumnsAction->isChecked())
resizeColumnsToContents();
}
} // namespace Utils
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@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 qt-info@nokia.com.
**
**************************************************************************/
#ifndef BASETREEVIEW_H
#define BASETREEVIEW_H
#include "utils_global.h"
#include <QTreeView>
namespace Utils {
class QTCREATOR_UTILS_EXPORT BaseTreeView : public QTreeView
{
Q_OBJECT
public:
BaseTreeView(QWidget *parent = 0);
void setAlwaysAdjustColumnsAction(QAction *action);
virtual void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
void setModel(QAbstractItemModel *model);
virtual void rowActivated(const QModelIndex &) {}
void mousePressEvent(QMouseEvent *ev);
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
void reset();
protected slots:
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
private slots:
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
void headerSectionClicked(int logicalIndex);
private:
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
};
} // namespace Utils
#endif // BASETREEVIEW_H
......@@ -97,7 +97,8 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/json.cpp \
$$PWD/portlist.cpp \
$$PWD/tcpportsgatherer.cpp \
$$PWD/appmainwindow.cpp
$$PWD/appmainwindow.cpp \
$$PWD/basetreeview.cpp
win32 {
SOURCES += \
......@@ -211,7 +212,8 @@ HEADERS += \
$$PWD/runextensions.h \
$$PWD/portlist.h \
$$PWD/tcpportsgatherer.h \
$$PWD/appmainwindow.h
$$PWD/appmainwindow.h \
$$PWD/basetreeview.h
FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \
......
......@@ -40,9 +40,6 @@
#include <find/treeviewfind.h>
#include <utils/savedaction.h>
#include <QContextMenuEvent>
#include <QDebug>
#include <QHeaderView>
#include <QMenu>
#include <QVBoxLayout>
......@@ -50,107 +47,20 @@ namespace Debugger {
namespace Internal {
BaseTreeView::BaseTreeView(QWidget *parent)
: QTreeView(parent)
: Utils::BaseTreeView(parent)
{
QAction *act = debuggerCore()->action(UseAlternatingRowColors);
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setAlternatingRowColors(act->isChecked());
setRootIsDecorated(false);
setIconSize(QSize(10, 10));
setSelectionMode(QAbstractItemView::ExtendedSelection);
setUniformRowHeights(true);
header()->setDefaultAlignment(Qt::AlignLeft);
header()->setClickable(true);
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex)));
connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(int)));
m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), 0);
m_alwaysAdjustColumnsAction = 0;
}
void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action)
{
m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
SLOT(setAlternatingRowColorsHelper(bool)));
}
void BaseTreeView::addBaseContextActions(QMenu *menu)
{
menu->addSeparator();
if (m_alwaysAdjustColumnsAction)
menu->addAction(m_alwaysAdjustColumnsAction);
menu->addAction(m_adjustColumnsAction);
menu->addSeparator();
Utils::BaseTreeView::addBaseContextActions(menu);
menu->addAction(debuggerCore()->action(SettingsDialog));
}
bool BaseTreeView::handleBaseContextAction(QAction *act)
{
if (act == 0)
return true;
if (act == m_adjustColumnsAction) {
resizeColumnsToContents();
return true;
}
if (act == m_alwaysAdjustColumnsAction) {
if (act->isChecked())
resizeColumnsToContents();
// Action triggered automatically.
return true;
}
return false;
}
void BaseTreeView::setModel(QAbstractItemModel *model)
{
QTreeView::setModel(model);
if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
}
void BaseTreeView::mousePressEvent(QMouseEvent *ev)
{
QTreeView::mousePressEvent(ev);
if (!indexAt(ev->pos()).isValid())
resizeColumnsToContents();
}
void BaseTreeView::resizeColumnsToContents()
{
const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c);
}
void BaseTreeView::setAlwaysResizeColumnsToContents(bool on)
{
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
header()->setResizeMode(0, mode);
}
void BaseTreeView::headerSectionClicked(int logicalIndex)
{
resizeColumnToContents(logicalIndex);
}
void BaseTreeView::reset()
{
QTreeView::reset();
if (header() && m_alwaysAdjustColumnsAction
&& m_alwaysAdjustColumnsAction->isChecked())
resizeColumnsToContents();
}
BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent)
: QWidget(parent), m_treeView(treeView)
{
......
......@@ -33,39 +33,18 @@
#ifndef DEBUGGER_BASEWINDOW_H
#define DEBUGGER_BASEWINDOW_H
#include <QTreeView>
#include <utils/basetreeview.h>
namespace Debugger {
namespace Internal {
class BaseTreeView : public QTreeView
class BaseTreeView : public Utils::BaseTreeView
{
Q_OBJECT
public:
BaseTreeView(QWidget *parent = 0);
void setAlwaysAdjustColumnsAction(QAction *action);
explicit BaseTreeView(QWidget *parent = 0);
void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
void setModel(QAbstractItemModel *model);
virtual void rowActivated(const QModelIndex &) {}
void mousePressEvent(QMouseEvent *ev);
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
private slots:
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
void headerSectionClicked(int logicalIndex);
void reset();
private:
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
};
class BaseWindow : public QWidget
......
......@@ -166,7 +166,6 @@ public:
RegisterTreeView::RegisterTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setAlwaysAdjustColumnsAction(debuggerCore()->action(UseAlternatingRowColors));
setItemDelegate(new RegisterDelegate(this));
}
......
......@@ -292,28 +292,13 @@ bool QmlJSPropertyInspectorModel::contentsValid() const
}
QmlJSPropertyInspector::QmlJSPropertyInspector(QWidget *parent)
: QTreeView(parent)
: Utils::BaseTreeView(parent)
{
setAttribute(Qt::WA_MacShowFocusRect, false);
setFrameStyle(QFrame::NoFrame);
setExpandsOnDoubleClick(true);
header()->setDefaultAlignment(Qt::AlignLeft);
header()->setClickable(true);
setRootIsDecorated(false);
setItemDelegateForColumn(PROPERTY_VALUE_COLUMN, new PropertyEditDelegate(this));
setModel(&m_model);
//Add an empty Row to make the headers visible!
addRow(QString(), QString(), QString(), -1, false);
connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(int)));
}
void QmlJSPropertyInspector::headerSectionClicked(int logicalIndex)
{
resizeColumnToContents(logicalIndex);
}
void QmlJSPropertyInspector::clear()
......@@ -491,8 +476,6 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu menu;
QModelIndex itemIndex = indexAt(ev->pos());
if (!itemIndex.isValid())
return;
bool isEditable = false;
bool isColor = false;
if (itemIndex.isValid()) {
......@@ -507,6 +490,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
QAction colorAction(tr("Choose color"), this);
if (isColor)
menu.addAction(&colorAction);
addBaseContextActions(&menu);
QAction *action = menu.exec(ev->globalPos());
if (action == 0)
......@@ -516,6 +500,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
openExpressionEditor(itemIndex);
if (action == &colorAction)
openColorSelector(itemIndex);
handleBaseContextAction(action);
}
void QmlJSPropertyInspector::openExpressionEditor(const QModelIndex &itemIndex)
......
......@@ -33,7 +33,7 @@
#define PROPERTYINSPECTOR_H
#include <qmljsprivateapi.h>
#include <QTreeView>
#include <utils/basetreeview.h>
#include <QStandardItemModel>
#include <QDialog>
......@@ -108,7 +108,7 @@ private:
bool m_contentsValid;
};
class QmlJSPropertyInspector : public QTreeView
class QmlJSPropertyInspector : public Utils::BaseTreeView
{
Q_OBJECT
public:
......@@ -138,9 +138,6 @@ public slots:
void openExpressionEditor(const QModelIndex &itemIndex);
void openColorSelector(const QModelIndex &itemIndex);
private slots:
void headerSectionClicked(int logicalIndex);
private:
friend class PropertyEditDelegate;
void buildPropertyTree(const QmlDebugObjectReference &);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment