示例#1
0
bool MyFileSystemModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	if (role == Qt::CheckStateRole)
	{
		if (value == Qt::Checked)
		{
			checkedIndexes.insert(index);
			if (hasChildren(index) == true)
			{
				recursiveCheck(index, value);
			}
		}
		else
		{
			checkedIndexes.remove(index);
			if (hasChildren(index) == true)
			{
				recursiveCheck(index, value);
			}
		}
		emit dataChanged(index, index);
		return true;
	}
	return QFileSystemModel::setData(index, value, role);
}
示例#2
0
int recursiveCheck(Graph G, Vertex actual, int *side, int *flag){
  int i;

  flag[actual] = 1;

  if(side[actual] == STANDING){
    for(i = 1; i < G->V; i++){
      if(G->adj[actual][i]){
        if(side[i] != STANDING){
          side[actual] = (side[i] % 2) + 1;
          i = G->V;
        }
      }
    }

    if(side[actual] == STANDING){
      side[actual] = LEFT;
    }
  }

  for(i = 1; i < G->V; i++){
    if(G->adj[actual][i]){
      if(side[i] == side[actual]){
        return 0;
      }else if(side[i] == STANDING){
        side[i] = (side[actual] % 2) + 1;
        return recursiveCheck(G, i, side, flag);
      }
    }
  }

  return 1;
}
示例#3
0
int processInstance(Graph G){
  int *flag, *side, i, j;

  side = malloc((G->V)*sizeof(int));
  flag = malloc((G->V)*sizeof(int));
  for(i = 0; i < G->V; i++){
    side[i] = STANDING;
  }

  for(i = 1; i < G->V; i++){
    if(!recursiveCheck(G, i, side, flag)){
      free(side);
      free(flag);
      return 0;
    }
    for(j = 1; j < G->V; j++){
      if(!flag[j]){
        i = j - 1;
        j = G->V;
      }
    }
  }

  free(side);
  free(flag);
  return 1;

}
示例#4
0
bool TraverserExpression::recursiveCheck(arangodb::aql::AstNode const* node,
                                         arangodb::velocypack::Slice& element,
                                         arangodb::velocypack::Slice& base) const {

  base = arangodb::basics::VelocyPackHelper::EmptyObjectValue();

  switch (node->type) {
    case arangodb::aql::NODE_TYPE_REFERENCE:
      // We are on the variable access
      return true;
    case arangodb::aql::NODE_TYPE_ATTRIBUTE_ACCESS: {
      std::string name(node->getString());
      if (!recursiveCheck(node->getMember(0), element, base)) {
        return false;
      }
      if (!element.isObject() || !element.hasKey(name)) {
        return false;
      }
      base = element; // set base object
      element = element.get(name);
      break;
    }
    case arangodb::aql::NODE_TYPE_INDEXED_ACCESS: {
      auto index = node->getMember(1);
      if (!index->isIntValue()) {
        return false;
      }
      if (!recursiveCheck(node->getMember(0), element, base)) {
        return false;
      }
      auto idx = index->getIntValue();
      if (!element.isArray()) {
        return false;
      }
      element = element.at(idx);
      break;
    }
    default:
      return false;
  }
  return true;
}
    //___________________________________________________________________
    bool LineEditData::initializeAnimation( void )
    {
        if( !( enabled() && _target && _target.data()->isVisible() ) ) return false;

        if( recursiveCheck() ) return false;

        QRect current( targetRect() );

        transition().data()->setOpacity(0);
        transition().data()->setGeometry( current );

        if( _widgetRect.isValid() &&
            !transition().data()->currentPixmap().isNull() &&
            _widgetRect != current )
        {

          // if label geometry has changed since last animation
          // one must clone the pixmap to make it match the right
          // geometry before starting the animation.
          QPixmap pixmap( current.size() );
          pixmap.fill( Qt::transparent );
          QPainter p( &pixmap );
          p.drawPixmap( _widgetRect.topLeft() - current.topLeft(), transition().data()->currentPixmap() );
          p.end();
          transition().data()->setStartPixmap( pixmap );

        } else {

            transition().data()->setStartPixmap( transition().data()->currentPixmap() );

        }

        bool valid( !transition().data()->startPixmap().isNull() );
        if( valid )
        {
            transition().data()->show();
            transition().data()->raise();
        }

        setRecursiveCheck( true );
        transition().data()->setEndPixmap( transition().data()->grab( _target.data(), targetRect() ) );
        setRecursiveCheck( false );

        return valid;

    }
示例#6
0
/** Pick Move
 *  Selects the best move for the AI given the current difficulty
 *
 *  @args 
 */
