2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2012-10-09 12:19:37 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2012-10-09 12:19:37 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-10-05 11:50:16 +02:00
|
|
|
**
|
2012-10-09 12:19:37 +02:00
|
|
|
****************************************************************************/
|
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
|
|
|
|
2015-11-10 16:59:02 +01:00
|
|
|
namespace Debugger {
|
2012-10-04 14:54:59 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2015-11-10 16:59:02 +01:00
|
|
|
// ConsoleItemModel
|
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();
|
2012-10-04 14:54:59 +02:00
|
|
|
const int pos = filename.lastIndexOf(QLatin1Char('/'));
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
filename = filename.mid(pos + 1);
|
|
|
|
|
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
m_maxSizeOfFileName = qMax(m_maxSizeOfFileName, fm.width(filename));
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
return fm.width(QLatin1String("88888"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
2015-11-10 16:59:02 +01:00
|
|
|
} // Debugger
|