Commit 8694ad98 authored by hjk's avatar hjk

Debugger: More column resizing

Turns out setting the column resize mode on the view itself
is counter-productive as it takes away the ability to
manually re-adjust.

So set the mode only temporarily to get the preferred width
than switch back to manually resize mode and use the hint
to set some initial size. Also use the length of the header
label as absolute minimum.

Change-Id: Ic17e31334b23ce6d541f9459cd22be65145046d3
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent ac930e4f
......@@ -34,6 +34,7 @@
#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
#include <QTimer>
namespace Utils {
......@@ -75,48 +76,38 @@ BaseTreeView::BaseTreeView(QWidget *parent)
connect(header(), SIGNAL(sectionClicked(int)),
SLOT(toggleColumnWidth(int)));
m_adjustColumnsAction = new QAction(tr("Adjust Column Widths to Contents"), this);
m_alwaysAdjustColumnsAction = 0;
}
m_alwaysAdjustColumns = false;
void BaseTreeView::setAlwaysAdjustColumnsAction(QAction *action)
{
m_alwaysAdjustColumnsAction = action;
connect(action, SIGNAL(toggled(bool)),
SLOT(setAlwaysResizeColumnsToContents(bool)));
m_layoutTimer.setSingleShot(true);
m_layoutTimer.setInterval(20);
connect(&m_layoutTimer, SIGNAL(timeout()), this, SLOT(resizeColumnsFinish()));
}
void BaseTreeView::addBaseContextActions(QMenu *menu)
void BaseTreeView::setModel(QAbstractItemModel *model)
{
menu->addSeparator();
if (m_alwaysAdjustColumnsAction)
menu->addAction(m_alwaysAdjustColumnsAction);
menu->addAction(m_adjustColumnsAction);
menu->addSeparator();
disconnectColumnAdjustment();
Utils::TreeView::setModel(model);
connectColumnAdjustment();
}
bool BaseTreeView::handleBaseContextAction(QAction *act)
void BaseTreeView::connectColumnAdjustment()
{
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;
if (m_alwaysAdjustColumns && model()) {
connect(model(), SIGNAL(layoutChanged()), this, SLOT(resizeColumns()));
connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(resizeColumns()));
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(resizeColumns()));
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(resizeColumns()));
}
return false;
}
void BaseTreeView::setModel(QAbstractItemModel *model)
void BaseTreeView::disconnectColumnAdjustment()
{
Utils::TreeView::setModel(model);
if (header() && m_alwaysAdjustColumnsAction)
setAlwaysResizeColumnsToContents(m_alwaysAdjustColumnsAction->isChecked());
if (m_alwaysAdjustColumns && model()) {
disconnect(model(), SIGNAL(layoutChanged()), this, SLOT(resizeColumns()));
disconnect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(resizeColumns()));
disconnect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(resizeColumns()));
disconnect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(resizeColumns()));
}
}
void BaseTreeView::mousePressEvent(QMouseEvent *ev)
......@@ -127,39 +118,64 @@ void BaseTreeView::mousePressEvent(QMouseEvent *ev)
toggleColumnWidth(columnAt(ev->x()));
}
void BaseTreeView::resizeColumnsToContents()
void BaseTreeView::resizeColumns()
{
const int columnCount = model()->columnCount();
for (int c = 0 ; c != columnCount; ++c)
resizeColumnToContents(c);
QHeaderView *h = header();
if (!h)
return;
const int n = h->count();
if (n) {
for (int i = 0; i != n; ++i)
h->setResizeMode(i, QHeaderView::ResizeToContents);
m_layoutTimer.start();
}
}
void BaseTreeView::setAlwaysResizeColumnsToContents(bool on)
void BaseTreeView::resizeColumnsFinish()
{
if (!header())
QHeaderView *h = header();
if (!h)
return;
QHeaderView::ResizeMode mode = on
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
for (int i = 0, n = header()->count(); i != n; ++i)
header()->setResizeMode(i, mode);
QFontMetrics fm(font());
for (int i = 0, n = h->count(); i != n; ++i) {
int headerSize = fm.width(model()->headerData(i, Qt::Horizontal).toString());
int targetSize = qMax(sizeHintForColumn(i), headerSize);
if (targetSize > 0) {
h->setResizeMode(i, QHeaderView::Interactive);
h->resizeSection(i, targetSize);
}
}
}
void BaseTreeView::toggleColumnWidth(int logicalIndex)
{
const int hint = sizeHintForColumn(logicalIndex);
const int size = 8 * QFontMetrics(font()).width(QLatin1Char('x'));
if (hint == header()->sectionSize(logicalIndex))
header()->resizeSection(logicalIndex, size);
else
QHeaderView *h = header();
const int currentSize = h->sectionSize(logicalIndex);
if (currentSize == sizeHintForColumn(logicalIndex)) {
QFontMetrics fm(font());
int headerSize = fm.width(model()->headerData(logicalIndex, Qt::Horizontal).toString());
int minSize = 10 * fm.width(QLatin1Char('x'));
h->resizeSection(logicalIndex, qMax(minSize, headerSize));
} else {
resizeColumnToContents(logicalIndex);
}
}
void BaseTreeView::reset()
{
Utils::TreeView::reset();
if (header() && m_alwaysAdjustColumnsAction
&& m_alwaysAdjustColumnsAction->isChecked())
resizeColumnsToContents();
if (m_alwaysAdjustColumns)
resizeColumns();
}
void BaseTreeView::setAlwaysAdjustColumns(bool on)
{
if (on == m_alwaysAdjustColumns)
return;
disconnectColumnAdjustment();
m_alwaysAdjustColumns = on;
connectColumnAdjustment();
}
QModelIndexList BaseTreeView::activeRows() const
......
......@@ -34,6 +34,8 @@
#include "itemviews.h"
#include <QTimer>
namespace Utils {
class QTCREATOR_UTILS_EXPORT BaseTreeView : public Utils::TreeView
......@@ -43,9 +45,6 @@ class QTCREATOR_UTILS_EXPORT BaseTreeView : public Utils::TreeView
public:
BaseTreeView(QWidget *parent = 0);
void setAlwaysAdjustColumnsAction(QAction *action);
virtual void addBaseContextActions(QMenu *menu);
bool handleBaseContextAction(QAction *action);
QModelIndexList activeRows() const;
void setModel(QAbstractItemModel *model);
......@@ -54,12 +53,13 @@ public:
void mousePressEvent(QMouseEvent *ev);
public slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
void resizeColumns();
void resizeColumnsFinish();
void reset();
protected slots:
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void setAlwaysAdjustColumns(bool on);
private slots:
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
......@@ -67,8 +67,11 @@ private slots:
void toggleColumnWidth(int logicalIndex);
private:
QAction *m_alwaysAdjustColumnsAction;
QAction *m_adjustColumnsAction;
void connectColumnAdjustment();
void disconnectColumnAdjustment();
bool m_alwaysAdjustColumns;
QTimer m_layoutTimer;
};
} // namespace Utils
......
......@@ -50,11 +50,16 @@ BaseTreeView::BaseTreeView(QWidget *parent)
setAlternatingRowColors(act->isChecked());
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlternatingRowColorsHelper(bool)));
act = debuggerCore()->action(AlwaysAdjustColumnWidths);
setAlwaysAdjustColumns(act->isChecked());
connect(act, SIGNAL(toggled(bool)),
SLOT(setAlwaysAdjustColumns(bool)));
}
void BaseTreeView::addBaseContextActions(QMenu *menu)
{
Utils::BaseTreeView::addBaseContextActions(menu);
menu->addSeparator();
menu->addAction(debuggerCore()->action(SettingsDialog));
}
......
......@@ -679,7 +679,6 @@ BreakTreeView::BreakTreeView(QWidget *parent)
{
setWindowIcon(QIcon(QLatin1String(":/debugger/images/debugger_breakpoints.png")));
setSelectionMode(QAbstractItemView::ExtendedSelection);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustBreakpointsColumnWidths));
connect(debuggerCore()->action(UseAddressInBreakpointsView),
SIGNAL(toggled(bool)), SLOT(showAddressColumn(bool)));
}
......@@ -844,7 +843,7 @@ void BreakTreeView::contextMenuEvent(QContextMenuEvent *ev)
else if (act == deleteByFileAction)
deleteBreakpoints(breakpointsInFile);
else if (act == adjustColumnAction)
resizeColumnsToContents();
resizeColumns();
else if (act == editBreakpointAction)
editBreakpoints(selectedIds);
else if (act == associateBreakpointAction)
......@@ -855,8 +854,6 @@ void BreakTreeView::contextMenuEvent(QContextMenuEvent *ev)
setBreakpointsEnabled(selectedIds, !enabled);
else if (act == addBreakpointAction)
addBreakpoint();
else
handleBaseContextAction(act);
}
void BreakTreeView::setBreakpointsEnabled(const BreakpointModelIds &ids, bool enabled)
......
......@@ -233,16 +233,11 @@ CommonOptionsPageWidget::CommonOptionsPageWidget
checkBoxFontSizeFollowsEditor);
m_group->insert(dc->action(AutoDerefPointers), 0);
m_group->insert(dc->action(UseToolTipsInLocalsView), 0);
m_group->insert(dc->action(AlwaysAdjustLocalsColumnWidths), 0);
m_group->insert(dc->action(AlwaysAdjustThreadsColumnWidths), 0);
m_group->insert(dc->action(AlwaysAdjustSnapshotsColumnWidths), 0);
m_group->insert(dc->action(AlwaysAdjustBreakpointsColumnWidths), 0);
m_group->insert(dc->action(AlwaysAdjustModulesColumnWidths), 0);
m_group->insert(dc->action(AlwaysAdjustColumnWidths), 0);
m_group->insert(dc->action(UseToolTipsInBreakpointsView), 0);
m_group->insert(dc->action(UseToolTipsInStackView), 0);
m_group->insert(dc->action(UseAddressInBreakpointsView), 0);
m_group->insert(dc->action(UseAddressInStackView), 0);
m_group->insert(dc->action(AlwaysAdjustStackColumnWidths), 0);
m_group->insert(dc->action(MaximalStackDepth), spinBoxMaximalStackDepth);
m_group->insert(dc->action(DisplayStringLimit), spinBoxDisplayStringLimit);
m_group->insert(dc->action(MaximalStringLength), spinBoxMaximalStringLength);
......
......@@ -106,69 +106,15 @@ DebuggerSettings::DebuggerSettings()
// View
//
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setText(tr("Always Adjust View Column Widths to Contents"));
item->setCheckable(true);
item->setValue(true);
item->setDefaultValue(true);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustLocalsColumnWidths2"));
insertItem(AlwaysAdjustLocalsColumnWidths, item);
QLatin1String("AlwaysAdjustColumnWidths"));
insertItem(AlwaysAdjustColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(true);
item->setDefaultValue(true);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustStackColumnWidths2"));
insertItem(AlwaysAdjustStackColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(true);
item->setDefaultValue(true);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustThreadsColumnWidths2"));
insertItem(AlwaysAdjustThreadsColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(false);
item->setDefaultValue(false);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustRegistersColumnWidths"));
insertItem(AlwaysAdjustRegistersColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(false);
item->setDefaultValue(false);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustSnapshotsColumnWidths"));
insertItem(AlwaysAdjustSnapshotsColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(false);
item->setDefaultValue(false);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustBreakpointsColumnWidths"));
insertItem(AlwaysAdjustBreakpointsColumnWidths, item);
item = new SavedAction(this);
item->setText(tr("Always Adjust Column Widths to Contents"));
item->setCheckable(true);
item->setValue(false);
item->setDefaultValue(false);
item->setSettingsKey(debugModeGroup,
QLatin1String("AlwaysAdjustModulesColumnWidths"));
insertItem(AlwaysAdjustModulesColumnWidths, item);
//Needed by QML Inspector
// Needed by QML Inspector
item = new SavedAction(this);
item->setText(tr("Use Alternating Row Colors"));
item->setSettingsKey(debugModeGroup, QLatin1String("UseAlternatingRowColours"));
......
......@@ -108,6 +108,8 @@ enum DebuggerActionCode
UseAddressInStackView,
RegisterForPostMortem,
AlwaysAdjustColumnWidths,
// Cdb
CdbAdditionalArguments,
......@@ -139,14 +141,12 @@ enum DebuggerActionCode
MaximalStackDepth,
ExpandStack,
CreateFullBacktrace,
AlwaysAdjustStackColumnWidths,
// Watchers & Locals
ShowStdNamespace,
ShowQtNamespace,
SortStructMembers,
AutoDerefPointers,
AlwaysAdjustLocalsColumnWidths,
MaximalStringLength,
DisplayStringLimit,
......@@ -162,7 +162,6 @@ enum DebuggerActionCode
AllPluginBreakpoints,
SelectedPluginBreakpoints,
AdjustBreakpointLocations,
AlwaysAdjustBreakpointsColumnWidths,
NoPluginBreakpoints,
SelectedPluginBreakpointsPattern,
BreakOnThrow,
......@@ -171,18 +170,6 @@ enum DebuggerActionCode
BreakOnFatal,
BreakOnAbort,
// Registers
AlwaysAdjustRegistersColumnWidths,
// Snapshots
AlwaysAdjustSnapshotsColumnWidths,
// Threads
AlwaysAdjustThreadsColumnWidths,
// Modules
AlwaysAdjustModulesColumnWidths,
// QML Tools
ShowQmlObjectTree,
ShowAppOnTop,
......
......@@ -57,7 +57,6 @@ ModulesTreeView::ModulesTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setSortingEnabled(true);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustModulesColumnWidths));
connect(this, SIGNAL(activated(QModelIndex)),
SLOT(moduleActivated(QModelIndex)));
......@@ -173,8 +172,6 @@ void ModulesTreeView::contextMenuEvent(QContextMenuEvent *ev)
engine->requestModuleSections(fileName);
else if (actShowDependencies && act == actShowDependencies)
QProcess::startDetached(QLatin1String("depends"), QStringList(fileName));
else
handleBaseContextAction(act);
}
ModulesWindow::ModulesWindow()
......
......@@ -257,8 +257,6 @@ void RegisterTreeView::contextMenuEvent(QContextMenuEvent *ev)
handler->setNumberBase(8);
else if (act == act2)
handler->setNumberBase(2);
else
handleBaseContextAction(act);
}
void RegisterTreeView::reloadRegisters()
......
......@@ -56,7 +56,6 @@ SnapshotTreeView::SnapshotTreeView(SnapshotHandler *handler)
{
m_snapshotHandler = handler;
setWindowTitle(tr("Snapshots"));
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustSnapshotsColumnWidths));
}
void SnapshotTreeView::rowActivated(const QModelIndex &index)
......@@ -101,8 +100,6 @@ void SnapshotTreeView::contextMenuEvent(QContextMenuEvent *ev)
m_snapshotHandler->createSnapshot(idx.row());
else if (act == actRemove)
removeSnapshot(idx.row());
else
handleBaseContextAction(act);
}
void SnapshotTreeView::removeSnapshot(int i)
......
......@@ -95,8 +95,6 @@ void SourceFilesTreeView::contextMenuEvent(QContextMenuEvent *ev)
engine->reloadSourceFiles();
else if (act == act2)
engine->gotoLocation(name);
else
handleBaseContextAction(act);
}
SourceFilesWindow::SourceFilesWindow()
......
......@@ -64,7 +64,6 @@ StackTreeView::StackTreeView(QWidget *parent)
: BaseTreeView(parent)
{
setWindowTitle(tr("Stack"));
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustStackColumnWidths));
connect(debuggerCore()->action(UseAddressInStackView), SIGNAL(toggled(bool)),
SLOT(showAddressColumn(bool)));
......@@ -248,8 +247,6 @@ void StackTreeView::contextMenuEvent(QContextMenuEvent *ev)
saveTaskFile(this, handler);
else if (act == additionalQmlStackAction)
engine->loadAdditionalQmlStack();
else
handleBaseContextAction(act);
}
void StackTreeView::copyContentsToClipboard()
......
......@@ -45,7 +45,6 @@ namespace Internal {
ThreadsTreeView::ThreadsTreeView()
{
setSortingEnabled(true);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustThreadsColumnWidths));
}
void ThreadsTreeView::rowActivated(const QModelIndex &index)
......@@ -57,20 +56,19 @@ void ThreadsTreeView::rowActivated(const QModelIndex &index)
void ThreadsTreeView::setModel(QAbstractItemModel *model)
{
BaseTreeView::setModel(model);
resizeColumnToContents(ThreadData::IdColumn);
resizeColumnToContents(ThreadData::LineColumn);
resizeColumnToContents(ThreadData::NameColumn);
resizeColumnToContents(ThreadData::StateColumn);
resizeColumnToContents(ThreadData::TargetIdColumn);
resizeColumnToContents(ThreadData::DetailsColumn);
// resizeColumnToContents(ThreadData::IdColumn);
// resizeColumnToContents(ThreadData::LineColumn);
// resizeColumnToContents(ThreadData::NameColumn);
// resizeColumnToContents(ThreadData::StateColumn);
// resizeColumnToContents(ThreadData::TargetIdColumn);
// resizeColumnToContents(ThreadData::DetailsColumn);
}
void ThreadsTreeView::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu menu;
addBaseContextActions(&menu);
QAction *act = menu.exec(ev->globalPos());
handleBaseContextAction(act);
menu.exec(ev->globalPos());
}
ThreadsWindow::ThreadsWindow()
......
......@@ -483,7 +483,6 @@ WatchTreeView::WatchTreeView(WatchType type, QWidget *parent)
setDragEnabled(true);
setAcceptDrops(true);
setDropIndicatorShown(true);
setAlwaysAdjustColumnsAction(debuggerCore()->action(AlwaysAdjustLocalsColumnWidths));
connect(this, SIGNAL(expanded(QModelIndex)),
SLOT(expandNode(QModelIndex)));
......
......@@ -48,9 +48,9 @@ class WatchTreeView : public BaseTreeView
Q_OBJECT
public:
explicit WatchTreeView(WatchType type, QWidget *parent = 0);
WatchType type() const { return m_type; }
void setModel(QAbstractItemModel *model);
void rowActivated(const QModelIndex &index);
void reset();
......
......@@ -100,13 +100,5 @@ CostDelegate::CostFormat CostView::costFormat() const
return m_costDelegate->format();
}
void CostView::contextMenuEvent(QContextMenuEvent *ev)
{
QMenu menu;
addBaseContextActions(&menu);
QAction *act = menu.exec(ev->globalPos());
handleBaseContextAction(act);
}
} // namespace Internal
} // namespace Valgrind
......@@ -60,8 +60,6 @@ public:
void setCostFormat(CostDelegate::CostFormat format);
CostDelegate::CostFormat costFormat() const;
void contextMenuEvent(QContextMenuEvent *ev);
private:
CostDelegate *m_costDelegate;
NameDelegate *m_nameDelegate;
......
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