Commit b488d975 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Show imports



Change-Id: If72caf241fcb3cda69790102e369e0ddac9d8d50
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 5dfde6e0
......@@ -29,16 +29,37 @@
#include "importlabel.h"
#include <QHBoxLayout>
#include <QPushButton>
namespace QmlDesigner {
ImportLabel::ImportLabel(QWidget *parent) :
QLabel(parent)
QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_removeButton = new QPushButton("X", this);
m_removeButton->setFlat(true);
m_removeButton->setMaximumWidth(20);
m_removeButton->setMaximumHeight(20);
m_removeButton->setFocusPolicy(Qt::NoFocus);
m_removeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
layout->addWidget(m_removeButton);
m_importLabel = new QLabel(this);
layout->addWidget(m_importLabel);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
void ImportLabel::setImport(const Import &import)
{
setText(import.toString());
m_importLabel->setText(import.toString(false));
if (import.url() == "QtQuick")
m_removeButton->setDisabled(true);
}
} // namespace QmlDesigner
......@@ -31,12 +31,13 @@
#define IMPORTLABEL_H
#include <QLabel>
#include <QPushButton>
#include <import.h>
namespace QmlDesigner {
class ImportLabel : public QLabel
class ImportLabel : public QWidget
{
Q_OBJECT
public:
......@@ -44,6 +45,9 @@ public:
void setImport(const Import &import);
private:
QLabel *m_importLabel;
QPushButton *m_removeButton;
};
}
......
......@@ -38,6 +38,7 @@ namespace QmlDesigner {
ImportsWidget::ImportsWidget(QWidget *parent) :
QWidget(parent)
{
setWindowTitle(tr("Import Manager"));
}
void ImportsWidget::removeAllImports()
......@@ -47,12 +48,39 @@ void ImportsWidget::removeAllImports()
updateLayout();
}
static bool importLess(const Import &firstImport, const Import &secondImport)
{
if (firstImport.url() == "QtQuick")
return true;
if (secondImport.url() == "QtQuick")
return false;
if (firstImport.isLibraryImport() && secondImport.isFileImport())
return true;
if (firstImport.isFileImport() && secondImport.isLibraryImport())
return false;
if (firstImport.isFileImport() && secondImport.isFileImport())
return QString::localeAwareCompare(firstImport.file(), secondImport.file()) < 0;
if (firstImport.isLibraryImport() && secondImport.isLibraryImport())
return QString::localeAwareCompare(firstImport.url(), secondImport.url()) < 0;
return false;
}
void ImportsWidget::setImports(const QList<Import> &imports)
{
qDeleteAll(m_importLabels);
m_importLabels.clear();
foreach (const Import &import, imports) {
QList<Import> sortedImports = imports;
qSort(sortedImports.begin(), sortedImports.end(), importLess);
foreach (const Import &import, sortedImports) {
ImportLabel *importLabel = new ImportLabel(this);
importLabel->setImport(import);
m_importLabels.append(importLabel);
......@@ -66,6 +94,7 @@ void ImportsWidget::updateLayout()
delete layout();
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
foreach (ImportLabel *importLabel, m_importLabels)
layout->addWidget(importLabel);
......
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