[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [rocs] src: Set pointer line style by pointer type.
From:       Andreas Cord-Landwehr <cola () uni-paderborn ! de>
Date:       2012-09-21 19:05:57
Message-ID: 20120921190557.8C81EA6094 () git ! kde ! org
[Download RAW message or body]

Git commit cb656c8d176ba7b223bb056bcf0d40e2e5ca10a4 by Andreas Cord-Landwehr.
Committed on 21/09/2012 at 20:49.
Pushed by cordlandwehr into branch 'master'.

Set pointer line style by pointer type.

M  +5    -11   src/Core/Pointer.cpp
M  +1    -9    src/Core/Pointer.h
M  +16   -1    src/Core/PointerType.cpp
M  +17   -4    src/Core/PointerType.h
M  +2    -13   src/GraphicsItem/PointerItem.cpp
M  +0    -11   src/Interface/PointerPropertiesWidget.cpp
M  +0    -1    src/Interface/PointerPropertiesWidget.h
M  +0    -46   src/Interface/PointerPropertiesWidget.ui
M  +25   -3    src/Interface/PointerTypePage.cpp
M  +1    -0    src/Interface/PointerTypePage.h
M  +18   -15   src/Interface/PointerTypePage.ui
M  +10   -6    src/LoadSave/RocsGraphFileFormatPlugin.cpp

http://commits.kde.org/rocs/cb656c8d176ba7b223bb056bcf0d40e2e5ca10a4

diff --git a/src/Core/Pointer.cpp b/src/Core/Pointer.cpp
index 5ebfe7c..88832f9 100644
--- a/src/Core/Pointer.cpp
+++ b/src/Core/Pointer.cpp
@@ -40,7 +40,6 @@ public:
     QString value;
     QString name;
     QColor color;
-    QString style;
     qreal width;
     PointerTypePtr pointerType;
 
@@ -87,12 +86,13 @@ Pointer::Pointer(DataStructurePtr parent, DataPtr from, DataPtr \
                to, int pointerT
     d->color         = \
                d->dataStructure->document()->pointerType(pointerType)->defaultColor();
                
     d->showName      = d->dataStructure->isPointerNameVisible(pointerType);
     d->showValue     = d->dataStructure->isPointerValueVisible(pointerType);
-    d->style         = "solid";
     d->width         = 1;
     d->pointerType   = d->dataStructure->document()->pointerType(pointerType);
 
     connect(d->pointerType.get(), SIGNAL(directionChanged(PointerType::Direction)),
             this, SIGNAL(directionChanged(PointerType::Direction)));
+    connect(d->pointerType.get(), SIGNAL(styleChanged()),
+            this, SIGNAL(changed()));
 }
 
 Pointer::~Pointer()
@@ -167,7 +167,7 @@ void Pointer::setPointerType(int typeIdentifier)
     d->dataStructure->updatePointer(getPointer());
 
     // connect to new pointer type and emit information about
-    connect(d->pointerType.get(), SIGNAL(directionChanged(Direction)),
+    connect(d->pointerType.get(), SIGNAL(directionChanged(PointerType::Direction)),
             this, SIGNAL(directionChanged(PointerType::Direction)));
     emit pointerTypeChanged(typeIdentifier);
 }
@@ -260,15 +260,9 @@ void Pointer::setWidth(qreal width)
     emit changed();
 }
 
-const QString& Pointer::style() const
+Qt::PenStyle Pointer::style() const
 {
-    return d->style;
-}
-
-void Pointer::setStyle(const QString& s)
-{
-    d->style = s;
-    emit changed();
+    return d->pointerType->lineStyle();
 }
 
 void Pointer::addDynamicProperty(QString property, QVariant value)
diff --git a/src/Core/Pointer.h b/src/Core/Pointer.h
index 140766c..b046099 100644
--- a/src/Core/Pointer.h
+++ b/src/Core/Pointer.h
@@ -56,7 +56,6 @@ class ROCSLIB_EXPORT Pointer : public QObject
     Q_PROPERTY(QString value READ value WRITE setValue)
     Q_PROPERTY(QString name READ name WRITE setName)
     Q_PROPERTY(qreal width READ width WRITE setWidth)
-    Q_PROPERTY(QString style READ style WRITE setStyle)
 
 public:
     /**
@@ -212,14 +211,7 @@ public slots:
     /**
      * \return line style of the pointer line
      */
