File indexing completed on 2024-04-28 08:25:24
0001 /* 0002 * This file is part of KDevelop project 0003 * Copyright 2016 Patrick José Pereira <patrickelectric@gmail.com> 0004 * Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU Library General Public License as 0008 * published by the Free Software Foundation; either version 2 of the 0009 * License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public 0017 * License along with this program; if not, write to the 0018 * Free Software Foundation, Inc., 0019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "projecttargetscombobox.h" 0023 0024 #include <QIcon> 0025 0026 #include <project/projectmodel.h> 0027 #include <interfaces/iproject.h> 0028 #include <util/kdevstringhandler.h> 0029 #include <interfaces/icore.h> 0030 #include <interfaces/iprojectcontroller.h> 0031 0032 using namespace KDevelop; 0033 0034 ProjectTargetsComboBox::ProjectTargetsComboBox(QWidget* parent) 0035 : QComboBox(parent) 0036 { 0037 0038 } 0039 0040 class ExecutablePathsVisitor 0041 : public ProjectVisitor 0042 { 0043 public: 0044 ExecutablePathsVisitor(bool exec) : m_onlyExecutables(exec) {} 0045 using ProjectVisitor::visit; 0046 void visit(ProjectExecutableTargetItem* eit) override 0047 { 0048 if (!m_onlyExecutables || eit->type()==ProjectTargetItem::ExecutableTarget) 0049 m_paths += 0050 KDevelop::joinWithEscaping(eit->model()->pathFromIndex(eit->index()), QChar::fromLatin1('/'), QChar::fromLatin1('\\')); 0051 } 0052 0053 QStringList paths() const 0054 { 0055 return m_paths; 0056 } 0057 0058 private: 0059 bool m_onlyExecutables; 0060 QStringList m_paths; 0061 }; 0062 0063 0064 void ProjectTargetsComboBox::setBaseItem(ProjectFolderItem* item, bool exec) 0065 { 0066 clear(); 0067 0068 QList<ProjectFolderItem*> items; 0069 if (item) 0070 { 0071 items += item; 0072 } 0073 else 0074 { 0075 foreach (IProject* p, ICore::self()->projectController()->projects()) 0076 { 0077 items += p->projectItem(); 0078 } 0079 } 0080 0081 ExecutablePathsVisitor walker(exec); 0082 foreach (ProjectFolderItem* item, items) 0083 { 0084 walker.visit(item); 0085 } 0086 0087 foreach (const QString& item, walker.paths()) 0088 addItem(QIcon::fromTheme(QStringLiteral("system-run")), item); 0089 0090 } 0091 0092 QStringList ProjectTargetsComboBox::currentItemPath() const 0093 { 0094 return KDevelop::splitWithEscaping(currentText(), QChar::fromLatin1('/'), QChar::fromLatin1('\\')); 0095 } 0096 0097 void ProjectTargetsComboBox::setCurrentItemPath(const QStringList& str) 0098 { 0099 setCurrentIndex(str.isEmpty() && count() ? 0 : 0100 findText(KDevelop::joinWithEscaping(str, QChar::fromLatin1('/'), QChar::fromLatin1('\\')))); 0101 }