diff --git a/plugins/execute/nativeappconfig.cpp b/plugins/execute/nativeappconfig.cpp index bea74e2bd1..64f43174b1 100644 --- a/plugins/execute/nativeappconfig.cpp +++ b/plugins/execute/nativeappconfig.cpp @@ -1,327 +1,328 @@ /* This file is part of KDevelop Copyright 2009 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "nativeappconfig.h" #include #include #include #include #include #include #include #include "nativeappjob.h" #include #include +#include #include #include #include #include #include #include #include #include "executeplugin.h" KIcon NativeAppConfigPage::icon() const { return KIcon("system-run"); } //TODO: Make sure to auto-add the executable target to the dependencies when its used. void NativeAppConfigPage::loadFromConfiguration(const KConfigGroup& cfg) { bool b = blockSignals( true ); if( cfg.readEntry( ExecutePlugin::isExecutableEntry, false ) ) { executableRadio->setChecked( true ); executablePath->setUrl( cfg.readEntry( ExecutePlugin::executableEntry, KUrl() ) ); } else { projectTargetRadio->setChecked( true ); projectTarget->setText( cfg.readEntry( ExecutePlugin::projectTargetEntry, "" ) ); } arguments->setText( cfg.readEntry( ExecutePlugin::argumentsEntry, "" ) ); workingDirectory->setUrl( cfg.readEntry( ExecutePlugin::workingDirEntry, KUrl() ) ); environment->setCurrentProfile( cfg.readEntry( ExecutePlugin::environmentGroupEntry, "default" ) ); runInTerminal->setChecked( cfg.readEntry( ExecutePlugin::useTerminalEntry, false ) ); dependencies->addItems( cfg.readEntry( ExecutePlugin::dependencyEntry, QStringList() ) ); dependencyAction->setCurrentIndex( dependencyAction->findData( cfg.readEntry( ExecutePlugin::dependencyActionEntry, "Nothing" ) ) ); blockSignals( b ); } NativeAppConfigPage::NativeAppConfigPage( QWidget* parent ) : LaunchConfigurationPage( parent ) { setupUi(this); //Setup completions for the target lineedits projectTarget->setCompleter( new ProjectItemCompleter( KDevelop::ICore::self()->projectController()->projectModel(), this ) ); targetDependency->setCompleter( new ProjectItemCompleter( KDevelop::ICore::self()->projectController()->projectModel(), this ) ); //Setup data info for combobox dependencyAction->setItemData(0, "Nothing" ); dependencyAction->setItemData(1, "Build" ); dependencyAction->setItemData(2, "Install" ); dependencyAction->setItemData(3, "SudoInstall" ); addDependency->setIcon( KIcon("list-add") ); removeDependency->setIcon( KIcon("list-remove") ); moveDepUp->setIcon( KIcon("go-up") ); moveDepDown->setIcon( KIcon("go-down") ); //Set workingdirectory widget to ask for directories rather than files workingDirectory->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly); //connect signals to changed signal connect( projectTarget, SIGNAL(textEdited(const QString&)), SIGNAL(changed()) ); connect( projectTargetRadio, SIGNAL(toggled(bool)), SIGNAL(changed()) ); connect( executableRadio, SIGNAL(toggled(bool)), SIGNAL(changed()) ); connect( executablePath->lineEdit(), SIGNAL(textEdited(const QString&)), SIGNAL(changed()) ); connect( executablePath, SIGNAL(urlSelected(const KUrl&)), SIGNAL(changed()) ); connect( arguments, SIGNAL(textEdited(const QString&)), SIGNAL(changed()) ); connect( workingDirectory, SIGNAL(urlSelected(const KUrl&)), SIGNAL(changed()) ); connect( workingDirectory->lineEdit(), SIGNAL(textEdited(const QString&)), SIGNAL(changed()) ); connect( environment, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) ); connect( addDependency, SIGNAL(clicked(bool)), SLOT(addDep()) ); connect( addDependency, SIGNAL(clicked(bool)), SIGNAL(changed()) ); connect( removeDependency, SIGNAL(clicked(bool)), SIGNAL(changed()) ); connect( removeDependency, SIGNAL(clicked(bool)), SLOT(removeDep()) ); connect( moveDepDown, SIGNAL(clicked(bool)), SIGNAL(changed()) ); connect( moveDepUp, SIGNAL(clicked(bool)), SIGNAL(changed()) ); connect( moveDepDown, SIGNAL(clicked(bool)), SLOT(moveDependencyDown()) ); connect( moveDepUp, SIGNAL(clicked(bool)), SLOT(moveDependencyUp()) ); connect( dependencies->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(checkActions(QItemSelection,QItemSelection)) ); connect( dependencyAction, SIGNAL(currentIndexChanged(int)), SIGNAL(changed()) ); connect( runInTerminal, SIGNAL(toggled(bool)), SIGNAL(changed()) ); connect( dependencyAction, SIGNAL(currentIndexChanged(int)), SLOT(activateDeps(int)) ); connect( targetDependency, SIGNAL(textEdited(QString)), SLOT(depEdited(QString))); } void NativeAppConfigPage::depEdited( const QString& str ) { int pos; QString tmp = str; kDebug() << str << targetDependency->validator(); addDependency->setEnabled( !str.isEmpty() && ( !targetDependency->validator() || targetDependency->validator()->validate( tmp, pos ) == QValidator::Acceptable ) ); } void NativeAppConfigPage::activateDeps( int idx ) { dependencies->setEnabled( dependencyAction->itemData( idx ).toString() != "Nothing" ); targetDependency->setEnabled( dependencyAction->itemData( idx ).toString() != "Nothing" ); } void NativeAppConfigPage::checkActions( const QItemSelection& selected, const QItemSelection& unselected ) { kDebug() << "checkActions"; if( !selected.indexes().isEmpty() ) { kDebug() << "have selection"; Q_ASSERT( selected.indexes().count() == 1 ); QModelIndex idx = selected.indexes().at( 0 ); kDebug() << "index" << idx; moveDepUp->setEnabled( idx.row() > 0 ); moveDepDown->setEnabled( idx.row() < dependencies->count() - 1 ); removeDependency->setEnabled( true ); } else { removeDependency->setEnabled( false ); moveDepUp->setEnabled( false ); moveDepDown->setEnabled( false ); } } void NativeAppConfigPage::moveDependencyDown() { QList list = dependencies->selectedItems(); if( !list.isEmpty() ) { Q_ASSERT( list.count() == 1 ); QListWidgetItem* item = list.at( 0 ); int row = dependencies->row( item ); dependencies->takeItem( row ); dependencies->insertItem( row+1, item ); dependencies->selectionModel()->select( dependencies->model()->index( row+1, 0, QModelIndex() ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::SelectCurrent ); } } void NativeAppConfigPage::moveDependencyUp() { QList list = dependencies->selectedItems(); if( !list.isEmpty() ) { Q_ASSERT( list.count() == 1 ); QListWidgetItem* item = list.at( 0 ); int row = dependencies->row( item ); dependencies->takeItem( row ); dependencies->insertItem( row-1, item ); dependencies->selectionModel()->select( dependencies->model()->index( row-1, 0, QModelIndex() ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::SelectCurrent ); } } void NativeAppConfigPage::addDep() { dependencies->addItem( targetDependency->text() ); targetDependency->setText(""); addDependency->setEnabled( false ); dependencies->selectionModel()->select( dependencies->model()->index( dependencies->model()->rowCount() - 1, 0, QModelIndex() ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::SelectCurrent ); } void NativeAppConfigPage::removeDep() { QList list = dependencies->selectedItems(); if( !list.isEmpty() ) { Q_ASSERT( list.count() == 1 ); int row = dependencies->row( list.at(0) ); delete dependencies->takeItem( row ); dependencies->selectionModel()->select( dependencies->model()->index( row - 1, 0, QModelIndex() ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::SelectCurrent ); } } void NativeAppConfigPage::saveToConfiguration(KConfigGroup cfg) const { cfg.writeEntry( ExecutePlugin::isExecutableEntry, executableRadio->isChecked() ); if( executableRadio-> isChecked() ) { cfg.writeEntry( ExecutePlugin::executableEntry, executablePath->url() ); cfg.deleteEntry( ExecutePlugin::projectTargetEntry ); } else { cfg.writeEntry( ExecutePlugin::projectTargetEntry, projectTarget->text() ); cfg.deleteEntry( ExecutePlugin::executableEntry ); } cfg.writeEntry( ExecutePlugin::argumentsEntry, arguments->text() ); cfg.writeEntry( ExecutePlugin::workingDirEntry, workingDirectory->url() ); cfg.writeEntry( ExecutePlugin::environmentGroupEntry, environment->currentProfile() ); cfg.writeEntry( ExecutePlugin::useTerminalEntry, runInTerminal->isChecked() ); cfg.writeEntry( ExecutePlugin::dependencyActionEntry, dependencyAction->itemData( dependencyAction->currentIndex() ).toString() ); QStringList deps; for( int i = 0; i < dependencies->count(); i++ ) { deps << dependencies->item( i )->text(); } cfg.writeEntry( ExecutePlugin::dependencyEntry, deps ); } QString NativeAppConfigPage::title() const { return i18n("Configure Native Application"); } QList< KDevelop::LaunchConfigurationPageFactory* > NativeAppLauncher::configPages() const { return QList(); } QString NativeAppLauncher::description() const { return "Executes Native Applications"; } QString NativeAppLauncher::id() { return "nativeAppLauncher"; } QString NativeAppLauncher::name() const { return i18n("Native Application"); } NativeAppLauncher::NativeAppLauncher() { } KJob* NativeAppLauncher::start(const QString& launchMode, KDevelop::ILaunchConfiguration* cfg) { Q_ASSERT(cfg); if( !cfg ) { return 0; } if( launchMode == "execute" ) { IExecutePlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecutePlugin")->extension(); Q_ASSERT(iface); KJob* depjob = iface->dependecyJob( cfg ); QList l; if( depjob ) { l << depjob; } l << new NativeAppJob( KDevelop::ICore::self()->runController(), cfg ); return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l ); } kWarning() << "Unknown launch mode " << launchMode << "for config:" << cfg->name(); return 0; } QStringList NativeAppLauncher::supportedModes() const { return QStringList() << "execute"; } KDevelop::LaunchConfigurationPage* NativeAppPageFactory::createWidget(QWidget* parent) { return new NativeAppConfigPage( parent ); } NativeAppPageFactory::NativeAppPageFactory() { } NativeAppConfigType::NativeAppConfigType() { factoryList.append( new NativeAppPageFactory() ); } QString NativeAppConfigType::name() const { return i18n("Native Application"); } QList NativeAppConfigType::configPages() const { return factoryList; } QString NativeAppConfigType::id() const { return ExecutePlugin::_nativeAppConfigTypeId; } KIcon NativeAppConfigType::icon() const { return KIcon("system-run"); } #include "nativeappconfig.moc" diff --git a/plugins/execute/projectitemlineedit.cpp b/plugins/execute/projectitemlineedit.cpp index 3dea863df9..6802aee64e 100644 --- a/plugins/execute/projectitemlineedit.cpp +++ b/plugins/execute/projectitemlineedit.cpp @@ -1,77 +1,65 @@ /*************************************************************************** * Copyright 2008 Aleix Pol * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "projectitemlineedit.h" #include #include #include #include #include //TODO: use a proper QValidator for the validation instead of doing it manually. ProjectItemLineEdit::ProjectItemLineEdit(QWidget* parent) : KLineEdit(parent) { connect(this, SIGNAL(textChanged(QString)), this, SLOT(updated(QString))); connect(this, SIGNAL(correctnessChanged(bool)), this, SLOT(correctnessChange(bool))); } void ProjectItemLineEdit::updated(const QString& newText) { QStringList tofetch=completer()->splitPath(newText); const KDevelop::ProjectModel* model=static_cast(completer()->model()); QModelIndex idx=model->pathToIndex(tofetch); emit correctnessChanged(idx.isValid()); } void ProjectItemLineEdit::correctnessChange(bool correct) { QColor textColor; if(correct) textColor=qApp->palette().color(QPalette::Active, QPalette::Text); else textColor=Qt::red; QPalette p = this->palette(); p.setColor(QPalette::Active, QPalette::Text, textColor); setPalette(p); } -ProjectItemCompleter::ProjectItemCompleter(QAbstractItemModel* model, QObject* parent) +ProjectItemCompleter::ProjectItemCompleter(KDevelop::ProjectModel* model, QObject* parent) : QCompleter(model, parent), mModel(model), sep("/") {} QString ProjectItemCompleter::pathFromIndex(const QModelIndex& index) const { - if (!index.isValid()) - return QString(); - - QModelIndex idx = index; - QStringList list; - do { - QString t = mModel->data(idx, Qt::EditRole).toString(); - list.prepend(t); - QModelIndex parent = idx.parent(); - idx = parent.sibling(parent.row(), index.column()); - } while (idx.isValid()); - - return list.join(sep); + return mModel->pathFromIndex(index).join(sep); } #include "projectitemlineedit.moc" diff --git a/plugins/execute/projectitemlineedit.h b/plugins/execute/projectitemlineedit.h index 238d122685..a931f28d63 100644 --- a/plugins/execute/projectitemlineedit.h +++ b/plugins/execute/projectitemlineedit.h @@ -1,56 +1,58 @@ /*************************************************************************** * Copyright 2008 Aleix Pol * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef PROJECTITEMLINEEDIT_H #define PROJECTITEMLINEEDIT_H #include #include #include +namespace KDevelop { class ProjectModel; } + class ProjectItemCompleter : public QCompleter { Q_OBJECT public: - ProjectItemCompleter(QAbstractItemModel* model, QObject* parent=0); + ProjectItemCompleter(KDevelop::ProjectModel* model, QObject* parent=0); - QString pathFromIndex(const QModelIndex& index) const; QString separator() const { return sep; } QStringList splitPath(const QString &path) const { return path.split(sep); } + QString pathFromIndex(const QModelIndex& index) const; private: - QAbstractItemModel *mModel; + KDevelop::ProjectModel* mModel; QString sep; }; class ProjectItemLineEdit : public KLineEdit { Q_OBJECT public: ProjectItemLineEdit(QWidget* parent=0); public Q_SLOTS: void updated(const QString& newText); void correctnessChange(bool correct); Q_SIGNALS: void correctnessChanged(bool isCorrect); }; #endif diff --git a/plugins/projectmanagerview/builditembuilderjob.cpp b/plugins/projectmanagerview/builditembuilderjob.cpp index 2edfa9d907..febabbaa49 100644 --- a/plugins/projectmanagerview/builditembuilderjob.cpp +++ b/plugins/projectmanagerview/builditembuilderjob.cpp @@ -1,47 +1,51 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "builditembuilderjob.h" #include #include #include "projectbuildsetmodel.h" BuildItemBuilderJob::BuildItemBuilderJob( KDevelop::BuilderJob::BuildType t, const QList& items ) { foreach( const BuildItem &item, items ) { - addItem( t, item.findItem() ); + KDevelop::ProjectBaseItem *it=item.findItem(); + //FIXME: should have disabled the building before + //convert to assert or remove "if(it)" when it's done + if(it) + addItem( t, it ); } } BuildItemBuilderJob::BuildItemBuilderJob( KDevelop::BuilderJob::BuildType t, const QList& items ) { addItems( t, items ); } BuildItemBuilderJob::BuildItemBuilderJob( KDevelop::BuilderJob::BuildType t, const QList& projects ) { addProjects( t, projects ); } #include "builditembuilderjob.moc" diff --git a/plugins/projectmanagerview/projectbuildsetmodel.cpp b/plugins/projectmanagerview/projectbuildsetmodel.cpp index 2ba2d73963..cf1390c5f2 100644 --- a/plugins/projectmanagerview/projectbuildsetmodel.cpp +++ b/plugins/projectmanagerview/projectbuildsetmodel.cpp @@ -1,341 +1,275 @@ /*************************************************************************** * This file is part of KDevelop * - * Copyright 2007 Andreas Pakulat * + * Copyright 2007 Andreas Pakulat * + * Copyright 2009 Aleix Pol * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "projectbuildsetmodel.h" #include #include #include #include #include #include #include #include #include -QString getRelativeFolder( KDevelop::ProjectBaseItem* item ) -{ - if( !item ) - return ""; - - if( item->type() == KDevelop::ProjectBaseItem::Folder - || item->type() == KDevelop::ProjectBaseItem::BuildFolder ) - { - - return item->project()->relativeUrl( item->folder()->url() ).toLocalFile(); - }else - { - return getRelativeFolder( dynamic_cast( item->parent() ) ); - } -} - -KDevelop::ProjectBaseItem* findItem( const QString& item, const QString& path, KDevelop::ProjectBaseItem* top ) -{ - if( top && top->text() == item && getRelativeFolder( top ) == path ) - { - return top; - }else if( top->hasChildren() ) - { - for( int i = 0; i < top->rowCount(); i++ ) - { - QStandardItem* sitem = top->child( i ); - KDevelop::ProjectBaseItem* prjitem = dynamic_cast(sitem); - if( prjitem ) - { - if( prjitem->file() - && prjitem->text() == item - && path == getRelativeFolder( prjitem->file() ) ) - { - return prjitem; - }else if( prjitem->folder() - && prjitem->text() == item - && path == getRelativeFolder( prjitem->folder() ) ) - { - return prjitem; - }else if( prjitem->target() - && prjitem->text() == item - && path == getRelativeFolder( prjitem->target() ) ) - { - return prjitem; - }else - { - KDevelop::ProjectBaseItem* tmp = findItem( item, path, prjitem ); - if( tmp ) - return tmp; - } - } - } - } - return 0; -} - - BuildItem::BuildItem() { } -BuildItem::BuildItem( const QString& itemName, const QString& projectName, const QString& itemPath ) - : m_itemName( itemName ), m_projectName( projectName ), m_itemPath( itemPath ) +BuildItem::BuildItem( const QStringList & itemPath ) + : m_itemPath( itemPath ) { } BuildItem::BuildItem( KDevelop::ProjectBaseItem* item ) { initializeFromItem( item ); } BuildItem::BuildItem( const BuildItem& rhs ) { - m_itemName = rhs.itemName(); - m_projectName = rhs.projectName(); m_itemPath = rhs.itemPath(); } void BuildItem::initializeFromItem( KDevelop::ProjectBaseItem* item ) { - if( item ) - { - m_itemName = item->text(); - m_itemPath = getRelativeFolder( item ); - m_projectName = item->project()->name(); - } + Q_ASSERT(item); + KDevelop::ProjectModel* model=KDevelop::ICore::self()->projectController()->projectModel(); + + m_itemPath = model->pathFromIndex(item->index()); +} + +QString BuildItem::itemName() const +{ + return m_itemPath.last(); +} + +QString BuildItem::itemProject() const +{ + return m_itemPath.first(); } KDevelop::ProjectBaseItem* BuildItem::findItem() const { - KDevelop::ProjectBaseItem* top = 0; - KDevelop::IProject* project = KDevelop::ICore::self()->projectController()->findProjectByName( projectName() ); - if( project ) - { - top = ::findItem( itemName(), itemPath(), project->projectItem() ); - } - return top; + KDevelop::ProjectModel* model=KDevelop::ICore::self()->projectController()->projectModel(); + QModelIndex idx = model->pathToIndex(m_itemPath); + KDevelop::ProjectBaseItem* item = dynamic_cast(model->itemFromIndex(idx)); + + return item; } bool operator==( const BuildItem& rhs, const BuildItem& lhs ) { - return( rhs.itemName() == lhs.itemName() && rhs.projectName() == lhs.projectName() && rhs.itemPath() == lhs.itemPath() ); + return( rhs.itemPath() == lhs.itemPath() ); } BuildItem& BuildItem::operator=( const BuildItem& rhs ) { if( this == &rhs ) return *this; - m_itemName = rhs.itemName(); - m_projectName = rhs.projectName(); m_itemPath = rhs.itemPath(); return *this; } ProjectBuildSetModel::ProjectBuildSetModel( QObject* parent ) : QAbstractTableModel( parent ) { } QVariant ProjectBuildSetModel::data( const QModelIndex& idx, int role ) const { if( !idx.isValid() || idx.row() < 0 || idx.column() < 0 - || idx.row() >= rowCount() || idx.column() >= columnCount() - || role != Qt::DisplayRole ) + || idx.row() >= rowCount() || idx.column() >= columnCount()) { return QVariant(); } - switch( idx.column() ) - { - case 0: - return m_items.at( idx.row() ).itemName(); - break; - case 1: - return m_items.at( idx.row() ).projectName(); - break; - case 2: - return m_items.at( idx.row() ).itemPath(); - break; + + if(role == Qt::DisplayRole) { + switch( idx.column() ) + { + case 0: + return m_items.at( idx.row() ).itemName(); + break; + case 1: + return m_items.at( idx.row() ).itemPath(); + break; + } + } else if(role == Qt::DecorationRole && idx.column()==0) { + return m_items.at( idx.row() ).findItem()->icon(); } return QVariant(); } QVariant ProjectBuildSetModel::headerData( int section, Qt::Orientation orientation, int role ) const { if( section < 0 || section >= columnCount() || orientation != Qt::Horizontal || role != Qt::DisplayRole ) return QVariant(); switch( section ) { case 0: return i18n("Name"); break; case 1: - return i18n("Project"); - break; - case 2: - return i18n("Folder"); + return i18n("Path"); break; } return QVariant(); } int ProjectBuildSetModel::rowCount( const QModelIndex& parent ) const { if( parent.isValid() ) return 0; return m_items.count(); } int ProjectBuildSetModel::columnCount( const QModelIndex& parent ) const { if( parent.isValid() ) return 0; - return 3; + return 2; } void ProjectBuildSetModel::addProjectItem( KDevelop::ProjectBaseItem* item ) { - if( m_items.contains( item ) ) + if( m_items.contains( BuildItem(item) ) ) return; beginInsertRows( QModelIndex(), rowCount(), rowCount() ); m_items.append(BuildItem(item)); endInsertRows(); } bool ProjectBuildSetModel::removeRows( int row, int count, const QModelIndex& parent ) { if( parent.isValid() || row > rowCount() || row < 0 || (row+count) > rowCount() || count <= 0 ) return false; beginRemoveRows( QModelIndex(), row, row+count-1 ); for( int i = row; i < row+count; i++ ) { m_items.removeAt( row ); } endRemoveRows(); return true; } KDevelop::ProjectBaseItem* ProjectBuildSetModel::itemForIndex( const QModelIndex& idx ) { if( !idx.isValid() || idx.row() < 0 || idx.column() < 0 || idx.column() >= columnCount() || idx.row() >= rowCount() ) return 0; return m_items.at( idx.row() ).findItem(); } QList ProjectBuildSetModel::items() { return m_items ; } void ProjectBuildSetModel::projectClosed( KDevelop::IProject* project ) { for( int i = m_items.count() - 1; i >= 0; i-- ) { - if( m_items.at(i).projectName() == project->name() ) + if( m_items.at(i).itemPath().startsWith(project->name()+"/") ) { beginRemoveRows( QModelIndex(), i, i ); m_items.removeAt(i); endRemoveRows(); } } } void ProjectBuildSetModel::saveToProject( KDevelop::IProject* project ) const { - KConfigGroup base = project->projectConfiguration()->group("Buildset"); - int count = 0; + QVariantList paths; foreach( const BuildItem &item, m_items) { - if( item.projectName() == project->name() ) - { - KConfigGroup grp = base.group(QString("Builditem%1").arg(count)); - grp.writeEntry("Projectname", item.projectName()); - grp.writeEntry("Itemname", item.itemName()); - grp.writeEntry("Itempath", item.itemPath()); - count++; - } + if( item.itemProject() == project->name() ) + paths.append(item.itemPath()); } - base.writeEntry("Number of Builditems", count); + KConfigGroup base = project->projectConfiguration()->group("Buildset"); + base.writeEntry("Builditems", paths); base.sync(); } void ProjectBuildSetModel::loadFromProject( KDevelop::IProject* project ) { KConfigGroup base = project->projectConfiguration()->group("Buildset"); - int count = base.readEntry("Number of Builditems", 0); - for( int i = 0; i < count; i++ ) + QVariantList items = base.readEntry("Builditems", QVariantList()); + + foreach(const QVariant& path, items) { - KConfigGroup grp = base.group(QString("Builditem%1").arg(i)); - QString name = grp.readEntry("Projectname"); - QString item = grp.readEntry("Itemname"); - QString path = grp.readEntry("Itempath"); beginInsertRows( QModelIndex(), rowCount(), rowCount() ); - m_items.append( BuildItem( item, name, path ) ); + m_items.append( BuildItem( path.toStringList() ) ); endInsertRows(); } } void ProjectBuildSetModel::moveRowsDown(int row, int count) { QList items = m_items.mid( row, count ); removeRows( row, count ); beginInsertRows( QModelIndex(), row+1, row+count ); for( int i = 0; i < count; i++ ) { m_items.insert( row+1+i, items.at( i ) ); } endInsertRows(); } void ProjectBuildSetModel::moveRowsToBottom(int row, int count) { QList items = m_items.mid( row, count ); removeRows( row, count ); beginInsertRows( QModelIndex(), rowCount(), rowCount()+count-1 ); m_items += items; endInsertRows(); } void ProjectBuildSetModel::moveRowsUp(int row, int count) { QList items = m_items.mid( row, count ); removeRows( row, count ); beginInsertRows( QModelIndex(), row-1, row-2+count ); for( int i = 0; i < count; i++ ) { m_items.insert( row-1+i, items.at( i ) ); } endInsertRows(); } void ProjectBuildSetModel::moveRowsToTop(int row, int count) { QList items = m_items.mid( row, count ); removeRows( row, count ); beginInsertRows( QModelIndex(), 0, count-1 ); for( int i = 0; i < count; i++ ) { m_items.insert( 0+i, items.at( i ) ); } endInsertRows(); } - diff --git a/plugins/projectmanagerview/projectbuildsetmodel.h b/plugins/projectmanagerview/projectbuildsetmodel.h index 721cf5d17f..d3394d33c9 100644 --- a/plugins/projectmanagerview/projectbuildsetmodel.h +++ b/plugins/projectmanagerview/projectbuildsetmodel.h @@ -1,85 +1,84 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2007 Andreas Pakulat * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef PROJECTBUILDSETMODEL_H #define PROJECTBUILDSETMODEL_H #include #include +#include namespace KDevelop { class ProjectBaseItem; class ICore; class IProject; } class KConfigGroup; class BuildItem { public: BuildItem(); - BuildItem( const QString& itemName, const QString& projectName, const QString& itemPath ); + explicit BuildItem( const QStringList& itemPath ); BuildItem( const BuildItem& rhs ); - BuildItem( KDevelop::ProjectBaseItem* ); + explicit BuildItem( KDevelop::ProjectBaseItem* ); void initializeFromItem( KDevelop::ProjectBaseItem* item ); KDevelop::ProjectBaseItem* findItem() const; BuildItem& operator=( const BuildItem& ); - QString itemName() const { return m_itemName; } - QString projectName() const { return m_projectName; } - QString itemPath() const { return m_itemPath; } + QString itemName() const; + QStringList itemPath() const { return m_itemPath; } + QString itemProject() const; private: - QString m_itemName; - QString m_projectName; - QString m_itemPath; + QStringList m_itemPath; }; bool operator==( const BuildItem& rhs, const BuildItem& lhs ); class ProjectBuildSetModel : public QAbstractTableModel { Q_OBJECT public: ProjectBuildSetModel( QObject* parent ); QVariant data( const QModelIndex&, int role = Qt::DisplayRole ) const; QVariant headerData( int, Qt::Orientation, int role = Qt::DisplayRole ) const; int rowCount( const QModelIndex& = QModelIndex() ) const; int columnCount( const QModelIndex& = QModelIndex() ) const; void addProjectItem( KDevelop::ProjectBaseItem* ); bool removeRows( int row, int count, const QModelIndex& parent = QModelIndex() ); void moveRowsUp( int row, int count ); void moveRowsDown( int row, int count ); void moveRowsToTop( int row, int count ); void moveRowsToBottom( int row, int count ); KDevelop::ProjectBaseItem* itemForIndex( const QModelIndex& ); QList items(); public slots: void saveToProject( KDevelop::IProject* ) const; void loadFromProject( KDevelop::IProject* ); void projectClosed( KDevelop::IProject* ); private: QList m_items; }; #endif //kate: space-indent on; indent-width 4; replace-tabs on; auto-insert-doxygen on; indent-mode cstyle; diff --git a/project/projectmodel.cpp b/project/projectmodel.cpp index aaac0e7940..9767801a62 100644 --- a/project/projectmodel.cpp +++ b/project/projectmodel.cpp @@ -1,476 +1,492 @@ /* This file is part of KDevelop Copyright 2005 Roberto Raggi Copyright 2007 Andreas Pakulat Copyright 2007 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projectmodel.h" #include #include #include #include #include #include #include #include #include #include #include namespace KDevelop { class ProjectBaseItemPrivate { public: ProjectBaseItemPrivate() : project(0) {} IProject* project; }; class ProjectFolderItemPrivate : public ProjectBaseItemPrivate { public: KUrl m_url; QString m_folderName; bool m_isProjectRoot; }; class ProjectBuildFolderItemPrivate : public ProjectFolderItemPrivate { public: }; class ProjectFileItemPrivate : public ProjectBaseItemPrivate { public: KUrl m_url; QString m_fileName; }; class ProjectTargetItemPrivate : public ProjectBaseItemPrivate { }; class WorkspaceItemPrivate { public: QString name; KSharedConfig::Ptr metadataConfig; QString metadataDir; }; class ProjectModelPrivate { }; ProjectBaseItem::ProjectBaseItem( IProject* project, const QString &name, QStandardItem *parent ) : QStandardItem( name ), d_ptr(new ProjectBaseItemPrivate) { Q_D(ProjectBaseItem); d->project = project; setParent( parent ); setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); } ProjectBaseItem::ProjectBaseItem( ProjectBaseItemPrivate& dd) : d_ptr(&dd) { setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); } ProjectBaseItem::~ProjectBaseItem() { Q_D(ProjectBaseItem); delete d; } IProject* ProjectBaseItem::project() const { Q_D(const ProjectBaseItem); return d->project; } void ProjectBaseItem::setParent( QStandardItem* parent ) { if( parent ) parent->setChild( parent->rowCount(), this ); } void ProjectBaseItem::setIcon() { } void ProjectBaseItem::add( ProjectBaseItem* item ) { appendRow( item ); } ProjectFolderItem *ProjectBaseItem::folder() const { return 0; } ProjectTargetItem *ProjectBaseItem::target() const { return 0; } ProjectExecutableTargetItem *ProjectBaseItem::executable() const { return 0; } ProjectFileItem *ProjectBaseItem::file() const { return 0; } QList ProjectBaseItem::folderList() const { QList lst; for ( int i = 0; i < rowCount(); ++i ) { QStandardItem* item = child( i ); if ( item->type() == Folder || item->type() == BuildFolder ) { ProjectFolderItem *kdevitem = dynamic_cast( item ); if ( kdevitem ) lst.append( kdevitem ); } } return lst; } QList ProjectBaseItem::targetList() const { QList lst; for ( int i = 0; i < rowCount(); ++i ) { QStandardItem* item = child( i ); if ( item->type() == Target || item->type() == LibraryTarget || item->type() == ExecutableTarget) { ProjectTargetItem *kdevitem = dynamic_cast( item ); if ( kdevitem ) lst.append( kdevitem ); } } return lst; } QList ProjectBaseItem::fileList() const { QList lst; for ( int i = 0; i < rowCount(); ++i ) { QStandardItem* item = child( i ); if ( item->type() == File ) { ProjectFileItem *kdevitem = dynamic_cast( item ); if ( kdevitem ) lst.append( kdevitem ); } } return lst; } ProjectModel::ProjectModel( QObject *parent ) : QStandardItemModel( parent ), d(0) { } ProjectModel::~ProjectModel() {} ProjectBaseItem *ProjectModel::item( const QModelIndex &index ) const { return dynamic_cast( itemFromIndex( index ) ); } void ProjectModel::resetModel() { reset(); } void ProjectModel::fetchMore( const QModelIndex &parent ) { QStandardItem *parentItem = itemFromIndex( parent ); if( !parentItem ) return; int rowcount = parentItem->rowCount(); for( int i=0; i(parentItem->child(i)); if( childItem && childItem->icon().isNull() ) childItem->setIcon(); } } bool ProjectModel::canFetchMore( const QModelIndex & parent ) const { QStandardItem *parentItem = itemFromIndex( parent ); if( !parentItem ) return false; return true; } ProjectFolderItem::ProjectFolderItem( IProject* project, const KUrl & dir, QStandardItem * parent ) : ProjectBaseItem( *new ProjectFolderItemPrivate ) { Q_D(ProjectFolderItem); d->project = project; d->m_url = dir; setParent(parent); setText( dir.fileName() ); } ProjectFolderItem::ProjectFolderItem( ProjectFolderItemPrivate& dd) : ProjectBaseItem( dd ) { } ProjectFolderItem::~ProjectFolderItem() { } ProjectFolderItem *ProjectFolderItem::folder() const { return const_cast(this); } int ProjectFolderItem::type() const { return ProjectBaseItem::Folder; } const KUrl& ProjectFolderItem::url( ) const { Q_D(const ProjectFolderItem); return d->m_url; } const QString& ProjectFolderItem::folderName() const { Q_D(const ProjectFolderItem); return d->m_folderName; } void ProjectFolderItem::setUrl( const KUrl& url ) { Q_D(ProjectFolderItem); d->m_url = url; d->m_folderName = d->m_url.fileName(); setText( d->m_folderName ); } void ProjectFolderItem::setIcon() { QStandardItem::setIcon( KIO::pixmapForUrl( url(), 0, KIconLoader::Small ) ); } bool ProjectFolderItem::hasFileOrFolder(const QString& name) const { for ( int i = 0; i < rowCount(); ++i ) { QStandardItem* item = child( i ); if ( ProjectFileItem* file = dynamic_cast(item)) if (file->fileName() == name) return true; if ( ProjectFolderItem* folder = dynamic_cast(item)) if (folder->folderName() == name) return true; } return false; } ProjectBuildFolderItem::ProjectBuildFolderItem( ProjectBuildFolderItemPrivate& dd ) : ProjectFolderItem( dd ) { } ProjectBuildFolderItem::ProjectBuildFolderItem( IProject* project, const KUrl &dir, QStandardItem *parent) : ProjectFolderItem( *new ProjectBuildFolderItemPrivate ) { Q_D(ProjectBuildFolderItem); d->project = project; setUrl( dir ); setParent( parent ); } int ProjectBuildFolderItem::type() const { return ProjectBaseItem::BuildFolder; } void ProjectBuildFolderItem::setIcon() { QStandardItem::setIcon( KIcon("folder-development") ); } void ProjectFolderItem::setProjectRoot(bool isRoot) { Q_D(ProjectFolderItem); d->m_isProjectRoot=isRoot; setText(project()->name()); } bool ProjectFolderItem::isProjectRoot() const { Q_D(const ProjectFolderItem); return d->m_isProjectRoot; } ProjectFileItem::ProjectFileItem( ProjectFileItemPrivate& dd) : ProjectBaseItem(dd) { setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); } ProjectFileItem::ProjectFileItem( IProject* project, const KUrl & file, QStandardItem * parent ) : ProjectBaseItem( *new ProjectFileItemPrivate ) { Q_D(ProjectFileItem); d->project = project; d->m_url = file; setText( file.fileName() ); setParent( parent ); setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable ); } const KUrl & ProjectFileItem::url( ) const { Q_D(const ProjectFileItem); return d->m_url; } const QString& ProjectFileItem::fileName() const { Q_D(const ProjectFileItem); return d->m_fileName; } void ProjectFileItem::setUrl( const KUrl& url ) { Q_D(ProjectFileItem); d->m_url = url; d->m_fileName = d->m_url.fileName(); } int ProjectFileItem::type() const { return ProjectBaseItem::File; } ProjectFileItem *ProjectFileItem::file() const { return const_cast( this ); } void ProjectFileItem::setIcon() { QStandardItem::setIcon( KIO::pixmapForUrl( url(), 0, KIconLoader::Small ) ); } ProjectTargetItem::ProjectTargetItem( ProjectTargetItemPrivate& dd) : ProjectBaseItem( dd ) { } ProjectTargetItem::ProjectTargetItem( IProject* project, const QString &name, QStandardItem *parent ) : ProjectBaseItem( *new ProjectTargetItemPrivate ) { Q_D(ProjectTargetItem); d->project = project; setText( name ); setParent( parent ); } int ProjectTargetItem::type() const { return ProjectBaseItem::Target; } ProjectTargetItem *ProjectTargetItem::target() const { return const_cast( this ); } void ProjectTargetItem::setIcon() { QStandardItem::setIcon( KIcon("system-run") ); } ProjectExecutableTargetItem::ProjectExecutableTargetItem( IProject* project, const QString &name, QStandardItem *parent ) : ProjectTargetItem(project, name, parent) {} ProjectExecutableTargetItem *ProjectExecutableTargetItem::executable() const { return const_cast( this ); } int ProjectExecutableTargetItem::type() const { return ProjectBaseItem::ExecutableTarget; } ProjectLibraryTargetItem::ProjectLibraryTargetItem( IProject* project, const QString &name, QStandardItem *parent ) : ProjectTargetItem(project, name, parent) {} int ProjectLibraryTargetItem::type() const { return ProjectBaseItem::LibraryTarget; } QModelIndex ProjectModel::pathToIndex(const QStringList& tofetch_) const { if(tofetch_.isEmpty()) return QModelIndex(); QStringList tofetch(tofetch_); if(tofetch.last().isEmpty()) tofetch.takeLast(); QModelIndex current=index(0,0, QModelIndex()); QModelIndex ret; foreach(const QString& currentName, tofetch) { QModelIndexList l = match(current, Qt::EditRole, currentName, 1, Qt::MatchExactly); if(l.count()==1) { ret=l.first(); current = index(0,0, ret); } else ret = current = QModelIndex(); } Q_ASSERT(!ret.isValid() || data(ret).toString()==tofetch.last()); return ret; } +QStringList ProjectModel::pathFromIndex(const QModelIndex& index) const +{ + if (!index.isValid()) + return QStringList(); + + QModelIndex idx = index; + QStringList list; + do { + QString t = data(idx, Qt::EditRole).toString(); + list.prepend(t); + QModelIndex parent = idx.parent(); + idx = parent.sibling(parent.row(), index.column()); + } while (idx.isValid()); + + return list; +} } #include "projectmodel.moc" diff --git a/project/projectmodel.h b/project/projectmodel.h index 46fa0e047d..66a19bbe6d 100644 --- a/project/projectmodel.h +++ b/project/projectmodel.h @@ -1,287 +1,288 @@ /* This file is part of KDevelop Copyright 2005 Roberto Raggi Copyright 2007 Andreas Pakulat Copyright 2007 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPROJECTMODEL_H #define KDEVPROJECTMODEL_H #include #include #include "projectexport.h" #include #include template class QPair; template class QList; namespace KDevelop { class IProject; class ProjectFolderItem; class ProjectBuildFolderItem; class ProjectFileItem; class ProjectTargetItem; class ProjectExecutableTargetItem; class ProjectLibraryTargetItem; /** * Interface that allows a developer to implement the three basic types of * items you would see in a multi-project * \li Folder * \li Project * \li Custom Target * \li Library Target * \li Executable Target * \li File */ class KDEVPLATFORMPROJECT_EXPORT ProjectBaseItem: public QStandardItem { public: ProjectBaseItem( IProject*, const QString &name, QStandardItem *parent = 0 ); virtual ~ProjectBaseItem(); /** * add the item @p item to the list of children for this item * do not use this function if you gave the item a parent when you * created it */ void add( ProjectBaseItem* item ); enum ProjectItemType { BuildFolder = QStandardItem::UserType /** item is a buildable folder */, Folder = QStandardItem::UserType+1 /** item is a folder */, ExecutableTarget = QStandardItem::UserType+2 /** item is an executable target */, LibraryTarget = QStandardItem::UserType+3 /** item is a library target */, Target = QStandardItem::UserType+5 /** item is a target */, File = QStandardItem::UserType+6 /** item is a file */ }; /** @returns Returns the project that the item belongs to. */ IProject* project() const; /** @returns If this item is a folder, it returns a pointer to the folder, otherwise returns a 0 pointer. */ virtual ProjectFolderItem *folder() const; /** @returns If this item is a target, it returns a pointer to the target, otherwise returns a 0 pointer. */ virtual ProjectTargetItem *target() const; /** @returns If this item is a file, it returns a pointer to the file, otherwise returns a 0 pointer. */ virtual ProjectFileItem *file() const; /** @returns If this item is a file, it returns a pointer to the file, otherwise returns a 0 pointer. */ virtual ProjectExecutableTargetItem *executable() const; /** @param parent sets the item parent to @p parent */ void setParent( QStandardItem* parent); virtual void setIcon(); /** @returns Returns a list of the folders that have this object as the parent. */ QList folderList() const; /** @returns Returns a list of the targets that have this object as the parent. */ QList targetList() const; /** @returns Returns a list of the files that have this object as the parent. */ QList fileList() const; protected: class ProjectBaseItemPrivate* const d_ptr; ProjectBaseItem( ProjectBaseItemPrivate& dd ); private: Q_DECLARE_PRIVATE(ProjectBaseItem) }; /** * Implementation of the ProjectBaseItem interface that is specific to a * folder */ class ProjectFolderItemPrivate; class KDEVPLATFORMPROJECT_EXPORT ProjectFolderItem: public ProjectBaseItem { public: ProjectFolderItem( IProject*, const KUrl &dir, QStandardItem *parent = 0 ); virtual ~ProjectFolderItem(); virtual ProjectFolderItem *folder() const; ///Reimplemented from QStandardItem virtual int type() const; /** Get the url of this folder */ const KUrl& url() const; /** Get the folder name, equal to url().fileName() but faster (precomputed) */ const QString& folderName() const; /** Set the url of this folder */ void setUrl( const KUrl& ); virtual void setIcon(); /** Returns whether it is the project root folder */ bool isProjectRoot() const; /** Sets whether it is the project root folder and sets the project name to the item */ void setProjectRoot(bool isRoot); /** @returns Returns whether this folder directly contains the specified file or folder. */ bool hasFileOrFolder(const QString& name) const; protected: ProjectFolderItem( ProjectFolderItemPrivate& ); private: Q_DECLARE_PRIVATE(ProjectFolderItem) }; /** * Folder which contains buildable targets as part of a buildable project */ class ProjectBuildFolderItemPrivate; class KDEVPLATFORMPROJECT_EXPORT ProjectBuildFolderItem: public ProjectFolderItem { public: ProjectBuildFolderItem( IProject*, const KUrl &dir, QStandardItem *parent = 0 ); ///Reimplemented from QStandardItem virtual int type() const; virtual void setIcon(); protected: ProjectBuildFolderItem( ProjectBuildFolderItemPrivate& ); private: Q_DECLARE_PRIVATE(ProjectBuildFolderItem) }; /** * Object which represents a target in a build system. * * This object contains all properties specific to a target. */ class ProjectTargetItemPrivate; class KDEVPLATFORMPROJECT_EXPORT ProjectTargetItem: public ProjectBaseItem { public: ProjectTargetItem( IProject*, const QString &name, QStandardItem *parent = 0 ); ///Reimplemented from QStandardItem virtual int type() const; virtual ProjectTargetItem *target() const; virtual void setIcon(); protected: ProjectTargetItem( ProjectTargetItemPrivate& ); private: Q_DECLARE_PRIVATE(ProjectTargetItem) }; /** * Object which represents an executable target in a build system. * * This object contains all properties specific to an executable. */ class KDEVPLATFORMPROJECT_EXPORT ProjectExecutableTargetItem: public ProjectTargetItem { public: ProjectExecutableTargetItem( IProject*, const QString &name, QStandardItem *parent = 0 ); virtual ProjectExecutableTargetItem *executable() const; virtual int type() const; virtual KUrl builtUrl() const=0; virtual KUrl installedUrl() const=0; }; /** * Object which represents a library target in a build system. * * This object contains all properties specific to a library. */ class KDEVPLATFORMPROJECT_EXPORT ProjectLibraryTargetItem: public ProjectTargetItem { public: ProjectLibraryTargetItem(IProject* project, const QString &name, QStandardItem *parent = 0 ); virtual int type() const; }; /** * Object which represents a file. */ class ProjectFileItemPrivate; class KDEVPLATFORMPROJECT_EXPORT ProjectFileItem: public ProjectBaseItem { public: ProjectFileItem( IProject*, const KUrl& file, QStandardItem *parent = 0 ); ///Reimplemented from QStandardItem virtual int type() const; virtual ProjectFileItem *file() const; /** Get the url of this file. */ const KUrl& url() const; /** Get the file name, equal to url().fileName() but faster (precomputed) */ const QString& fileName() const; /** Set the url of this file. */ void setUrl( const KUrl& ); virtual void setIcon(); protected: ProjectFileItem( ProjectFileItemPrivate& ); private: Q_DECLARE_PRIVATE(ProjectFileItem) }; /** * Class providing some convenience methods for accessing the project model * @todo: maybe switch to QAbstractItemModel, would make the implementation * for at least the checkbox-behaviour easier */ class KDEVPLATFORMPROJECT_EXPORT ProjectModel: public QStandardItemModel { Q_OBJECT public: ProjectModel( QObject *parent = 0 ); virtual ~ProjectModel(); using QStandardItemModel::item; ProjectBaseItem *item( const QModelIndex &index ) const; void resetModel(); virtual void fetchMore( const QModelIndex &parent ); virtual bool canFetchMore( const QModelIndex & parent ) const; QModelIndex pathToIndex(const QStringList& tofetch) const; + QStringList pathFromIndex(const QModelIndex& index) const; private: class ProjectModelPrivate* const d; }; } #endif // KDEVPROJECTMODEL_H