forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/2.5'
This commit is contained in:
@@ -74,15 +74,11 @@ 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())
|
||||
bool categoryFound;
|
||||
categoryForIndex(parent, &categoryFound);
|
||||
if (!parent.isValid() || toolForIndex(parent) || categoryFound)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -91,9 +87,11 @@ 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);
|
||||
bool found;
|
||||
QString category = categoryForIndex(index, &found);
|
||||
if (found)
|
||||
return data(category, role);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ExternalToolModel::data(ExternalTool *tool, int role) const
|
||||
@@ -113,10 +111,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;
|
||||
}
|
||||
@@ -130,8 +127,9 @@ QMimeData *ExternalToolModel::mimeData(const QModelIndexList &indexes) const
|
||||
QModelIndex modelIndex = indexes.first();
|
||||
ExternalTool *tool = toolForIndex(modelIndex);
|
||||
QTC_ASSERT(tool, return 0);
|
||||
QString category = categoryForIndex(modelIndex.parent());
|
||||
QTC_ASSERT(!category.isEmpty(), return 0);
|
||||
bool found;
|
||||
QString category = categoryForIndex(modelIndex.parent(), &found);
|
||||
QTC_ASSERT(found, return 0);
|
||||
QMimeData *md = new QMimeData();
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||
@@ -149,8 +147,9 @@ bool ExternalToolModel::dropMimeData(const QMimeData *data,
|
||||
Q_UNUSED(column)
|
||||
if (action != Qt::MoveAction || !data)
|
||||
return false;
|
||||
QString toCategory = categoryForIndex(parent);
|
||||
QTC_ASSERT(!toCategory.isEmpty(), return false);
|
||||
bool found;
|
||||
QString toCategory = categoryForIndex(parent, &found);
|
||||
QTC_ASSERT(found, return false);
|
||||
QByteArray ba = data->data(QLatin1String("application/qtcreator-externaltool-config"));
|
||||
if (ba.isEmpty())
|
||||
return false;
|
||||
@@ -159,15 +158,14 @@ bool ExternalToolModel::dropMimeData(const QMimeData *data,
|
||||
int pos = -1;
|
||||
stream >> category;
|
||||
stream >> pos;
|
||||
QTC_ASSERT(!category.isEmpty(), 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;
|
||||
@@ -181,8 +179,9 @@ QStringList ExternalToolModel::mimeTypes() const
|
||||
QModelIndex ExternalToolModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (column == 0 && parent.isValid()) {
|
||||
QString category = categoryForIndex(parent);
|
||||
if (!category.isEmpty()) {
|
||||
bool found;
|
||||
QString category = categoryForIndex(parent, &found);
|
||||
if (found) {
|
||||
QList<ExternalTool *> items = m_tools.value(category);
|
||||
if (row < items.count()) {
|
||||
return createIndex(row, 0, items.at(row));
|
||||
@@ -197,11 +196,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();
|
||||
@@ -214,8 +215,9 @@ int ExternalToolModel::rowCount(const QModelIndex &parent) const
|
||||
if (toolForIndex(parent)) {
|
||||
return 0;
|
||||
}
|
||||
QString category = categoryForIndex(parent);
|
||||
if (!category.isEmpty()) {
|
||||
bool found;
|
||||
QString category = categoryForIndex(parent, &found);
|
||||
if (found) {
|
||||
return m_tools.value(category).count();
|
||||
}
|
||||
|
||||
@@ -226,9 +228,10 @@ 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())
|
||||
bool found;
|
||||
QString category = categoryForIndex(index, &found);
|
||||
if (found) {
|
||||
if (category.isEmpty())
|
||||
return TOOLSMENU_ITEM_FLAGS;
|
||||
return CATEGORY_ITEM_FLAGS;
|
||||
}
|
||||
@@ -248,18 +251,17 @@ bool ExternalToolModel::setData(const QModelIndex &modelIndex, const QVariant &v
|
||||
emit dataChanged(modelIndex, modelIndex);
|
||||
return true;
|
||||
} else {
|
||||
QString category = categoryForIndex(modelIndex);
|
||||
if (!category.isEmpty()) {
|
||||
bool found;
|
||||
QString category = categoryForIndex(modelIndex, &found);
|
||||
if (found) {
|
||||
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...
|
||||
@@ -293,34 +295,19 @@ ExternalTool *ExternalToolModel::toolForIndex(const QModelIndex &index) const
|
||||
return static_cast<ExternalTool *>(index.internalPointer());
|
||||
}
|
||||
|
||||
QString ExternalToolModel::categoryForIndex(const QModelIndex &index) const
|
||||
QString ExternalToolModel::categoryForIndex(const QModelIndex &index, bool *found) 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 (found) *found = true;
|
||||
return keys.at(index.row());
|
||||
}
|
||||
}
|
||||
if (found) *found = false;
|
||||
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 +330,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);
|
||||
@@ -357,9 +342,10 @@ QModelIndex ExternalToolModel::addCategory()
|
||||
|
||||
QModelIndex ExternalToolModel::addTool(const QModelIndex &atIndex)
|
||||
{
|
||||
QString category = categoryForIndex(atIndex);
|
||||
if (category.isEmpty())
|
||||
category = categoryForIndex(atIndex.parent());
|
||||
bool found;
|
||||
QString category = categoryForIndex(atIndex, &found);
|
||||
if (!found)
|
||||
category = categoryForIndex(atIndex.parent(), &found);
|
||||
|
||||
ExternalTool *tool = new ExternalTool;
|
||||
tool->setDisplayCategory(category);
|
||||
@@ -491,8 +477,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();
|
||||
}
|
||||
|
||||
@@ -73,14 +73,12 @@ public:
|
||||
QMap<QString, QList<ExternalTool *> > tools() const;
|
||||
|
||||
ExternalTool *toolForIndex(const QModelIndex &modelIndex) const;
|
||||
QString categoryForIndex(const QModelIndex &modelIndex) const;
|
||||
int rowForCategory(const QString &category) const;
|
||||
QString categoryForIndex(const QModelIndex &modelIndex, bool *found) const;
|
||||
void revertTool(const QModelIndex &modelIndex);
|
||||
QModelIndex addCategory();
|
||||
QModelIndex addTool(const QModelIndex &atIndex);
|
||||
void removeTool(const QModelIndex &modelIndex);
|
||||
Qt::DropActions supportedDropActions() const;
|
||||
QString uncategorizedDisplayName() const;
|
||||
private:
|
||||
QVariant data(ExternalTool *tool, int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QString &category, int role = Qt::DisplayRole) const;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "vcsmanager.h"
|
||||
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <QDir>
|
||||
@@ -42,6 +43,7 @@
|
||||
#include <QTreeWidget>
|
||||
#include <QHeaderView>
|
||||
#include <QCheckBox>
|
||||
#include <QtDebug>
|
||||
|
||||
Q_DECLARE_METATYPE(Core::IDocument*)
|
||||
|
||||
@@ -54,10 +56,15 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Do not Save"), QDialogButtonBox::DestructiveRole);
|
||||
#ifdef Q_OS_MAC
|
||||
// QDialogButtonBox's behavior for "destructive" is wrong, the "do not save" should be left-aligned
|
||||
QDialogButtonBox::ButtonRole discardButtonRole = QDialogButtonBox::ResetRole;
|
||||
#else
|
||||
QDialogButtonBox::ButtonRole discardButtonRole = QDialogButtonBox::DestructiveRole;
|
||||
#endif
|
||||
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Do not Save"), discardButtonRole);
|
||||
m_ui.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
|
||||
m_ui.buttonBox->button(QDialogButtonBox::Save)->setFocus(Qt::TabFocusReason);
|
||||
m_ui.buttonBox->button(QDialogButtonBox::Save)->setMinimumWidth(130); // bad magic number to avoid resizing of button
|
||||
m_ui.treeWidget->setFocus();
|
||||
|
||||
m_ui.saveBeforeBuildCheckBox->setVisible(false);
|
||||
|
||||
@@ -74,11 +81,17 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
||||
}
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
|
||||
<< visibleName << QDir::toNativeSeparators(directory));
|
||||
if (!fileName.isEmpty())
|
||||
item->setIcon(0, FileIconProvider::instance()->icon(QFileInfo(fileName)));
|
||||
item->setData(0, Qt::UserRole, qVariantFromValue(document));
|
||||
}
|
||||
|
||||
m_ui.treeWidget->resizeColumnToContents(0);
|
||||
m_ui.treeWidget->selectAll();
|
||||
#ifdef Q_OS_MAC
|
||||
m_ui.treeWidget->setAlternatingRowColors(true);
|
||||
#endif
|
||||
adjustButtonWidths();
|
||||
updateSaveButton();
|
||||
|
||||
connect(m_ui.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
|
||||
@@ -108,6 +121,32 @@ void SaveItemsDialog::updateSaveButton()
|
||||
}
|
||||
}
|
||||
|
||||
void SaveItemsDialog::adjustButtonWidths()
|
||||
{
|
||||
// give save button a size that all texts fit in, so it doesn't get resized
|
||||
// Mac: make cancel + save button same size (work around dialog button box issue)
|
||||
QStringList possibleTexts;
|
||||
possibleTexts << tr("Save") << tr("Save All");
|
||||
if (m_ui.treeWidget->topLevelItemCount() > 1)
|
||||
possibleTexts << tr("Save Selected");
|
||||
int maxTextWidth = 0;
|
||||
QPushButton *saveButton = m_ui.buttonBox->button(QDialogButtonBox::Save);
|
||||
foreach (const QString &text, possibleTexts) {
|
||||
saveButton->setText(text);
|
||||
int hint = saveButton->sizeHint().width();
|
||||
if (hint > maxTextWidth)
|
||||
maxTextWidth = hint;
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
QPushButton *cancelButton = m_ui.buttonBox->button(QDialogButtonBox::Cancel);
|
||||
int cancelButtonWidth = cancelButton->sizeHint().width();
|
||||
if (cancelButtonWidth > maxTextWidth)
|
||||
maxTextWidth = cancelButtonWidth;
|
||||
cancelButton->setMinimumWidth(maxTextWidth);
|
||||
#endif
|
||||
saveButton->setMinimumWidth(maxTextWidth);
|
||||
}
|
||||
|
||||
void SaveItemsDialog::collectItemsToSave()
|
||||
{
|
||||
m_itemsToSave.clear();
|
||||
|
||||
@@ -70,6 +70,8 @@ private slots:
|
||||
void updateSaveButton();
|
||||
|
||||
private:
|
||||
void adjustButtonWidths();
|
||||
|
||||
Ui::SaveItemsDialog m_ui;
|
||||
QList<Core::IDocument*> m_itemsToSave;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user