Esempio n. 1
0
int main(){
    sample num1, num2;
    num1.pp=8;
    num1.qq=16;
    num2.pp=4;
    num2.qq=14;
    reduce(num1);
    reduce(num2);
    int output1=action2(num1,num2).pp;
    int output2=action2(num1,num2).qq;
    int output3=action1(num1,num2).pp;
    int output4=action1(num1,num2).qq;
    return 0;
}
void tst_QToolBar::addWidget()
{
    QToolBar tb;
    QWidget w(&tb);

    QAction action1(0);
    QAction action2(0);

    tb.addAction(&action1);
    QAction *widget = tb.addWidget(&w);
    tb.addAction(&action2);

    QCOMPARE(tb.actions().count(), 3);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], widget);
    QCOMPARE(tb.actions()[2], &action2);

    // it should be possible to reuse the action returned by
    // addWidget() to place the widget somewhere else in the toolbar
    tb.removeAction(widget);
    QCOMPARE(tb.actions().count(), 2);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], &action2);

    tb.addAction(widget);
    QCOMPARE(tb.actions().count(), 3);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], &action2);
    QCOMPARE(tb.actions()[2], widget);

    tb.clear();
    QCOMPARE(tb.actions().count(), 0);
}
TEST(MarkovActionChainTest, Marginalize) {
  MarkovActionChain<X, U> mac;
  mac.Set(x0, u0, x0, 1.0);
  mac.Set(x1, u0, x0, 0.0);
  mac.Set(x0, u1, x0, 0.25);
  mac.Set(x1, u1, x0, 0.75);
  mac.Set(x0, u0, x1, 0.0);
  mac.Set(x1, u0, x1, 1.0);
  mac.Set(x0, u1, x1, 0.75);
  mac.Set(x1, u1, x1, 0.25);

  DistributionValueMap<XU> action0(XU(x0, u0), 0.5, XU(x1, u0), 0.5);
  auto x = mac.Marginalize(action0);
  EXPECT_DOUBLE_EQ(0.5, x->ProbabilityOf(x0));
  EXPECT_DOUBLE_EQ(0.5, x->ProbabilityOf(x1));

  DistributionValueMap<XU> action1(XU(x0, u1), 0.5, XU(x1, u1), 0.5);
  x = mac.Marginalize(action1);
  EXPECT_DOUBLE_EQ(0.5, x->ProbabilityOf(x0));
  EXPECT_DOUBLE_EQ(0.5, x->ProbabilityOf(x1));

  DistributionValueMap<XU> action2(XU(x0, u0), 0.5, XU(x1, u1), 0.5);
  x = mac.Marginalize(action2);
  EXPECT_DOUBLE_EQ(7.0/8.0, x->ProbabilityOf(x0));
  EXPECT_DOUBLE_EQ(1.0/8.0, x->ProbabilityOf(x1));
}
void X360_button (void)
{
		switch (button)
					{
						case 1:action1();break;
						case 2:action2();break;
					}
}
Esempio n. 5
0
int main(void)
{
  Action<Animal> action1 = [](Animal *a) { std::cout << a->name() << "\n"; };
  Action<Giraffe> action2 = action1;
  action2(new Giraffe());
  
  Meta<Mammal> meta1 = [](Action<Mammal> action) { action(new Giraffe()); };
  Meta<Animal> meta2 = meta1;
  meta2(action1);
  
}
void tst_QToolBar::insertWidget()
{
    QToolBar tb;
    QWidget w(&tb);

    QAction action1(0);
    QAction action2(0);

    tb.addAction(&action1);
    tb.addAction(&action2);
    QAction *widget = tb.insertWidget(&action2, &w);

    QCOMPARE(tb.actions().count(), 3);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], widget);
    QCOMPARE(tb.actions()[2], &action2);

    // it should be possible to reuse the action returned by
    // addWidget() to place the widget somewhere else in the toolbar
    tb.removeAction(widget);
    QCOMPARE(tb.actions().count(), 2);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], &action2);

    tb.insertAction(&action1, widget);
    QCOMPARE(tb.actions().count(), 3);
    QCOMPARE(tb.actions()[0], widget);
    QCOMPARE(tb.actions()[1], &action1);
    QCOMPARE(tb.actions()[2], &action2);

    tb.clear();
    QCOMPARE(tb.actions().count(), 0);

    {
        QToolBar tb;
        QPointer<QWidget> widget = new QWidget;
        QAction *action = tb.addWidget(widget);
        QVERIFY(action->parent() == &tb);

        QToolBar tb2;
        tb.removeAction(action);
        tb2.addAction(action);
        QVERIFY(widget && widget->parent() == &tb2);
        QVERIFY(action->parent() == &tb2);
    }
}
Esempio n. 7
0
void EventInterpreter::update(Event *e) {
	if(actions[e->name()].size() == 0 || e->currentActionID() == -1) {
		e->currentActionID(0);
		while(actions[e->name()].size() != 0) {
			delete actions[e->name()].back();
			actions[e->name()].pop_back();
		}
		return;
	}

	switch(actions[e->name()][e->currentActionID()]->actionType()) {
		case 0:		action0(e);		break;
		case 1:		action1(e);		break;
		case 2:		action2(e);		break;
		default:					break;
	};
}
void tst_QActionGroup::unCheckCurrentAction()
{
    QActionGroup group(0);
    QAction action1(&group) ,action2(&group);
    action1.setCheckable(true);
    action2.setCheckable(true);
    QVERIFY(!action1.isChecked());
    QVERIFY(!action2.isChecked());
    action1.setChecked(true);
    QVERIFY(action1.isChecked());
    QVERIFY(!action2.isChecked());
    QAction *current = group.checkedAction();
    QCOMPARE(current, &action1);
    current->setChecked(false);
    QVERIFY(!action1.isChecked());
    QVERIFY(!action2.isChecked());
    QVERIFY(group.checkedAction() == 0);
}
void tst_QToolBar::insertSeparator()
{
    QToolBar tb;

    QAction action1(0);
    QAction action2(0);

    tb.addAction(&action1);
    tb.addAction(&action2);
    QAction *sep = tb.insertSeparator(&action2);

    QCOMPARE(tb.actions().count(), 3);
    QCOMPARE(tb.actions()[0], &action1);
    QCOMPARE(tb.actions()[1], sep);
    QCOMPARE(tb.actions()[2], &action2);

    tb.clear();
    QCOMPARE(tb.actions().count(), 0);
}
Esempio n. 10
0
int main()  {
    void action1(int, int), action2(int,int);
    char ch;
    int a = 15,b = 23;
    ch = getchar();
    switch(ch) {
        case 'a'    :
        case 'A'    :   {
                          action1(a,b);break;
                        }
        case 'b'    :
        case 'B'    :   {
                            action2(a,b);break;
                        }

        default:    putchar('\a');
    }
    return 0;
}
Esempio n. 11
0
void AiAction::doAction()
{
	switch (m_actionID)
	{
	case 0:
		action0();
		break;
	case 1:
		action1();
		break;
	case 2:
		action2();
		break;
	case 3:
		action3();
		break;
	default:
		break;
	}
}
Esempio n. 12
0
int main()
{
	int a,b;
	void action1(int,int),action2(int,int);
	char ch;
	printf("plese enter two integer numbers:");
	scanf("%d%d",&a,&b);
	getchar();
	printf("enter a or A to sum.\nenter b or B to product.\n");
	ch=getchar();
	switch(ch)
	{
		case'a':
		case'A':action1(a,b);break;
		case'b':
		case'B':action2(a,b);break;
		default:putchar('\a');
	}
	return 0;
}
void tst_QToolBar::insertAction()
{
    QToolBar tb;
    QAction action1(0);
    QAction action2(0);
    QAction action3(0);
    QAction action4(0);

    QCOMPARE(tb.actions().count(), 0);
    tb.insertAction(0, &action1);
    tb.insertAction(&action1, &action2);
    tb.insertAction(&action2, &action3);
    tb.insertAction(&action3, &action4);
    QCOMPARE(tb.actions().count(), 4);
    QCOMPARE(tb.actions()[0], &action4);
    QCOMPARE(tb.actions()[1], &action3);
    QCOMPARE(tb.actions()[2], &action2);
    QCOMPARE(tb.actions()[3], &action1);

    tb.clear();
    QCOMPARE(tb.actions().count(), 0);
}
void tst_QToolBar::actionTriggered()
{
    QToolBar tb;
    connect(&tb, SIGNAL(actionTriggered(QAction *)), SLOT(slot(QAction *)));

    QAction action1(0);
    QAction action2(0);
    QAction action3(0);
    QAction action4(0);

    tb.addAction(&action1);
    tb.addAction(&action2);
    tb.addAction(&action3);
    tb.addAction(&action4);

    tb.show();
#ifdef Q_WS_X11
    qt_x11_wait_for_window_manager(&tb);
#endif

    QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>();

    QRect rect01;
    QRect rect02;
    QRect rect03;
    QRect rect04;
    QMenu *popupMenu;

    if (extensions.size() != 0)
    {
        QToolBarExtension *extension = extensions.at(0);
        if (extension->isVisible()) {
            QRect rect0 = extension->geometry();
            QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 );
            QApplication::processEvents();
            popupMenu = qobject_cast<QMenu *>(extension->menu());
            rect01 = popupMenu->actionGeometry(&action1);
            rect02 = popupMenu->actionGeometry(&action2);
            rect03 = popupMenu->actionGeometry(&action3);
            rect04 = popupMenu->actionGeometry(&action4);
        }
    }

    QRect rect1 = tb.actionGeometry(&action1);
    QRect rect2 = tb.actionGeometry(&action2);
    QRect rect3 = tb.actionGeometry(&action3);
    QRect rect4 = tb.actionGeometry(&action4);

    QAbstractButton *button1;
    QAbstractButton *button2;
    QAbstractButton *button3;
    QAbstractButton *button4;

    if (!rect01.isValid()) {
        button1 = qobject_cast<QAbstractButton *>(tb.childAt(rect1.center()));
        QVERIFY(button1 != 0);
    }
    if (!rect02.isValid()) {
        button2 = qobject_cast<QAbstractButton *>(tb.childAt(rect2.center()));
        QVERIFY(button2 != 0);
    }
    if (!rect03.isValid()) {
        button3 = qobject_cast<QAbstractButton *>(tb.childAt(rect3.center()));
        QVERIFY(button3 != 0);
    }
    if (!rect04.isValid()) {
        button4 = qobject_cast<QAbstractButton *>(tb.childAt(rect4.center()));
        QVERIFY(button4 != 0);
    }

    ::triggered = 0;
    if (!rect01.isValid())
        QTest::mouseClick(button1, Qt::LeftButton);
    else
        QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect01.center(), -1 );
    QCOMPARE(::triggered, &action1);

    ::triggered = 0;
    if (!rect02.isValid())
        QTest::mouseClick(button2, Qt::LeftButton);
    else
        QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect02.center(), -1 );
    QCOMPARE(::triggered, &action2);

    ::triggered = 0;
    if (!rect03.isValid())
        QTest::mouseClick(button3, Qt::LeftButton);
    else
        QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect03.center(), -1 );
    QCOMPARE(::triggered, &action3);

    ::triggered = 0;
    if (!rect04.isValid())
        QTest::mouseClick(button4, Qt::LeftButton);
    else
        QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect04.center(), -1 );
    QCOMPARE(::triggered, &action4);
}
void tst_QToolBar::actionGeometry()
{
    QToolBar tb;

    QAction action1(0);
    QAction action2(0);
    QAction action3(0);
    QAction action4(0);

    tb.addAction(&action1);
    tb.addAction(&action2);
    tb.addAction(&action3);
    tb.addAction(&action4);

    tb.show();
#ifdef Q_WS_X11
    qt_x11_wait_for_window_manager(&tb);
#endif

    QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>();

    QRect rect01;
    QRect rect02;
    QRect rect03;
    QRect rect04;
    QMenu *popupMenu;

    if (extensions.size() != 0)
    {
        QToolBarExtension *extension = extensions.at(0);
        if (extension->isVisible()) {
            QRect rect0 = extension->geometry();
            QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 );
            QApplication::processEvents();
            popupMenu = qobject_cast<QMenu *>(extension->menu());
            rect01 = popupMenu->actionGeometry(&action1);
            rect02 = popupMenu->actionGeometry(&action2);
            rect03 = popupMenu->actionGeometry(&action3);
            rect04 = popupMenu->actionGeometry(&action4);
        }
    }

    QRect rect1 = tb.actionGeometry(&action1);
    QRect rect2 = tb.actionGeometry(&action2);
    QRect rect3 = tb.actionGeometry(&action3);
    QRect rect4 = tb.actionGeometry(&action4);

    QVERIFY(rect1.isValid());
    QVERIFY(!rect1.isNull());
    QVERIFY(!rect1.isEmpty());

    QVERIFY(rect2.isValid());
    QVERIFY(!rect2.isNull());
    QVERIFY(!rect2.isEmpty());

    QVERIFY(rect3.isValid());
    QVERIFY(!rect3.isNull());
    QVERIFY(!rect3.isEmpty());

    QVERIFY(rect4.isValid());
    QVERIFY(!rect4.isNull());
    QVERIFY(!rect4.isEmpty());

    if (rect01.isValid())
        QCOMPARE(popupMenu->actionAt(rect01.center()), &action1);
    else
        QCOMPARE(tb.actionAt(rect1.center()), &action1);

    if (rect02.isValid())
        QCOMPARE(popupMenu->actionAt(rect02.center()), &action2);
    else
        QCOMPARE(tb.actionAt(rect2.center()), &action2);

    if (rect03.isValid())
        QCOMPARE(popupMenu->actionAt(rect03.center()), &action3);
    else
        QCOMPARE(tb.actionAt(rect3.center()), &action3);

    if (rect04.isValid())
        QCOMPARE(popupMenu->actionAt(rect04.center()), &action4);
    else
        QCOMPARE(tb.actionAt(rect4.center()), &action4);
}
Esempio n. 16
0
void MainWindow::slotRadarMenu(QPoint pos){

    qDebug() << "MainWindow::slotRadarMenu(QPoint pos)";

    //////////////////////////////////////////////
    ///
    ///  radarTypeMenu
    ///
    //////////////////////////////////////////////

    QMenu radarTypeMenu(tr("Radar Type"), this);

    QAction action1("Base", this);
    QAction action2("Long Range", this);
    QAction action3("Storm Motion", this);
    QAction action4("Velocity", this);
    QAction action5("One-Hour Precipitation", this);
    QAction action6("Composite", this);
    QAction action7("Storm Precipitation", this);

    radarTypeMenu.addAction(&action1);
    radarTypeMenu.addAction(&action2);
    radarTypeMenu.addAction(&action3);
    radarTypeMenu.addAction(&action4);
    radarTypeMenu.addAction(&action5);
    radarTypeMenu.addAction(&action6);
    radarTypeMenu.addAction(&action7);

    //radarTypeMenu.setStyleSheet("QMenu::item:selected{border:1px solid red;}");

    connect(&action1, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::N0R); });
    connect(&action2, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::N0Z); });
    connect(&action3, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::N0S); });
    connect(&action4, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::N0V); });
    connect(&action5, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::N1P); });
    connect(&action6, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::NCR); });
    connect(&action7, &QAction::triggered, this, [this]{ slotRadarChanged(RadarType::NTP); });

    QMenu radarImageContextMenu(tr("Context Menu"), this);

    radarImageContextMenu.addMenu(&radarTypeMenu);

    //////////////////////////////////////////////
    ///
    ///  radarStationMenu
    ///
    //////////////////////////////////////////////

    QMenu radarStationMenu(tr("Radar Station"), this);

    RadarTreeWidget radarTreeWidget(this);

    connect(&radarTreeWidget, SIGNAL(signalDoubleClick(QString)), this, SLOT(slotWeatherStationSelected(QString)));

    QWidgetAction *radarTreeAction = new QWidgetAction(this);

    radarTreeAction->setDefaultWidget(&radarTreeWidget);

    radarStationMenu.addAction(radarTreeAction);

    radarImageContextMenu.addMenu(&radarStationMenu);

    //////////////////////////////////////////////
    ///
    ///  radarOverlayMenu
    ///
    //////////////////////////////////////////////

    bool rangeRing = m_radar_station->getCurrentRadarProductType() != RadarType::N0Z;

    QMenu radarOverlayMenu(tr("Overlays"), this);

    QCheckBox *checkTopography = new QCheckBox("Topography", this);
    QCheckBox *checkCities = new QCheckBox("Cities", this);
    QCheckBox *checkCounties = new QCheckBox("Counties", this);
    QCheckBox *checkHighways = new QCheckBox("Highways", this);
    QCheckBox *checkRivers = new QCheckBox("Rivers", this);
    QCheckBox *checkRangeRing = new QCheckBox("Range Ring", this);
    QCheckBox *checkWarnings = new QCheckBox("Warnings", this);
    QCheckBox *checkLegend = new QCheckBox("Legend", this);

    checkTopography->setStyleSheet("padding: 6px;");
    checkCities->setStyleSheet("padding: 6px;");
    checkCounties->setStyleSheet("padding: 6px;");
    checkHighways->setStyleSheet("padding: 6px;");
    checkRivers->setStyleSheet("padding: 6px;");
    if (rangeRing) checkRangeRing->setStyleSheet("padding: 6px;");
    checkWarnings->setStyleSheet("padding: 6px;");
    checkLegend->setStyleSheet("padding: 6px;");

    checkTopography->setChecked(this->m_radar_settings.topoEnabled);
    checkCities->setChecked(this->m_radar_settings.cityEnabled);
    checkCounties->setChecked(this->m_radar_settings.countiesEnabled);
    checkHighways->setChecked(this->m_radar_settings.highwaysEnabled);
    checkRivers->setChecked(this->m_radar_settings.riversEnabled);
    if (rangeRing) checkRangeRing->setChecked(this->m_radar_settings.rangeEnabled);
    checkWarnings->setChecked(this->m_radar_settings.warningsEnabled);
    checkLegend->setChecked(this->m_radar_settings.legendEnabled);

    QWidgetAction *radarTopographyAction = new QWidgetAction(this);
    QWidgetAction *radarCitiesAction = new QWidgetAction(this);
    QWidgetAction *radarCountiesAction = new QWidgetAction(this);
    QWidgetAction *radarHighwaysAction = new QWidgetAction(this);
    QWidgetAction *radarRiversAction = new QWidgetAction(this);
    QWidgetAction *radarRangeRingAction = new QWidgetAction(this);
    QWidgetAction *radarWarningsAction = new QWidgetAction(this);
    QWidgetAction *radarLegendAction = new QWidgetAction(this);

    radarTopographyAction->setDefaultWidget(checkTopography);
    radarCitiesAction->setDefaultWidget(checkCities);
    radarCountiesAction->setDefaultWidget(checkCounties);
    radarHighwaysAction->setDefaultWidget(checkHighways);
    radarRiversAction->setDefaultWidget(checkRivers);
    if (rangeRing) radarRangeRingAction->setDefaultWidget(checkRangeRing);
    radarWarningsAction->setDefaultWidget(checkWarnings);
    radarLegendAction->setDefaultWidget(checkLegend);

    radarOverlayMenu.addAction(radarTopographyAction);
    radarOverlayMenu.addAction(radarCitiesAction);
    radarOverlayMenu.addAction(radarCountiesAction);
    radarOverlayMenu.addAction(radarHighwaysAction);
    radarOverlayMenu.addAction(radarRiversAction);
    if (rangeRing) radarOverlayMenu.addAction(radarRangeRingAction);
    radarOverlayMenu.addAction(radarWarningsAction);
    radarOverlayMenu.addAction(radarLegendAction);

    connect(checkTopography, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(1); } );
    connect(checkCities, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(2); } );
    connect(checkCounties, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(3); } );
    connect(checkHighways, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(4); } );
    connect(checkRivers, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(5); } );
    if (rangeRing) connect(checkRangeRing, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(6); } );
    connect(checkWarnings, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(7); } );
    connect(checkLegend, &QCheckBox::clicked, this, [this]{ slotOverlayChanged(8); } );

    radarImageContextMenu.addMenu(&radarOverlayMenu);

    ////////////////////////////////////////////////

    radarImageContextMenu.exec(ui->radarDisplay->mapToGlobal(pos));

    return;
}