Skip to content

Commit

Permalink
Visibility conditions added. It is possible to specify one enum prope…
Browse files Browse the repository at this point in the history
…rty to be a visibility condition to an item of a shape
  • Loading branch information
Ashatta committed Apr 2, 2013
1 parent fccb9af commit 0074d26
Show file tree
Hide file tree
Showing 18 changed files with 589 additions and 255 deletions.
9 changes: 5 additions & 4 deletions qrgui/editorPluginInterface/elementImpl.h
Expand Up @@ -89,10 +89,11 @@ struct StatLine
class ElementImpl {
public:
virtual ~ElementImpl() {}
virtual void init(QRectF &contents, QList<StatPoint> &pointPorts,
QList<StatLine> &linePorts, ElementTitleFactoryInterface &factory,
QList<ElementTitleInterface*> &titles,
SdfRendererInterface *renderer, SdfRendererInterface *portRenderer) = 0;
virtual void init(QRectF &contents, QList<StatPoint> &pointPorts
, QList<StatLine> &linePorts, ElementTitleFactoryInterface &factory
, QList<ElementTitleInterface*> &title
, SdfRendererInterface *renderer, SdfRendererInterface *portRenderer
, ElementRepoInterface *elementRepo = 0) = 0;
virtual void init(ElementTitleFactoryInterface &factory,
QList<ElementTitleInterface*> &titles) = 0;
virtual void paint(QPainter *painter, QRectF &contents) = 0;
Expand Down
3 changes: 3 additions & 0 deletions qrgui/editorPluginInterface/sdfRendererInterface.h
Expand Up @@ -5,11 +5,14 @@
#include <QtGui/QPainter>
#include <QtGui/QIconEngineV2>

#include "elementRepoInterface.h"

class SdfRendererInterface : public QObject
{
public:
virtual bool load (const QString &filename) = 0;
virtual void render(QPainter *painter, const QRectF &bounds) = 0;
virtual void setElementRepo(ElementRepoInterface *elementRepo) = 0;
};

class SdfIconEngineV2Interface : public QIconEngineV2
Expand Down
3 changes: 2 additions & 1 deletion qrgui/mainwindow/mainWindow.cpp
Expand Up @@ -910,7 +910,8 @@ void MainWindow::setSceneFont()

void MainWindow::openShapeEditor(QPersistentModelIndex const &index, int role, QString const &propertyValue)
{
ShapeEdit *shapeEdit = new ShapeEdit(index, role);
ShapeEdit *shapeEdit = new ShapeEdit(dynamic_cast<models::details::LogicalModel *>(mModels->logicalModel())
, index, role);
if (!propertyValue.isEmpty()) {
shapeEdit->load(propertyValue);
}
Expand Down
3 changes: 3 additions & 0 deletions qrgui/mainwindow/mainwindow.pri
Expand Up @@ -86,6 +86,7 @@ HEADERS += \
mainwindow/shapeEdit/textPicture.h \
mainwindow/shapeEdit/path.h \
mainwindow/shapeEdit/image.h \
mainwindow/shapeEdit/visibilityConditionsDialog.h \

SOURCES += \
mainwindow/shapeEdit/shapeEdit.cpp \
Expand All @@ -106,6 +107,8 @@ SOURCES += \
mainwindow/shapeEdit/view.cpp \
mainwindow/shapeEdit/textPicture.cpp \
mainwindow/shapeEdit/image.cpp \
mainwindow/shapeEdit/visibilityConditionsDialog.cpp \

FORMS += \
mainwindow/shapeEdit/shapeEdit.ui \
mainwindow/shapeEdit/visibilityConditionsDialog.ui \
30 changes: 30 additions & 0 deletions qrgui/mainwindow/shapeEdit/item.cpp
Expand Up @@ -220,3 +220,33 @@ void Item::setXandY(QDomElement& dom, QRectF const &rect)
dom.setAttribute("y2", setScaleForDoc(7, rect.toRect()));
dom.setAttribute("x2", setScaleForDoc(3, rect.toRect()));
}

void Item::setVisibilityCondition(VisibilityCondition const &condition)
{
mVisibilityCondition = condition;
}

void Item::setVisibilityCondition(QString const &property, QString const &value)
{
mVisibilityCondition.property = property;
mVisibilityCondition.value = value;
}

Item::VisibilityCondition Item::visibilityCondition()
{
return mVisibilityCondition;
}

QPair<QDomElement, Item::DomElementTypes> Item::generateDom(QDomDocument &document, const QPoint &topLeftPicture)
{
QPair<QDomElement, Item::DomElementTypes> result = generateItem(document, topLeftPicture);

if (mVisibilityCondition.property != QString() && mVisibilityCondition.value != QString()) {
QDomElement visibility = document.createElement("showIf");
result.first.appendChild(visibility);
visibility.setAttribute("property", mVisibilityCondition.property);
visibility.setAttribute("value", mVisibilityCondition.value);
}

return result;
}
13 changes: 13 additions & 0 deletions qrgui/mainwindow/shapeEdit/item.h
Expand Up @@ -31,6 +31,12 @@ class Item : public graphicsUtils::AbstractItem
bottomRightY
};

