1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "openpagesmodel.h"
34 #include "helpviewer.h"
36 #include <QtCore/QUrl>
38 using namespace Help::Internal;
40 OpenPagesModel::OpenPagesModel(QObject *parent)
41 : QAbstractTableModel(parent)
45 int OpenPagesModel::rowCount(const QModelIndex &parent) const
47 return parent.isValid() ? 0 : m_pages.count();
50 int OpenPagesModel::columnCount(const QModelIndex &/*parent*/) const
55 QVariant OpenPagesModel::data(const QModelIndex &index, int role) const
57 if (!index.isValid() || index.row() >= rowCount()
58 || index.column() >= columnCount() - 1)
63 return m_pages.at(index.row())->source().toString();
64 case Qt::DisplayRole: {
65 QString title = m_pages.at(index.row())->title();
66 title.replace(QLatin1Char('&'), QLatin1String("&&"));
67 return title.isEmpty() ? tr("(Untitled)") : title;
75 void OpenPagesModel::addPage(const QUrl &url, qreal zoom)
77 beginInsertRows(QModelIndex(), rowCount(), rowCount());
78 HelpViewer *page = new HelpViewer(zoom);
79 connect(page, SIGNAL(titleChanged()), this, SLOT(handleTitleChanged()));
85 void OpenPagesModel::removePage(int index)
87 Q_ASSERT(index >= 0 && index < rowCount());
88 beginRemoveRows(QModelIndex(), index, index);
89 HelpViewer *page = m_pages.at(index);
90 m_pages.removeAt(index);
95 HelpViewer *OpenPagesModel::pageAt(int index) const
97 Q_ASSERT(index >= 0 && index < rowCount());
98 return m_pages.at(index);
101 void OpenPagesModel::handleTitleChanged()
103 HelpViewer *page = static_cast<HelpViewer *>(sender());
104 const int row = m_pages.indexOf(page);
105 Q_ASSERT(row != -1 );
106 const QModelIndex &item = index(row, 0);
107 emit dataChanged(item, item);