2010-02-02 17:25:14 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-02 17:25:14 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "snapshotwindow.h"
|
|
|
|
|
|
|
|
|
|
#include "debuggeractions.h"
|
2010-06-15 12:15:25 +02:00
|
|
|
#include "debuggerconstants.h"
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <utils/savedaction.h>
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
2010-06-15 12:15:25 +02:00
|
|
|
#include <QtGui/QKeyEvent>
|
2010-02-02 17:25:14 +01:00
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
|
|
|
|
|
|
static QModelIndexList normalizeIndexes(const QModelIndexList &list)
|
|
|
|
|
{
|
|
|
|
|
QModelIndexList res;
|
|
|
|
|
foreach (const QModelIndex &idx, list)
|
|
|
|
|
if (idx.column() == 0)
|
|
|
|
|
res.append(idx);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// SnapshotWindow
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-06-15 12:15:25 +02:00
|
|
|
SnapshotWindow::SnapshotWindow(QWidget *parent)
|
|
|
|
|
: QTreeView(parent), m_alwaysResizeColumnsToContents(false)
|
2010-02-02 17:25:14 +01:00
|
|
|
{
|
|
|
|
|
QAction *act = theDebuggerAction(UseAlternatingRowColors);
|
|
|
|
|
setWindowTitle(tr("Snapshots"));
|
2010-04-16 11:39:36 +02:00
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
2010-03-16 16:55:56 +01:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
2010-02-02 17:25:14 +01:00
|
|
|
setAlternatingRowColors(act->isChecked());
|
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
|
setIconSize(QSize(10, 10));
|
|
|
|
|
|
|
|
|
|
header()->setDefaultAlignment(Qt::AlignLeft);
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(activated(QModelIndex)),
|
|
|
|
|
this, SLOT(rowActivated(QModelIndex)));
|
|
|
|
|
connect(act, SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(setAlternatingRowColorsHelper(bool)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SnapshotWindow::~SnapshotWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::rowActivated(const QModelIndex &index)
|
|
|
|
|
{
|
2010-06-15 12:15:25 +02:00
|
|
|
model()->setData(index, index.row(), RequestActivateSnapshotRole);
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::removeSnapshots(const QModelIndexList &indexes)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!indexes.isEmpty(), return);
|
|
|
|
|
foreach (const QModelIndex &idx, indexes)
|
2010-07-20 18:06:34 +02:00
|
|
|
model()->setData(idx, QVariant(), RequestRemoveSnapshotRole);
|
2010-02-02 17:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::keyPressEvent(QKeyEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
if (ev->key() == Qt::Key_Delete) {
|
|
|
|
|
QItemSelectionModel *sm = selectionModel();
|
|
|
|
|
QTC_ASSERT(sm, return);
|
|
|
|
|
QModelIndexList si = sm->selectedIndexes();
|
|
|
|
|
if (si.isEmpty())
|
|
|
|
|
si.append(currentIndex().sibling(currentIndex().row(), 0));
|
|
|
|
|
removeSnapshots(normalizeIndexes(si));
|
|
|
|
|
}
|
|
|
|
|
QTreeView::keyPressEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|
|
|
|
{
|
2010-07-13 15:57:34 +02:00
|
|
|
QModelIndex idx = indexAt(ev->pos());
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
QAction *actCreate = menu.addAction(tr("Create Snapshot"));
|
|
|
|
|
actCreate->setEnabled(idx.data(SnapshotCapabilityRole).toBool());
|
|
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2010-07-20 18:06:34 +02:00
|
|
|
QAction *actRemove = menu.addAction(tr("Remove Snapshot"));
|
|
|
|
|
actRemove->setEnabled(idx.isValid());
|
|
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2010-02-12 10:52:09 +01:00
|
|
|
QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
|
2010-02-02 17:25:14 +01:00
|
|
|
|
|
|
|
|
QAction *actAlwaysAdjust =
|
2010-02-12 10:52:09 +01:00
|
|
|
menu.addAction(tr("Always Adjust Column Widths to Contents"));
|
2010-02-02 17:25:14 +01:00
|
|
|
actAlwaysAdjust->setCheckable(true);
|
|
|
|
|
actAlwaysAdjust->setChecked(m_alwaysResizeColumnsToContents);
|
|
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
|
|
|
|
menu.addAction(theDebuggerAction(SettingsDialog));
|
|
|
|
|
|
|
|
|
|
QAction *act = menu.exec(ev->globalPos());
|
|
|
|
|
|
2010-07-13 15:57:34 +02:00
|
|
|
if (act == actCreate)
|
|
|
|
|
model()->setData(idx, idx.row(), RequestMakeSnapshotRole);
|
2010-07-20 18:06:34 +02:00
|
|
|
else if (act == actRemove)
|
|
|
|
|
model()->setData(idx, idx.row(), RequestRemoveSnapshotRole);
|
2010-07-13 15:57:34 +02:00
|
|
|
else if (act == actAdjust)
|
2010-02-02 17:25:14 +01:00
|
|
|
resizeColumnsToContents();
|
|
|
|
|
else if (act == actAlwaysAdjust)
|
|
|
|
|
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::resizeColumnsToContents()
|
|
|
|
|
{
|
|
|
|
|
for (int i = model()->columnCount(); --i >= 0; )
|
|
|
|
|
resizeColumnToContents(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnapshotWindow::setAlwaysResizeColumnsToContents(bool on)
|
|
|
|
|
{
|
|
|
|
|
m_alwaysResizeColumnsToContents = on;
|
|
|
|
|
QHeaderView::ResizeMode mode =
|
|
|
|
|
on ? QHeaderView::ResizeToContents : QHeaderView::Interactive;
|
|
|
|
|
for (int i = model()->columnCount(); --i >= 0; )
|
|
|
|
|
header()->setResizeMode(i, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|