bool GlobalSearchSortModel::lessThan(const QModelIndex& left,
                                     const QModelIndex& right) const {
  // Compare the provider sort index first.
  const int index_left =
      left.data(GlobalSearchModel::Role_ProviderIndex).toInt();
  const int index_right =
      right.data(GlobalSearchModel::Role_ProviderIndex).toInt();
  if (index_left < index_right) return true;
  if (index_left > index_right) return false;

  // Dividers always go first
  if (left.data(LibraryModel::Role_IsDivider).toBool()) return true;
  if (right.data(LibraryModel::Role_IsDivider).toBool()) return false;

  // Containers go before songs if they're at the same level
  const bool left_is_container =
      left.data(LibraryModel::Role_ContainerType).isValid();
  const bool right_is_container =
      right.data(LibraryModel::Role_ContainerType).isValid();
  if (left_is_container && !right_is_container) return true;
  if (right_is_container && !left_is_container) return false;

  // Containers get sorted on their sort text.
  if (left_is_container) {
    return QString::localeAwareCompare(
               left.data(LibraryModel::Role_SortText).toString(),
               right.data(LibraryModel::Role_SortText).toString()) < 0;
  }

  // Otherwise we're comparing songs.  Sort by disc, track, then title.
  const SearchProvider::Result r1 =
      left.data(GlobalSearchModel::Role_Result).value<SearchProvider::Result>();
  const SearchProvider::Result r2 = right.data(GlobalSearchModel::Role_Result)
                                        .value<SearchProvider::Result>();

#define CompareInt(field)                                       \
  if (r1.metadata_.field() < r2.metadata_.field()) return true; \
  if (r1.metadata_.field() > r2.metadata_.field()) return false

  int ret = 0;

#define CompareString(field)                                                   \
  ret =                                                                        \
      QString::localeAwareCompare(r1.metadata_.field(), r2.metadata_.field()); \
  if (ret < 0) return true;                                                    \
  if (ret > 0) return false

  CompareInt(disc);
  CompareInt(track);
  CompareString(title);

  return false;

#undef CompareInt
#undef CompareString
}
// -----------------------------------------------------------------------------
// CSensorDataCompensatorItem::TItemType::Compare
// -----------------------------------------------------------------------------
//
TInt CSensorDataCompensatorItem::TItemType::Compare(
        const CSensorDataCompensatorItem::TItemType& aType1,
        const CSensorDataCompensatorItem::TItemType& aType2 )
    {
    TInt ret( CompareInt( aType1.iType, aType2.iType ) );
    if ( !ret )
        {
        ret = CompareInt( aType1.iNumber, aType2.iNumber ); 
        }
    return ret;
    }
bool GlobalSearchSortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const {
  const SearchProvider::Result r1 = left.data(GlobalSearchWidget::Role_PrimaryResult)
      .value<SearchProvider::Result>();
  const SearchProvider::Result r2 = right.data(GlobalSearchWidget::Role_PrimaryResult)
      .value<SearchProvider::Result>();

  // Order results that arrived first first, so that the results don't jump
  // around while the user is trying to navigate through them.
  const int order_left  = left.data(GlobalSearchWidget::Role_OrderArrived).toInt();
  const int order_right = right.data(GlobalSearchWidget::Role_OrderArrived).toInt();

  if (order_left < order_right) return true;
  if (order_left > order_right) return false;

#define CompareInt(field) \
  if (r1.field < r2.field) return true; \
  if (r1.field > r2.field) return false

  int ret = 0;

#define CompareString(field) \
  ret = QString::localeAwareCompare(r1.metadata_.field(), r2.metadata_.field()); \
  if (ret < 0) return true; \
  if (ret > 0) return false

  // If they arrived at the same time then sort by quality and type.
  CompareInt(match_quality_);
  CompareInt(type_);

  // Failing that, compare title, artist and album
  switch (r1.type_) {
  case globalsearch::Type_Track:
  case globalsearch::Type_Stream:
    CompareString(title);
    // fallthrough
  case globalsearch::Type_Album:
    CompareString(artist);
    CompareString(album);
    break;
  }

  return false;

#undef CompareInt
#undef CompareString
}
//-------------------------------------------------------------------
// Sort::CompareForMerge
//
// Input   : Two tuples containint <record pointer, array index>
// Output  : None
// Return  : The comparison result
//-------------------------------------------------------------------
bool Sort::CompareForMerge(std::tuple<char *,int>& t1, std::tuple<char *,int>& t2) { 
	switch (_sortType) {
		case attrInteger:
			return CompareInt(std::get<0>(t1),std::get<0>(t2))<0;
			break;
		case attrString:
			return CompareString(std::get<0>(t1),std::get<0>(t2))<0;
		default:
			break;
	}
}
Exemple #5
0
int
VerifyState(const Options &opts, const ReadUserLog::FileState &state )
{
    ReadUserLogState	rstate( state, 60 );
    const ReadUserLogState::FileState	*istate;
    ReadUserLogState::convertState( state, istate );

    const FieldData	*wdata = opts.getField( );
    if ( wdata == NULL ) {
        fprintf( stderr, "Verify: no field!\n" );
        return -1;
    }

    bool	ok;
    switch( wdata->m_field )
    {
    case FIELD_SIGNATURE:
        ok = CompareStr( opts, istate->m_signature );
        break;

    case FIELD_VERSION:
        ok = CompareInt( opts, istate->m_version );
        break;

    case FIELD_UPDATE_TIME:
        ok = CompareTime( opts, istate->m_update_time );
        break;

    case FIELD_BASE_PATH:
        ok = CompareStr( opts, istate->m_base_path );
        break;

    case FIELD_CUR_PATH:
        ok = CompareStr( opts, rstate.CurPath(state) );
        break;

    case FIELD_UNIQ_ID:
        ok = CompareStr( opts, istate->m_uniq_id );
        break;

    case FIELD_SEQUENCE:
        ok = CompareInt( opts, istate->m_sequence );
        break;

    case FIELD_MAX_ROTATION:
        ok = CompareInt( opts, istate->m_max_rotations );
        break;

    case FIELD_ROTATION:
        ok = CompareInt( opts, istate->m_rotation );
        break;

    case FIELD_OFFSET:
        ok = CompareFsize( opts, istate->m_offset.asint );
        break;

    case FIELD_EVENT_NUM:
        ok = CompareFsize( opts, istate->m_event_num.asint );
        break;

    case FIELD_GLOBAL_POSITION:
        ok = CompareFsize( opts, istate->m_log_position.asint );
        break;

    case FIELD_GLOBAL_RECORD_NUM:
        ok = CompareFsize( opts, istate->m_log_record.asint );
        break;

    case FIELD_INODE:
        ok = CompareInode( opts, istate->m_inode );
        break;

    case FIELD_CTIME:
        ok = CompareTime( opts, istate->m_ctime );
        break;

    case FIELD_SIZE:
        ok = CompareFsize( opts, istate->m_size.asint );
        break;

    default:
        return -1;
    }
    return ok ? 0 : 1;
}