本文整理汇总了C++中QVector类的典型用法代码示例。如果您正苦于以下问题:C++ QVector类的具体用法?C++ QVector怎么用?C++ QVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizes
QString toListViewFormatterText::getFormattedString(toExportSettings &settings,
//const toResultModel *model);
const QAbstractItemModel * model)
{
int columns = model->columnCount();
int rows = model->rowCount();
QString output;
QVector<int> sizes(columns);
QVector<int> rlist = selectedRows(settings.selected);
QVector<int> clist = selectedColumns(settings.selected);
// must get widest length for each column
// zero array or (if writing headers, set their size)
for (int i = 0; i < columns - 1; i++)
{
if (settings.columnsHeader)
{
if (settings.columnsExport == toExportSettings::ColumnsSelected && !clist.contains(i))
continue;
sizes[i] = model->headerData(
i,
Qt::Horizontal,
Qt::DisplayRole).toString().length();
}
else
sizes[i] = 0;
}
sizes[columns - 1] = 1;
// loop through model and get column widths
QModelIndex mi;
for (int row = 0; row < rows; row++)
{
for (int column = 0; column < columns - 1; column++)
{
if (settings.columnsExport == toExportSettings::ColumnsSelected && !clist.contains(column))
continue;
if (!settings.rowsHeader && column == 0)
continue;
mi = model->index(row, column);
QVariant data = model->data(mi, Qt::EditRole);
QString v;
if (data.isNull())
v = "{null}";
else
v = data.toString();
int len = v.length();
if (len > sizes[column])
sizes[column] = len;
}
}
// write header data to fixed widths
if (settings.columnsHeader)
{
for (int column = 0; column < columns; column++)
{
if (settings.columnsExport == toExportSettings::ColumnsSelected && !clist.contains(column))
continue;
if (!settings.rowsHeader && column == 0)
continue;
QString value = model->headerData(
column,
Qt::Horizontal,
Qt::DisplayRole).toString();
output += value;
for (int left = value.length(); left <= sizes[column]; left++)
output += ' ';
}
endLine(output);
// write ==== border
for (int column = 0; column < columns; column++)
{
if (settings.columnsExport == toExportSettings::ColumnsSelected && !clist.contains(column))
continue;
if (!settings.rowsHeader && column == 0)
continue;
for (int left = 0; left < sizes[column]; left++)
output += '=';
output += ' ';
}
endLine(output);
}
// write data
for (int row = 0; row < rows; row++)
{
if (settings.rowsExport == toExportSettings::RowsSelected && !rlist.contains(row))
continue;
for (int column = 0; column < columns; column++)
{
//.........这里部分代码省略.........
示例2: names
static inline QVector<QString> names(QVector<Node> nodes) {
QVector<QString> names;
for (const Node &node : nodes)
names.append(node._name);
return names;
}
示例3: setHomeDir
/// TODO:名称和路径需要联系起来
// 不能使用QHash ,会出现string相同的情况,那用什么方法呢
// QMultiMap??
void QJDMainWindow::setHomeDir(QString homePath)
{
areaWidget->clear();
/// 第一层 -- 工区
QDir dir1;
// 这个需要能设置,程序需要有settings.ini
dir1.setPath(homePath);
QStringList dirLev1;
dirLev1<<dir1.entryList(QDir::NoDotAndDotDot|QDir::Dirs);
// qDebug()<<dir1.count(); // 包含./..
/// 第二层 -- 线, 目前要向里面加入data文件夹,data文件夹与flow并列并且继续有往下的选择,可以不用descname
QStringList areaStringList;
QStringList areaPathList;
QStringList lineStringList;
QStringList linePathList;
QVector<QStringList> flowStringList;
QVector<QStringList> flowPathList;
QVector<QVector<QStringList> > dataStringList;
QVector<QVector<QStringList> > dataPathList;
for(int i=0; i<dirLev1.count(); i++)
{
// 遍历
QDir dir2;
QString dir2path=dir1.path()+"/"+dirLev1.at(i);
dir2.setPath(dir2path);
QStringList dirLev2;
dirLev2=dir2.entryList(QDir::NoDotAndDotDot|QDir::Dirs);
// 解析 DescName -- 工区名称
QFile file2;
file2.setFileName(dir2path+"/DescName");
if(!file2.exists())
{
continue;
}
areaPathList<<dir2path;
file2.open(QFile::ReadOnly);
QTextStream stream2(&file2);
QString areatmp=stream2.readAll();
areatmp.chop(1);
areaStringList<<areatmp; // 路径就是dir2path
// qDebug()<<dir2path;
file2.close();
/// 第三层 -- 流程/Data, 同一层的data文件夹需要特殊处理
for(int j=0; j<dirLev2.count(); j++)
{
QDir dir3;
QString dir3path=dir2.path()+"/"+dirLev2.at(j);
dir3.setPath(dir3path);
QStringList dirLev3;
dirLev3=dir3.entryList(QDir::NoDotAndDotDot|QDir::Dirs); // 线名
// 解析 DescName -- 线名称
QFile file3;
file3.setFileName(dir3path+"/DescName");
if(!file3.exists())
{
continue;
}
linePathList<<dir3path;
file3.open(QFile::ReadOnly);
QTextStream stream3(&file3);
QString linetmp=stream3.readAll();
linetmp.chop(1);
lineStringList<<linetmp;
file3.close();
// qDebug()<<"line::"<<lineStringList;
/// 第四层 -- 具体流程
flowStringList.resize(dirLev2.count());
flowPathList.resize(dirLev2.count());
dataStringList.resize(dirLev2.count());
dataPathList.resize(dirLev2.count());
for(int k=0; k<dirLev3.count(); k++)
{
// 应当没有文件夹了,只剩下文件了
QDir dir4;
QString dir4path=dir3.path()+"/"+dirLev3.at(k);
dir4.setPath(dir4path);
QStringList dirLev4;
dirLev4=dir4.entryList(QDir::NoDotAndDotDot|QDir::Files); // 文件名列表了
flowPathList[j]<<dir4path;
/// 底下应当有个记录流程xml文件
// 解析 DescName -- 线名称
QFile file4;
file4.setFileName(dir4path+"/DescName");
if(!file4.exists())
{
continue;
//.........这里部分代码省略.........
示例4: close
void SerialConnection::open() {
QString status_msg = "connected.";
QString theport = portname;
if (context != NULL) {
close();
}
if (theport.length() == 0) {
QVector<QString> ports = enumerate();
if (ports.size() > 0) {
theport = ports[0];
} else {
emit status("no serial port found");
return;
}
}
#ifdef _WIN32
HANDLE handle = CreateFile(theport.toStdWString().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DCB dcbSerialParams = {0};
if (handle == INVALID_HANDLE_VALUE) {
status_msg = QString("unable to open %1. check if device is already in use.").arg(theport);
} else if (!GetCommState(handle, &dcbSerialParams)) {
status_msg = QString("unable to get device attributes");
} else {
//Define serial connection parameters for the arduino board
dcbSerialParams.BaudRate=CBR_38400;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
//Set the parameters and check for their proper application
if(!SetCommState(handle, &dcbSerialParams))
status_msg = QString("unable to set device attributes");
else {
context = new HANDLE(handle);
}
}
#else
int fd = ::open(theport.toStdString().c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
struct termios toptions;
if (fd == -1) {
status_msg = QString("unable to open %1. check if device is already in use.").arg(theport);
} else if (ioctl(fd, TIOCEXCL) == -1) {
status_msg = QString("unable to get exclusive access");
} else if (fcntl(fd, F_SETFL, 0) == -1) {
status_msg = QString("unable to restore blocking access");
} else if (tcgetattr(fd, &toptions) < 0) {
status_msg = QString("unable to get device attributes");
} else {
cfsetispeed(&toptions, B38400);
cfsetospeed(&toptions, B38400);
// 8N1
toptions.c_cflag &= ~PARENB;
toptions.c_cflag &= ~CSTOPB;
toptions.c_cflag &= ~CSIZE;
toptions.c_cflag |= CS8;
// no flow control
toptions.c_cflag &= ~CRTSCTS;
//toptions.c_cflag &= ~HUPCL; // disable hang-up-on-close to avoid reset
toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines
toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
toptions.c_oflag &= ~OPOST; // make raw
// see: http://unixwiz.net/techtips/termios-vmin-vtime.html
toptions.c_cc[VMIN] = 0;
toptions.c_cc[VTIME] = 0;
tcsetattr(fd, TCSANOW, &toptions);
if (tcsetattr(fd, TCSAFLUSH, &toptions) < 0) {
status_msg = QString("unable to set device attributes");
} else {
tcflush(fd, TCIOFLUSH);
context = new int(fd);
}
}
#endif
emit status(status_msg);
}
示例5: parseTrace
void TraceLoader::parseTrace()
{
QList<ApiTraceFrame*> frames;
ApiTraceFrame *currentFrame = 0;
int frameCount = 0;
QStack<ApiTraceCall*> groups;
QVector<ApiTraceCall*> topLevelItems;
QVector<ApiTraceCall*> allCalls;
quint64 binaryDataSize = 0;
int lastPercentReport = 0;
trace::Call *call = m_parser.parse_call();
while (call) {
//std::cout << *call;
if (!currentFrame) {
currentFrame = new ApiTraceFrame();
currentFrame->number = frameCount;
++frameCount;
}
ApiTraceCall *apiCall =
apiCallFromTraceCall(call, m_helpHash, currentFrame, groups.isEmpty() ? 0 : groups.top(), this);
allCalls.append(apiCall);
if (groups.count() == 0) {
topLevelItems.append(apiCall);
}
if (call->flags & trace::CALL_FLAG_MARKER_PUSH) {
groups.push(apiCall);
} else if (call->flags & trace::CALL_FLAG_MARKER_POP) {
groups.top()->finishedAddingChildren();
groups.pop();
}
if (!groups.isEmpty()) {
groups.top()->addChild(apiCall);
}
if (apiCall->hasBinaryData()) {
QByteArray data =
apiCall->arguments()[apiCall->binaryDataIndex()].toByteArray();
binaryDataSize += data.size();
}
if (call->flags & trace::CALL_FLAG_END_FRAME) {
allCalls.squeeze();
topLevelItems.squeeze();
if (topLevelItems.count() == allCalls.count()) {
currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
} else {
currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
}
allCalls.clear();
groups.clear();
topLevelItems.clear();
frames.append(currentFrame);
currentFrame = 0;
binaryDataSize = 0;
if (frames.count() >= FRAMES_TO_CACHE) {
emit framesLoaded(frames);
frames.clear();
}
if (m_parser.percentRead() - lastPercentReport >= 5) {
emit parsed(m_parser.percentRead());
lastPercentReport = m_parser.percentRead();
}
}
delete call;
call = m_parser.parse_call();
}
//last frames won't have markers
// it's just a bunch of Delete calls for every object
// after the last SwapBuffers
if (currentFrame) {
allCalls.squeeze();
if (topLevelItems.count() == allCalls.count()) {
currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
} else {
currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
}
frames.append(currentFrame);
currentFrame = 0;
}
if (frames.count()) {
emit framesLoaded(frames);
}
}
示例6: Q_ASSERT
bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInfo &fi) const
{
Q_ASSERT(!fileName.isEmpty());
// filter . and ..?
const int fileNameSize = fileName.size();
const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
&& ((fileNameSize == 1)
||(fileNameSize == 2 && fileName[1] == QLatin1Char('.')));
if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
return false;
if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
return false;
if ((filters & QDir::NoDotAndDotDot) && dotOrDotDot) // ### Qt5 remove (NoDotAndDotDot == NoDot|NoDotDot)
return false;
// name filter
#ifndef QT_NO_REGEXP
// Pass all entries through name filters, except dirs if the AllDirs
if (!nameFilters.isEmpty() && !((filters & QDir::AllDirs) && fi.isDir())) {
bool matched = false;
for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(),
end = nameRegExps.constEnd();
iter != end; ++iter) {
if (iter->exactMatch(fileName)) {
matched = true;
break;
}
}
if (!matched)
return false;
}
#endif
// skip symlinks
const bool skipSymlinks = (filters & QDir::NoSymLinks);
const bool includeSystem = (filters & QDir::System);
if(skipSymlinks && fi.isSymLink()) {
// The only reason to save this file is if it is a broken link and we are requesting system files.
if(!includeSystem || fi.exists())
return false;
}
// filter hidden
const bool includeHidden = (filters & QDir::Hidden);
if (!includeHidden && !dotOrDotDot && fi.isHidden())
return false;
// filter system files
if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink())
|| (!fi.exists() && fi.isSymLink())))
return false;
// skip directories
const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
if (skipDirs && fi.isDir())
return false;
// skip files
const bool skipFiles = !(filters & QDir::Files);
if (skipFiles && fi.isFile())
// Basically we need a reason not to exclude this file otherwise we just eliminate it.
return false;
// filter permissions
const bool filterPermissions = ((filters & QDir::PermissionMask)
&& (filters & QDir::PermissionMask) != QDir::PermissionMask);
const bool doWritable = !filterPermissions || (filters & QDir::Writable);
const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
const bool doReadable = !filterPermissions || (filters & QDir::Readable);
if (filterPermissions
&& ((doReadable && !fi.isReadable())
|| (doWritable && !fi.isWritable())
|| (doExecutable && !fi.isExecutable()))) {
return false;
}
return true;
}
示例7: countFN
void OptimizationPasses::Coordinator::init()
{
static bool isInitialized = false; // STATIC DATA
if(isInitialized)
return;
isInitialized = true;
/* Note, below is many of the building blocks re-used in several passes
* in order to reduce memory use. Thus, when changing one building block
* it potentially affects many passes. */
/* ****************************************************** */
/* Rewrite "count(<expr>) ge 1" into "exists(<expr>)" */
OptimizationPass::ExpressionMarker firstFirstChild;
firstFirstChild.append(0);
firstFirstChild.append(0);
ExpressionIdentifier::List geOpIDs;
const ExpressionIdentifier::Ptr countFN(new ByIDIdentifier(Expression::IDCountFN));
geOpIDs.append(countFN);
geOpIDs.append(ExpressionIdentifier::Ptr(new IntegerIdentifier(1)));
QVector<Expression::ID> geMatcher;
geMatcher.append(Expression::IDValueComparison);
geMatcher.append(Expression::IDGeneralComparison);
const ExpressionIdentifier::Ptr ge(new ComparisonIdentifier(geMatcher,
AtomicComparator::OperatorGreaterOrEqual));
const ExpressionCreator::Ptr existsFN(new ByIDCreator(Expression::IDExistsFN));
const OptimizationPass::Ptr geToExists(new OptimizationPass(ge, geOpIDs, firstFirstChild, existsFN));
comparisonPasses.append(geToExists);
/* ****************************************************** */
/* ****************************************************** */
/* Rewrite "count(<expr>) gt 0" into "exists(<expr>)" */
ExpressionIdentifier::List countAndIntZero;
countAndIntZero.append(countFN);
const ExpressionIdentifier::Ptr zeroInteger(new IntegerIdentifier(0));
countAndIntZero.append(zeroInteger);
const ExpressionIdentifier::Ptr gt(new ComparisonIdentifier(geMatcher,
AtomicComparator::OperatorGreaterThan));
const OptimizationPass::Ptr gtToExists(new OptimizationPass(gt, countAndIntZero,
firstFirstChild, existsFN));
comparisonPasses.append(gtToExists);
/* ****************************************************** */
/* ****************************************************** */
/* Rewrite "count(<expr>) ne 0" into "exists(<expr>)" */
const ExpressionIdentifier::Ptr ne(new ComparisonIdentifier(geMatcher,
AtomicComparator::OperatorNotEqual));
const OptimizationPass::Ptr neToExists(new OptimizationPass(ne, countAndIntZero, firstFirstChild,
existsFN,
OptimizationPass::AnyOrder));
comparisonPasses.append(neToExists);
/* ****************************************************** */
/* ****************************************************** */
/* Rewrite "count(<expr>) eq 0" into "empty(<expr>)" */
ExpressionIdentifier::List eqOpIDs;
eqOpIDs.append(countFN);
eqOpIDs.append(zeroInteger);
const ExpressionCreator::Ptr emptyFN(new ByIDCreator(Expression::IDEmptyFN));
const ExpressionIdentifier::Ptr eq(new ComparisonIdentifier(geMatcher,
AtomicComparator::OperatorEqual));
const OptimizationPass::Ptr eqToEmpty(new OptimizationPass(eq, eqOpIDs, firstFirstChild,
emptyFN,
OptimizationPass::AnyOrder));
comparisonPasses.append(eqToEmpty);
/* ****************************************************** */
/* ****************************************************** */
/* Rewrite "for $var in <expr> return $var" into "<expr>" */
ExpressionIdentifier::List forOps;
OptimizationPass::ExpressionMarker firstChild;
firstChild.append(0);
forOps.append(ExpressionIdentifier::Ptr());
forOps.append(ExpressionIdentifier::Ptr(new ByIDIdentifier(Expression::IDRangeVariableReference)));
const OptimizationPass::Ptr simplifyFor(new OptimizationPass(ExpressionIdentifier::Ptr(), forOps,
firstChild, ExpressionCreator::Ptr()));
forPasses.append(simplifyFor);
/* ****************************************************** */
/* ****************************************************** */
/* Rewrite "if(<expr>) then true() else false()" to "<expr>" */
OptimizationPass::ExpressionMarker marker;
marker.append(0);
ExpressionIdentifier::List opIDs;
opIDs.append(ExpressionIdentifier::Ptr(new BySequenceTypeIdentifier(
CommonSequenceTypes::ExactlyOneBoolean)));
opIDs.append(ExpressionIdentifier::Ptr(new BooleanIdentifier(true)));
opIDs.append(ExpressionIdentifier::Ptr(new BooleanIdentifier(false)));
//.........这里部分代码省略.........
示例8: sizeof
QVector<ushort> CryptXOR::crypt(const QVector<ushort> input) {
QVector<ushort> output = input;
for (int i = 0; i < input.size(); i++)
output[i] ^= m_key[i % (sizeof(m_key) / sizeof(char)) ];
return output;
}
示例9: toString
QString CryptXOR::toString(QVector<ushort> vector){
QString result = "";
for (QVector<ushort>::iterator i = vector.begin();i != vector.end() ;++i)
result += uchar(*i);
return result;
}
示例10: spaced
void FuzzySearchImpl::query(const QString &req, QVector<Service::Item *> *res) const
{
QVector<QString> words;
for (QString &word : req.split(QRegExp("\\W+"), QString::SkipEmptyParts))
words.append(word.toLower());
QVector<QMap<Service::Item *, unsigned int>> resultsPerWord;
// Quit if there are no words in query
if (words.empty())
return;
// Split the query into words
for (QString &word : words)
{
unsigned int delta = word.size()/3;
// Get qGrams with counts of this word
QMap<QString, unsigned int> qGrams;
QString spaced(_q-1,' ');
spaced.append(word.toLower());
for (unsigned int i = 0 ; i < static_cast<unsigned int>(word.size()); ++i)
++qGrams[spaced.mid(i,_q)];
// Get the words referenced by each qGram an increment their
// reference counter
QMap<QString, unsigned int> wordMatches;
// Iterate over the set of qgrams in the word
for (QMap<QString, unsigned int>::const_iterator it = qGrams.cbegin(); it != qGrams.end(); ++it)
{
// Iterate over the set of words referenced by this qGram
for (QMap<QString, unsigned int>::const_iterator wit = _qGramIndex[it.key()].begin(); wit != _qGramIndex[it.key()].cend(); ++wit)
{
// CRUCIAL: The match can contain only the commom amount of qGrams
wordMatches[wit.key()] += (it.value() < wit.value()) ? it.value() : wit.value();
}
}
// Allocate a new set
resultsPerWord.push_back(QMap<Service::Item *, unsigned int>());
QMap<Service::Item *, unsigned int>& resultsRef = resultsPerWord.back();
// Unite the items referenced by the words accumulating their #matches
for (QMap<QString, unsigned int>::const_iterator wm = wordMatches.begin(); wm != wordMatches.cend(); ++wm)
{
// // Do some kind of (cheap) preselection by mathematical bound
// if (wm.value() < qGrams.size()-delta*_q)
// continue;
// Now check the (expensive) prefix edit distance
if (!checkPrefixEditDistance(word, wm.key(), delta))
continue;
for(Service::Item * item: _invertedIndex[wm.key()])
{
resultsRef[item] += wm.value();
}
}
}
// Intersect the set of items references by the (referenced) words
// This assusmes that there is at least one word (the query would not have
// been started elsewise)
QVector<QPair<Service::Item *, unsigned int>> finalResult;
if (resultsPerWord.size() > 1)
{
// Get the smallest list for intersection (performance)
unsigned int smallest=0;
for (unsigned int i = 1; i < static_cast<unsigned int>(resultsPerWord.size()); ++i)
if (resultsPerWord[i].size() < resultsPerWord[smallest].size())
smallest = i;
bool allResultsContainEntry;
for (QMap<Service::Item *, unsigned int>::const_iterator r = resultsPerWord[smallest].begin(); r != resultsPerWord[smallest].cend(); ++r)
{
// Check if all results contain this entry
allResultsContainEntry=true;
unsigned int accMatches = resultsPerWord[smallest][r.key()];
for (unsigned int i = 0; i < static_cast<unsigned int>(resultsPerWord.size()); ++i)
{
// Ignore itself
if (i==smallest)
continue;
// If it is in: check next relutlist
if (resultsPerWord[i].contains(r.key()))
{
// Accumulate matches
accMatches += resultsPerWord[i][r.key()];
continue;
}
allResultsContainEntry = false;
break;
}
// If this is not common, check the next entry
if (!allResultsContainEntry)
continue;
//.........这里部分代码省略.........
示例11: setupDemo
// plots heart-rate data
void MainWindow::setupDemo(QCustomPlot *customPlot)
{
// opens heart-rate data and checks if something selected
dataname = QFileDialog::getOpenFileName(this,"Open a Heart-Rate Data Text File","","*.txt");
if(dataname.isEmpty()){
QMessageBox::information(this, "File Status", "No heart-rate data was loaded.");
return;
}
// parses heart-rate data text file and plots it into ui->customPlot (for heart rate)
QVector<QString> v;
QFile textFile(dataname);
QFile d(dataname);
QFileInfo dInfo(d.fileName());
QString dataname_display(dInfo.fileName());
if(textFile.open(QIODevice::ReadOnly))
{
QString all;
QTextStream textStream(&textFile);
while (!textStream.atEnd()) {
textStream >> all;
if(textStream.status() == QTextStream::Ok){
v.append(all);
}
else
break;
}
if (heart_rate_plots_count == 0){
a.resize(v.size()-1), b.resize(v.size()-1);
}
if (heart_rate_plots_count == 1){
a2.resize(v.size()-1), b2.resize(v.size()-1);
}
if (heart_rate_plots_count == 2){
a3.resize(v.size()-1), b3.resize(v.size()-1);
}
if (heart_rate_plots_count == 3){
a4.resize(v.size()-1), b4.resize(v.size()-1);
}
if (heart_rate_plots_count == 4){
a5.resize(v.size()-1), b5.resize(v.size()-1);
}
if (heart_rate_plots_count == 5){
a6.resize(v.size()-1), b6.resize(v.size()-1);
}
if (heart_rate_plots_count == 6){
a7.resize(v.size()-1), b7.resize(v.size()-1);
}
if (heart_rate_plots_count == 7){
a8.resize(v.size()-1), b8.resize(v.size()-1);
}
if (heart_rate_plots_count == 8){
a9.resize(v.size()-1), b9.resize(v.size()-1);
}
if (heart_rate_plots_count == 9){
a10.resize(v.size()-1), b10.resize(v.size()-1);
}
for(int i=1; i<v.size(); ++i)
{
string v_i_as_string = v[i].toUtf8().constData();
int comma_pos = v_i_as_string.find(",");
double x_double = stod(v_i_as_string.substr(0,comma_pos));
double y_double = stod(v_i_as_string.substr(comma_pos+1,v_i_as_string.length()));
if (heart_rate_plots_count == 0){
a[i-1] = x_double;
b[i-1] = y_double;
}
if (heart_rate_plots_count == 1){
a2[i-1] = x_double;
b2[i-1] = y_double;
}
if (heart_rate_plots_count == 2){
a3[i-1] = x_double;
b3[i-1] = y_double;
}
if (heart_rate_plots_count == 3){
a4[i-1] = x_double;
b4[i-1] = y_double;
}
if (heart_rate_plots_count == 4){
a5[i-1] = x_double;
b5[i-1] = y_double;
}
if (heart_rate_plots_count == 5){
a6[i-1] = x_double;
b6[i-1] = y_double;
}
if (heart_rate_plots_count == 6){
a7[i-1] = x_double;
b7[i-1] = y_double;
}
if (heart_rate_plots_count == 7){
a8[i-1] = x_double;
b8[i-1] = y_double;
}
if (heart_rate_plots_count == 8){
a9[i-1] = x_double;
//.........这里部分代码省略.........
示例12: numberRegExp
void BikerHttpRequestProcessor::processRequest()
{
std::cerr << "processing request..." << std::endl;
QRegExp numberRegExp("(\\d+(?:.\\d+)?)");
//Es wird nur GET unterstützt, der Rest nicht. Bei was anderem: Grantig sein und 405 antworten.
if (_requestType != "GET")
{
this->send405();
return;
}
if (_requestPath.contains(".."))
{
//".." im Pfad ist ein falscher Request. Damit könnte man ins Dateisystem gelangen.
std::cerr << "\"..\" in request: not allowed." << std::endl;
this->send400();
}
std::cerr << "request file: " << _requestPath << std::endl;
if (_requestPath.startsWith("/files/"))
{
if (! ProgramOptions::getInstance()->webserver_no_serve_files)
{
//"/files/" entfernen!
QString _myRequestPath = _requestPath.remove(0, 7);
QDir mainDir((ProgramOptions::getInstance()->webserver_public_html_folder).c_str());
if ((ProgramOptions::getInstance()->webserver_public_html_folder == "") || !mainDir.exists())
{
this->send404();
return;
}
QFile file(QString(ProgramOptions::getInstance()->webserver_public_html_folder.c_str()) + "/" + _myRequestPath);
QDir dir(QString(ProgramOptions::getInstance()->webserver_public_html_folder.c_str()) + "/" + _myRequestPath);
//Wenn die Datei existiert, und alle sie lesen dürfen (nicht nur
// Benutzer oder Gruppe): Datei senden. Sonst: 404 Not found.
if ((!dir.exists()) && file.exists() && (file.permissions() & QFile::ReadOther))
{
std::cerr << "serving file: \"" << file.fileName() << "\"" << std::endl;
this->sendFile(file);
}
else
{
if (dir.exists())
std::cerr << "file is a directory: \"" << file.fileName() << "\". Not serving." << std::endl;
else if (!file.exists())
std::cerr << "file not found: \"" << file.fileName() << "\". Not serving." << std::endl;
else if (file.permissions() & QFile::ReadOther)
std::cerr << "file does not have read permissions for everybody: \"" << file.fileName() << "\". Not serving." << std::endl;
//In jedem Fall: 404 senden.
this->send404();
}
return;
}
else
{ //Dateien ausliefern durch Einstellungen verboten: Nicht ausliefern.
std::cerr << "webserver configured not to serve files." << std::endl;
this->send404();
return;
}
}
else
{
/**
* @todo RegExp nur einmal erzeugen und dann wiederverwenden!
*/
QRegExp cloudmadeApiKeyRegExp("^/([\\da-fA-F]{1,64})/(?:api|API)/0.(\\d)");
//QRegExp cloudmadeApiPointListRegExp("^/(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16})),(?:\\[(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))(?:,(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))){0,20}\\],)?(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))");
QRegExp cloudmadeApiPointListRegExp("^/(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16})),(?:\\[(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))(?:,(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16})){0,200}\\],)?(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))");
QRegExp cloudmadeApiPointListExtractor("(?:(\\d{1,3}.\\d{1,16}),(\\d{1,3}.\\d{1,16}))");
QRegExp cloudmadeApiRouteTypeRegExp("^/([a-zA-Z0-9]{1,64})(?:/([a-zA-Z0-9]{1,64}))?.(gpx|GPX|js|JS)$");
QString apiKey="";
int apiVersion=0;
QVector<GPSPosition> routePointList;
QString routeType="";
QString routeModifier="";
QString routeDataType="";
int position=0;
if ((position=cloudmadeApiKeyRegExp.indexIn(_requestPath)) != -1)
{
apiKey = cloudmadeApiKeyRegExp.cap(1).toLower();
apiVersion = cloudmadeApiKeyRegExp.cap(2).toInt();
//API-Key gefunden. Falls uns der interessiert, hier was damit machen!
if (ProgramOptions::getInstance()->webserver_apikey != "")
{
if (ProgramOptions::getInstance()->webserver_apikey != apiKey.toStdString())
{
std::cerr << "api key \"" << apiKey << "\" is not valid." << std::endl;
this->send403();
return;
}
}
if (apiVersion != 3)
//.........这里部分代码省略.........
示例13: clear
void DiagramScene::setValues(QMap<QString, QVector<QPointF> > values)
{
if(!values.keys().size())
{
mouseline=0;
clear();
return;
}
if(!values[values.keys().at(0)].size())
{
mouseline=0;
clear();
return;
}
bool dirty = true;
int searchiteration=0;
while(dirty && searchiteration<1000)
{
searchiteration++;
mouseline=0;
clear();
for(int index=0; index < value.size(); index++)
delete value[value.keys().at(index)];
value.clear();
minvaluex=0.0;
maxvaluex=0.0;
minvaluey=0.0;
maxvaluey=0.0;
if(!yscale)
yscale=1;
data=values;
if(!values.size())
return;
for(int index=0; index < values.size(); index++)
{
QPen pen(QColor(((index+1)*948)%200+50,((index+1)*123)%200+50,((index+1)*11)%200+50));
QPainterPath tmppath;
QVector<QPointF> result = values[values.keys().at(index)];
value[data.keys().at(index)] = new QMap<qreal,qreal>();
for(int pointindex=0; pointindex < result.size(); pointindex++)
{
qreal x = (qreal)(result[pointindex].x());
qreal y = (qreal)(result[pointindex].y());
(*value[data.keys().at(index)])[x]=y;
if(!pointindex && !index)
{
minvaluex=x;
maxvaluex=x;
minvaluey=(double)y/(double)yscale;
maxvaluey=(double)y/(double)yscale;
}
if(!pointindex)
tmppath.moveTo(x*prec,(-y/yscale)*prec);
else
tmppath.lineTo(x*prec,(-y/yscale)*prec);
if(x > maxvaluex)
maxvaluex=(double)x;
if(x < minvaluex)
minvaluex=(double)x;
if((double)y/yscale > maxvaluey)
maxvaluey=(double)y/yscale;
if((double)y/yscale < minvaluey)
minvaluey=(double)y/yscale;
}
addPath(tmppath,pen);
}
dirty = false;
qreal maxyvalue = maxvaluey-minvaluey;
if(maxvaluey==minvaluey)
maxyvalue = qAbs(maxvaluey);
qreal LOWY = 20.0;
qreal UPPERY = 80.0;
if(maxyvalue < LOWY || maxyvalue > UPPERY)
{
yscale *=maxyvalue/((double)(UPPERY-LOWY)/2.0 + LOWY);
dirty = true;
}
}
showGrid();
qreal w , h;
//.........这里部分代码省略.........
示例14: dataToDotString
QString MyString::dataToDotString(Data *data, int type)
{
QString s;
//select edges/titles based on type
QVector<Arrow> *edgesPtr;
QHash<int, QString> *titlesPtr;
QString filter;
switch (type)
{
case DOT_TYPE_AFFORDANCE:
titlesPtr = &(data->affordanceStateTitles);
edgesPtr = &(data->affordanceEdges);
filter = data->affordanceFilter;
break;
case DOT_TYPE_ACTION:
titlesPtr = &(data->actionStateTitles);
edgesPtr = &(data->actionEdges);
filter = data->actionFilter;
break;
case DOT_TYPE_ABSTRACT:
titlesPtr = &(data->abstractStateTitles);
edgesPtr = &(data->abstractEdges);
break;
default:
return s;
break;
}
//parse filter string
QStringList stateNos = filter.split(",");
QSet<int> filteredSet;
int filteredSetSize = stateNos.count();
//build set of filtered states
for (int index = 0; index < filteredSetSize; index++)
{
int value = stateNos.at(index).toInt();
if (!value)
continue;
filteredSet.insert(value);
}
s += ("digraph d {\n");
s += ("graph [ bgcolor=\"white\", resolution=\"128\", fontname=\"Helvetica\", fontcolor=\"black\", fontsize=\"10\" ];");
s += ("node [ fontname=\"Helvetica\", penwidth=\"0.25\", fontcolor=\"gray32\", fontsize=\"8\"];");
s += ("edge [ color=\"gray32\", arrowsize=\"0.75\", penwidth=\"0.25\", fontname=\"Helvetica\", fontcolor=\"dodgerblue4\", fontsize=\"8\", arrowhead=\"vee\" ];");
//states
std::map<int, QString> states; //tbd: check if necessary
int size = edgesPtr->count();
for (int i = 1; i < size; i++) //omit initial state 0
{
int sourceId, targetId;
sourceId = edgesPtr->at(i).source;
targetId = edgesPtr->at(i).target;
QString source, target;
source = MyString::makeState(sourceId, (*titlesPtr)[sourceId]);
target = MyString::makeState(targetId, (*titlesPtr)[targetId]);
states.insert(std::make_pair(sourceId, source));
states.insert(std::make_pair(targetId, target));
}
std::map<int, QString>::iterator it;
for (it = states.begin(); it != states.end(); it++)
{
bool active = true;
if (!filter.isEmpty() && !filteredSet.contains(it->first))
{
active = false;
}
QString state;
if (!active)
{
state += "//";
}
state += QString::number(it->first);
state += " [label=\"";
state += it->second;
state += "\"]\n";
s += state;
}
//arrows
size = edgesPtr->count();
int source, target;
for (int i = 1; i < size; i++) //omit initial state 0
{
Arrow a = edgesPtr->at(i);
source = a.source;
target = a.target;
bool active = true;
if (!filter.isEmpty() &&
((!filteredSet.contains(source) || !filteredSet.contains(target))))
//.........这里部分代码省略.........
示例15: insertRows
/*!
\fn void QTextTable::removeColumns(int index, int columns)
Removes a number of \a columns starting with the column at the specified
\a index.
\sa insertRows() insertColumns() removeRows() resize() appendRows() appendColumns()
*/
void QTextTable::removeColumns(int pos, int num)
{
Q_D(QTextTable);
// qDebug() << "-------- removeCols" << pos << num;
if (num <= 0 || pos < 0)
return;
if (d->dirty)
d->update();
if (pos >= d->nCols)
return;
if (pos + num > d->nCols)
pos = d->nCols - num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *collection = p->formatCollection();
p->beginEditBlock();
// delete whole table?
if (pos == 0 && num == d->nCols) {
const int pos = p->fragmentMap().position(d->fragment_start);
p->remove(pos, p->fragmentMap().position(d->fragment_end) - pos + 1);
p->endEditBlock();
return;
}
p->aboutToRemoveCell(cellAt(0, pos).firstPosition(), cellAt(d->nRows - 1, pos + num - 1).lastPosition());
QList<int> touchedCells;
for (int r = 0; r < d->nRows; ++r) {
for (int c = pos; c < pos + num; ++c) {
int cell = d->grid[r*d->nCols + c];
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = collection->charFormat(it->format);
int span = fmt.tableCellColumnSpan();
if (touchedCells.contains(cell) && span <= 1)
continue;
touchedCells << cell;
if (span > 1) {
fmt.setTableCellColumnSpan(span - 1);
p->setCharFormat(it.position(), 1, fmt);
} else {
// remove cell
int index = d->cells.indexOf(cell) + 1;
int f_end = index < d->cells.size() ? d->cells.at(index) : d->fragment_end;
p->remove(it.position(), p->fragmentMap().position(f_end) - it.position());
}
}
}
QTextTableFormat tfmt = format();
tfmt.setColumns(tfmt.columns()-num);
QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints();
if (columnWidths.count() > pos) {
columnWidths.remove(pos, num);
tfmt.setColumnWidthConstraints (columnWidths);
}
QTextObject::setFormat(tfmt);
p->endEditBlock();
// qDebug() << "-------- end removeCols" << pos << num;
}