Layermanager in C++

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Tom
Newbie Member
Posts: 4
Joined: Thu Feb 18, 2016 5:29 pm

Layermanager in C++

Post by Tom » Thu Mar 03, 2016 4:14 am

Hi Readers,

I'm a newbie in QCAD, but not in CAD Developement. So I try port some old and tested Features like a Layer Manager to QCAD. At first I want get a feeling for the system, specifically the Transaction system. I wrote this code:
RDocumentInterface *di = RMainWindow::getDocumentInterfaceStatic();
   if(di)
   {
      RDocument &document = di->getDocument();

      QSet<RLayer::Id> LayerSet = document.queryAllLayers();

      foreach(RLayer::Id theLayerID, LayerSet)
      {
         QSharedPointer<RLayer> theLayer = document.queryLayer(theLayerID);
         if(!theLayer.isNull())
         {
            // For testing I pick a layer, but on the end I want traverse the whole layer tabel
            if(Globals::getLyrNmSeamData() == theLayer->getName())
            {
               RTransaction theTransaction(document.getStorage(), QObject::tr("Set layer properties"), false);

               theLayer->setFrozen(false);
               theLayer->setLocked(false);

               theTransaction.addObject(theLayer, false);  // true hasn't any effect in this kind
               theTransaction.end();

               document.setCurrentLayer(theLayerID);

               break;
            }
         }
      }

      di->regenerateScenes() ; // Important if you want see the changes on the screen
   }
A lot work. The Current Layer was changed. I can draw entities and can see them. But the old entities was not shown, even during I draw a new line, too. I try call methods from notify system but no effect. I search in internet an look in this board. Then I found the reason as I inspect the DocumentInterface class. I'm sure before that I have to find a method for rebuild the internal display lists. A call of regenerateScenes() was the solution.

User avatar
andrew
Site Admin
Posts: 9052
Joined: Fri Mar 30, 2007 6:07 am

Re: Layermanager in C++

Post by andrew » Mon Mar 07, 2016 10:18 am

Transactions are usually only used on a lower level in QCAD (a transaction records all changes on a set of objects caused by an operation, i.e. when adding, deleting or modifying objects).

Operations are the concept used for more comfortable, higher level modifications:
RModifyObjectsOperation op;
op.addObject(layer);
di->applyOperation(&op);
This will update the document and also the views, layer lists, etc. accordingly. A transaction object is returned by applyOperation which contains information about objects that were changed.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”