Commit bb13b69e authored by Friedemann Kleint's avatar Friedemann Kleint

Further header cleanup.

Introduce some more private classes for the coreplugin,
use header include convention
<QtModule/QClass>, de-qobjectify VariableManager.
parent 64aeb904
#ifndef PLUGINCOLLECTION_H
#define PLUGINCOLLECTION_H
#include <QList>
#include <QString>
#include "extensionsystem_global.h"
#include <QtCore/QList>
#include <QtCore/QString>
namespace ExtensionSystem {
class PluginSpec;
......@@ -26,6 +26,6 @@ private:
};
}
} // namespace ExtensionSystem
#endif // PLUGINCOLLECTION_H
......@@ -30,12 +30,13 @@
#include "crumblepath.h"
#include "stylehelper.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QStyle>
#include <QResizeEvent>
#include <QPainter>
#include <QImage>
#include <QtCore/QList>
#include <QtGui/QHBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QStyle>
#include <QtGui/QResizeEvent>
#include <QtGui/QPainter>
#include <QtGui/QImage>
namespace Utils {
......@@ -177,31 +178,43 @@ void CrumblePathButton::setSegmentType(int type)
m_textPos.setX(useLeftPadding ? 18 : 4);
}
struct CrumblePathPrivate {
explicit CrumblePathPrivate(CrumblePath *q);
QColor m_baseColor;
QList<CrumblePathButton*> m_buttons;
QWidget *m_background;
};
CrumblePathPrivate::CrumblePathPrivate(CrumblePath *q) :
m_baseColor(StyleHelper::baseColor()),
m_background(new QWidget(q))
{
}
//
// CrumblePath
//
CrumblePath::CrumblePath(QWidget *parent) :
QWidget(parent), m_background(new QWidget(this))
QWidget(parent), d(new CrumblePathPrivate(this))
{
m_baseColor = StyleHelper::baseColor();
setMinimumHeight(25);
setMaximumHeight(25);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
setBackgroundStyle();
m_background->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
d->m_background->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
}
CrumblePath::~CrumblePath()
{
qDeleteAll(m_buttons);
m_buttons.clear();
qDeleteAll(d->m_buttons);
d->m_buttons.clear();
}
void CrumblePath::setBackgroundStyle()
{
m_background->setStyleSheet("QWidget { background-color:" + m_baseColor.name() + ";}");
d->m_background->setStyleSheet("QWidget { background-color:" + d->m_baseColor.name() + ";}");
}
void CrumblePath::pushElement(const QString &title)
......@@ -212,38 +225,38 @@ void CrumblePath::pushElement(const QString &title)
connect(newButton, SIGNAL(customContextMenuRequested(QPoint)), SLOT(mapContextMenuRequestToIndex()));
int segType = CrumblePathButton::MiddleSegment;
if (!m_buttons.isEmpty()) {
if (m_buttons.length() == 1)
if (!d->m_buttons.isEmpty()) {
if (d->m_buttons.length() == 1)
segType = segType | CrumblePathButton::FirstSegment;
m_buttons.last()->setSegmentType(segType);
d->m_buttons.last()->setSegmentType(segType);
} else {
segType = CrumblePathButton::FirstSegment | CrumblePathButton::LastSegment;
newButton->setSegmentType(segType);
}
m_buttons.append(newButton);
d->m_buttons.append(newButton);
resizeButtons();
}
void CrumblePath::popElement()
{
QWidget *last = m_buttons.last();
m_buttons.removeLast();
QWidget *last = d->m_buttons.last();
d->m_buttons.removeLast();
last->setParent(0);
last->deleteLater();
int segType = CrumblePathButton::MiddleSegment | CrumblePathButton::LastSegment;
if (!m_buttons.isEmpty()) {
if (m_buttons.length() == 1)
if (!d->m_buttons.isEmpty()) {
if (d->m_buttons.length() == 1)
segType = CrumblePathButton::FirstSegment | CrumblePathButton::LastSegment;
m_buttons.last()->setSegmentType(segType);
d->m_buttons.last()->setSegmentType(segType);
}
resizeButtons();
}
void CrumblePath::clear()
{
while (!m_buttons.isEmpty()) {
while (!d->m_buttons.isEmpty()) {
popElement();
}
}
......@@ -259,21 +272,21 @@ void CrumblePath::resizeButtons()
int buttonMaxWidth = 0;
int totalWidthLeft = width();
if (m_buttons.length() >= 1) {
if (d->m_buttons.length() >= 1) {
QPoint nextElementPosition(0,0);
m_buttons[0]->raise();
d->m_buttons[0]->raise();
// rearrange all items so that the first item is on top (added last).
for(int i = 0; i < m_buttons.length() ; ++i) {
CrumblePathButton *button = m_buttons[i];
for(int i = 0; i < d->m_buttons.length() ; ++i) {
CrumblePathButton *button = d->m_buttons[i];
QFontMetrics fm(button->font());
buttonMinWidth = ArrowBorderSize + fm.width(button->text()) + ArrowBorderSize * 2 ;
buttonMaxWidth = (totalWidthLeft + ArrowBorderSize * (m_buttons.length() - i)) / (m_buttons.length() - i);
buttonMaxWidth = (totalWidthLeft + ArrowBorderSize * (d->m_buttons.length() - i)) / (d->m_buttons.length() - i);
if (buttonMinWidth > buttonMaxWidth && i < m_buttons.length() - 1) {
if (buttonMinWidth > buttonMaxWidth && i < d->m_buttons.length() - 1) {
buttonMinWidth = buttonMaxWidth;
} else if (i > 3 && (i == m_buttons.length() - 1)) {
} else if (i > 3 && (i == d->m_buttons.length() - 1)) {
buttonMinWidth = width() - nextElementPosition.x();
buttonMaxWidth = buttonMinWidth;
}
......@@ -287,20 +300,20 @@ void CrumblePath::resizeButtons()
button->show();
if (i > 0)
button->stackUnder(m_buttons[i - 1]);
button->stackUnder(d->m_buttons[i - 1]);
}
}
m_background->setGeometry(0,0, width(), height());
m_background->update();
d->m_background->setGeometry(0,0, width(), height());
d->m_background->update();
}
void CrumblePath::mapClickToIndex()
{
QObject *element = sender();
for (int i = 0; i < m_buttons.length(); ++i) {
if (m_buttons[i] == element) {
for (int i = 0; i < d->m_buttons.length(); ++i) {
if (d->m_buttons[i] == element) {
emit elementClicked(i);
return;
}
......@@ -310,8 +323,8 @@ void CrumblePath::mapClickToIndex()
void CrumblePath::mapContextMenuRequestToIndex()
{
QObject *element = sender();
for (int i = 0; i < m_buttons.length(); ++i) {
if (m_buttons[i] == element) {
for (int i = 0; i < d->m_buttons.length(); ++i) {
if (d->m_buttons[i] == element) {
emit elementContextMenuRequested(i);
return;
}
......@@ -320,8 +333,8 @@ void CrumblePath::mapContextMenuRequestToIndex()
void CrumblePath::paintEvent(QPaintEvent *event)
{
if (StyleHelper::baseColor() != m_baseColor) {
m_baseColor = StyleHelper::baseColor();
if (StyleHelper::baseColor() != d->m_baseColor) {
d->m_baseColor = StyleHelper::baseColor();
setBackgroundStyle();
}
......
......@@ -30,15 +30,15 @@
#ifndef CRUMBLEPATH_H
#define CRUMBLEPATH_H
#include <QWidget>
#include <QList>
#include "utils_global.h"
#include <QtGui/QWidget>
QT_FORWARD_DECLARE_CLASS(QResizeEvent);
namespace Utils {
class CrumblePathButton;
struct CrumblePathPrivate;
class QTCREATOR_UTILS_EXPORT CrumblePath : public QWidget
{
......@@ -69,9 +69,7 @@ private:
void setBackgroundStyle();
private:
QColor m_baseColor;
QList<CrumblePathButton*> m_buttons;
QWidget *m_background;
QScopedPointer<CrumblePathPrivate> d;
};
} // namespace QmlViewer
......
#include "debuggerlanguagechooser.h"
#include <QHBoxLayout>
#include <QCheckBox>
#include <QSpinBox>
#include <QLabel>
#include <QtGui/QHBoxLayout>
#include <QtGui/QCheckBox>
#include <QtGui/QSpinBox>
#include <QtGui/QLabel>
namespace Utils {
......
#ifndef DEBUGGERLANGUAGECHOOSER_H
#define DEBUGGERLANGUAGECHOOSER_H
#include <QWidget>
#include "utils_global.h"
#include <QtGui/QWidget>
QT_FORWARD_DECLARE_CLASS(QCheckBox);
QT_FORWARD_DECLARE_CLASS(QLabel);
QT_FORWARD_DECLARE_CLASS(QSpinBox);
......
......@@ -31,7 +31,7 @@
#define TREEWIDGETCOLUMNSTRETCHER_H
#include "utils_global.h"
#include <QObject>
#include <QtCore/QObject>
QT_BEGIN_NAMESPACE
class QTreeWidget;
......
......@@ -35,6 +35,7 @@
#include "openwithdialog.h"
#include "filemanager.h"
#include "icore.h"
#include "ieditor.h"
#include "iversioncontrol.h"
#include "mimedatabase.h"
#include "tabpositionindicator.h"
......@@ -435,11 +436,7 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
connect(m_d->m_openInExternalEditorAction, SIGNAL(triggered()), this, SLOT(openInExternalEditor()));
// Connect to VariableManager for CURRENT_DOCUMENT variable setting
VariableManager *vm = VariableManager::instance();
connect(this, SIGNAL(currentEditorChanged(Core::IEditor *)),
vm, SLOT(updateCurrentDocument(Core::IEditor *)));
VariableManager::initEditorManagerConnections();
// other setup
m_d->m_splitter = new SplitterOrView(m_d->m_editorModel);
m_d->m_view = m_d->m_splitter->view();
......
......@@ -38,21 +38,44 @@ Q_DECLARE_METATYPE(Core::IEditor*)
namespace Core {
OpenEditorsModel::OpenEditorsModel(QObject *parent) :
QAbstractItemModel(parent),
struct OpenEditorsModelPrivate {
OpenEditorsModelPrivate();
const QIcon m_lockedIcon;
const QIcon m_unlockedIcon;
QList<OpenEditorsModel::Entry> m_editors;
QList<IEditor *> m_duplicateEditors;
};
OpenEditorsModelPrivate::OpenEditorsModelPrivate() :
m_lockedIcon(QLatin1String(":/core/images/locked.png")),
m_unlockedIcon(QLatin1String(":/core/images/unlocked.png"))
{
}
OpenEditorsModel::Entry::Entry() :
editor(0)
{
}
OpenEditorsModel::OpenEditorsModel(QObject *parent) :
QAbstractItemModel(parent), d(new OpenEditorsModelPrivate)
{
}
OpenEditorsModel::~OpenEditorsModel()
{
}
QIcon OpenEditorsModel::lockedIcon() const
{
return m_lockedIcon;
return d->m_lockedIcon;
}
QIcon OpenEditorsModel::unlockedIcon() const
{
return m_unlockedIcon;
return d->m_unlockedIcon;
}
QString OpenEditorsModel::Entry::fileName() const {
......@@ -77,14 +100,14 @@ int OpenEditorsModel::columnCount(const QModelIndex &parent) const
int OpenEditorsModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid())
return m_editors.count();
return d->m_editors.count();
return 0;
}
QList<IEditor *> OpenEditorsModel::editors() const
{
QList<IEditor *> result;
foreach (const Entry &entry, m_editors)
foreach (const Entry &entry, d->m_editors)
if (entry.editor)
result += entry.editor;
return result;
......@@ -96,7 +119,7 @@ void OpenEditorsModel::addEditor(IEditor *editor, bool isDuplicate)
return;
if (isDuplicate) {
m_duplicateEditors.append(editor);
d->m_duplicateEditors.append(editor);
return;
}
......@@ -116,8 +139,8 @@ void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString
QModelIndex OpenEditorsModel::firstRestoredEditor() const
{
for (int i = 0; i < m_editors.count(); ++i)
if (!m_editors.at(i).editor)
for (int i = 0; i < d->m_editors.count(); ++i)
if (!d->m_editors.at(i).editor)
return createIndex(i, 0);
return QModelIndex();
}
......@@ -128,8 +151,8 @@ void OpenEditorsModel::addEntry(const Entry &entry)
int previousIndex = findFileName(fileName);
if (previousIndex >= 0) {
if (entry.editor && m_editors.at(previousIndex).editor == 0) {
m_editors[previousIndex] = entry;
if (entry.editor && d->m_editors.at(previousIndex).editor == 0) {
d->m_editors[previousIndex] = entry;
connect(entry.editor, SIGNAL(changed()), this, SLOT(itemChanged()));
}
return;
......@@ -137,13 +160,13 @@ void OpenEditorsModel::addEntry(const Entry &entry)
int index;
QString displayName = entry.displayName();
for (index = 0; index < m_editors.count(); ++index) {
if (displayName < m_editors.at(index).displayName())
for (index = 0; index < d->m_editors.count(); ++index) {
if (displayName < d->m_editors.at(index).displayName())
break;
}
beginInsertRows(QModelIndex(), index, index);
m_editors.insert(index, entry);
d->m_editors.insert(index, entry);
if (entry.editor)
connect(entry.editor, SIGNAL(changed()), this, SLOT(itemChanged()));
endInsertRows();
......@@ -152,8 +175,8 @@ void OpenEditorsModel::addEntry(const Entry &entry)
int OpenEditorsModel::findEditor(IEditor *editor) const
{
for (int i = 0; i < m_editors.count(); ++i)
if (m_editors.at(i).editor == editor)
for (int i = 0; i < d->m_editors.count(); ++i)
if (d->m_editors.at(i).editor == editor)
return i;
return -1;
}
......@@ -162,8 +185,8 @@ int OpenEditorsModel::findFileName(const QString &filename) const
{
if (filename.isEmpty())
return -1;
for (int i = 0; i < m_editors.count(); ++i) {
if (m_editors.at(i).fileName() == filename)
for (int i = 0; i < d->m_editors.count(); ++i) {
if (d->m_editors.at(i).fileName() == filename)
return i;
}
return -1;
......@@ -171,12 +194,12 @@ int OpenEditorsModel::findFileName(const QString &filename) const
void OpenEditorsModel::removeEditor(IEditor *editor)
{
m_duplicateEditors.removeAll(editor);
d->m_duplicateEditors.removeAll(editor);
int idx = findEditor(editor);
if (idx < 0)
return;
beginRemoveRows(QModelIndex(), idx, idx);
m_editors.removeAt(idx);
d->m_editors.removeAt(idx);
endRemoveRows();
disconnect(editor, SIGNAL(changed()), this, SLOT(itemChanged()));
}
......@@ -186,9 +209,9 @@ void OpenEditorsModel::removeEditor(const QModelIndex &index)
int idx = index.row();
if (idx < 0)
return;
IEditor *editor= m_editors.at(idx).editor;
IEditor *editor= d->m_editors.at(idx).editor;
beginRemoveRows(QModelIndex(), idx, idx);
m_editors.removeAt(idx);
d->m_editors.removeAt(idx);
endRemoveRows();
if (editor)
disconnect(editor, SIGNAL(changed()), this, SLOT(itemChanged()));
......@@ -196,10 +219,10 @@ void OpenEditorsModel::removeEditor(const QModelIndex &index)
void OpenEditorsModel::removeAllRestoredEditors()
{
for (int i = m_editors.count()-1; i >= 0; --i) {
if (!m_editors.at(i).editor) {
for (int i = d->m_editors.count()-1; i >= 0; --i) {
if (!d->m_editors.at(i).editor) {
beginRemoveRows(QModelIndex(), i, i);
m_editors.removeAt(i);
d->m_editors.removeAt(i);
endRemoveRows();
}
}
......@@ -208,9 +231,9 @@ void OpenEditorsModel::removeAllRestoredEditors()
QList<OpenEditorsModel::Entry> OpenEditorsModel::restoredEditors() const
{
QList<Entry> result;
for (int i = m_editors.count()-1; i >= 0; --i) {
if (!m_editors.at(i).editor) {
result.append(m_editors.at(i));
for (int i = d->m_editors.count()-1; i >= 0; --i) {
if (!d->m_editors.at(i).editor) {
result.append(d->m_editors.at(i));
}
}
return result;
......@@ -218,13 +241,13 @@ QList<OpenEditorsModel::Entry> OpenEditorsModel::restoredEditors() const
bool OpenEditorsModel::isDuplicate(IEditor *editor) const
{
return editor && m_duplicateEditors.contains(editor);
return editor && d->m_duplicateEditors.contains(editor);
}
IEditor *OpenEditorsModel::originalForDuplicate(IEditor *duplicate) const
{
IFile *file = duplicate->file();
foreach(const Entry &e, m_editors)
foreach(const Entry &e, d->m_editors)
if (e.editor && e.editor->file() == file)
return e.editor;
return 0;
......@@ -234,7 +257,7 @@ QList<IEditor *> OpenEditorsModel::duplicatesFor(IEditor *editor) const
{
QList<IEditor *> result;
IFile *file = editor->file();
foreach(IEditor *e, m_duplicateEditors)
foreach(IEditor *e, d->m_duplicateEditors)
if (e->file() == file)
result += e;
return result;
......@@ -246,9 +269,9 @@ void OpenEditorsModel::makeOriginal(IEditor *duplicate)
IEditor *original = originalForDuplicate(duplicate);
Q_ASSERT(original);
int i = findEditor(original);
m_editors[i].editor = duplicate;
m_duplicateEditors.removeOne(duplicate);
m_duplicateEditors.append(original);
d->m_editors[i].editor = duplicate;
d->m_duplicateEditors.removeOne(duplicate);
d->m_duplicateEditors.append(original);
disconnect(original, SIGNAL(changed()), this, SLOT(itemChanged()));
connect(duplicate, SIGNAL(changed()), this, SLOT(itemChanged()));
}
......@@ -265,7 +288,7 @@ void OpenEditorsModel::emitDataChanged(IEditor *editor)
QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent)
if (column < 0 || column > 1 || row < 0 || row >= m_editors.count())
if (column < 0 || column > 1 || row < 0 || row >= d->m_editors.count())
return QModelIndex();
return createIndex(row, column);
}
......@@ -274,7 +297,7 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole))
return QVariant();
Entry e = m_editors.at(index.row());
Entry e = d->m_editors.at(index.row());
switch (role) {
case Qt::DisplayRole:
return (e.editor && e.editor->file()->isModified())
......@@ -282,7 +305,7 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
: e.displayName();
case Qt::DecorationRole:
return (e.editor && e.editor->file()->isReadOnly())
? m_lockedIcon : QIcon();
? d->m_lockedIcon : QIcon();
case Qt::ToolTipRole:
return e.fileName().isEmpty()
? e.displayName()
......@@ -307,9 +330,9 @@ QModelIndex OpenEditorsModel::indexOf(IEditor *editor) const
QString OpenEditorsModel::displayNameForFile(IFile *file) const
{
for (int i = 0; i < m_editors.count(); ++i)
if (m_editors.at(i).editor && m_editors.at(i).editor->file() == file)
return m_editors.at(i).editor->displayName();
for (int i = 0; i < d->m_editors.count(); ++i)
if (d->m_editors.at(i).editor && d->m_editors.at(i).editor->file() == file)
return d->m_editors.at(i).editor->displayName();
return QString();
}
......@@ -318,4 +341,14 @@ void OpenEditorsModel::itemChanged()
emitDataChanged(qobject_cast<IEditor*>(sender()));
}
QList<OpenEditorsModel::Entry> OpenEditorsModel::entries() const
{
return d->m_editors;
}
IEditor *OpenEditorsModel::editorAt(int row) const
{
return d->m_editors.at(row).editor;
}
} // namespace Core
<
......@@ -33,10 +33,13 @@
#include "../core_global.h"
#include <QtCore/QAbstractItemModel>
#include <QtGui/QIcon>
#include <QtCore/QScopedPointer>
QT_FORWARD_DECLARE_CLASS(QIcon)
namespace Core {
struct OpenEditorsModelPrivate;
class IEditor;