mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #358, adjusted samples for model matching
This commit is contained in:
45
src/blackmisc/sampleutils.cpp
Normal file
45
src/blackmisc/sampleutils.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "sampleutils.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
QString CSampleUtils::selectDirectory(const QStringList &directoryOptions, QTextStream &streamOut, QTextStream &streamIn)
|
||||
{
|
||||
Q_ASSERT(!directoryOptions.isEmpty());
|
||||
if (directoryOptions.isEmpty()) { return ""; }
|
||||
if (directoryOptions.size() < 2) { return directoryOptions.first(); }
|
||||
|
||||
QString selectedDir;
|
||||
do
|
||||
{
|
||||
for (int i = 0; i < directoryOptions.size(); i++)
|
||||
{
|
||||
if (i > 0) { streamOut << " "; }
|
||||
streamOut << (i + 1) << ") " << directoryOptions.at(i) ;
|
||||
}
|
||||
streamOut << endl;
|
||||
streamOut << "Select [1-" << directoryOptions.size() << "]: ";
|
||||
streamOut.flush();
|
||||
|
||||
QString input = streamIn.readLine();
|
||||
bool ok;
|
||||
int s = input.trimmed().toInt(&ok);
|
||||
if (ok && s > 0 && s <= directoryOptions.size())
|
||||
{
|
||||
selectedDir = directoryOptions.at(s - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (true);
|
||||
return selectedDir;
|
||||
}
|
||||
}
|
||||
33
src/blackmisc/sampleutils.h
Normal file
33
src/blackmisc/sampleutils.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SAMPLEUTILS_H
|
||||
#define BLACKMISC_SAMPLEUTILS_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
//! Utils for sample programms
|
||||
class CSampleUtils
|
||||
{
|
||||
|
||||
public:
|
||||
//! Select directory among given ones
|
||||
static QString selectDirectory(const QStringList &directoryOptions, QTextStream &streamOut, QTextStream &streamIn);
|
||||
|
||||
private:
|
||||
CSampleUtils() = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user