Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Component inserted automatically disappears from the components list

2 posters

Go down  Message [Page 1 of 1]

feri



I am trying to simulate a simple 4-button remote control, it works but when I use the "UNDO" (Ctrl+Z) command in the shema the automatically inserted transmitter appears 2 times because the code:

    std :: string nameID = getId ();
    QString qnameID (nameID.c_str ());
    qnameID.replace (0, 11, "");
    int m_id = qnameID.toInt ();
    m_id ++;
    qnameID = "Command4-" + QString :: number (m_id);
    command_id = Circuit :: self () -> getCompId (qnameID);
    m_command = Circuit :: self () -> getCompById (command_id);

it does not find the component that even if present in the diagram no longer appears in the components list used by "getCompById".
I do not understand where am I wrong if you can take a look thank you.
I attach the files.
Greetings
Attachments
Component inserted automatically disappears from the components list AttachmentCommand4.zip
Simulide 0.4.15
You don't have permission to download attachments.
(1 Kb) Downloaded 2 times
Component inserted automatically disappears from the components list AttachmentCommand.zip
Simulide 0.4.15
You don't have permission to download attachments.
(8 Kb) Downloaded 2 times

arcachofo

arcachofo

I don't understan how it should work...
First step is defining exactly how it should work:

Do you want Transmitter-Receiver pairs?
Or one Transmitter with several receivers?
Or several Transmitters with several receivers each one?


About your code:

I see 2 components: Command4 and Command4rx which are both intended to be in the component list.
Then Command4rx "searchs" for an exixting Command4, if it does not find it, then creates a new one.

But Command4rx has no way to know the id of an arbitrary comoponent existing in the circuit.
Why this should be the id of an existing component: ??
std :: string nameID = getId ();
QString qnameID (nameID.c_str ());
qnameID.replace (0, 11, "");
int m_id = qnameID.toInt ();
m_id ++;
qnameID = "Command4-" + QString :: number (m_id);

This code is getting it's own id number, and increment by 1.
There is no component with such id number in the circuit.

Basically there is no way to know the id of an existing component in the circuit.
You could search for all Command4 in the circuit, but what if there are more than 1?

feri



There must be a receiver and a transmitter.
When I insert command4rx it is assigned an arbitrary id, it automatically enters commsnd4 which receives the id of command4rx + 1.
When I open the saved scheme I look for the component with id + 1 e
if I find it I don't insert another command4 but I create the slots for the buttons and it works because it finds the command4 with id + 1.
For example, when I move command4rx and then cancel with Ctrl + Z "Command4rx :: Command4rx (QObject * parent, QString type, QString id)" is executed but does not find command4 with id + 1 which however is present and inserts another command4 with id arbitrary.
Greetings

arcachofo

arcachofo

Ok, now I understand.

If you only need Transmitter-Receiver pairs, then it's better to just create both every time.
But you need to delete Command4 from component list to avoid being saved:

Code:
m_command = Circuit::self()->createItem( "Command4", "Command4-"+Circuit::self()->newSceneId());
Circuit::self()->compList()->removeOne( m_command );

Also Command4 doesn't need Command4::construct and Command4::libraryItem.

EDIT:
Thinking about it, there are still some issues to solve.
For example: what happens if you copy/paste only the transmitter?

I think, Command4 should not be a component, just a QGraphicsItem.

feri



A good result is achieved by deleting command4 and inserting it each time command4rx is entered.
I would like to know if it is possible to execute a function at the moment the component is inserted here and after the mouse button is released.
"Command4rx :: paint" runs before the mouse button is released.
Greetings

arcachofo

arcachofo

After the component is inserted, at the moment of mouse release, Circuit::dropEvent is executed.

feri



I issued a SIGNAL in "Circuit :: dropEvent" and created a SLOT in "Command4rx" but I don't understand what to put as first argument:

connect (???????, SIGNAL (inserted ()),
this, SLOT (isinserted ()));

I wish when "Circuit :: dropEvent" ends in "Command4rx" execute a function.
it is correct to use SIGNAL and SLOT.
Greetings

arcachofo

arcachofo

but I don't understand what to put as first argument:

connect (???????, SIGNAL (inserted ()),
this, SLOT (isinserted ()));
Use: Circuit::self()

connect (Circuit::self(), SIGNAL (inserted ()),
this, SLOT (isinserted ()));

it is correct to use SIGNAL and SLOT.
Yes, it is one option.
But you will receive a call to the slot every time a component is inserted.
Maybe you should disconnect the signal after operation is completed.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum