2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2012-10-05 11:50:16 +02:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
#include "consoleitemmodel.h"
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
#include <QFontMetrics>
|
2013-04-03 10:43:37 +02:00
|
|
|
#include <QFont>
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
namespace Debugger::Internal {
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
ConsoleItemModel::ConsoleItemModel(QObject *parent) :
|
2018-07-23 22:28:49 +02:00
|
|
|
Utils::TreeModel<>(new ConsoleItem, parent)
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2015-08-21 17:33:53 +02:00
|
|
|
clear();
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleItemModel::clear()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2016-06-24 09:36:42 +02:00
|
|
|
Utils::TreeModel<>::clear();
|
2015-08-21 17:33:53 +02:00
|
|
|
appendItem(new ConsoleItem(ConsoleItem::InputType));
|
|
|
|
|
emit selectEditableRow(index(0, 0, QModelIndex()), QItemSelectionModel::ClearAndSelect);
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-05 15:25:13 +01:00
|
|
|
void ConsoleItemModel::setCanFetchMore(bool canFetchMore)
|
|
|
|
|
{
|
|
|
|
|
m_canFetchMore = canFetchMore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConsoleItemModel::canFetchMore(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return m_canFetchMore && TreeModel::canFetchMore(parent);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleItemModel::appendItem(ConsoleItem *item, int position)
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
if (position < 0)
|
2015-08-21 17:33:53 +02:00
|
|
|
position = rootItem()->childCount() - 1; // append before editable row
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
if (position < 0)
|
|
|
|
|
position = 0;
|
|
|
|
|
|
2015-08-21 17:33:53 +02:00
|
|
|
rootItem()->insertChild(position, item);
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
void ConsoleItemModel::shiftEditableRow()
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2015-08-21 17:33:53 +02:00
|
|
|
int position = rootItem()->childCount();
|
|
|
|
|
Q_ASSERT(position > 0);
|
2012-10-04 14:54:59 +02:00
|
|
|
|
2015-08-21 17:33:53 +02:00
|
|
|
appendItem(new ConsoleItem(ConsoleItem::InputType), position);
|
|
|
|
|
emit selectEditableRow(index(position, 0, QModelIndex()), QItemSelectionModel::ClearAndSelect);
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
int ConsoleItemModel::sizeOfFile(const QFont &font)
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
2015-08-21 17:33:53 +02:00
|
|
|
int lastReadOnlyRow = rootItem()->childCount();
|
|
|
|
|
lastReadOnlyRow -= 2; // skip editable row
|
2012-10-04 14:54:59 +02:00
|
|
|
if (lastReadOnlyRow < 0)
|
|
|
|
|
return 0;
|
2016-07-06 13:38:00 +02:00
|
|
|
QString filename = static_cast<ConsoleItem *>(rootItem()->childAt(lastReadOnlyRow))->file();
|
2018-10-07 22:38:47 +03:00
|
|
|
const int pos = filename.lastIndexOf('/');
|
2012-10-04 14:54:59 +02:00
|
|
|
if (pos != -1)
|
|
|
|
|
filename = filename.mid(pos + 1);
|
|
|
|
|
|
|
|
|
|
QFontMetrics fm(font);
|
2019-02-11 10:32:46 +01:00
|
|
|
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.horizontalAdvance(filename));
|
2012-10-04 14:54:59 +02:00
|
|
|
|
|
|
|
|
return m_maxSizeOfFileName;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
int ConsoleItemModel::sizeOfLineNumber(const QFont &font)
|
2012-10-04 14:54:59 +02:00
|
|
|
{
|
|
|
|
|
QFontMetrics fm(font);
|
2019-02-11 10:32:46 +01:00
|
|
|
return fm.horizontalAdvance("88888");
|
2012-10-04 14:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
} // Debugger::Internal
|