-    const QString& style() const;
-
-    /**
-     * Set line style for the pointer.
-     *
-     * \param s is the style identifier
-     */
-    void setStyle(const QString& s);
+    Qt::PenStyle style() const;
 
     /**
      * Add new dynamic property with identifier \p property to this data element and
diff --git a/src/Core/PointerType.cpp b/src/Core/PointerType.cpp
index c331e9d..97ebb6a 100644
--- a/src/Core/PointerType.cpp
+++ b/src/Core/PointerType.cpp
@@ -32,6 +32,7 @@ public:
     QString _name;
     int _identifier;
     PointerType::Direction _pointerDirection;
+    Qt::PenStyle _lineStyle;
     QColor _defaultColor;
     bool _valueVisibility;
     bool _nameVisibility;
@@ -54,6 +55,7 @@ PointerType::PointerType(Document* document, int identifier):
 {
     d->_identifier = identifier;
     d->_pointerDirection = Unidirectional;
+    d->_lineStyle = Qt::SolidLine;
     d->_defaultColor = QColor("gray");
     d->_name = i18n("Connection");
     d->_document = document;
@@ -97,10 +99,23 @@ void PointerType::setDirection(PointerType::Direction direction)
 }
 
 
+Qt::PenStyle PointerType::lineStyle() const
+{
+    return d->_lineStyle;
+}
+
+
+void PointerType::setLineStyle(Qt::PenStyle lineStyle)
+{
+    d->_lineStyle = lineStyle;
+    emit(styleChanged());
+}
+
+
 void PointerType::setDefaultColor(QColor color)
 {
     d->_defaultColor = color;
-    emit(colorChanged(d->_defaultColor));
+    emit(styleChanged());
 }
 
 
diff --git a/src/Core/PointerType.h b/src/Core/PointerType.h
index baf45cd..6b8137e 100644
--- a/src/Core/PointerType.h
+++ b/src/Core/PointerType.h
@@ -73,12 +73,17 @@ public:
     int identifier() const;
 
     /**
-     * \return direction of pointers of this type
+     * \return direction for pointers of this type
      */
     Direction direction() const;
 
     /**
-     * \return default color for data elements of this pointer type
+     * \return line style for pointers of this type
+     */
+    Qt::PenStyle lineStyle() const;
+
+    /**
+     * \return default color for pointers of this type
      */
     const QColor& defaultColor() const;
 
@@ -104,6 +109,13 @@ public slots:
      */
     void setDirection(PointerType::Direction direction);
 
+    /**
+     * Set line style for all pointers of this type.
+     *
+     * \param lineStyle is the new line style
+     */
+    void setLineStyle(Qt::PenStyle lineStyle);
+
 signals:
     /**
      * Emitted when name was changed.
@@ -111,9 +123,9 @@ signals:
     void nameChanged(const QString& name);
 
     /**
-     * Emitted when default color was changed.
+     * Emitted when settings for the visual representation changed.
      */
