forked from qt-creator/qt-creator
Revert "Fix adding external tools."
This patch breaks lots of other things,
it just gets insanely complicated for no gain whatsoever.
This reverts commit bdb5ecd1bc.
Change-Id: If38302c38ef42abd86e0b01021ded5162faf9e93
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
@@ -74,15 +74,9 @@ Qt::DropActions ExternalToolModel::supportedDropActions() const
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
QString ExternalToolModel::uncategorizedDisplayName() const
|
||||
{
|
||||
static QString uncategorized = tr("Uncategorized");
|
||||
return uncategorized;
|
||||
}
|
||||
|
||||
int ExternalToolModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!parent.isValid() || toolForIndex(parent) || !categoryForIndex(parent).isEmpty())
|
||||
if (!parent.isValid() || toolForIndex(parent) || !categoryForIndex(parent).isNull())
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -92,8 +86,9 @@ QVariant ExternalToolModel::data(const QModelIndex &index, int role) const
|
||||
if (ExternalTool *tool = toolForIndex(index))
|
||||
return data(tool, role);
|
||||
QString category = categoryForIndex(index);
|
||||
QTC_ASSERT(!category.isEmpty(), return QVariant());
|
||||
return data(category, role);
|
||||
if (!category.isNull())
|
||||
return data(category, role);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ExternalToolModel::data(ExternalTool *tool, int role) const
|
||||
@@ -113,10 +108,9 @@ QVariant ExternalToolModel::data(const QString &category, int role) const
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
return category;
|
||||
return category.isEmpty() ? tr("Uncategorized") : category;
|
||||
case Qt::ToolTipRole:
|
||||
return category == uncategorizedDisplayName()
|
||||
? tr("Tools that will appear directly under the External Tools menu.") : QVariant();
|
||||
return category.isEmpty() ? tr("Tools that will appear directly under the External Tools menu.") : QVariant();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -131,7 +125,7 @@ QMimeData *ExternalToolModel::mimeData(const QModelIndexList &indexes) const
|
||||
ExternalTool *tool = toolForIndex(modelIndex);
|
||||
QTC_ASSERT(tool, return 0);
|
||||
QString category = categoryForIndex(modelIndex.parent());
|
||||
QTC_ASSERT(!category.isEmpty(), return 0);
|
||||
QTC_ASSERT(!category.isNull(), return 0);
|
||||
QMimeData *md = new QMimeData();
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||
@@ -150,7 +144,7 @@ bool ExternalToolModel::dropMimeData(const QMimeData *data,
|
||||
if (action != Qt::MoveAction || !data)
|
||||
return false;
|
||||
QString toCategory = categoryForIndex(parent);
|
||||
QTC_ASSERT(!toCategory.isEmpty(), return false);
|
||||
QTC_ASSERT(!toCategory.isNull(), return false);
|
||||
QByteArray ba = data->data(QLatin1String("application/qtcreator-externaltool-config"));
|
||||
if (ba.isEmpty())
|
||||
return false;
|
||||
@@ -159,15 +153,15 @@ bool ExternalToolModel::dropMimeData(const QMimeData *data,
|
||||
int pos = -1;
|
||||
stream >> category;
|
||||
stream >> pos;
|
||||
QTC_ASSERT(!category.isEmpty(), return false);
|
||||
QTC_ASSERT(!category.isNull(), return false);
|
||||
QList<ExternalTool *> &items = m_tools[category];
|
||||
QTC_ASSERT(pos >= 0 && pos < items.count(), return false);
|
||||
beginRemoveRows(index(rowForCategory(category), 0), pos, pos);
|
||||
beginRemoveRows(index(m_tools.keys().indexOf(category), 0), pos, pos);
|
||||
ExternalTool *tool = items.takeAt(pos);
|
||||
endRemoveRows();
|
||||
if (row < 0)
|
||||
row = m_tools.value(toCategory).count();
|
||||
beginInsertRows(index(rowForCategory(toCategory), 0), row, row);
|
||||
beginInsertRows(index(m_tools.keys().indexOf(toCategory), 0), row, row);
|
||||
m_tools[toCategory].insert(row, tool);
|
||||
endInsertRows();
|
||||
return true;
|
||||
@@ -182,7 +176,7 @@ QModelIndex ExternalToolModel::index(int row, int column, const QModelIndex &par
|
||||
{
|
||||
if (column == 0 && parent.isValid()) {
|
||||
QString category = categoryForIndex(parent);
|
||||
if (!category.isEmpty()) {
|
||||
if (!category.isNull()) {
|
||||
QList<ExternalTool *> items = m_tools.value(category);
|
||||
if (row < items.count()) {
|
||||
return createIndex(row, 0, items.at(row));
|
||||
@@ -197,11 +191,13 @@ QModelIndex ExternalToolModel::index(int row, int column, const QModelIndex &par
|
||||
QModelIndex ExternalToolModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
if (ExternalTool *tool = toolForIndex(child)) {
|
||||
int categoryIndex = 0;
|
||||
QMapIterator<QString, QList<ExternalTool *> > it(m_tools);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value().contains(tool))
|
||||
return index(rowForCategory(it.key()), 0);
|
||||
return index(categoryIndex, 0);
|
||||
++categoryIndex;
|
||||
}
|
||||
}
|
||||
return QModelIndex();
|
||||
@@ -215,7 +211,7 @@ int ExternalToolModel::rowCount(const QModelIndex &parent) const
|
||||
return 0;
|
||||
}
|
||||
QString category = categoryForIndex(parent);
|
||||
if (!category.isEmpty()) {
|
||||
if (!category.isNull()) {
|
||||
return m_tools.value(category).count();
|
||||
}
|
||||
|
||||
@@ -227,8 +223,8 @@ Qt::ItemFlags ExternalToolModel::flags(const QModelIndex &index) const
|
||||
if (toolForIndex(index))
|
||||
return TOOL_ITEM_FLAGS;
|
||||
QString category = categoryForIndex(index);
|
||||
if (!category.isEmpty()) {
|
||||
if (category == uncategorizedDisplayName())
|
||||
if (!category.isNull()) {
|
||||
if (category.isEmpty())
|
||||
return TOOLSMENU_ITEM_FLAGS;
|
||||
return CATEGORY_ITEM_FLAGS;
|
||||
}
|
||||
@@ -249,17 +245,15 @@ bool ExternalToolModel::setData(const QModelIndex &modelIndex, const QVariant &v
|
||||
return true;
|
||||
} else {
|
||||
QString category = categoryForIndex(modelIndex);
|
||||
if (!category.isEmpty()) {
|
||||
if (!category.isNull()) {
|
||||
if (string.isEmpty() || m_tools.contains(string))
|
||||
return false;
|
||||
// rename category
|
||||
QList<QString> categories = m_tools.keys();
|
||||
int previousIndex = rowForCategory(category);
|
||||
categories.removeAll(uncategorizedDisplayName()); // prepended again after sorting new list
|
||||
int previousIndex = categories.indexOf(category);
|
||||
categories.removeAt(previousIndex);
|
||||
categories.append(string);
|
||||
qSort(categories);
|
||||
categories.prepend(uncategorizedDisplayName()); // prepend, so order is like in view
|
||||
int newIndex = categories.indexOf(string);
|
||||
if (newIndex != previousIndex) {
|
||||
// we have same parent so we have to do special stuff for beginMoveRows...
|
||||
@@ -297,30 +291,12 @@ QString ExternalToolModel::categoryForIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid() && !index.parent().isValid() && index.column() == 0 && index.row() >= 0) {
|
||||
const QList<QString> &keys = m_tools.keys();
|
||||
if (index.row() == 0)
|
||||
return uncategorizedDisplayName();
|
||||
if (index.row() < keys.count()) {
|
||||
int uncategorizedIndex = keys.indexOf(uncategorizedDisplayName());
|
||||
if (index.row() <= uncategorizedIndex)
|
||||
return keys.at(index.row() - 1);
|
||||
if (index.row() < keys.count())
|
||||
return keys.at(index.row());
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
int ExternalToolModel::rowForCategory(const QString &category) const
|
||||
{
|
||||
if (category == uncategorizedDisplayName())
|
||||
return 0;
|
||||
const QList<QString> &keys = m_tools.keys();
|
||||
int uncategorizedIndex = keys.indexOf(uncategorizedDisplayName());
|
||||
int index = keys.indexOf(category);
|
||||
if (index < uncategorizedIndex)
|
||||
return index + 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
void ExternalToolModel::revertTool(const QModelIndex &modelIndex)
|
||||
{
|
||||
ExternalTool *tool = toolForIndex(modelIndex);
|
||||
@@ -343,10 +319,8 @@ QModelIndex ExternalToolModel::addCategory()
|
||||
category = categoryBase + QString::number(count);
|
||||
}
|
||||
QList<QString> categories = m_tools.keys();
|
||||
categories.removeAll(uncategorizedDisplayName()); // prepended again after sorting new list
|
||||
categories.append(category);
|
||||
qSort(categories);
|
||||
categories.prepend(uncategorizedDisplayName()); // prepend, so order is like in view
|
||||
int pos = categories.indexOf(category);
|
||||
|
||||
beginInsertRows(QModelIndex(), pos, pos);
|
||||
@@ -358,7 +332,7 @@ QModelIndex ExternalToolModel::addCategory()
|
||||
QModelIndex ExternalToolModel::addTool(const QModelIndex &atIndex)
|
||||
{
|
||||
QString category = categoryForIndex(atIndex);
|
||||
if (category.isEmpty())
|
||||
if (category.isNull())
|
||||
category = categoryForIndex(atIndex.parent());
|
||||
|
||||
ExternalTool *tool = new ExternalTool;
|
||||
@@ -491,8 +465,8 @@ void ExternalToolConfig::setTools(const QMap<QString, QList<ExternalTool *> > &t
|
||||
itemCopy.append(new ExternalTool(tool));
|
||||
toolsCopy.insert(it.key(), itemCopy);
|
||||
}
|
||||
if (!toolsCopy.contains(m_model->uncategorizedDisplayName()))
|
||||
toolsCopy.insert(m_model->uncategorizedDisplayName(), QList<ExternalTool *>());
|
||||
if (!toolsCopy.contains(QString()))
|
||||
toolsCopy.insert(QString(), QList<ExternalTool *>());
|
||||
m_model->setTools(toolsCopy);
|
||||
ui->toolTree->expandAll();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user