struct VisibilityCondition
{
QString property;
QString value;
};

Item(graphicsUtils::AbstractItem* parent = 0);
virtual Item* clone() = 0;
virtual void setItemZValue(int zValue);
Expand Down Expand Up @@ -58,12 +64,19 @@ class Item : public graphicsUtils::AbstractItem
QString setScaleForDoc(int i, QRect const &rect);
QString setSingleScaleForDoc(int i, int x, int y);
virtual void setXandY(QDomElement& dom, QRectF const &rect);

QPair<QDomElement, Item::DomElementTypes> generateDom(QDomDocument &document, QPoint const &topLeftPicture);
virtual QPair<QDomElement, Item::DomElementTypes> generateItem(QDomDocument &document, QPoint const &topLeftPicture) = 0;

void setVisibilityCondition(VisibilityCondition const &condition);
void setVisibilityCondition(QString const &property, QString const &value);
VisibilityCondition visibilityCondition();

protected:
QList<QPair<ScalingPointState, QColor> > mListScalePoint;
bool mNeedScalingRect;
DomElementTypes mDomElementType;
ScalingPointState mScalingState;
int mZValue;
VisibilityCondition mVisibilityCondition;
};
3 changes: 2 additions & 1 deletion qrgui/mainwindow/shapeEdit/scene.h
Expand Up @@ -49,6 +49,8 @@ class Scene : public graphicsUtils::AbstractScene
void addStylus(bool checked);
void addNone(bool checked);

QList<Item *> selectedSceneItems();

signals:
void noSelectedItems();
void existSelectedItems(QPen const &penItem, QBrush const &brushItem);
Expand Down Expand Up @@ -121,7 +123,6 @@ private slots:

void initListSelectedItemsForPaste();
QRectF selectedItemsBoundingRect() const;
QList<Item *> selectedSceneItems();
QList<TextPicture *> selectedTextPictureItems();
QPointF setCXandCY(QGraphicsSceneMouseEvent *event);
void reshapeLine(QGraphicsSceneMouseEvent *event);
Expand Down
43 changes: 40 additions & 3 deletions qrgui/mainwindow/shapeEdit/shapeEdit.cpp
Expand Up @@ -4,6 +4,7 @@
#include "../../../qrutils/xmlUtils.h"
#include "xmlLoader.h"
#include "../../../qrutils/graphicsUtils/colorlisteditor.h"
#include "visibilityConditionsDialog.h"

#include <QtGui/QFileDialog>
#include <QtGui/QGraphicsItem>
Expand All @@ -25,8 +26,8 @@ ShapeEdit::ShapeEdit(QWidget *parent)
connect(this, SIGNAL(saveSignal()), this, SLOT(saveToXml()));
}