-    void colorChanged(const QColor& color);
+    void styleChanged();
 
     /**
      * Emitted when direction was changed.
@@ -135,3 +147,4 @@ private:
 };
 
 #endif // POINTERTYPE_H
+
diff --git a/src/GraphicsItem/PointerItem.cpp b/src/GraphicsItem/PointerItem.cpp
index c1f1239..7250312 100644
--- a/src/GraphicsItem/PointerItem.cpp
+++ b/src/GraphicsItem/PointerItem.cpp
@@ -102,20 +102,9 @@ void PointerItem::updatePos()
 
 void PointerItem::updateAttributes()
 {
-    Qt::PenStyle s;
-    if (_pointer->style() == "dash") {
-        s = Qt::DashLine;
-    } else if (_pointer->style() == "dot") {
-        s = Qt::DotLine;
-    } else if (_pointer->style() == "dash dot") {
-        s = Qt::DashDotLine;
-    } else if (_pointer->style() == "solid") {
-        s = Qt::SolidLine;
-    } else                                 {
-        s = Qt::SolidLine;
-    }
+    Qt::PenStyle style = pointer()->style();
 
-    setPen(QPen(QBrush(QColor(_pointer->color())), _pointer->width(), s, \
Qt::RoundCap, Qt::RoundJoin)); +    setPen(QPen(QBrush(QColor(_pointer->color())), \
_pointer->width(), style, Qt::RoundCap, Qt::RoundJoin));  _value->hide();
     _name->hide();
     this->hide();
diff --git a/src/Interface/PointerPropertiesWidget.cpp \
b/src/Interface/PointerPropertiesWidget.cpp index 26e42d5..6c39b59 100644
--- a/src/Interface/PointerPropertiesWidget.cpp
+++ b/src/Interface/PointerPropertiesWidget.cpp
@@ -99,17 +99,6 @@ void PointerPropertiesWidget::on__color_activated(const QColor& c)
 }
 
 
-void PointerPropertiesWidget::on__style_activated(int index)
-{
-    switch (index) {
-    case 0 : _pointer->setStyle("solid");    break;
-    case 1 : _pointer->setStyle("dash");     break;
-    case 2 : _pointer->setStyle("dot");      break;
-    case 3 : _pointer->setStyle("dash dot"); break;
-    }
-}
-
-
 void PointerPropertiesWidget::on__addProperty_clicked()
 {
 
diff --git a/src/Interface/PointerPropertiesWidget.h \
b/src/Interface/PointerPropertiesWidget.h index 1ce0286..52e4e32 100644
--- a/src/Interface/PointerPropertiesWidget.h
+++ b/src/Interface/PointerPropertiesWidget.h
@@ -42,7 +42,6 @@ public:
 
 public slots:
     void on__color_activated(const QColor& c);
-    void on__style_activated(int index);
     void reflectAttributes();
     void on__addProperty_clicked();
     void disconnectPointer();
diff --git a/src/Interface/PointerPropertiesWidget.ui \
b/src/Interface/PointerPropertiesWidget.ui index a9cfde8..9be8b66 100644
--- a/src/Interface/PointerPropertiesWidget.ui
+++ b/src/Interface/PointerPropertiesWidget.ui
@@ -100,46 +100,6 @@
    <item row="1" column="4">
     <widget class="KDoubleNumInput" name="_width"/>
    </item>
-   <item row="2" column="0">
-    <widget class="QLabel" name="label_5">
-     <property name="text">
-      <string>Style:</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-     </property>
-     <property name="buddy">
-      <cstring>_style</cstring>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="1">
-    <widget class="KComboBox" name="_style">
-     <property name="toolTip">
-      <string>Edge style</string>
-     </property>
-     <item>
-      <property name="text">
-       <string>solid</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>dash</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>dot</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>dash dot</string>
-      </property>
-     </item>
-    </widget>
-   </item>
    <item row="3" column="0" colspan="2">
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
@@ -276,11 +236,6 @@
    <header>knuminput.h</header>
   </customwidget>
   <customwidget>
-   <class>KComboBox</class>
-   <extends>QComboBox</extends>
-   <header>kcombobox.h</header>
-  </customwidget>
-  <customwidget>
    <class>KLineEdit</class>
    <extends>QLineEdit</extends>
    <header>klineedit.h</header>
@@ -293,7 +248,6 @@
  </customwidgets>
  <tabstops>
   <tabstop>_name</tabstop>
-  <tabstop>_style</tabstop>
   <tabstop>_color</tabstop>
   <tabstop>_showName</tabstop>
   <tabstop>_showValue</tabstop>
diff --git a/src/Interface/PointerTypePage.cpp b/src/Interface/PointerTypePage.cpp
index fa62861..bca4914 100644
--- a/src/Interface/PointerTypePage.cpp
+++ b/src/Interface/PointerTypePage.cpp
@@ -39,6 +39,16 @@ PointerTypePage::PointerTypePage(QWidget* parent)
     ui = new Ui::PointerTypePage;
     ui->setupUi(this);
 
+    // create line style selector
+    ui->typeLineStyle->addItem(i18nc("@item:inlistbox", "solid line"), \
Qt::SolidLine); +    ui->typeLineStyle->addItem(i18nc("@item:inlistbox", "dash \
line"), Qt::DashLine); +    ui->typeLineStyle->addItem(i18nc("@item:inlistbox", "dot \
line "), Qt::DotLine); +    ui->typeLineStyle->addItem(i18nc("@item:inlistbox", "dash \
dot line"), Qt::DashDotLine); +
+    // create pointer direction selector
+    ui->typePointerDirection->addItem(i18nc("@item:inlistbox", "Unidirectional"), \
PointerType::Unidirectional); +    \
ui->typePointerDirection->addItem(i18nc("@item:inlistbox", "Bidirectional"), \
PointerType::Bidirectional); +
     connect(ui->typeSelector, SIGNAL(currentIndexChanged(int)),
             this, SLOT(setCurrentType(int)));
     connect(ui->exportNewType, SIGNAL(clicked(bool)),
@@ -49,6 +59,8 @@ PointerTypePage::PointerTypePage(QWidget* parent)
             this, SLOT(updateCurrentTypeName()));
     connect(ui->typePointerDirection, SIGNAL(activated(int)),
             this, SLOT(updateCurrentTypeDirection()));
+    connect(ui->typeLineStyle, SIGNAL(activated(int)),
+            this, SLOT(updateCurrentTypeLineStyle()));
     connect(ui->typeName, SIGNAL(textEdited(QString)),
             this, SLOT(setTypeName()));
     connect(ui->typeDefaultColor, SIGNAL(activated(QColor)),
@@ -92,8 +104,10 @@ void PointerTypePage::setCurrentType(int index)
     }
 
     ui->typeName->setText(_document->pointerType(type)->name());
-    //TODO insert style
-    ui->typePointerDirection->setCurrentIndex(_document->pointerType(type)->direction());
 +    ui->typeLineStyle->setCurrentIndex(
+        ui->typeLineStyle->findData(_document->pointerType(type)->lineStyle()));
+    ui->typePointerDirection->setCurrentIndex(
+        ui->typePointerDirection->findData(_document->pointerType(type)->direction()));
                
     ui->typeDefaultColor->setColor(_document->pointerType(type)->defaultColor());
     ui->typeIdentifier->setText(QString::number(type));
 }
@@ -123,11 +137,19 @@ void PointerTypePage::updateCurrentTypeName()
 void PointerTypePage::updateCurrentTypeDirection()
 {
     int type = ui->typeSelector->itemData(ui->typeSelector->currentIndex()).toInt();
-    int direction = ui->typePointerDirection->currentIndex();
+    int direction = \
                ui->typePointerDirection->itemData(ui->typePointerDirection->currentIndex()).toInt();
                
     _document->pointerType(type)->setDirection(PointerType::Direction(direction));
 }
 
 
+void PointerTypePage::updateCurrentTypeLineStyle()
+{
+    int type = ui->typeSelector->itemData(ui->typeSelector->currentIndex()).toInt();
+    int style = ui->typeLineStyle->itemData(ui->typeLineStyle->currentIndex()).toInt();
 +    _document->pointerType(type)->setLineStyle(Qt::PenStyle(style));
+}
+
+
 void PointerTypePage::createNewType()
 {
     int newType = _document->registerPointerType(ui->newTypeName->text());
diff --git a/src/Interface/PointerTypePage.h b/src/Interface/PointerTypePage.h
index fe66cd4..217c467 100644
--- a/src/Interface/PointerTypePage.h
+++ b/src/Interface/PointerTypePage.h
@@ -51,6 +51,7 @@ private slots:
     void removeType();
     void updateCurrentTypeName();
     void updateCurrentTypeDirection();
+    void updateCurrentTypeLineStyle();
 
 private:
     Document* _document;
diff --git a/src/Interface/PointerTypePage.ui b/src/Interface/PointerTypePage.ui
index 330711b..8fe4d87 100644
--- a/src/Interface/PointerTypePage.ui
+++ b/src/Interface/PointerTypePage.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>346</width>
-    <height>208</height>
+    <height>246</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
@@ -42,7 +42,7 @@
    </item>
    <item>
     <layout class="QGridLayout" name="gridLayout_3">
-     <item row="2" column="0">
+     <item row="3" column="0">
       <widget class="QLabel" name="typeDefaultColorLabel">
        <property name="text">
         <string>Default Color:</string>
@@ -52,10 +52,10 @@
        </property>
       </widget>
      </item>
-     <item row="2" column="1">
+     <item row="3" column="1">
       <widget class="KColorCombo" name="typeDefaultColor"/>
      </item>
-     <item row="3" column="0">
+     <item row="4" column="0">
       <widget class="QLabel" name="label_2">
        <property name="text">
         <string>Identifier:</string>
@@ -65,7 +65,7 @@
        </property>
       </widget>
      </item>
-     <item row="3" column="1">
+     <item row="4" column="1">
       <widget class="QLabel" name="typeIdentifier">
        <property name="toolTip">
         <string>This is the unique identifier for the pointer type.</string>
@@ -116,18 +116,21 @@
        <property name="toolTip">
         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select if pointers of \
this type is unidirectional or bidirectional. Changing this value changes directions \
of all pointers of this type.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>  \
                </property>
-       <item>
-        <property name="text">
-         <string>Unidirectional</string>
-        </property>
-       </item>
-       <item>
-        <property name="text">
-         <string>Bidirectional</string>
-        </property>
-       </item>
       </widget>
      </item>
+     <item row="2" column="0">
+      <widget class="QLabel" name="label_4">
+       <property name="text">
+        <string>Style:</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="1">
+      <widget class="KComboBox" name="typeLineStyle"/>
+     </item>
     </layout>
    </item>
    <item>
diff --git a/src/LoadSave/RocsGraphFileFormatPlugin.cpp \
b/src/LoadSave/RocsGraphFileFormatPlugin.cpp index 599ec4a..a3acb1c 100644
--- a/src/LoadSave/RocsGraphFileFormatPlugin.cpp
+++ b/src/LoadSave/RocsGraphFileFormatPlugin.cpp
@@ -166,9 +166,15 @@ void RocsGraphFileFormatPlugin::readFile()
 
             QString dataLine = in.readLine().simplified();
             while (!in.atEnd() && !dataLine.isEmpty()) {
-                /**/ if (dataLine.startsWith(QLatin1String("Name :")))      \
                tmpPointerType->setName(dataLine.section(' ', 2));
