diff options
Diffstat (limited to 'examples')
19 files changed, 7 insertions, 956 deletions
diff --git a/examples/uml/nested-packages/main.cpp b/examples/uml/nested-packages/main.cpp index b9e1b492..1120aa99 100644 --- a/examples/uml/nested-packages/main.cpp +++ b/examples/uml/nested-packages/main.cpp @@ -12,7 +12,6 @@ #include <QtCore/QDebug> using namespace QtUml; -using namespace QtWrappedObjects; void checkProperties(QWrappedObject *wrappedObject) { diff --git a/examples/uml/profiles/main.cpp b/examples/uml/profiles/main.cpp index a03fb268..c30c884c 100644 --- a/examples/uml/profiles/main.cpp +++ b/examples/uml/profiles/main.cpp @@ -13,7 +13,6 @@ #include <QtCore/QDebug> using namespace QtUml; -using QtWrappedObjects::QWrappedObjectPointer; typedef const QSet<QStereotype *> QStereotypeList; typedef const QSet<QPackageableElement *> QPackageableElementList; diff --git a/examples/uml/qtumleditor/filterwidget.cpp b/examples/uml/qtumleditor/filterwidget.cpp deleted file mode 100644 index 0bc3fdfd..00000000 --- a/examples/uml/qtumleditor/filterwidget.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Designer of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "filterwidget.h" - -#include <QtCore/QPropertyAnimation> - -#include <QtGui/QFocusEvent> -#include <QtGui/QPainter> - -#include <QtWidgets/QHBoxLayout> -#include <QtWidgets/QStyle> - -enum { debugFilter = 0 }; - -HintLineEdit::HintLineEdit(QWidget *parent) : - QLineEdit(parent), - m_defaultFocusPolicy(focusPolicy()), - m_refuseFocus(false) -{ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); -} - -IconButton::IconButton(QWidget *parent) - : QToolButton(parent) -{ - setCursor(Qt::ArrowCursor); -} - -void IconButton::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - // Note isDown should really use the active state but in most styles - // this has no proper feedback - QIcon::Mode state = QIcon::Disabled; - if (isEnabled()) - state = isDown() ? QIcon::Selected : QIcon::Normal; - QPixmap iconpixmap = icon().pixmap(QSize(ICONBUTTON_SIZE, ICONBUTTON_SIZE), - state, QIcon::Off); - QRect pixmapRect = QRect(0, 0, iconpixmap.width(), iconpixmap.height()); - pixmapRect.moveCenter(rect().center()); - painter.setOpacity(m_fader); - painter.drawPixmap(pixmapRect, iconpixmap); -} - -void IconButton::animateShow(bool visible) -{ - if (visible) { - QPropertyAnimation *animation = new QPropertyAnimation(this, "fader"); - animation->setDuration(160); - animation->setEndValue(1.0); - animation->start(QAbstractAnimation::DeleteWhenStopped); - } else { - QPropertyAnimation *animation = new QPropertyAnimation(this, "fader"); - animation->setDuration(160); - animation->setEndValue(0.0); - animation->start(QAbstractAnimation::DeleteWhenStopped); - } -} - -bool HintLineEdit::refuseFocus() const -{ - return m_refuseFocus; -} - -void HintLineEdit::setRefuseFocus(bool v) -{ - if (v == m_refuseFocus) - return; - m_refuseFocus = v; - setFocusPolicy(m_refuseFocus ? Qt::NoFocus : m_defaultFocusPolicy); -} - -void HintLineEdit::mousePressEvent(QMouseEvent *e) -{ - // Explicitly focus on click. - if (m_refuseFocus && !hasFocus()) - setFocus(Qt::OtherFocusReason); - QLineEdit::mousePressEvent(e); -} - -void HintLineEdit::focusInEvent(QFocusEvent *e) -{ - if (m_refuseFocus) { - // Refuse the focus if the mouse it outside. In addition to the mouse - // press logic, this prevents a re-focussing which occurs once - // we actually had focus - const Qt::FocusReason reason = e->reason(); - if (reason == Qt::ActiveWindowFocusReason || reason == Qt::PopupFocusReason) { - const QPoint mousePos = mapFromGlobal(QCursor::pos()); - const bool refuse = !geometry().contains(mousePos); - if (refuse) { - e->ignore(); - return; - } - } - } - - QLineEdit::focusInEvent(e); -} - -// ------------------- FilterWidget -FilterWidget::FilterWidget(QWidget *parent, LayoutMode lm) : - QWidget(parent), - m_editor(new HintLineEdit(this)), - m_button(new IconButton(m_editor)), - m_buttonwidth(0) -{ - m_editor->setPlaceholderText(tr("Filter")); - - // Let the style determine minimum height for our widget - QSize size(ICONBUTTON_SIZE + 6, ICONBUTTON_SIZE + 2); - - // Note KDE does not reserve space for the highlight color - if (style()->inherits("OxygenStyle")) { - size = size.expandedTo(QSize(24, 0)); - } - - // Make room for clear icon - QMargins margins = m_editor->textMargins(); - if (layoutDirection() == Qt::LeftToRight) - margins.setRight(size.width()); - else - margins.setLeft(size.width()); - - m_editor->setTextMargins(margins); - - QHBoxLayout *l = new QHBoxLayout(this); - l->setMargin(0); - l->setSpacing(0); - if (lm == LayoutAlignRight) - l->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); - - l->addWidget(m_editor); - - // KDE has custom icons for this. Notice that icon namings are counter intuitive - // If these icons are not available we use the freedesktop standard name before - // falling back to a bundled resource - QIcon icon = QIcon::fromTheme(layoutDirection() == Qt::LeftToRight ? - QStringLiteral("edit-clear-locationbar-rtl") : - QStringLiteral("edit-clear-locationbar-ltr"), - QIcon::fromTheme(QStringLiteral("edit-clear"), createIconSet(QStringLiteral("cleartext.png")))); - - m_button->setIcon(icon); - m_button->setToolTip(tr("Clear text")); - connect(m_button, SIGNAL(clicked()), this, SLOT(reset())); - connect(m_editor, SIGNAL(textChanged(QString)), this, SLOT(checkButton(QString))); - connect(m_editor, SIGNAL(textEdited(QString)), this, SIGNAL(filterChanged(QString))); -} - -QString FilterWidget::text() const -{ - return m_editor->text(); -} - -void FilterWidget::checkButton(const QString &text) -{ - if (m_oldText.isEmpty() || text.isEmpty()) - m_button->animateShow(!m_editor->text().isEmpty()); - m_oldText = text; -} - -QIcon FilterWidget::createIconSet(const QString &name) -{ - QStringList candidates = QStringList() - << (QString::fromUtf8(":/icons/") + name) -#ifdef Q_OS_MAC - << (QString::fromUtf8(":/icons/mac/") + name); -#else - << (QString::fromUtf8(":/icons/win/") + name); -#endif - - foreach (const QString &f, candidates) { - if (QFile::exists(f)) - return QIcon(f); - } - - return QIcon(); -} - -void FilterWidget::reset() -{ - if (!m_editor->text().isEmpty()) { - // Editor has lost focus once this is pressed - m_editor->clear(); - emit filterChanged(QString()); - } -} - -void FilterWidget::resizeEvent(QResizeEvent *) -{ - QRect contentRect = m_editor->rect(); - if (layoutDirection() == Qt::LeftToRight) { - const int iconoffset = m_editor->textMargins().right() + 4; - m_button->setGeometry(contentRect.adjusted(m_editor->width() - iconoffset, 0, 0, 0)); - } else { - const int iconoffset = m_editor->textMargins().left() + 4; - m_button->setGeometry(contentRect.adjusted(0, 0, -m_editor->width() + iconoffset, 0)); - } -} - -bool FilterWidget::refuseFocus() const -{ - return m_editor->refuseFocus(); -} - -void FilterWidget::setRefuseFocus(bool v) -{ - m_editor->setRefuseFocus(v); -} diff --git a/examples/uml/qtumleditor/filterwidget.h b/examples/uml/qtumleditor/filterwidget.h deleted file mode 100644 index c163190b..00000000 --- a/examples/uml/qtumleditor/filterwidget.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt Designer of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef FILTERWIDGET_H -#define FILTERWIDGET_H - -#include <QtWidgets/QLineEdit> -#include <QtWidgets/QToolButton> - -#define ICONBUTTON_SIZE 16 - -class HintLineEdit : public QLineEdit { - Q_OBJECT -public: - explicit HintLineEdit(QWidget *parent = 0); - - bool refuseFocus() const; - void setRefuseFocus(bool v); - -protected: - virtual void mousePressEvent(QMouseEvent *event); - virtual void focusInEvent(QFocusEvent *e); - -private: - const Qt::FocusPolicy m_defaultFocusPolicy; - bool m_refuseFocus; -}; - -// IconButton: This is a simple helper class that represents clickable icons - -class IconButton: public QToolButton -{ - Q_OBJECT - Q_PROPERTY(float fader READ fader WRITE setFader) -public: - IconButton(QWidget *parent); - void paintEvent(QPaintEvent *event); - float fader() { return m_fader; } - void setFader(float value) { m_fader = value; update(); } - void animateShow(bool visible); - -private: - float m_fader; -}; - -// FilterWidget: For filtering item views, with reset button Uses HintLineEdit. - -class FilterWidget : public QWidget -{ - Q_OBJECT -public: - enum LayoutMode { - // For use in toolbars: Expand to the right - LayoutAlignRight, - // No special alignment - LayoutAlignNone - }; - - explicit FilterWidget(QWidget *parent = 0, LayoutMode lm = LayoutAlignNone); - - QString text() const; - void resizeEvent(QResizeEvent *); - bool refuseFocus() const; // see HintLineEdit - void setRefuseFocus(bool v); - -Q_SIGNALS: - void filterChanged(const QString &); - -public Q_SLOTS: - void reset(); - -private Q_SLOTS: - void checkButton(const QString &text); - -private: - QIcon createIconSet(const QString &name); - - HintLineEdit *m_editor; - IconButton *m_button; - int m_buttonwidth; - QString m_oldText; -}; - -#endif diff --git a/examples/uml/qtumleditor/mainwindow.cpp b/examples/uml/qtumleditor/mainwindow.cpp index beb37a48..dcbc8409 100644 --- a/examples/uml/qtumleditor/mainwindow.cpp +++ b/examples/uml/qtumleditor/mainwindow.cpp @@ -17,8 +17,6 @@ #include <QtMof/QXmiWriter> #include <QtMof/QXmiReader> -using QtWrappedObjectsWidgets::QWrappedObjectPropertyModel; - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), diff --git a/examples/uml/qtumleditor/mainwindow.h b/examples/uml/qtumleditor/mainwindow.h index ce4d29f0..4cdae52c 100644 --- a/examples/uml/qtumleditor/mainwindow.h +++ b/examples/uml/qtumleditor/mainwindow.h @@ -13,18 +13,9 @@ namespace Ui { class AboutPlugins; } -namespace QtWrappedObjects { - class QWrappedObject; - class QMetaModelPlugin; -} - -namespace QtWrappedObjectsWidgets { - class QWrappedObjectModel; -} - -using QtWrappedObjects::QWrappedObject; -using QtWrappedObjects::QMetaModelPlugin; -using QtWrappedObjectsWidgets::QWrappedObjectModel; +class QWrappedObject; +class QMetaModelPlugin; +class QWrappedObjectModel; class MainWindow : public QMainWindow { diff --git a/examples/uml/qtumleditor/propertyeditor.cpp b/examples/uml/qtumleditor/propertyeditor.cpp deleted file mode 100644 index 36745f68..00000000 --- a/examples/uml/qtumleditor/propertyeditor.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "propertyeditor.h" - -#include <QtWidgets/QHBoxLayout> -#include <QtWidgets/QToolButton> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QCheckBox> - -#include <QtWrappedObjects/QMetaPropertyInfo> -#include <QtWrappedObjects/QWrappedObject> - -PropertyEditor::PropertyEditor(QWidget *widget, QMetaPropertyInfo *metaPropertyInfo, QWidget *parent) : - QWidget(parent), _widget(widget), _metaPropertyInfo(metaPropertyInfo) -{ - QHBoxLayout *layout = new QHBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(_widget); - if (widget && _metaPropertyInfo->metaProperty.isResettable()) { - QToolButton *toolButton = new QToolButton; - toolButton->setIcon(QPixmap(":/icons/resetproperty.png")); - toolButton->setMaximumSize(22, 22); - toolButton->setEnabled(_metaPropertyInfo->propertyWrappedObject->isPropertyModified(_metaPropertyInfo->metaProperty)); - connect(toolButton, &QToolButton::clicked, this, &PropertyEditor::resetClicked); - layout->addWidget(toolButton); - } - setLayout(layout); - if (QComboBox *comboBox = qobject_cast<QComboBox *>(_widget)) - connect(comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](){ emit commitData(this); }); - if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(_widget)) - connect(checkBox, &QCheckBox::stateChanged, [=](){ emit commitData(this); }); -} - -int PropertyEditor::value() const -{ - if (QComboBox *comboBox = qobject_cast<QComboBox *>(_widget)) - return comboBox->currentIndex(); - if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(_widget)) - return checkBox->isChecked() ? 1:0; - return -1; -} - -void PropertyEditor::setValue(int value) -{ - if (QComboBox *comboBox = qobject_cast<QComboBox *>(_widget)) { - if (comboBox->currentIndex() != value) { - comboBox->setCurrentIndex(value); - emit commitData(this); - } - } - if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(_widget)) { - if (checkBox->isChecked() != (value == 0 ? false:true)) { - checkBox->setChecked(value == 0 ? false:true); - emit commitData(this); - } - } -} - -void PropertyEditor::resetClicked() -{ - _metaPropertyInfo->metaProperty.reset(_metaPropertyInfo->propertyWrappedObject); - emit closeEditor(this); -} diff --git a/examples/uml/qtumleditor/propertyeditor.h b/examples/uml/qtumleditor/propertyeditor.h deleted file mode 100644 index f1f5153f..00000000 --- a/examples/uml/qtumleditor/propertyeditor.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef PROPERTYEDITOR_H -#define PROPERTYEDITOR_H - -#include <QtWidgets/QWidget> -#include <QtWidgets/QAbstractItemDelegate> - -namespace QtWrappedObjects { - class QMetaPropertyInfo; -} -using QtWrappedObjects::QMetaPropertyInfo; - -class PropertyEditor : public QWidget -{ - Q_OBJECT - Q_PROPERTY(int value READ value WRITE setValue USER true) - -public: - explicit PropertyEditor(QWidget *widget, QMetaPropertyInfo *metaPropertyInfo, QWidget *parent = 0); - - int value() const; - -public Q_SLOTS: - void setValue(int value); - -Q_SIGNALS: - void commitData(QWidget *editor); - void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint = QAbstractItemDelegate::NoHint); - -private Q_SLOTS: - void resetClicked(); - -private: - QWidget *_widget; - QMetaPropertyInfo *_metaPropertyInfo; -}; - -#endif // PROPERTYEDITOR_H diff --git a/examples/uml/qtumleditor/propertyeditoritemdelegate.cpp b/examples/uml/qtumleditor/propertyeditoritemdelegate.cpp deleted file mode 100644 index 88cf9645..00000000 --- a/examples/uml/qtumleditor/propertyeditoritemdelegate.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "propertyeditoritemdelegate.h" - -#include <QtWidgets/QApplication> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QLineEdit> - -#include <QtWrappedObjects/QWrappedObject> -#include <QtWrappedObjects/QMetaPropertyInfo> - -#include "propertyeditor.h" - -using QtWrappedObjects::QMetaPropertyInfo; - -PropertyEditorItemDelegate::PropertyEditorItemDelegate(QObject *parent) : - QStyledItemDelegate(parent) -{ -} - -QWidget *PropertyEditorItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (QMetaPropertyInfo *metaPropertyInfo = qvariant_cast<QMetaPropertyInfo *>(index.data(Qt::UserRole))) { - QMetaProperty metaProperty = metaPropertyInfo->metaProperty; - - if (metaProperty.type() == QVariant::Bool || metaProperty.isEnumType()) { - QWidget *widget = 0; - if (metaProperty.type() == QVariant::Bool) { - widget = new QCheckBox; - } - else if (metaProperty.isEnumType()) { - QComboBox *comboBox = new QComboBox(parent); - QMetaEnum metaEnum = metaProperty.enumerator(); - int keyCount = metaEnum.keyCount(); - for (int j = 0; j < keyCount; ++j) - comboBox->addItem(QString(metaEnum.key(j)).toLower().remove(QString(metaProperty.name()))); - comboBox->setMaximumHeight(22); - widget = comboBox; - } - PropertyEditor *propertyEditor = new PropertyEditor(widget, metaPropertyInfo, parent); - connect(propertyEditor, &PropertyEditor::commitData, this, &PropertyEditorItemDelegate::commitData); - connect(propertyEditor, &PropertyEditor::closeEditor, this, &PropertyEditorItemDelegate::closeEditor); - return propertyEditor; - } - else if (metaProperty.type() == QVariant::String) - return QStyledItemDelegate::createEditor(parent, option, index); - else return 0; - } - return QStyledItemDelegate::createEditor(parent, option, index); -} - -void PropertyEditorItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - if (QMetaPropertyInfo *metaPropertyInfo = qvariant_cast<QMetaPropertyInfo *>(index.data(Qt::UserRole))) { - QMetaProperty metaProperty = metaPropertyInfo->metaProperty; - PropertyEditor *propertyEditor = qobject_cast<PropertyEditor *>(editor); - if (metaProperty.type() == QVariant::Bool) - propertyEditor->setValue(metaProperty.read(metaPropertyInfo->propertyWrappedObject).toBool() == true ? 1:0); - else if (metaProperty.isEnumType()) - propertyEditor->setValue(metaProperty.read(metaPropertyInfo->propertyWrappedObject).toInt()); - else - QStyledItemDelegate::setEditorData(editor, index); - } - else - QStyledItemDelegate::setEditorData(editor, index); -} - -void PropertyEditorItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (index.column() == 1 && index.isValid()) { - QVariant variant = index.data(Qt::DisplayRole); - if (variant.isValid() && variant.type() == QVariant::Bool) { - bool checked = variant.toBool(); - QStyleOptionButton opt; - opt.state = QStyle::State_Enabled; - opt.state |= (checked) ? QStyle::State_On:QStyle::State_Off; - opt.direction = QApplication::layoutDirection(); - opt.rect = option.rect; - QApplication::style()->drawControl(QStyle::CE_CheckBox, &opt, painter); - } - else QStyledItemDelegate::paint(painter, option, index); - } - else - QStyledItemDelegate::paint(painter, option, index); -} - -void PropertyEditorItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const -{ - if (QMetaPropertyInfo *metaPropertyInfo = qvariant_cast<QMetaPropertyInfo *>(index.data(Qt::UserRole))) { - QMetaProperty metaProperty = metaPropertyInfo->metaProperty; - if (metaProperty.type() == QVariant::Bool || metaProperty.isEnumType()) { - PropertyEditor *propertyEditor = qobject_cast<PropertyEditor *>(editor); - model->setData(index, propertyEditor->value(), Qt::DisplayRole); - } - else if (metaProperty.type() == QVariant::String) { - QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor); - model->setData(index, lineEdit->text(), Qt::DisplayRole); - } - else - QStyledItemDelegate::setModelData(editor, model, index); - } - else - QStyledItemDelegate::setModelData(editor, model, index); -} - -bool PropertyEditorItemDelegate::eventFilter(QObject *object, QEvent *event) -{ - if (event->type() == QEvent::FocusOut) - return false; - else - return QStyledItemDelegate::eventFilter(object, event); -} diff --git a/examples/uml/qtumleditor/propertyeditoritemdelegate.h b/examples/uml/qtumleditor/propertyeditoritemdelegate.h deleted file mode 100644 index c39bfdfd..00000000 --- a/examples/uml/qtumleditor/propertyeditoritemdelegate.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PROPERTYEDITORITEMDELEGATE_H -#define PROPERTYEDITORITEMDELEGATE_H - -#include <QStyledItemDelegate> - -class PropertyEditorItemDelegate : public QStyledItemDelegate -{ - Q_OBJECT -public: - explicit PropertyEditorItemDelegate(QObject *parent = 0); - - virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; - virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; - virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; - bool eventFilter(QObject *object, QEvent *event); -}; - -#endif // PROPERTYEDITORITEMDELEGATE_H diff --git a/examples/uml/qtumleditor/qtumleditor.pro b/examples/uml/qtumleditor/qtumleditor.pro index 4ffb3c21..77bd4971 100644 --- a/examples/uml/qtumleditor/qtumleditor.pro +++ b/examples/uml/qtumleditor/qtumleditor.pro @@ -4,9 +4,7 @@ # #------------------------------------------------- -QT = wrappedobjects wrappedobjectswidgets mof - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT = wrappedobjectswidgets mof TARGET = qtumleditor TEMPLATE = app @@ -20,25 +18,13 @@ INSTALLS += target xmi CONFIG += c++11 -SOURCES += main.cpp\ - mainwindow.cpp \ - propertyeditoritemdelegate.cpp \ - propertyeditor.cpp \ - wrappedobjectpropertyfiltermodel.cpp \ - filterwidget.cpp \ - qwrappedobjectpropertyeditor.cpp \ - qwrappedobjectview.cpp +SOURCES += main.cpp \ + mainwindow.cpp HEADERS += mainwindow.h \ - propertyeditoritemdelegate.h \ - propertyeditor.h \ - wrappedobjectpropertyfiltermodel.h \ - filterwidget.h \ - qwrappedobjectpropertyeditor.h \ - qwrappedobjectview.h FORMS += mainwindow.ui \ - aboutplugins.ui + aboutplugins.ui RESOURCES += \ qtumleditor.qrc diff --git a/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.cpp b/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.cpp deleted file mode 100644 index 3b8ea6c2..00000000 --- a/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "qwrappedobjectpropertyeditor.h" - -#include <QtWidgets/QLabel> -#include <QtWidgets/QTreeView> -#include <QtWidgets/QVBoxLayout> - -#include <QtWrappedObjects/QWrappedObject> -#include <QtWrappedObjectsWidgets/QWrappedObjectPropertyModel> - -#include "filterwidget.h" -#include "propertyeditoritemdelegate.h" -#include "wrappedobjectpropertyfiltermodel.h" - -using QtWrappedObjects::QWrappedObject; - -QWrappedObjectPropertyEditor::QWrappedObjectPropertyEditor(QWidget *parent) : - QWidget(parent), - _filter(new FilterWidget), - _label(new QLabel), - _treeView(new QTreeView), - _proxyModel(new WrappedObjectPropertyFilterModel(this)), - _propertyModel(0) -{ - _treeView->setMinimumSize(QSize(350, 0)); - _treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); - _treeView->setAlternatingRowColors(true); - QPalette propertyPallete = _treeView->palette(); - propertyPallete.setColor(QPalette::Active, QPalette::Base, QColor(255, 242, 222)); - propertyPallete.setColor(QPalette::Inactive, QPalette::Base, QColor(255, 242, 222)); - propertyPallete.setColor(QPalette::Active, QPalette::AlternateBase, QColor(255, 255, 191)); - propertyPallete.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(255, 255, 191)); - _treeView->setPalette(propertyPallete); - _treeView->setUniformRowHeights(true); - _treeView->setItemDelegateForColumn(1, new PropertyEditorItemDelegate(_treeView)); - _treeView->setModel(_proxyModel); - - _proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setSpacing(2); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(_filter); - layout->addWidget(_label); - layout->addWidget(_treeView); - - connect(_filter, &FilterWidget::filterChanged, - _proxyModel, static_cast<void (QSortFilterProxyModel::*)(const QString &)>(&QSortFilterProxyModel::setFilterRegExp)); - connect(_filter, &FilterWidget::filterChanged, [=](){ - _treeView->expandAll(); - _treeView->resizeColumnToContents(0); - _treeView->resizeColumnToContents(1); - }); -} - -void QWrappedObjectPropertyEditor::setModel(QWrappedObjectPropertyModel *propertyModel) -{ - if (_propertyModel) - disconnect(_propertyModel, 0, this, 0); - _propertyModel = propertyModel; - _proxyModel->setSourceModel(_propertyModel); - if (propertyModel) { - connect(propertyModel, &QAbstractItemModel::modelReset, [=]() { - _label->setText(QString::fromLatin1("%1: %2").arg(_propertyModel->wrappedObject()->objectName()).arg(_propertyModel->wrappedObject()->metaObject()->className())); - _treeView->expandAll(); - _treeView->resizeColumnToContents(0); - _treeView->resizeColumnToContents(1); - }); - } -} - -QWrappedObjectPropertyModel *QWrappedObjectPropertyEditor::model() const -{ - return _propertyModel; -} diff --git a/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.h b/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.h deleted file mode 100644 index d020519a..00000000 --- a/examples/uml/qtumleditor/qwrappedobjectpropertyeditor.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef QWRAPPEDOBJECTPROPERTYEDITOR_H -#define QWRAPPEDOBJECTPROPERTYEDITOR_H - -#include <QtWidgets/QWidget> - -class FilterWidget; -class QLabel; -class QTreeView; - -namespace QtWrappedObjectsWidgets { - class QWrappedObjectPropertyModel; -} - -class WrappedObjectPropertyFilterModel; - -using QtWrappedObjectsWidgets::QWrappedObjectPropertyModel; - -class QWrappedObjectPropertyEditor : public QWidget -{ - Q_OBJECT -public: - explicit QWrappedObjectPropertyEditor(QWidget *parent = 0); - - QWrappedObjectPropertyModel *model() const; - -public Q_SLOTS: - void setModel(QWrappedObjectPropertyModel *model); - -private: - FilterWidget *_filter; - QLabel *_label; - QTreeView *_treeView; - WrappedObjectPropertyFilterModel *_proxyModel; - QWrappedObjectPropertyModel *_propertyModel; -}; - -#endif // QWRAPPEDOBJECTPROPERTYEDITOR_H diff --git a/examples/uml/qtumleditor/qwrappedobjectview.cpp b/examples/uml/qtumleditor/qwrappedobjectview.cpp deleted file mode 100644 index e821e9b2..00000000 --- a/examples/uml/qtumleditor/qwrappedobjectview.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "qwrappedobjectview.h" - -#include <QtCore/QRegularExpression> - -#include <QtWidgets/QMenu> -#include <QtWidgets/QTreeView> -#include <QtWidgets/QVBoxLayout> - -#include <QtGui/QContextMenuEvent> - -#include <QtWrappedObjects/QWrappedObject> -#include <QtWrappedObjects/QMetaWrappedObject> -#include <QtWrappedObjectsWidgets/QWrappedObjectModel> - -using QtWrappedObjects::QMetaWrappedObject; -using QtWrappedObjectsWidgets::QWrappedObjectModel; - -QWrappedObjectView::QWrappedObjectView(QWidget *parent) : - QWidget(parent), - _treeView(new QTreeView) -{ - _treeView->setEditTriggers(QAbstractItemView::AllEditTriggers); - _treeView->setAlternatingRowColors(true); - QPalette modelPallete = _treeView->palette(); - modelPallete.setColor(QPalette::Active, QPalette::Base, QColor(255, 255, 255)); - modelPallete.setColor(QPalette::Inactive, QPalette::Base, QColor(255, 255, 255)); - modelPallete.setColor(QPalette::Active, QPalette::AlternateBase, QColor(248, 247, 246)); - modelPallete.setColor(QPalette::Inactive, QPalette::AlternateBase, QColor(248, 247, 246)); - _treeView->setPalette(modelPallete); - _treeView->setUniformRowHeights(true); - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setSpacing(0); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(_treeView); -} - -void QWrappedObjectView::setModel(QAbstractItemModel *model) -{ - if (_treeView->model()) - disconnect(_treeView->model(), 0, this, 0); - if (_treeView->selectionModel()) - disconnect(_treeView->selectionModel(), 0, this, 0); - _treeView->setModel(model); - if (model) { - connect(model, &QAbstractItemModel::modelReset, [=]() { - _treeView->setCurrentIndex(model->index(0, 0)); - _treeView->expandAll(); - _treeView->resizeColumnToContents(0); - _treeView->resizeColumnToContents(1); - }); - connect(model, &QAbstractItemModel::rowsInserted, [=](const QModelIndex &parent, int first){ - _treeView->setCurrentIndex(model->index(first, 0, parent)); - }); - connect(_treeView->selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &selected){ - emit wrappedObjectChanged(qvariant_cast<QWrappedObject *>(selected.indexes().first().data(Qt::UserRole))); - }); - } -} - -void QWrappedObjectView::updateSelected() -{ - (dynamic_cast<QWrappedObjectModel *>(_treeView->model()))->updateIndex(_treeView->selectionModel()->selectedIndexes().first()); -} - -void QWrappedObjectView::contextMenuEvent(QContextMenuEvent *event) -{ - QMenu menu(this); - QWrappedObject *element = qvariant_cast<QWrappedObject *>(_treeView->currentIndex().data(Qt::UserRole)); - _visitedAddMethods.clear(); - populateContextMenu(menu, element); - menu.exec(event->globalPos()); -} - -void QWrappedObjectView::handleAddMethod() -{ - QAction *action = qobject_cast<QAction *>(sender()); - if (action) { - QObject *element = _visitedAddMethods[action->text()].first; - QMetaMethod metaMethod = _visitedAddMethods[action->text()].second; - QString elementType = action->data().toString(); - int type; - if ((type = QMetaType::type(elementType.toLatin1())) != QMetaType::UnknownType) { - const QMetaObject *metaObject = QMetaType::metaObjectForType(type); - if (metaObject) { - QObject *addedElement = metaObject->newInstance(); - if (addedElement) { - addedElement->setObjectName(QString("Unamed %1").arg(elementType.remove("*"))); - metaMethod.invoke(element, ::Q_ARG(QObject *, addedElement)); - } - } - } - } - QWrappedObjectModel *wrappedObjectModel = dynamic_cast<QWrappedObjectModel *>(_treeView->model()); - wrappedObjectModel->updateIndex(QModelIndex()); -} - -void QWrappedObjectView::populateContextMenu(QMenu &menu, QtWrappedObjects::QWrappedObject *element) -{ - const QMetaWrappedObject *metaWrappedObject = element->metaWrappedObject(); - int propertyCount = metaWrappedObject->propertyCount(); - for (int i = 0; i < propertyCount; ++i) { - QString propertyName = metaWrappedObject->property(i).metaProperty.name(); - QString propertyType = metaWrappedObject->property(i).metaProperty.typeName(); - QString modifiedPropertyName = QString(propertyName.left(1).toUpper()+propertyName.mid(1)).remove(QRegularExpression("s$")).replace(QRegularExpression("ie$"), "y").replace(QRegularExpression("se$"), "s").replace(QRegularExpression("ice$"), "ex").replace(QRegularExpression("ce$"), "x").remove(QRegularExpression("_$")); - QString methodSignature; - QString actionText; - if (propertyType.contains("QList") || propertyType.contains("QSet") || propertyType.endsWith("*")) { - if (propertyType.contains("QList") || propertyType.contains("QSet")) { - propertyType = propertyType.remove("QList<").remove("QSet<").remove(">"); - methodSignature = QString("add%1(%2)").arg(modifiedPropertyName).arg(propertyType); - actionText = tr("Add %1").arg(modifiedPropertyName); - } - else if (propertyType.endsWith("*")) { - methodSignature = QString("set%1(%2)").arg(modifiedPropertyName).arg(propertyType); - actionText = tr("Set %1").arg(modifiedPropertyName); - } - int metaMethodIndex; - if ((metaMethodIndex = element->metaObject()->indexOfMethod(methodSignature.toLatin1())) != -1 and !_visitedAddMethods.contains(actionText)) { - QAction *action = new QAction(actionText, this); - _visitedAddMethods[actionText] = QPair<QObject *, QMetaMethod>(element, element->metaObject()->method(metaMethodIndex)); - action->setData(propertyType); - connect(action, &QAction::triggered, this, &QWrappedObjectView::handleAddMethod); - menu.addAction(action); - } - } - } -} diff --git a/examples/uml/qtumleditor/qwrappedobjectview.h b/examples/uml/qtumleditor/qwrappedobjectview.h deleted file mode 100644 index 7de4cf7e..00000000 --- a/examples/uml/qtumleditor/qwrappedobjectview.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef QWRAPPEDOBJECTVIEW_H -#define QWRAPPEDOBJECTVIEW_H - -#include <QtWidgets/QWidget> - -#include <QtCore/QMetaMethod> - -class QMenu; -class QTreeView; -class QAbstractItemModel; - -namespace QtWrappedObjects -{ - class QWrappedObject; -}; -using QtWrappedObjects::QWrappedObject; - -class QWrappedObjectView : public QWidget -{ - Q_OBJECT -public: - explicit QWrappedObjectView(QWidget *parent = 0); - -public Q_SLOTS: - virtual void setModel(QAbstractItemModel *model); - void updateSelected(); - -Q_SIGNALS: - void wrappedObjectChanged(QWrappedObject *selectedWrappedObject); - -protected: - void contextMenuEvent(QContextMenuEvent *event); - -private Q_SLOTS: - void handleAddMethod(); - -private: - void populateContextMenu(QMenu &menu, QtWrappedObjects::QWrappedObject *element); - - QTreeView *_treeView; - QHash< QString, QPair<QObject *, QMetaMethod> > _visitedAddMethods; -}; - -#endif // QWRAPPEDOBJECTVIEW_H diff --git a/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.cpp b/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.cpp deleted file mode 100644 index 683a8e9d..00000000 --- a/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "wrappedobjectpropertyfiltermodel.h" - -WrappedObjectPropertyFilterModel::WrappedObjectPropertyFilterModel(QObject *parent) : - QSortFilterProxyModel(parent) -{ -} - -bool WrappedObjectPropertyFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const -{ - int rows; - QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); - if ((rows = sourceModel()->rowCount(sourceIndex)) > 0) { - for (int i = 0; i < rows; ++i) - if (filterAcceptsRow(i, sourceIndex)) - return true; - return false; - } - else { - return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); - } -} diff --git a/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.h b/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.h deleted file mode 100644 index 9740825b..00000000 --- a/examples/uml/qtumleditor/wrappedobjectpropertyfiltermodel.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef WRAPPEDOBJECTPROPERTYFILTERMODEL_H -#define WRAPPEDOBJECTPROPERTYFILTERMODEL_H - -#include <QSortFilterProxyModel> - -class WrappedObjectPropertyFilterModel : public QSortFilterProxyModel -{ - Q_OBJECT -public: - explicit WrappedObjectPropertyFilterModel(QObject *parent = 0); - -protected: - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; -}; - -#endif // WRAPPEDOBJECTPROPERTYFILTERMODEL_H diff --git a/examples/uml/xmi-read/main.cpp b/examples/uml/xmi-read/main.cpp index 7f2fe7a6..0a27c3a3 100644 --- a/examples/uml/xmi-read/main.cpp +++ b/examples/uml/xmi-read/main.cpp @@ -6,8 +6,6 @@ using QtMof::QXmiReader; using QtMof::QXmiWriter; -using namespace QtWrappedObjects; - int main () { QFile file("test.xmi"); diff --git a/examples/uml/xmi-write/main.cpp b/examples/uml/xmi-write/main.cpp index 31e7d40a..ccd321b8 100644 --- a/examples/uml/xmi-write/main.cpp +++ b/examples/uml/xmi-write/main.cpp @@ -4,7 +4,6 @@ #include <QtMof/QXmiWriter> -using namespace QtWrappedObjects; using namespace QtUml; using QtMof::QXmiWriter; |