Commit a918b478 authored by El Mehdi Fekari's avatar El Mehdi Fekari Committed by hjk

Debugger: Refactor DebuggerItemManager class

Task-number: QTCREATORBUG-10252

Change-Id: Ia8545fd0255f59290a6bab6e35ef1c082649f794
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 37f90fd6
......@@ -38,7 +38,6 @@
#include <utils/detailswidget.h>
#include <utils/fileutils.h>
#include <utils/pathchooser.h>
#include <utils/persistentsettings.h>
#include <QDialog>
#include <QStandardItemModel>
......@@ -57,37 +56,27 @@ class DebuggerItemConfigWidget;
class DebuggerKitConfigWidget;
// -----------------------------------------------------------------------
// DebuggerItemManager
// -----------------------------------------------------------------------
class DebuggerItemManager : public QStandardItemModel
// DebuggerItemModel
//------------------------------------------------------------------------
class DebuggerItemModel : public QStandardItemModel
{
Q_OBJECT
public:
DebuggerItemManager(QObject *parent);
~DebuggerItemManager();
static const DebuggerItem *debuggerFromKit(const ProjectExplorer::Kit *kit);
// Returns id.
QVariant registerDebugger(const DebuggerItem &item);
DebuggerItemModel(QObject *parent);
QModelIndex currentIndex() const;
void setCurrentIndex(const QModelIndex &index);
void setCurrentData(const QString &displayName, const Utils::FileName &fileName);
// Returns id.
QVariant defaultDebugger(ProjectExplorer::ToolChain *tc);
static void restoreDebuggers();
public slots:
void saveDebuggers();
void autoDetectDebuggers();
void readLegacyDebuggers();
void addDebugger();
void cloneDebugger();
void removeDebugger();
void removeCurrentDebugger();
void markCurrentDirty();
void cloneDebugger();
private slots:
void onDebuggerAdded(const DebuggerItem &item);
void onDebuggerRemoved(const QVariant &id);
void onDebuggerUpdated(const QVariant &id);
signals:
void debuggerAdded(const QVariant &id, const QString &display);
......@@ -100,16 +89,12 @@ private:
friend class DebuggerItemConfigWidget;
friend class DebuggerOptionsPage;
QVariant doAddDebugger(const DebuggerItem &item);
const DebuggerItem *findByCommand(const Utils::FileName &command);
const DebuggerItem *findById(const QVariant &id);
void addDebugger(const DebuggerItem &item);
void removeDebugger(const QVariant &id);
QStandardItem *currentStandardItem() const;
QStandardItem *findStandardItemById(const QVariant &id) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QString uniqueDisplayName(const QString &base) const;
void autoDetectCdbDebugger();
Utils::PersistentSettingsWriter *m_writer;
QList<DebuggerItem> m_debuggers;
QVariant m_currentDebugger;
QStandardItem *m_autoRoot;
......@@ -182,7 +167,7 @@ private:
QWidget *m_configWidget;
QString m_searchKeywords;
DebuggerItemManager *m_manager;
DebuggerItemModel *m_model;
DebuggerItemConfigWidget *m_itemConfigWidget;
QTreeView *m_debuggerView;
Utils::DetailsWidget *m_container;
......
......@@ -36,9 +36,15 @@
#include <projectexplorer/abi.h>
#include <projectexplorer/kitinformation.h>
#include <utils/persistentsettings.h>
namespace Debugger {
namespace Internal { class DebuggerItemManager; }
namespace Internal { class DebuggerItemModel; }
// -----------------------------------------------------------------------
// DebuggerItem
// -----------------------------------------------------------------------
class DEBUGGER_EXPORT DebuggerItem
{
......@@ -74,7 +80,8 @@ public:
QStringList abiNames() const;
private:
friend class Debugger::Internal::DebuggerItemManager;
friend class Debugger::Internal::DebuggerItemModel;
friend class DebuggerItemManager;
void setId(const QVariant &id);
QVariant m_id;
......@@ -85,6 +92,56 @@ private:
QList<ProjectExplorer::Abi> m_abis;
};
// -----------------------------------------------------------------------
// DebuggerItemManager
// -----------------------------------------------------------------------
class DEBUGGER_EXPORT DebuggerItemManager : public QObject
{
Q_OBJECT
public:
static QObject *instance();
~DebuggerItemManager();
static QList<DebuggerItem> debuggers();
static Debugger::Internal::DebuggerItemModel *model();
static void registerDebugger(const DebuggerItem &item);
static void deregisterDebugger(const DebuggerItem &item);
static const DebuggerItem *findByCommand(const Utils::FileName &command);
static const DebuggerItem *findById(const QVariant &id);
static QVariant defaultDebugger(ProjectExplorer::ToolChain *tc);
static void restoreDebuggers();
static QString uniqueDisplayName(const QString &base);
static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName);
public slots:
void saveDebuggers();
signals:
void debuggerAdded(const DebuggerItem &item);
void debuggerRemoved(const QVariant &id);
void debuggerUpdated(const QVariant &id);
private:
explicit DebuggerItemManager(QObject *parent = 0);
static void autoDetectDebuggers();
static void autoDetectCdbDebugger();
static void readLegacyDebuggers();
static void addDebugger(const DebuggerItem &item);
static void removeDebugger(const QVariant &id);
static Utils::PersistentSettingsWriter *m_writer;
static QList<DebuggerItem> m_debuggers;
static Debugger::Internal::DebuggerItemModel *m_model;
friend class Internal::DebuggerItemModel;
friend class DebuggerPlugin; // Enable constrcutor for DebuggerPlugin
};
class DEBUGGER_EXPORT DebuggerKitInformation : public ProjectExplorer::KitInformation
{
Q_OBJECT
......@@ -99,6 +156,8 @@ public:
void setup(ProjectExplorer::Kit *k);
static const DebuggerItem *debugger(const ProjectExplorer::Kit *kit);
static QList<ProjectExplorer::Task> validateDebugger(const ProjectExplorer::Kit *k);
static bool isValidDebugger(const ProjectExplorer::Kit *k);
......
......@@ -3401,6 +3401,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
mstart->addSeparator(globalcontext, Constants::G_GENERAL);
mstart->addSeparator(globalcontext, Constants::G_SPECIAL);
addAutoReleasedObject(new DebuggerItemManager);
DebuggerItemManager::restoreDebuggers();
KitManager::registerKitInformation(new DebuggerKitInformation);
......
......@@ -54,6 +54,7 @@
using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;
using namespace Debugger;
namespace Qnx {
namespace Internal {
......@@ -218,15 +219,17 @@ Kit *BlackBerryConfiguration::createKit(QnxAbstractQtVersion *version, ToolChain
QtKitInformation::setQtVersion(kit, version);
ToolChainKitInformation::setToolChain(kit, toolChain);
Debugger::DebuggerItem debugger;
DebuggerItem debugger;
debugger.setCommand(isSimulator ? m_simulatorDebugger : m_deviceDebugger);
debugger.setEngineType(Debugger::GdbEngineType);
debugger.setEngineType(GdbEngineType);
debugger.setAutoDetected(true);
debugger.setAbi(toolChain->targetAbi());
debugger.setDisplayName(tr("Debugger for Qt %1 for %2 %3 - %4").arg(
version->qtVersionString(), version->platformDisplayName(),
version->archString(), m_targetName));
Debugger::DebuggerKitInformation::setDebugger(kit, debugger);
DebuggerItemManager::registerDebugger(debugger);
DebuggerKitInformation::setDebugger(kit, debugger);
if (isSimulator)
Qt4ProjectManager::QmakeKitInformation::setMkspec(
......@@ -247,7 +250,7 @@ Kit *BlackBerryConfiguration::createKit(QnxAbstractQtVersion *version, ToolChain
kit->setSticky(ToolChainKitInformation::id(), true);
kit->setSticky(DeviceTypeKitInformation::id(), true);
kit->setSticky(SysRootKitInformation::id(), true);
kit->setSticky(Debugger::DebuggerKitInformation::id(), true);
kit->setSticky(DebuggerKitInformation::id(), true);
kit->setSticky(Qt4ProjectManager::QmakeKitInformation::id(), true);
return kit;
......@@ -326,7 +329,10 @@ void BlackBerryConfiguration::deactivate()
}
}
// unable to deregistering debuggers because of missing API
foreach (const DebuggerItem &item, DebuggerItemManager::debuggers())
if (item.isAutoDetected() &&
(item.command() == m_simulatorDebugger || item.command() == m_deviceDebugger))
DebuggerItemManager::deregisterDebugger(item);
foreach (ToolChain *toolChain, ToolChainManager::toolChains())
if (toolChain->isAutoDetected()
......@@ -335,6 +341,7 @@ void BlackBerryConfiguration::deactivate()
foreach (BaseQtVersion *version, versions)
QtVersionManager::removeVersion(version);
}
} // namespace Internal
......
Markdown is supported
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