bool HistoryChatsModelProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
	// chats?
	Chat *leftChat = left.data(ChatRole).value<Chat *>();
	Chat *rightChat = right.data(ChatRole).value<Chat *>();

	if (leftChat && rightChat)
		return compareNames(leftChat->name(), rightChat->name()) < 0;

	ChatType leftType = left.data(ChatTypeRole).value<ChatType>();
	ChatType rightType = right.data(ChatTypeRole).value<ChatType>();

	return compareNames(leftType.displayName(), rightType.displayName()) < 0;
}
示例#2
0
bool ContactsModelProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
	if (!SourceContactModel)
		return QSortFilterProxyModel::lessThan(left, right);

	Contact leftContact = SourceContactModel->contact(left);
	Contact rightContact = SourceContactModel->contact(right);

	Account *leftAccount = leftContact.prefferedAccount();
	Account *rightAccount = rightContact.prefferedAccount();

	ContactAccountData *leftContactAccountData = leftContact.accountData(leftAccount);
	ContactAccountData *rightContactAccountData = rightContact.accountData(rightAccount);

	Status leftStatus = leftContactAccountData
		? leftContactAccountData->status()
		: Status();
	Status rightStatus = rightContactAccountData
		? rightContactAccountData->status()
		: Status();

	if (leftStatus.isDisconnected() && !rightStatus.isDisconnected())
		return false;

	if (!leftStatus.isDisconnected() && rightStatus.isDisconnected())
		return true;

	int displayCompare = compareNames(leftContact.display(), rightContact.display());
	return displayCompare < 0;
}
int compare(const void* fe, const void* se)
{
  const ClazzInfo** fci = (const ClazzInfo**)fe;
  const ClazzInfo** sci = (const ClazzInfo**)se;
  return compareNames(*fci, *sci);

}
bool NetworkProxyProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
	NetworkProxy leftNetworkProxy = left.data(NetworkProxyRole).value<NetworkProxy>();
	NetworkProxy rightNetworkProxy = right.data(NetworkProxyRole).value<NetworkProxy>();

	if (leftNetworkProxy.isNull())
		return false;
	if (rightNetworkProxy.isNull())
		return true;

	int displayCompare = compareNames(leftNetworkProxy.address(), rightNetworkProxy.address());
	return displayCompare < 0;
}
示例#5
0
bool PlaylistsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
    PlaylistsModel::Item *l=static_cast<PlaylistsModel::Item *>(left.internalPointer());
    PlaylistsModel::Item *r=static_cast<PlaylistsModel::Item *>(right.internalPointer());

    if (l->isPlaylist() && r->isPlaylist()) {
        return compareNames(static_cast<PlaylistsModel::PlaylistItem *>(l)->name, static_cast<PlaylistsModel::PlaylistItem *>(r)->name);
    } else if(!l->isPlaylist() && !r->isPlaylist()) {
        return left.row()<right.row();
    }

    return false;
}
示例#6
0
bool ProtocolsModelProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
    if (!sourceModel())
        return QSortFilterProxyModel::lessThan(left, right);

    QVariant lVariant = sourceModel()->data(left, ProtocolRole);
    QVariant rVariant = sourceModel()->data(right, ProtocolRole);

    if (!lVariant.canConvert<ProtocolFactory *>() || !rVariant.canConvert<ProtocolFactory *>())
        return QSortFilterProxyModel::lessThan(left, right);

    ProtocolFactory *leftProtocol = lVariant.value<ProtocolFactory *>();
    ProtocolFactory *rightProtocol = rVariant.value<ProtocolFactory *>();

    int displayCompare = compareNames(leftProtocol->name(), rightProtocol->name());
    return displayCompare < 0;
}
示例#7
0
/* sort functions lexically between indices "start" and "ends" */
static void sortByName(FileInfo *data, int functionList[], int start, int ends)
{
  int i, location = start;
  if (ends <= start)
    {
    return;
    }
  for (i = start; i < ends; i++)
    {
    if (compareNames(data, functionList[ends], functionList[i]) > 0)
      {
      swapArrayItems(functionList, location, i);
      location++;
      }
    }
  swapArrayItems(functionList, location, ends);
  sortByName(data, functionList, start, location - 1);
  sortByName(data, functionList, location + 1, ends);
}
示例#8
0
double TagComparator::compareTags(const Tags &t1, const Tags &t2, bool strict)
{
  // compare and get a score for name comparison
  double nameScore, nameWeight;
  compareNames(t1, t2, nameScore, nameWeight, strict);
  //LOG_WARN("Name score: " << nameScore << "(" << nameWeight << ")");

  double textScore, textWeight;
  compareTextTags(t1, t2, textScore, textWeight);
  //LOG_WARN("Text score: " << textScore << " (" << textWeight << ")");

  // compare the enumerated tags
  double enumScore, enumWeight;
  compareEnumeratedTags(t1, t2, enumScore, enumWeight);
  //LOG_WARN("enumScore: " << enumScore << "(" << enumWeight << ")");

  // comparing numerical tags is difficult without some concept of the distribution. For that
  // reason I'm avoiding it for now.

  if (nameWeight + enumWeight <= 0)
  {
    return -1;
  }
  else
  {
//    if (enumWeight <= 0)
//    {
//      return nameScore;
//    }
//    else if (nameWeight <= 0)
//    {
//      return enumScore;
//    }
//    else
    {
      //LOG_DEBUG("tag score: " << nameScore * enumScore << " name: " << nameScore << " enum: " << enumScore);
      return nameScore * enumScore * textScore;
    }
    //return (nameScore * nameWeight + enumScore * enumWeight) / (nameWeight + enumWeight);
  }
}
bool Condition::compareNameLiteral(string name, string lit, string op) {
	// If comparing integers...
	if(isInteger(lit)) {
		int attrValue = stoi(name),
			litValue = stoi(lit);

		if(op.compare("==") == 0) {
			 return attrValue == litValue;
		} else if(op.compare("!=") == 0) {
			return attrValue != litValue;
		} else if(op.compare(">") == 0) {
			return attrValue > litValue;			
		} else if(op.compare("<") == 0) {
			return attrValue < litValue;
		} else if(op.compare(">=") == 0) {
			return attrValue >= litValue;
		} else if(op.compare("<=") == 0) {
			return attrValue <= litValue;
		}
	}
	
	// If comparing varchars...	
	else return compareNames(name, lit, op);
}