Commit 5ab250fe authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

purge ProEditorModel and ProCommandManager

they were remnants of the pro editor, which was removed long time ago.
they were still used for automatic editing of pro files, but were
totally overengineered for that purpose (removed 1300 LOC, added 40).
parent 547912af
......@@ -27,8 +27,6 @@
**
**************************************************************************/
#include "proeditormodel.h"
#include "profilereader.h"
#include "prowriter.h"
#include "qt4nodes.h"
......@@ -553,6 +551,23 @@ bool Qt4PriFileNode::saveModifiedEditors(const QString &path)
return true;
}
static void findProVariables(ProBlock *block, const QStringList &vars,
QList<ProVariable *> *proVars)
{
foreach (ProItem *item, block->items()) {
if (item->kind() == ProItem::BlockKind) {
ProBlock *subBlock = static_cast<ProBlock *>(item);
if (subBlock->blockKind() == ProBlock::VariableKind) {
ProVariable *proVar = static_cast<ProVariable*>(subBlock);
if (vars.contains(proVar->variable()))
*proVars << proVar;
} else {
findProVariables(subBlock, vars, proVars);
}
}
}
}
void Qt4PriFileNode::changeFiles(const FileType fileType,
const QStringList &filePaths,
QStringList *notChanged,
......@@ -581,28 +596,24 @@ void Qt4PriFileNode::changeFiles(const FileType fileType,
return;
}
// Check if file is readonly
ProEditorModel proModel;
proModel.setProFiles(QList<ProFile*>() << includeFile);
const QStringList vars = varNames(fileType);
QDir priFileDir = QDir(m_projectDir);
if (change == AddToProFile) {
// root item "<Global Scope>"
const QModelIndex root = proModel.index(0, 0);
ProVariable *proVar = 0;
// Check if variable item exists as child of root item
ProVariable *proVar = 0;
int row = 0;
for (; row < proModel.rowCount(root); ++row) {
if ((proVar = proModel.proVariable(root.child(row, 0)))) {
if (vars.contains(proVar->variable())
&& proVar->variableOperator() != ProVariable::RemoveOperator
&& proVar->variableOperator() != ProVariable::ReplaceOperator)
break;
else
foreach (ProItem *item, includeFile->items()) {
if (item->kind() == ProItem::BlockKind) {
ProBlock *block = static_cast<ProBlock *>(item);
if (block->blockKind() == ProBlock::VariableKind) {
proVar = static_cast<ProVariable*>(block);
if (vars.contains(proVar->variable())
&& proVar->variableOperator() != ProVariable::RemoveOperator
&& proVar->variableOperator() != ProVariable::ReplaceOperator)
break;
proVar = 0;
}
}
}
......@@ -610,54 +621,45 @@ void Qt4PriFileNode::changeFiles(const FileType fileType,
// Create & append new variable item
// TODO: This will always store e.g. a source file in SOURCES and not OBJECTIVE_SOURCES
proVar = new ProVariable(vars.first(), proModel.proBlock(root));
proVar = new ProVariable(vars.first(), includeFile);
proVar->setVariableOperator(ProVariable::AddOperator);
proModel.insertItem(proVar, row, root);
includeFile->appendItem(proVar);
}
const QModelIndex varIndex = root.child(row, 0);
const QString &proFilePath = includeFile->fileName();
foreach (const QString &filePath, filePaths) {
if (filePath == proFilePath)
continue;
const QString &relativeFilePath = priFileDir.relativeFilePath(filePath);
proModel.insertItem(new ProValue(relativeFilePath, proVar),
proModel.rowCount(varIndex), varIndex);
proVar->appendItem(new ProValue(relativeFilePath, proVar));
notChanged->removeOne(filePath);
}
} else { // RemoveFromProFile
QList<QModelIndex> proVarIndexes = proModel.findVariables(vars);
QList<QModelIndex> toRemove;
QList<ProVariable *> proVars;
findProVariables(includeFile, vars, &proVars);
QStringList relativeFilePaths;
foreach (const QString &absoluteFilePath, filePaths)
relativeFilePaths << priFileDir.relativeFilePath(absoluteFilePath);
foreach (const QModelIndex &proVarIndex, proVarIndexes) {
ProVariable *proVar = proModel.proVariable(proVarIndex);
foreach (ProVariable *proVar, proVars) {
if (proVar->variableOperator() != ProVariable::RemoveOperator
&& proVar->variableOperator() != ProVariable::ReplaceOperator) {
for (int row = proModel.rowCount(proVarIndex) - 1; row >= 0; --row) {
QModelIndex itemIndex = proModel.index(row, 0, proVarIndex);
ProItem *item = proModel.proItem(itemIndex);
QList<ProItem *> values = proVar->items();
for (int i = values.count(); --i >= 0; ) {
ProItem *item = values.at(i);
if (item->kind() == ProItem::ValueKind) {
ProValue *val = static_cast<ProValue *>(item);
int index = relativeFilePaths.indexOf(val->value());
if (index != -1) {
toRemove.append(itemIndex);
delete values.takeAt(i);
notChanged->removeAt(index);
}
}
}
proVar->setItems(values);
}
}
foreach (const QModelIndex &index, toRemove) {
proModel.removeItem(index);
}
}
// save file
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "procommandmanager.h"
using namespace Qt4ProjectManager::Internal;
ProCommandGroup::ProCommandGroup(const QString &name)
: m_name(name)
{ }
ProCommandGroup::~ProCommandGroup()
{
qDeleteAll(m_commands);
}
void ProCommandGroup::appendCommand(ProCommand *cmd)
{
m_commands.append(cmd);
}
void ProCommandGroup::undo()
{
for (int i = m_commands.count(); i > 0; --i)
m_commands[i-1]->undo();
}
void ProCommandGroup::redo()
{
for (int i = 0; i < m_commands.count(); ++i)
m_commands[i]->redo();
}
ProCommandManager::ProCommandManager(QObject *parent)
: QObject(parent)
{
m_savepoint = 0;
m_pos = 0;
m_group = 0;
}
ProCommandManager::~ProCommandManager()
{
qDeleteAll(m_groups);
}
void ProCommandManager::beginGroup(const QString &name)
{
Q_ASSERT(!m_group);
if (m_pos != m_groups.count()) {
int removecount = m_groups.count() - m_pos;
for (int i = 0; i < removecount; ++i)
delete m_groups.takeLast();
m_pos = m_groups.count();
}
m_group = new ProCommandGroup(name);
}
bool ProCommandManager::hasGroup() const
{
return m_group != 0;
}
void ProCommandManager::endGroup()
{
Q_ASSERT(m_group);
m_groups.append(m_group);
m_pos = m_groups.count();
m_group = 0;
emit modified();
}
bool ProCommandManager::command(ProCommand *cmd)
{
Q_ASSERT(m_group);
if (cmd->redo()) {
m_group->appendCommand(cmd);
return true;
}
return false;
}
void ProCommandManager::undo()
{
if (canUndo()) {
--m_pos;
m_groups[m_pos]->undo();
}
emit modified();
}
void ProCommandManager::redo()
{
if (canRedo()) {
m_groups[m_pos]->redo();
++m_pos;
}
emit modified();
}
bool ProCommandManager::isDirty() const
{
if (m_groups.isEmpty())
return false;
if (m_pos != 0 && m_groups.at(m_pos - 1) == m_savepoint)
return false;
return true;
}
void ProCommandManager::notifySave()
{
if (m_pos > 0)
m_savepoint = m_groups.at(m_pos - 1);
}
bool ProCommandManager::canUndo() const
{
return !m_groups.isEmpty() && m_pos > 0;
}
bool ProCommandManager::canRedo() const
{
return m_groups.count() > m_pos;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef PROCOMMANDMANAGER_H
#define PROCOMMANDMANAGER_H
#include "namespace_global.h"
#include <QtCore/QModelIndex>
QT_BEGIN_NAMESPACE
class ProItem;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class ProCommand
{
public:
virtual ~ProCommand() {}
virtual bool redo() = 0;
virtual void undo() = 0;
};
class ProCommandGroup
{
public:
ProCommandGroup(const QString &name);
~ProCommandGroup();
void appendCommand(ProCommand *cmd);
void undo();
void redo();
private:
QString m_name;
QList<ProCommand *> m_commands;
};
class ProCommandManager : public QObject
{
Q_OBJECT
public:
ProCommandManager(QObject *parent);
~ProCommandManager();
void beginGroup(const QString &name);
void endGroup();
// excutes the Command and adds it to the open group
bool command(ProCommand *cmd);
bool hasGroup() const;
bool isDirty() const;
void notifySave();
bool canUndo() const;
bool canRedo() const;
public slots:
void undo();
void redo();
signals:
void modified();
private:
ProCommandGroup *m_group;
QList<ProCommandGroup *> m_groups;
int m_pos;
ProCommandGroup *m_savepoint;
};
} //namespace Internal
} //namespace Qt4ProjectManager
#endif // PROCOMMANDMANAGER_H
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef PROEDITORMODEL_H
#define PROEDITORMODEL_H
#include "namespace_global.h"
#include <QtCore/QAbstractItemModel>
#include <QtCore/QList>
#include <QtCore/QSet>
#include <QtCore/QStringList>
#include <QtGui/QSortFilterProxyModel>
QT_BEGIN_NAMESPACE
class ProBlock;
class ProFile;
class ProItem;
class ProVariable;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class ProCommandManager;
class ProEditorModel : public QAbstractItemModel
{
Q_OBJECT
public:
ProEditorModel(QObject *parent = 0);
~ProEditorModel();
ProCommandManager *cmdManager() const;
void setProFiles(QList<ProFile*> proFiles);
QList<ProFile*> proFiles() const;
QList<QModelIndex> findVariables(const QStringList &varname, const QModelIndex &parent = QModelIndex()) const;
QList<QModelIndex> findBlocks(const QModelIndex &parent = QModelIndex()) const;
bool insertItem(ProItem *item, int row, const QModelIndex &parent);
bool removeItem(const QModelIndex &index);
ProItem *proItem(const QModelIndex &index) const;
ProBlock *proBlock(const QModelIndex &index) const;
ProVariable *proVariable(const QModelIndex &index) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QMimeData *mimeData(const QModelIndexList &indexes) const;
inline QList<ProFile*> changed() const { return m_changed.toList(); }
protected:
ProItem *createExpressionItem(QString &str) const;
QString blockName(ProBlock *block) const;
ProBlock *scopeContents(ProBlock *block) const;
QString expressionToString(ProBlock *block, bool display = false) const;
QList<ProItem *> stringToExpression(const QString &exp) const;
bool insertModelItem(ProItem *item, int row, const QModelIndex &parent);
bool removeModelItem(const QModelIndex &index);
private:
void markProFileModified(QModelIndex index);
ProCommandManager *m_cmdmanager;
QList<ProFile*> m_proFiles;
QSet<ProFile*> m_changed;
friend class ProAddCommand;
friend class ProRemoveCommand;
friend class ChangeProScopeCommand;
friend class ChangeProAdvancedCommand;
};
class ProScopeFilter : public QSortFilterProxyModel
{
Q_OBJECT
public:
enum CheckableType {
None,
Variable,
Blocks
};
void setVariableFilter(const QStringList &vars);
void setCheckable( CheckableType ct );
// returns the checked (source) indexes
QList<QModelIndex> checkedIndexes() const;
Qt::ItemFlags flags(const QModelIndex &index) const;
ProScopeFilter(QObject *parent);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
protected:
ProVariable *sourceVariable(const QModelIndex &index) const;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
private:
CheckableType m_checkable;
QStringList m_vars;
QMap<QModelIndex, bool> m_checkStates;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // PROEDITORMODEL_H
......@@ -7,8 +7,6 @@ DEPENDPATH *= $$PWD $$PWD/..
# Input
HEADERS += \
abstractproitemvisitor.h \
procommandmanager.h \
proeditormodel.h \
profileevaluator.h \
proitems.h \
prowriter.h \
......@@ -16,8 +14,6 @@ HEADERS += \
$$PWD/../namespace_global.h
SOURCES += \
procommandmanager.cpp \
proeditormodel.cpp \
profileevaluator.cpp \
proitems.cpp \
prowriter.cpp \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment