Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. same actions to execute different slots
Forum Updated to NodeBB v4.3 + New Features

same actions to execute different slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 475 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    this is rather a logic implementation question.

    so i have two views - tree and table.

    items in both views open a context menu with the same list of actions.
    when opened from table view, it should be applied to the selected table rows, and when opened from tree view, it should be applied to all items.

    the actions are stored in a common place:

    class actionHandler
    {
    public:
        void onAction1Trig() {}
        void onAction2Trig() {}
        ...
    };
    

    one way to differentiate which view invoked the context menu i think is to set a bool: void setApplyAll(bool bAll);
    the tree view will set true, and table view will set false.
    what other option would you suggest?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since you build up the context menu it should be possible to store this information in your action handler.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      U 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Since you build up the context menu it should be possible to store this information in your action handler.

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @christian-ehrlicher
        that's almost what i mean. when building up the context menu, i should be setting the bool value?

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          Sorry, I misread the last sentence from you. This is something similar to what I would do. But on the other hand - since you need to do different things inside the actions for the table and the tree I would maybe add this specific part inside the tree/table view derived class and the common stuff somewhere else.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          U 1 Reply Last reply
          0
          • M Offline
            M Offline
            mpergand
            wrote on last edited by mpergand
            #5

            The common way is to look at the sender object in your slot method:

            if(sender() == myTable)
               do ...
            else if(sender() == myTree)
                do ...
            etc ...
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Sorry, I misread the last sentence from you. This is something similar to what I would do. But on the other hand - since you need to do different things inside the actions for the table and the tree I would maybe add this specific part inside the tree/table view derived class and the common stuff somewhere else.

              U Offline
              U Offline
              user4592357
              wrote on last edited by
              #6

              @christian-ehrlicher
              actually it's not different things, it's the same thing (e.g. update), only applied to different number of items.
              table view applies to only selected rows, and tree views applies to all items.
              so in case of tree view i need to tell the action handler to update ALL items.

              @mpergand
              yeah right. if i don't find a more elegant solution, i'll use that.

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @mpergand said in same actions to execute different slots:

                The common way is to look at the sender object in your slot method:

                The problem is that the sender here is the QAction and/or QMenu...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @user4592357 said in same actions to execute different slots:

                  actually it's not different things, it's the same thing (e.g. update), only applied to different number of items.

                  So why do you need to distinguish then at all?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  U 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @user4592357 said in same actions to execute different slots:

                    actually it's not different things, it's the same thing (e.g. update), only applied to different number of items.

                    So why do you need to distinguish then at all?

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #9

                    @christian-ehrlicher
                    to pass the correct parameters - the numbers of selected rows, or * (to indicate all items)

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by Christian Ehrlicher
                      #10

                      Then do what I said above - implement the different logic inside the view, then call a function which does the common stuff.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      U 1 Reply Last reply
                      2
                      • Christian EhrlicherC Christian Ehrlicher

                        Then do what I said above - implement the different logic inside the view, then call a function which does the common stuff.

                        U Offline
                        U Offline
                        user4592357
                        wrote on last edited by
                        #11

                        @christian-ehrlicher
                        i'm thinking of another solution, have a method in actionHandler to take the rows to be updated. the table will set the selected rows numbers, and the tree will set *. that way processing will be done the actions handler now.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved