Skip to content

Commit

Permalink
Made a change of regular expression format immediately update
Browse files Browse the repository at this point in the history
visualisation
  • Loading branch information
aelliott committed Feb 17, 2012
1 parent ab1a88b commit b447b7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 11 additions & 1 deletion expressiongraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#include "expressiongraphicsscene.hpp"

#include <QGraphicsView>
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
#include <QSettings>
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
12 changes: 8 additions & 4 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ MainWindow::MainWindow(QWidget *parent)
, _filePath("")
, _expression("")
, _edited(false)
, _visualisation(0)
{
QSettings settings;
_ui->setupUi(this);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -198,6 +197,8 @@ void MainWindow::setRegexpFormat(int format)
break;
#endif // NO_CPP11
}

updateExpression(_expression);
}

void MainWindow::showPreferences()
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit b447b7a

Please sign in to comment.