move_t pickMove ( board_t board[3][3], uint32_t difficulty, uint32_t current_depth )
{
	// We need the current progress of the board before doing anythin
	//status_t progress = boardStatus( board );
	move_t m;
	m.x = -1;
	m.y = -1;
	int i, j;
	for ( i = 0; i < 3; ++i ) {
		for ( j = 0; j < 3; ++j ) {
			// Do stuff at each location
			if ( EMPTY != board[i][j] )
				continue;
			board[i][j] = AI;
			status_t results = recursiveCheck( board, USER );
			if ( WIN == results ) {
				board[i][j] = EMPTY;
				m.x = i;
				m.y = j;
				printf("picking a winner\n");
				return m;
			}
			else if ( ONGOING == results ) {
				m.x = i;
				m.y = j;
			}
			else if ( LOSS == results ) {
				printf("%d\t%d\n",i,j);
			}
			board[i][j] = EMPTY;
		}
	}
	if ( -1 == m.x ) {
		// Losses everywhere, pick at random
		int g = rand() % 9;
		while ( EMPTY != board[g/3][g%3] )
			g = rand() % 9;
		m.x = g/3;
		m.y = g%3;
		printf("Random Guessing!\n");
		return m;
	}
	printf("Meh!\n");
	return m;
}
示例#7
0
status_t recursiveCheck ( board_t board[3][3] , board_t current_user )
{
	int i, j;
	status_t result;
	int wins=0, count=0, losses=0;
	board_t next_user = (current_user == AI) ? USER : AI;
	assert( next_user != current_user );

	if ( ONGOING != boardStatus(board) )
		return boardStatus(board);

	for ( i = 0; i < 3; ++i ) {
		for ( j = 0; j < 3; ++j ) {
			// Do stuff at each location
			if ( EMPTY != board[i][j] )
				continue;
			board[i][j] = current_user;
			//result = tmp( board, ...);
			result = recursiveCheck( board, next_user );
			if ( WIN == result )
				++wins;
			else if ( LOSS == result )
				++losses;
			board[i][j] = EMPTY;
			++count;
		}
	}
	assert( 0 != count );

	if ( USER == current_user ) {
		if ( 0 != losses )
			return LOSS;
		if ( wins == count )
			return WIN;
		return ONGOING;
	}

	if ( 0 != wins )
		return WIN;
	if ( count == losses )
		return LOSS;
	return ONGOING;
}
bool PointsFileSystem::setData(const QModelIndex &index, const QVariant &value, int role)
{
    bool is_point_cloud = (filePath(index).right(3) == "pcd");
    if(role == Qt::CheckStateRole)
    {
        if (is_point_cloud)
        {
            if(value == Qt::Checked)
                showPointCloud(index);
            else
                hidePointCloud(index);
        }

        if(hasChildren(index) == true)
            recursiveCheck(index, value);

        emit dataChanged(index, index);

        return true;
    }

    return FileSystemModel::setData(index, value, role);
}
示例#9
0
bool TraverserExpression::matchesCheck(arangodb::Transaction* trx,
                                       VPackSlice const& element) const {
  TRI_ASSERT(trx != nullptr);
  VPackSlice base = arangodb::basics::VelocyPackHelper::EmptyObjectValue();

  VPackSlice value = element.resolveExternal(); 
  
  // initialize compare value to Null
  VPackSlice result = arangodb::basics::VelocyPackHelper::NullValue();
  // perform recursive check. this may modify value
  if (recursiveCheck(varAccess, value, base)) {
    result = value;
  }

  // hack for _id attribute
  TransactionBuilderLeaser builder(trx);
  if (result.isCustom() && base.isObject()) {
    builder->add(VPackValue(trx->extractIdString(base)));
    result = builder->slice();
  }

  TRI_ASSERT(compareTo != nullptr);
  VPackOptions* options = trx->transactionContext()->getVPackOptions();

  switch (comparisonType) {
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_EQ:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), false, options) == 0; 
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_NE:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), false, options) != 0; 
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LT:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), true, options) < 0; 
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_LE:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), true, options) <= 0; 
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GE:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), true, options) >= 0; 
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_GT:
      return arangodb::basics::VelocyPackHelper::compare(result, compareTo->slice(), true, options) > 0;
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_IN: {
      // In means any of the elements in compareTo is identical
      VPackSlice compareArray = compareTo->slice();
      for (auto const& cmp : VPackArrayIterator(compareArray)) {
        if (arangodb::basics::VelocyPackHelper::compare(result, cmp, false, options) == 0) {
          // One is identical
          return true;
        }
      }
      // If we get here non is identical
      return false;
    }
    case arangodb::aql::NODE_TYPE_OPERATOR_BINARY_NIN: {
      // NIN means none of the elements in compareTo is identical
      VPackSlice compareArray = compareTo->slice();
      for (auto const& cmp : VPackArrayIterator(compareArray)) {
        if (arangodb::basics::VelocyPackHelper::compare(result, cmp, false, options) == 0) {
          // One is identical
          return false;
        }
      }
      // If we get here non is identical
      return true;
    }
    default:
      TRI_ASSERT(false);
  }
  return false;
}
 //___________________________________________________________________
 void LineEditData::selectionChanged( void )
 {
     if( !recursiveCheck() )
     { _timer.start( 0, this ); }
 }