Browse files

Made a change of regular expression format immediately update

visualisation
  • Loading branch information...
1 parent ab1a88b commit b447b7ab08d26e8937ed403d4ccc4f4dc7cd6d14 @aelliott committed Feb 17, 2012
Showing with 25 additions and 5 deletions.
  1. +11 −1 expressiongraphicsscene.cpp
  2. +8 −4 mainwindow.cpp
  3. +6 −0 mainwindow.ui
View
12 expressiongraphicsscene.cpp
@@ -21,6 +21,7 @@
*/
#include "expressiongraphicsscene.hpp"
+#include <QGraphicsView>
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
#include <QSettings>
@@ -43,12 +44,19 @@ void ExpressionGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
}
QList<QGraphicsItem *> itemList = items();
+
+ if(itemList.size() < 2)
+ {
+ setBackgroundBrush(Qt::BDiagPattern);
+ event->accept();
+ return;
+ }
+
for(int i = 0; i < itemList.size()-1; ++i)
{
QGraphicsItem *item = itemList.at(i);
QPointF itemPos = item->scenePos();
QRectF bounds = item->boundingRect();
- qDebug() << bounds;
QColor dropZoneColour(210, 210, 255, 80);
QBrush brush(dropZoneColour);
@@ -105,6 +113,7 @@ void ExpressionGraphicsScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
void ExpressionGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
+ setBackgroundBrush(Qt::white);
while(_dropZoneLabels.size() > 0)
{
removeItem(_dropZoneLabels.at(0));
@@ -116,6 +125,7 @@ void ExpressionGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
void ExpressionGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
+ setBackgroundBrush(Qt::white);
while(_dropZoneLabels.size() > 0)
{
removeItem(_dropZoneLabels.at(0));
View
12 mainwindow.cpp
@@ -33,6 +33,7 @@ MainWindow::MainWindow(QWidget *parent)
, _filePath("")
, _expression("")
, _edited(false)
+ , _visualisation(0)
{
QSettings settings;
_ui->setupUi(this);
@@ -64,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent)
_factory = new RegexFactory(RegexFactory::Qt);
- _visualisation = new ExpressionGraphicsItem("", RegexFactory::Qt);
-
ExpressionGraphicsScene *scene = new ExpressionGraphicsScene();
_ui->expressionView->setScene(scene);
_ui->expressionView->setRenderHint(QPainter::Antialiasing, true);
@@ -198,6 +197,8 @@ void MainWindow::setRegexpFormat(int format)
break;
#endif // NO_CPP11
}
+
+ updateExpression(_expression);
}
void MainWindow::showPreferences()
@@ -249,8 +250,11 @@ void MainWindow::updateExpression(QString expression)
parser->parse(expression);
QGraphicsScene *scene = _ui->expressionView->scene();
- scene->removeItem(_visualisation);
- delete _visualisation;
+ if(_visualisation != 0)
+ {
+ scene->removeItem(_visualisation);
+ delete _visualisation;
+ }
_visualisation = new ExpressionGraphicsItem(_expression, _factory->format());
scene->addItem(_visualisation);
scene->setSceneRect(scene->itemsBoundingRect());
View
6 mainwindow.ui
@@ -63,6 +63,12 @@
</item>
<item>
<widget class="QListWidget" name="listWidget">
+ <property name="dragEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::DragOnly</enum>
+ </property>
<item>
<property name="text">
<string>Literal String</string>

0 comments on commit b447b7a

Please sign in to comment.