qwt save plot configuration? - qt

The user has spent a lot of time setting up a nice qwt plot (picking curves from the database, configuring line colour and style, scaling them, scrolling and panning to the interesting places, and so on). Now he wants to save this layout, not as a picture, but as a configuration which he can load again later, and refine even more.
What's the most elegant way to make a QwtPlot save itself to a file, so that I can load it again? I'd love to simply write
outf << myQwtPlot;
which obviously isn't possible out of the box. Maybe there is something simpler than making my own QwtPlod-derived class which implements operator<< and operator>> to read and write all "important" attributes.. ?

You could try Qt's new property system, but I think you still end up doing approximately what you have in mind.
http://qt-project.org/doc/qt-4.7/properties.html

Related

Is there any method for fix manually an Alloy Analyzer graph?

I need to fix my Alloy graph, for example I have this output:
I can't move "node2" rectangle over the row of "node0" and "node1", and I can't move "node1" under "node2" whitout also move "node0". Is there any solution? Thank you.
PS: I am using Alloy Analyzer 4.2 under Windows.
PPS: This is only an example, i get a big graph with 5 or 6 rows of 20-25 rectangles, and if I can't fix it manually, it's only a mess.
To answer the direct question: I for one have never found a way to make the visualizer change its mind about which nodes should be on the same horizontal level. (That doesn't quite mean it's not possible, but it does mean that if it's possible it's not immediately obvious how to do it. But I guess you knew that already.)
If your goal is to make the auto-generated diagrams easier to read, the simplest approach is to experiment with adjustments to the visualizer theme. The "Magic Layout" button can be helpful; manual adjustments to hide some nodes or display some relations as labels rather than arcs can help with diagrams which are otherwise too cluttered.
If your goal is to make a 'good' version of a diagram for inclusion on a slide for a talk or a figure for a paper, you may want to export to Dot and import into a graph-drawing tool that gives you the kind of manual control you want (or edit the .dot file yourself, if you are familiar with graphviz and can make it do what you want), or export to XML and generate the graph description language of your choice from the XML.
I hope this helps.
The Lightning tool is an Ecplise plugin relying on Alloy4.2 to formally define Domain Specific Languages and might be a solution to your problem.
It's still under development, but if you are only interested in being able to freely reorganize each atom and label of generated instances, there shouldn't be any problems, as it uses Ecplise draw2D to render those latter.
If now you're really interested in providing an intuitive visualization to your generated instance (by intuitive I mean a visualization that is closer to its domain rather than the structure of your model), then you can define your own language (with your model as abstract syntax ) and define a concrete syntax for it.
The update site to be used for the installation of the tool is : http://lightning.gforge.uni.lu/update-site
Don't hesitate to contact me if you plan to give it a shot and get any issues.
(I'm eager of constructive feedbacks ;-) )
The steps to follow to generate a graphical instance in which any components can be moved are :
Install Lightning
Create a new Lightning Project
Create a new Language in this project
Put your model in the ASM folder
generate instances of the language by "running the project"

Learning Qt: Which methodology to be used for this "advanced UI"?

I am learning Qt5 using PyQt.
My goal is to create a UI with several goals (I will base my need on the screenshot below).
So here are my goals:
My need
Add directories to a list of directories to be scanned (I know how to use QFileDialog.getExistingDirectory for that). For this I'd like to have a "+" button.
When pressed the QFileDialog would open and a new row would be added.
Then I would scan the directory to look for files. It won't be my first implementation but I'd like to have a circular progress bar being displayed during the scan (at the place of the classic progress bar).
When the scan is done, the UI would display the number of files found during the scan. And the progress bar would be replaced by a tick mark icon (not shown on the screenshot...).
At the beginning of each row, I'd like to have a "-" button to delete the row.
My goal is to learn
This is important, I know I am not the first one to have the idea of such a UI.
So I not looking for a third party lib on top of Qt.
My goal is to learn Qt5 (with PyQt) with this example.
But if its unrealistic, please tell me!
My knowledge
Mode View: I implemented some basic model view widgets to display strings, and I understand how to extend the idea to tables or trees.
In this case the number of rows in the table would be handled automatically.
But is it possible to created a table that would display not only strings but also widgets?
Widget Mapper: I read that another methodology is the QDataWidgetMapper. In this case, I would have to deal with creation of news rows by myself, and then I would map data onto them.
But it seems to be a hard and long job.
So, is it a good idea?
So finally could someone tell what is the best direction for that?
I am not looking for code, but since it takes a lots of time to learn new concepts, I'd like to learn and use the correct one before starting coding.
Thank you for your help :)!
After so more searches, I found that I need to use the delegate methodology.
In Qt5 it's QStyledItemDelegate and in Qt4 it's QItemDelegate.
I could find a nice tutorial at the moment, but I started coded it.