-                else if (dataLine.startsWith(QLatin1String("Color :")))     \
                tmpPointerType->setDefaultColor(QColor(dataLine.section(' ', 2)));
-                else if (!dataLine.isEmpty())               break;  // go to the \
last if and finish populating. +                /**/ if \
(dataLine.startsWith(QLatin1String("Name :"))) { +                    \
tmpPointerType->setName(dataLine.section(' ', 2)); +                } else if \
(dataLine.startsWith(QLatin1String("Color :"))) { +                    \
tmpPointerType->setDefaultColor(QColor(dataLine.section(' ', 2))); +                } \
else if (dataLine.startsWith(QLatin1String("LineStyle :"))) { +                    \
tmpPointerType->setLineStyle(Qt::PenStyle(dataLine.section(' ', 2).toInt())); +       \
} else if (!dataLine.isEmpty()) { +                    break;  // go to the last if \
and finish populating. +                }
                 dataLine = in.readLine().simplified();
             }
         }
@@ -225,13 +231,11 @@ void RocsGraphFileFormatPlugin::readFile()
             QString value = "";
             int type = 0;
             QString color = "";
-            QString style = "";
             while (!in.atEnd() && !dataLine.isEmpty()) {
                 /**/ if (dataLine.startsWith(QLatin1String("width :")))     width = \
                dataLine.section(' ', 2).toInt();
                 else if (dataLine.startsWith(QLatin1String("value :")))     value = \
                dataLine.section(' ', 2);
                 else if (dataLine.startsWith(QLatin1String("type :")))      type = \
                dataLine.section(' ', 2).toInt();
                 else if (dataLine.startsWith(QLatin1String("color :")))     color = \
                dataLine.section(' ', 2);
-                else if (dataLine.startsWith(QLatin1String("style :")))     style = \
                dataLine.section(' ', 2);
                 else if (!dataLine.isEmpty())                break;  // go to the \
last if and finish populating.  dataLine = in.readLine().simplified();
             }
@@ -245,7 +249,6 @@ void RocsGraphFileFormatPlugin::readFile()
                 tmpPointer->setWidth(width);
                 tmpPointer->setValue(value);
                 tmpPointer->setColor(color);
-                tmpPointer->setStyle(style);
                 tmpObject = tmpPointer.get();
             }
         }
@@ -314,6 +317,7 @@ QString RocsGraphFileFormatPlugin::serialize(const Document& \
                document)
         d->_buffer += QString("[PointerType \
                %1]").arg(QString::number(pointerTypeIdentifier)) % QChar('\n')
             % QString("Name : ") % \
                document.pointerType(pointerTypeIdentifier)->name() % QChar('\n')
             % QString("Color : ") % \
document.pointerType(pointerTypeIdentifier)->defaultColor().name() % QChar('\n') +    \
% QString("LineStyle : ") % \
QString::number(document.pointerType(pointerTypeIdentifier)->lineStyle()) % \
QChar('\n')  % QChar('\n');
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic