c++ - Qt GUI programming query -


im developing gui application using qt framework. application basic "2d cad" interface less complexities of commercial 2d cad software.

the idea is, there tool box (like ms paint) contains rectangle , square shapes of various sizes (the purpose of gui design rc circuit design on flexible substrates. software generate g-codes (basically coordinate information cnc machine) fed cnc printer prints these circuits on flexible substrates based on g-code information generated). each rectangle/square shape contains gcode 'shape' in text file in known directory (lets text file original). these g-codes in text files based on shapes drawn origin of coordinate system of gui. when user clicks on specific square/rectangle, movable/draggable shape appears on "origin" of qtgraphicsview widget , action automatically creates new text file in known directory copies g-codes text file (from original text file) containing original g-codes specific shape drawn @ origin (lets text file clone). since these shapes movable, when user drags/moves specific item on screen, software should able access clone file created specific item , edit/offset coordinates copied original specific shape current coordinate position of shape.

for example when user first clicks shape , shape appears on origin of qtgraphicsview widget, create clone item containing coordinate/g-codes shape original shape. user moves item (100,-65). action of user offsets each coordinate information of clone created before new coordinates (100,-65) , saves clone text file. further more, lets user adds same 'shape' toolbox again, results in same 'shape' appearing on qtgraphicsview widget's origin. in case there 2 duplicates of same 'shape' on qtgraphicsview widget. when second action happens gui should generate new clone file duplicate of same shape , should execute editing/offsetting coordinates of clone when corresponding duplicate of shape moved/dragged. likewise, when specific item deleted qtgraphicsview widget, corresponding clone of item should deleted directory well. gui should able generate clones multiple shapes provided on toolbox based on specific original files.

having said idea, have created layout gui toolbox , qtgraphicsview widget. im able access original files various shapes , create respective clones each item on added on qtgraphicsview widget. challenge face here i'm unable code/programme following actions,

1) whenever duplicate of item present on screen added again, im not able create specific clone item. following code when 1 such item clicked/added toolbox qtgraphicsview widget.

void mainwindow::on_toolbutton_3_clicked()  {     //32 ohms resitance (base square resistor)      ui->graphicsview->setscene(scene);     qbrush blackbrush(qt::darkgray);     qpen outlinepen(qt::black);     outlinepen.setwidth(2);      rect = scene->addrect(-100,-100,20,20,outlinepen,blackbrush);     rect->setflag(qgraphicsitem::itemisselectable);     rect->setflag(qgraphicsitem::itemismovable);     text = scene->addtext("32ohms");     text->setflag(qgraphicsitem::itemismovable);     text->setflag(qgraphicsitem::itemisselectable);      qfile file_in("/users/vinokanthvelu/desktop/graphite circuitry printer/gui/gcodes/32_ohm_in.rtf");     qfile file_out("/users/vinokanthvelu/desktop/graphite circuitry printer/gui/gcodes/output.txt");      if(file_in.exists() == true)     {         qmessagebox::information(this,"found","file exists");     }     else     {         qmessagebox::information(this,"error","not found");     }      if(!file_in.open(qiodevice::readonly|qiodevice::text))     {         qmessagebox::information(this,"error","file_in error");         return;     }      qtextstream in(&file_in);     while(!file_in.atend())     {         qstring line = in.readall();         if(!file_out.open(qiodevice::writeonly|qiodevice::text))         {             qmessagebox::information(this,"error","file_out error");             return;         }         qtextstream out(&file_out);          //copy gcodes source file output file         out << line << endl;     } } 

this because when duplicate created, actions tries create clone same name clone of previous duplicate of same item. not whats required.

2) how create ids clones of each of duplicates of same shape added qtgraphicsview widget? important because when duplicate of specific shape moved/fragged/deleted, id specific duplicate used access corresponding clone.

3) other idea of creating clones various duplicates of several shapes keep track of coordinate positions of items on qtgraphicsview widget corresponding originals, there other efficient way achieve this?

sorry long post. wanted deliver clear detailed question easier grasp , address problem (im newbie qt , object oriented programming).

accessing files in blocking fashion direct result of action on drawing canvas bad idea. user experience bad.

you should preload predefined shapes in background thread on program startup, , maintain them data structures. should save cloned shapes when user wants save data, or automatically, should done in separate thread well, proper short-term locking. file writer should lock long enough make copy of data, , release lock before performing file access.

this makes id generation trivial: can generate unique sequential id you're writing shapes disk. question necessity of writing cloned shapes individual files. ideally, if printer supports it, should write used shapes once rs-274x macros, , instantiate macros each clone. minimize size of output file, , make retain of structure of original design. rs-274x might sufficient design file format.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -