Esempio n. 1
0
void MainWindow::createMenu()
{
    QMenu *menuFile = new QMenu("File");
    menuFile->addAction( "Open base", this, SLOT( openBS() ) );
    menuFile->addAction( "Create base", this, SLOT( createBS() ) );
    menuFile->addSeparator();
    menuFile->addAction( "Close base", this, SLOT( closeBS() ) );
    menuFile->addAction( "Clear base", this, SLOT( clearBS() ) );
    menuFile->addSeparator();
    menuFile->addAction( "Quit", this, SLOT( close() ) );

    QMenu *menuEdit = new QMenu("Edit");
    menuEdit->addAction( "Add record", this, SLOT( addRS() ) );
    menuEdit->addAction( "Edit record", this, SLOT( editRS() ) );
    menuEdit->addAction( "Show record", this, SLOT( showRS() ) );
    menuEdit->addAction( "Select records", this, SLOT( selectRS() ) );
    menuEdit->addSeparator();
    menuEdit->addAction( "Delete record", this, SLOT( delRS() ) );

    QMenu *menuDraw = new QMenu("Draw");
    menuDraw->addAction( "Diagram", this, SLOT( diagramS() ) );
    menuDraw->addAction( "Fun", this, SLOT( funS() ) );

    menuBar()->addMenu(menuFile);
    menuBar()->addMenu(menuEdit);
    menuBar()->addMenu(menuDraw);

    menuBar()->addAction( "Help", this, SLOT( helpS() ) );
}
Esempio n. 2
0
void MainWindow::openBS()
{
    QString path = QFileDialog::getOpenFileName( this, tr("Open File"), "D:\\Project\\Qt_Creator\\DataBase_0.6", tr("*.sqlite") );

    if( path != "" )
    {
        closeBS();

        base = QSqlDatabase::addDatabase("QSQLITE");

        base.setDatabaseName(path);

        if( base.open() )
            qDebug() << "Open successful";
        else
        {
            qDebug() << "Open falied";
            return;
        }

        model = new SqlTableModel;
        model->setTable("my_table");
        model->select();
        model->setEditStrategy(QSqlTableModel::OnFieldChange);

        setView();

        this->setWindowTitle(path);
    }
}
Esempio n. 3
0
void MainWindow::createBS()
{
    QString path = QFileDialog::getSaveFileName( this, tr("Create File"), "D:\\", tr("*.sqlite") );

    if( path != "" )
    {
        closeBS();

        base = QSqlDatabase::addDatabase("QSQLITE");

        base.setDatabaseName(path);

        if( base.open() )
            qDebug() << "Open successful";
        else
        {
            qDebug() << "Open falied";
            return;
        }

        QSqlQuery query;

        QString str = "CREATE TABLE my_table ("
                "ID integer PRIMARY KEY NOT NULL, "
                "Surname VARCHAR(31), "
                "Name VARCHAR(31), "
                "Patronimic VARCHAR(31), "
                "Sex VARCHAR(6), "
                "Birth date, "
                "Education VARCHAR(10), "
                "MatrialStatus VARCHAR(9), "
                "EntryDate date"
                ");";

        if(query.exec(str))
            qDebug() << "Create successful";
        else
        {
            qDebug() << "Create falied";
            return;
        }

        model = new SqlTableModel;
        model->setTable("my_table");
        model->select();
        model->setEditStrategy(QSqlTableModel::OnFieldChange);

        setView();

        this->setWindowTitle(path);
    }
}
Esempio n. 4
0
void MainWindow::clearBS()
{
    if(model)
        model->clear();

    QSqlQuery query;

    QString str = "DROP TABLE my_table;";

    query.exec(str);

    closeBS();
}
Esempio n. 5
0
void MainWindow::setConnect()
{
    QObject::connect( openBase, SIGNAL( pressed() ), this, SLOT( openBS() ) );
    QObject::connect( closeBase, SIGNAL( pressed() ), this, SLOT( closeBS() ) );
    QObject::connect( createBase, SIGNAL( pressed() ), this, SLOT( createBS() ) );
    QObject::connect( clearBase, SIGNAL( pressed() ), this, SLOT( clearBS() ) );
    QObject::connect( addRecord, SIGNAL( pressed() ), this, SLOT( addRS() ) );
    QObject::connect( deleteRecord, SIGNAL( pressed() ), this, SLOT( delRS() ) );
    QObject::connect( editRecord, SIGNAL( pressed() ), this, SLOT( editRS() ) );
    QObject::connect( showRecord, SIGNAL( pressed() ), this, SLOT( showRS() ) );
    QObject::connect( selectRecord, SIGNAL( pressed() ), this, SLOT( selectRS() ) );
    QObject::connect( diagram, SIGNAL( pressed() ), this, SLOT( diagramS() ) );
}
Esempio n. 6
0
void MainWindow::closeEvent(QCloseEvent *event)
{
    closeBS();

    emit( closeSignal() );

    if(view)
        delete view;

    if(openBase)
        delete openBase;
    if(closeBase)
        delete closeBase;
    if(createBase)
        delete createBase;
    if(clearBase)
        delete clearBase;
    if(addRecord)
        delete addRecord;
    if(deleteRecord)
        delete deleteRecord;
    if(editRecord)
        delete editRecord;
    if(showRecord)
        delete showRecord;
    if(selectRecord)
        delete selectRecord;
    if(diagram)
        delete diagram;

    if(buttonGroupLeft)
        delete buttonGroupLeft;
    if(buttonGroupRight)
        delete buttonGroupRight;
    if(mainLayout)
        delete mainLayout;
    if(box)
        delete box;

    event->accept();
}
AI_Waypoint_t *CAI_Pathfinder::FindBestPath(int startID, int endID) 
{
	if ( !GetNetwork()->NumNodes() )
		return NULL;

	int nNodes = GetNetwork()->NumNodes();
	CAI_Node **pAInode = GetNetwork()->AccessNodes();

	CVarBitVec	openBS(nNodes);
	CVarBitVec	closeBS(nNodes);

	// ------------- INITIALIZE ------------------------
	float* nodeG = (float *)stackalloc( nNodes * sizeof(float) );
	float* nodeH = (float *)stackalloc( nNodes * sizeof(float) );
	float* nodeF = (float *)stackalloc( nNodes * sizeof(float) );
	int*   nodeP = (int *)stackalloc( nNodes * sizeof(int) );		// Node parent 

	for (int node=0;node<nNodes;node++)
	{
		nodeG[node] = FLT_MAX;
		nodeP[node] = -1;
	}

	nodeG[startID] = 0;

	nodeH[startID] = 0.1*(pAInode[startID]->GetPosition(GetHullType())-pAInode[endID]->GetPosition(GetHullType())).Length(); // Don't want to over estimate
	nodeF[startID] = nodeG[startID] + nodeH[startID];

	openBS.Set(startID);
	closeBS.Set( startID );

	// --------------- FIND BEST PATH ------------------
	while (!openBS.IsAllClear()) 
	{
		int smallestID = CAI_Network::FindBSSmallest(&openBS,nodeF,nNodes);
	
		openBS.Clear(smallestID);

		CAI_Node *pSmallestNode = pAInode[smallestID];
		
		if (GetOuter()->IsUnusableNode(smallestID, pSmallestNode->m_pHint))
			continue;

		if (smallestID == endID) 
		{
			AI_Waypoint_t* route = MakeRouteFromParents(&nodeP[0], endID);
			return route;
		}

		// Check this if the node is immediately in the path after the startNode 
		// that it isn't blocked
		for (int link=0; link < pSmallestNode->NumLinks();link++) 
		{
			CAI_Link *nodeLink = pSmallestNode->GetLinkByIndex(link);
			
			if (!IsLinkUsable(nodeLink,smallestID))
				continue;

			// FIXME: the cost function should take into account Node costs (danger, flanking, etc).
			int moveType = nodeLink->m_iAcceptedMoveTypes[GetHullType()] & CapabilitiesGet();
			int testID	 = nodeLink->DestNodeID(smallestID);

			Vector r1 = pSmallestNode->GetPosition(GetHullType());
			Vector r2 = pAInode[testID]->GetPosition(GetHullType());
			float dist   = GetOuter()->GetNavigator()->MovementCost( moveType, r1, r2 ); // MovementCost takes ref parameters!!

			if ( dist == FLT_MAX )
				continue;

			float new_g  = nodeG[smallestID] + dist;

			if ( !closeBS.IsBitSet(testID) || (new_g < nodeG[testID]) ) 
			{
				nodeP[testID] = smallestID;
				nodeG[testID] = new_g;
				nodeH[testID] = (pAInode[testID]->GetPosition(GetHullType())-pAInode[endID]->GetPosition(GetHullType())).Length();
				nodeF[testID] = nodeG[testID] + nodeH[testID];

				closeBS.Set( testID );
				openBS.Set( testID );
			}
		}
	}

	return NULL;   
}