ShapeEdit::ShapeEdit(const QPersistentModelIndex &index, const int &role)
: QWidget(NULL), mUi(new Ui::ShapeEdit),mIndex(index), mRole(role)
ShapeEdit::ShapeEdit(qReal::models::details::LogicalModel *model, QPersistentModelIndex const &index, const int &role)
: QWidget(NULL), mUi(new Ui::ShapeEdit), mModel(model), mIndex(index), mRole(role)
{
init();
mUi->saveButton->setEnabled(true);
Expand Down Expand Up @@ -83,6 +84,7 @@ void ShapeEdit::init()
connect(mUi->boldCheckBox, SIGNAL(toggled(bool)), mScene, SLOT(changeFontBold(bool)));
connect(mUi->underlineCheckBox, SIGNAL(toggled(bool)), mScene, SLOT(changeFontUnderline(bool)));

connect(mUi->visibilityConditionsButton, SIGNAL(clicked()), this, SLOT(visibilityButtonClicked()));
connect(mUi->deleteItemButton, SIGNAL(clicked()), mScene, SLOT(deleteItem()));
connect(mUi->graphicsView, SIGNAL(deleteItem()), mScene, SLOT(deleteItem()));
connect(mUi->clearButton, SIGNAL(clicked()), mScene, SLOT(clearScene()));
Expand Down Expand Up @@ -206,7 +208,7 @@ QList<QDomElement> ShapeEdit::generateGraphics()

Item* item = dynamic_cast<Item*>(graphicsItem);
if (item != NULL) {
QPair<QDomElement, Item::DomElementTypes> genItem = item->generateItem(mDocument, mTopLeftPicture);
QPair<QDomElement, Item::DomElementTypes> genItem = item->generateDom(mDocument, mTopLeftPicture);
QDomElement domItem = genItem.first;
Item::DomElementTypes domType = genItem.second;
switch (domType) {
Expand Down Expand Up @@ -501,3 +503,38 @@ void ShapeEdit::addStylus(bool checked)
if (checked)
setHighlightOneButton(mUi->stylusButton);
}

void ShapeEdit::visibilityButtonClicked()
{
QList<Item *> selectedItems = mScene->selectedSceneItems();
if (selectedItems.isEmpty()) {
return;
}
VisibilityConditionsDialog vcDialog(getEnumValues(), selectedItems);
vcDialog.exec();
}

QMap<QString, QStringList> ShapeEdit::getEnumValues() const
{
QMap<QString, QStringList> result;

qrRepo::RepoApi *repoApi = dynamic_cast<qrRepo::RepoApi *>(&mModel->mutableApi());
qReal::IdList enums = repoApi->elementsByType("MetaEntityEnum");

foreach (qReal::Id child, repoApi->children(mModel->idByIndex(mIndex))) {
QString type = repoApi->stringProperty(child, "attributeType");
foreach (qReal::Id e, enums) {
if (!repoApi->isLogicalElement(e)) {
continue;
}
if (repoApi->name(e) == type) {
QStringList enumValues;
foreach (qReal::Id value, repoApi->children(e)) {
enumValues << repoApi->stringProperty(value, "valueName");
}
result.insert(repoApi->name(child), enumValues);
}
}
}
return result;
}
9 changes: 8 additions & 1 deletion qrgui/mainwindow/shapeEdit/shapeEdit.h
Expand Up @@ -8,6 +8,7 @@
#include "scene.h"
#include "item.h"
#include "../../../qrutils/graphicsUtils/abstractItemView.h"
#include "../../models/details/logicalModel.h"

namespace Ui {
class ShapeEdit;
Expand All @@ -17,7 +18,7 @@ class ShapeEdit : public QWidget {
Q_OBJECT
public:
explicit ShapeEdit(QWidget *parent = NULL);
ShapeEdit(QPersistentModelIndex const &index, int const &role);
ShapeEdit(qReal::models::details::LogicalModel *model, QPersistentModelIndex const &index, int const &role);
graphicsUtils::AbstractView* getView();
void load(const QString &text);
~ShapeEdit();
Expand All @@ -43,6 +44,8 @@ private slots:
void addLinePort(bool checked);
void addStylus(bool checked);

void visibilityButtonClicked();

void savePicture();
void saveToXml();
void save();
Expand All @@ -62,6 +65,8 @@ private slots:
QDomDocument mDocument;
QPoint mTopLeftPicture;
Ui::ShapeEdit *mUi;

qReal::models::details::LogicalModel *mModel;
QPersistentModelIndex const mIndex;
int const mRole;
void initButtonGroup();
Expand All @@ -88,4 +93,6 @@ private slots:
void generateDom();
void exportToXml(QString const &fileName);
QList<QDomElement> generateGraphics();

QMap<QString, QStringList> getEnumValues() const;
};

0 comments on commit 0074d26

Please sign in to comment.