Login  Register

Re: new toolbars

Posted by ravas on Sep 11, 2015; 2:31am
URL: https://forum.librecad.org/new-toolbars-tp5712125p5712206.html

/**
 * Called from the application.
 */
void QG_CadToolBar::forceNext() {
    if(activeToolbars.size()==0) return;
        auto p=activeToolbars.back();
        if (p && p->rtti() == RS2::ToolBarSelect)
                p->runNextAction();
}
void QG_CadToolBarSelect::runNextAction() {
        if (selectAction) {
        if(selectAction->rtti() == RS2::ActionSelect){
            //refuse to run next action if no entity is selected, to avoid segfault by action upon empty selection
            //issue#235
            if( static_cast<RS_ActionSelect*>(selectAction)->countSelected()==0) return;
        }
        selectAction->finish();
                selectAction = nullptr;
    }
    if (nextAction!=-1) {
        actionHandler->killSelectActions();
        actionHandler->setCurrentAction((RS2::ActionType)nextAction);
    }
}
void QG_CadToolBar::showToolBarSelect(RS_ActionInterface* selectAction,
                                      int nextAction) {
        auto p=m_toolbars[RS2::ToolBarSelect];

        p->setNextAction(nextAction);
        p->setSelectAction(selectAction);
    showToolBar(RS2::ToolBarSelect);
        showSubToolBar();
}
/**
 * Shows the select toolbar with the given action to launch.
 */
void QG_DialogFactory::requestToolBarSelect(RS_ActionInterface* selectAction,
        RS2::ActionType nextAction) {
        if (cadToolBar) {
        cadToolBar->showToolBarSelect(selectAction, nextAction);
    }
}
void RS_ActionSelect::updateToolBar() {
    if (RS_DIALOGFACTORY) {
        if (isFinished()){
            if(container->countSelected()==0){
                //some nextAction segfault with empty selection
                //todo: make actions safe with empty selection, issue#235
                RS_DIALOGFACTORY->commandMessage(tr("No entity selected!"));
                //do not keep toolbar select after this action finishes, issue#291
//                RS_DIALOGFACTORY->requestToolBarSelect(this, nextAction);
                RS_DIALOGFACTORY->requestPreviousToolBar();
            } else{
                if ( entityTypeList.size()){
                    //only select entity types from the given list
                    //fixme, need to handle resolution level

                                        for(auto e: *container){
                                                if (e && e->isSelected()) {
                                                        if(!entityTypeList.count(e->rtti()))
                                                                e->setSelected(false);
                        }
                    }
                }
                RS_DIALOGFACTORY->requestPreviousToolBar();
            }
        }else{
            RS_DIALOGFACTORY->requestToolBarSelect(this, nextAction);
        }

    }
}
wow... so complicated... @_@

Let me know if you can come up with a solution...