How to do chalk style drawing with Qt

I want to use Qt to draw lines in chalk style, as you typically see on a blackboard. Here is an example of what I have in mind:
What is the best way to achieve this rendering style? Do I need to draw a lot of little lines with a special brush, or is there a better way to get the "curvy" style you see in the sample image?
And where is the best place to integrate this? Theoretically it would be ideal to get this underneath QPainter, e.g. in a custom QPaintEngine, so that e.g. all the various QPainter::drawLine calls end up using the chalk style. However, it seems while the QPaintEngine interface looks perfect for this, the class itself isn't meant to be used for this purpose...
Thanks in advance for any help.
Greetings,
Fabian
I have solved the problem in a different way. Using textured brushes didn't provide good results (maybe my fault). QGraphicsEffect was unfortunately not an option since my rendering is not based on QGraphicsView.
What I have done in the end:
Derived an own class from QPainter (i.e. ChalkPainter)
Added a new drawChalkLine() method to ChalkPainter. This method takes the passed line, splits it into smaller chunks and renders these chunks as bezier curves via QPainter::drawPath. For each bezier curve chunk I randomly shift the control point orthogonal to the line.
Next I added additional rendering methods to the ChalkPainter class, such as drawChalkRect(), all internally using the drawChalkLine() method.
This is not the most elegant method since I can't use the QPainter methods directly, but it provides good results for my purpose. Here is an example:
I would start looking in QGraphicsEffect's way.. I think it should be possible to develop such a filter which will produce similar effect..
I'll update in here answer on your comment.
No, QGraphicsEffect can be applied 'per graphics item'. If you have a look on QGraphicsItem you will see that there is a setGraphicsEffect method, so you can design an effect which works on QGraphicsLineItem for example and set it only on lines you want to look chalky..
Important thing is that you don't have to operate on pre-drawn image, you can either make it completely owner-draw item with graphicsEffect (for example make an assumption that effect is only applicable on QGraphicsLineItem) pre-draw it using drawSource() and then modify OR draw it completely from scratch..
I would love to help you with some coding, probably will do it somewhere around next week, since I will need similar thing for project I am working on now.. but physically don't have time next few days..
I'll update an answer with sources link as soon as it's done.
Custom brush also looks really promising..

saving a movieClip to disk as swf in air, then reading it again

i have seen almost all relevant threads on almost whole internet. and i m still confused..
i m working on a drawing app ( flex / air ),
1- where user loads image file,(bitmapdata > bitmap > movieclip base layer)
2- add layer ( new sprite > movieclip "second object in display list")
3- draw on this sprite ( graphics.draw circle / etc, lot of other details etc)
4- usr can add more layers etc, name layers etc ... all sprites are of same size as bitmap
Q1. now i wanted to save this main movieClip (part of UIComponent ) as swf file. so user can read again and continue work. almost like i do with photoshop.
comment: i know it sounds too generic, to ask such detailed thing. so please be patient..
i have been fiddling around with byteArray. and Air File Object, flash.net.fileReference etc...
Q2. (main question), i don't want to convert drawn sprites to bitmapdata and then do bytearray. ( in my mind) it will convert everything to pixels, which i don't want.
Q3. is there some auto magical line which will do everything..(save drawn vectors / shapes) in sprites as is?? (less chances). if i can read swf as movieClip, i can check sprites for layers and everything else... problem is writing this to disk as swf file.
please share your thoughts and feel free to guide,in all possible directions..
thanks in advance for your valuable time..
In an ideal world you would just write
YourByteArray.writeObject(YourCanvasSprite);
That doesn't work however since serialize only works with data that is readable and writeable (and public). So you need to make it possible to recreate the graphic. You might be able to simplify that by using IGraphics (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/IGraphicsData.html) as these should be possible to serialize. So if you subclass Sprite and store "drawing commands" and the parameters, and let the object have a restore function, it should be possible to save it to a byteArray. It's far from a one-liner though, but probably a little bit easier than making and reading SVG.
i'm thinking the cleanest solution to this problem would be to use SVG (maybe EPS). i'm unfamiliar with any library that will convert drawn vector objects into SVG, but since SVG is simply an XML file you could study the SVG architecture and create your own: W3C - Scalable Vector Graphics (SVG) 1.1 (Second Edition). the following open source project may help you write one and can also be used to read SVG into Flash: New Flex and Flash SVGWeb Components
a less clean, and perhaps more complicated way to solve this problem could be to write your own SWFs, as you mentioned. in order to do so you would have to generate .swf file at runtime, which you could accomplish by using NativeProcess to pass arguments (namely an ActionScript file containing your drawing information, child layers with names, etc.) to MXMLC from the Flex SDK.
i find both answers useful. and with time,i have realized that in both cases it might be more work than i can handle. meanwhile, i was testing other pixels bases approaches as well. so i finally took decision of going through pixel way. user can save layers as png files with transparency.
if some person (other readers) come to this post, i wanted to conclude quickly, i have found really valuable drawing library named "graffiti" for as3. it almost does 80% of things, which i was hoping to do. so i am using that and tweaking it for my needs. huge thanks and respect to all great ppl who replied from their valuable time..

Latitude/Longitude Qt4 widget?

What is the best starting point for a Qt4 widget for entering Latitude/Longitude in DD:MM:SS format (degrees, minutes, seconds)? Customize a QLineEdit? A series of spin boxes?
There are some variants:
QLineEdit with Validator - wasn't good enough for us, we couldn't achieve usable editing and proper view (with ', '' and degree symbols in place and ability to forbid incorrect values and still allow semi-correct states, and the target behaviour is not to mark errors and force user to fix them, but to allow user to enter only valid values).
Three spin edits in a line with the proper symbols between them grouped as a single widget and some code to move keyboard input from one no next when needed etc. Looks good enough in some cases, and you can find the variant of realization in the famous Marble project.
Still, my boss said that this approach is almost as ugly as first, so here is another approach: subclass QAbstractSpinBox, as Trolltech did in their QDateTimeEditor. In fact, behaviour of such a widget is near similar to one, implemented in QDateTimeEditor.
I, myself didn't do it yet, cause of task priorities, but will have to do.
I would use a QValidator, attaching it to a QLineEdit using QLineEdit::setValidator().
You'll need to subclass so you can implement the validate() function and possibly the fixup() function for your particular case, since the two validators included with Qt only cover integers and doubles.
It's a bit friendlier, in my opinion, to provide a single input box for this rather than three separate spin boxes (which could look cluttered and isn't as nice to type in).
[Edit: One other alternative is to set a "validation input mask" on your QLineEdit using QLineEdit::setInputMask(). You might want a line edit with symbols already in place and placeholders for other characters, for example, and this approach will give you something similar to that. The QtDemo app has an example of this which you can check out by choosing Widgets->Line Edits (Widgets is on the second page).]

Resources