forked from qt-creator/qt-creator
Debugger: Adjust watcher column size to locals content
Change-Id: Iec6b4478862578397ee2b3953cd06730bd0db121 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -133,18 +133,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int suggestedColumnSize(int column) const
|
|
||||||
{
|
|
||||||
QHeaderView *h = q->header();
|
|
||||||
QTC_ASSERT(h, return -1);
|
|
||||||
QAbstractItemModel *m = q->model();
|
|
||||||
QTC_ASSERT(m, return -1);
|
|
||||||
|
|
||||||
QModelIndex a = q->indexAt(QPoint(1, 1));
|
void considerItems(int column, QModelIndex start, int *minimum, bool single) const
|
||||||
|
{
|
||||||
|
QModelIndex a = start;
|
||||||
a = a.sibling(a.row(), column);
|
a = a.sibling(a.row(), column);
|
||||||
QFontMetrics fm = q->fontMetrics();
|
QFontMetrics fm = q->fontMetrics();
|
||||||
int minimum = fm.width(m->headerData(column, Qt::Horizontal).toString());
|
|
||||||
const int ind = q->indentation();
|
const int ind = q->indentation();
|
||||||
|
QAbstractItemModel *m = q->model();
|
||||||
for (int i = 0; i < 100 && a.isValid(); ++i) {
|
for (int i = 0; i < 100 && a.isValid(); ++i) {
|
||||||
const QString s = m->data(a).toString();
|
const QString s = m->data(a).toString();
|
||||||
int w = fm.width(s) + 10;
|
int w = fm.width(s) + 10;
|
||||||
@@ -152,10 +148,29 @@ public:
|
|||||||
for (QModelIndex b = a.parent(); b.isValid(); b = b.parent())
|
for (QModelIndex b = a.parent(); b.isValid(); b = b.parent())
|
||||||
w += ind;
|
w += ind;
|
||||||
}
|
}
|
||||||
if (w > minimum)
|
if (w > *minimum)
|
||||||
minimum = w;
|
*minimum = w;
|
||||||
|
if (single)
|
||||||
|
break;
|
||||||
a = q->indexBelow(a);
|
a = q->indexBelow(a);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int suggestedColumnSize(int column) const
|
||||||
|
{
|
||||||
|
QHeaderView *h = q->header();
|
||||||
|
QTC_ASSERT(h, return -1);
|
||||||
|
QAbstractItemModel *m = q->model();
|
||||||
|
QTC_ASSERT(m, return -1);
|
||||||
|
|
||||||
|
QFontMetrics fm = q->fontMetrics();
|
||||||
|
int minimum = fm.width(m->headerData(column, Qt::Horizontal).toString()) + 2 * fm.width(QLatin1Char('m'));
|
||||||
|
considerItems(column, q->indexAt(QPoint(1, 1)), &minimum, false);
|
||||||
|
|
||||||
|
QVariant extraIndices = m->data(QModelIndex(), BaseTreeView::ExtraIndicesForColumnWidth);
|
||||||
|
foreach (const QModelIndex &a, extraIndices.value<QModelIndexList>())
|
||||||
|
considerItems(column, a, &minimum, true);
|
||||||
|
|
||||||
return minimum;
|
return minimum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ class QTCREATOR_UTILS_EXPORT BaseTreeView : public TreeView
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum { ExtraIndicesForColumnWidth = 12734 };
|
||||||
|
|
||||||
BaseTreeView(QWidget *parent = 0);
|
BaseTreeView(QWidget *parent = 0);
|
||||||
~BaseTreeView();
|
~BaseTreeView();
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ public:
|
|||||||
static QString nameForFormat(int format);
|
static QString nameForFormat(int format);
|
||||||
TypeFormatList typeFormatList(const WatchData &value) const;
|
TypeFormatList typeFormatList(const WatchData &value) const;
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &idx, int role) const;
|
||||||
bool setData(const QModelIndex &idx, const QVariant &value, int role);
|
bool setData(const QModelIndex &idx, const QVariant &value, int role);
|
||||||
|
|
||||||
void insertDataItem(const WatchData &data);
|
void insertDataItem(const WatchData &data);
|
||||||
@@ -850,6 +851,19 @@ QVariant WatchItem::data(int column, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant WatchModel::data(const QModelIndex &idx, int role) const
|
||||||
|
{
|
||||||
|
if (role == BaseTreeView::ExtraIndicesForColumnWidth) {
|
||||||
|
QModelIndexList l;
|
||||||
|
foreach (TreeItem *item, m_watchRoot->children())
|
||||||
|
l.append(indexFromItem(item));
|
||||||
|
foreach (TreeItem *item, m_returnRoot->children())
|
||||||
|
l.append(indexFromItem(item));
|
||||||
|
return QVariant::fromValue(l);
|
||||||
|
}
|
||||||
|
return WatchModelBase::data(idx, role);
|
||||||
|
}
|
||||||
|
|
||||||
bool WatchModel::setData(const QModelIndex &idx, const QVariant &value, int role)
|
bool WatchModel::setData(const QModelIndex &idx, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!idx.isValid())
|
if (!idx.isValid())
|
||||||
|
|||||||
Reference in New Issue
Block a user