Detection transaction operation

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
caramel
Newbie Member
Posts: 4
Joined: Mon Jan 08, 2018 7:01 pm

Detection transaction operation

Post by caramel » Tue Jan 09, 2018 8:22 pm

Hi,

I'm using transaction listener for change detection :

Code: Select all

TransactionListener.init = function (basePath) {

  var adapter = new RTransactionListenerAdapter();
  var appWin = EAction.getMainWindow();
  appWin.addTransactionListener(adapter);

  adapter.transactionUpdated.connect(function (document, transaction) {
    if (isNull(document) || isNull(transaction)) {
      return;
    }
    
    var doc = EAction.getDocument();
    var objIds = transaction.getAffectedObjects();

    for (var i = 0; i < objIds.length; i++) {
      var objId = objIds[i];     

      var obj = doc.queryObjectDirect(objIds[i]);

      if (isLineEntity(obj)) {
        if (transaction.getText().toLowerCase() == "supprimer") {
          qDebug("line deleted");
          //mycode...
        }

        else if (transaction.getText().toLowerCase().indexOf("déplacer") != -1) {          
          qDebug("line moved");   
          //mycode...    
        }

      }
    }

  });

  EAction.handleUserMessage("Mod_TransactionListener.js: Transaction listener installed.");

};
And as you can see I'm temporarily basing on transaction.getText() to detect operation type, but I know that isn't the appropriate way, could you tell me the rightr way to detect it ?

Thanks a lot !
Caramel

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

Re: Detection transaction operation

Post by andrew » Mon Mar 12, 2018 12:53 pm

There is no transaction type as such. A transaction encapsulates a change in the drawing (changing objects, adding objects, removing objects). Transactions are unaware of the particular tool that was used to cause that change (apart from the transaction text which can be optionally set by the tool responsible for the transaction).

transaction.getAffectedObjects() returns a list of object IDs of objects that were changed / added/ deleted by a transaction.
transaction.getStatusChanges() returns a list of object IDs of objects that were either created or deleted (check undo status of object)
transaction.getPropertyChanges() returns a list of exact property changes per object as shown in ExTransactionListener.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”