#include "utils.h"
#include <QDebug>

namespace UKUI {

QString fromQListIntToString(const QList<int> sequence)
{
    QString itemSequence;
    if(!sequence.isEmpty()) {
        itemSequence = QString::number(sequence.first());
        for(int i = 1; i < sequence.size(); i++) {
            itemSequence += QString(",") += QString::number(sequence.at(i));
        }
    }
    return itemSequence;
}

QString fromQListUIntToString(const QList<quint32> sequence)
{
    QString itemSequence;
    if(!sequence.isEmpty()) {
        itemSequence = QString::number(sequence.first());
        for(int i = 1; i < sequence.size(); i++) {
            itemSequence += QString(",") += QString::number(sequence.at(i));
        }
    }
    return itemSequence;
}

QPair<int,int> fromStringToInt(const QString layoutString)
{
    QList<int> list;
    QPair<int,int> pair;
    QRegExp rx("\\d+");
    int index = 0;
    while ((index = rx.indexIn(layoutString, index)) != -1) {
        index += rx.matchedLength();
        list.push_back(rx.cap(0).toInt());
    }
    if (list.count() != 2) {
        qWarning() << "row or column is incorrect!!!" << __func__;
        return pair;
    }
    pair.first = list[0];
    pair.second = list[1];
    return pair;
}

}


