//---------------------------------------------------------------------------
//  getWordItems
//
//! Construct a list of word items to be inserted into a word list, based on
//! the results of a list of searches.
//
//! @param searchSpecs the list of search specifications
//! @return a list of word items
//---------------------------------------------------------------------------
QList<WordTableModel::WordItem>
WordVariationDialog::getWordItems(const QList<SearchSpec>& searchSpecs) const
{
    QList<WordTableModel::WordItem> wordItems;
    QMap<QString, QString> wordMap;
    QListIterator<SearchSpec> lit (searchSpecs);
    while (lit.hasNext()) {
        QStringList wordList = wordEngine->search(lexicon, lit.next(), false);
        QStringListIterator wit (wordList);
        while (wit.hasNext()) {
            QString str = wit.next();
            wordMap.insert(str.toUpper(), str);
        }
    }

    QMapIterator<QString, QString> mit (wordMap);
    while (mit.hasNext()) {
        mit.next();
        QString value = mit.value();
        QList<QChar> wildcardChars;
        for (int i = 0; i < value.length(); ++i) {
            QChar c = value[i];
            if (c.isLower())
                wildcardChars.append(c);
        }
        QString wildcard;
        if (!wildcardChars.isEmpty()) {
            qSort(wildcardChars.begin(), wildcardChars.end(),
                  Auxil::localeAwareLessThanQChar);
            foreach (const QChar& c, wildcardChars)
                wildcard.append(c.toUpper());
        }
        wordItems.append(WordTableModel::WordItem(
            mit.key(), WordTableModel::WordNormal, wildcard));
    }
Esempio n. 2
0
void LocationTable::splitByAnchors(const PreprocessedContents& text, const Anchor& textStartPosition, QList<PreprocessedContents>& strings, QList<Anchor>& anchors) const {

  Anchor currentAnchor = Anchor(textStartPosition);
  size_t currentOffset = 0;

  QMapIterator<std::size_t, Anchor> it = m_offsetTable;

  while (currentOffset < (size_t)text.size())
  {
    Anchor nextAnchor(KDevelop::CursorInRevision::invalid());
    size_t nextOffset;

    if(it.hasNext()) {
      it.next();
      nextOffset = it.key();
      nextAnchor = it.value();
    }else{
      nextOffset = text.size();
      nextAnchor = Anchor(KDevelop::CursorInRevision::invalid());
    }

    if( nextOffset-currentOffset > 0 ) {
      strings.append(text.mid(currentOffset, nextOffset-currentOffset));
      anchors.append(currentAnchor);
    }

    currentOffset = nextOffset;
    currentAnchor = nextAnchor;
  }
}
void Emotions::storeClass(QString klassName, NaiveBayesClassifier *classifier){
    double acc=0;
    if(klassName.contains("calm") || klassName.contains("exited")){
        acc=EMOTION_AROUSAL_ACCURACY;
    }else if(klassName.contains("positive") || klassName.contains("negative")){
        acc=EMOTION_VALENCE_ACCURACY;
    }else{
        return;
    }

    if(classifier->getTrainedClasses().contains(klassName)){
        QFile file(_dataPath+"."+klassName);
        if (!file.open(QIODevice::WriteOnly)) {
            qDebug() << "Emotions : cannot open file "+file.fileName()+" : "
                     << qPrintable(file.errorString()) << file.fileName()<< endl;
            return;
        }

        QMapIterator<double, double>* clasIt = new QMapIterator<double,double>(*classifier->getTrainedClasses().value(klassName));
        while(clasIt->hasNext()){
            clasIt->next();
            for(int j=0;j<clasIt->value();++j){
                QString* strVal=new QString("");
                strVal->setNum(clasIt->key(),'f', acc);
                file.write(strVal->toAscii());
                file.putChar('\n');
            }
        }
    }
}
Esempio n. 4
0
void LocationTable::splitByAnchors(const QByteArray& text, const KDevelop::SimpleCursor& textStartPosition, QList<QByteArray>& strings, QList<KDevelop::SimpleCursor>& anchors) const {

  KDevelop::SimpleCursor currentCursor = textStartPosition;
  size_t currentOffset = 0;
  
  QMapIterator<std::size_t, KDevelop::SimpleCursor> it = m_offsetTable;

  while (currentOffset < (size_t)text.length())
  {
    KDevelop::SimpleCursor nextCursor;
    size_t nextOffset;
    
    if(it.hasNext()) {
      it.next();
      nextOffset = it.key();
      nextCursor = it.value();
    }else{
      nextOffset = text.length();
      nextCursor = KDevelop::SimpleCursor::invalid();
    }

    if( nextOffset-currentOffset > 0 ) {
      strings.append(text.mid(currentOffset, nextOffset-currentOffset));
      anchors.append(currentCursor);
    }
    
    currentOffset = nextOffset;
    currentCursor = nextCursor;
  }
}
Esempio n. 5
0
void SingleXmlSerializer::exportProperties(const Id&id, QDomDocument &doc, QDomElement &root
		, QHash<Id, Object *> const &objects)
{
	QDomElement props = doc.createElement("properties");

	const GraphicalObject * const graphicalObject = dynamic_cast<const GraphicalObject *>(objects[id]);
	const LogicalObject * const logicalObject
			= dynamic_cast<const LogicalObject *>(objects[graphicalObject->logicalId()]);

	QMap<QString, QVariant> properties;

	QMapIterator<QString, QVariant> i = logicalObject->propertiesIterator();
	while (i.hasNext()) {
		i.next();
		properties[i.key()] = i.value();

	}

	i = graphicalObject->propertiesIterator();
	while (i.hasNext()) {
		i.next();
		properties[i.key()] = i.value();
	}

	foreach (const QString &key, properties.keys()) {
		QDomElement prop = doc.createElement("property");

		QString typeName = properties[key].typeName();
		QVariant value = properties[key];
		if (typeName == "qReal::IdList" && (value.value<IdList>().size() != 0)) {
			QDomElement list = ValuesSerializer::serializeIdList("list", value.value<IdList>(), doc);
			prop.appendChild(list);
		} else if (typeName == "qReal::Id"){
			prop.setAttribute("value", value.value<Id>().toString());
		} else if (value.toString().isEmpty()) {
			continue;
		} else {
			prop.setAttribute("value", properties[key].toString());
		}

		prop.setAttribute("name", key);

		props.appendChild(prop);
	}

	root.appendChild(props);
}
Esempio n. 6
0
void KisBaseNode::mergeNodeProperties(const KoProperties & properties)
{
    QMapIterator<QString, QVariant> iter = properties.propertyIterator();
    while (iter.hasNext()) {
        iter.next();
        m_d->properties.setProperty(iter.key(), iter.value());
    }
}
Esempio n. 7
0
bool InformWindow::keyProcessing(const int &key)
{
    QMapIterator<int, Command*> it (kbCommand);
    while (it.hasNext())
    {
        it.next();
        if (key == it.key())
        {
            if (it.value() != NULL)
            {
                it.value()->execute();
                return true;
            }
        }
    }
    return false;
}
Esempio n. 8
0
void LocationTable::dump() const
{
  QMapIterator<std::size_t, KDevelop::SimpleCursor> it = m_offsetTable;
  kDebug(9007) << "Location Table:";
  while (it.hasNext()) {
    it.next();
    kDebug(9007) << it.key() << " => " << it.value().textCursor();
  }
}
Esempio n. 9
0
void LocationTable::dump() const
{
  QMapIterator<std::size_t, Anchor> it = m_offsetTable;
  qCDebug(RPP) << "Location Table:";
  while (it.hasNext()) {
    it.next();
    qCDebug(RPP) << it.key() << " => " << it.value().castToSimpleCursor();
  }
}
Esempio n. 10
0
void DraggerManagerPrivate::clear()
{
    QMapIterator<WidgetProperties *, QDeclarativeItem *> iterator =
            QMapIterator<WidgetProperties *, QDeclarativeItem *>(draggers);
    while (iterator.hasNext()) {
        iterator.next();
        iterator.value()->deleteLater();
    }
    draggers.clear();
}
Esempio n. 11
0
void DraggerManager::disableDraggers()
{
    Q_D(DraggerManager);
    QMapIterator<WidgetProperties *, QDeclarativeItem *> iterator =
            QMapIterator<WidgetProperties *, QDeclarativeItem *>(d->draggers);
    while (iterator.hasNext()) {
        iterator.next();
        iterator.value()->setVisible(false);
    }
}
Esempio n. 12
0
KisBaseNode::KisBaseNode(const KisBaseNode & rhs)
        : QObject()
        , KisShared(rhs)
        ,  m_d(new Private())
{
    QMapIterator<QString, QVariant> iter = rhs.m_d->properties.propertyIterator();
    while (iter.hasNext()) {
        iter.next();
        m_d->properties.setProperty(iter.key(), iter.value());
    }
    m_d->linkedTo = rhs.m_d->linkedTo;
}
Esempio n. 13
0
bool MSqlQuery::exec()
{
    // Database connection down.  Try to restart it, give up if it's still
    // down
    if (!m_db)
    {
        // Database structure's been deleted
        return false;
    }

    if (!m_db->isOpen() && !m_db->Reconnect())
    {
        LOG(VB_GENERAL, LOG_INFO, "MySQL server disconnected");
        return false;
    }

    bool result = QSqlQuery::exec();

    // if the query failed with "MySQL server has gone away"
    // Close and reopen the database connection and retry the query if it
    // connects again
    if (!result && QSqlQuery::lastError().number() == 2006 && m_db->Reconnect())
        result = QSqlQuery::exec();

    if (VERBOSE_LEVEL_CHECK(VB_DATABASE) && logLevel <= LOG_DEBUG)
    {
        QString str = lastQuery();

        // Database logging will cause an infinite loop here if not filtered
        // out
        if (!str.startsWith("INSERT INTO logging "))
        {
       	    // Sadly, neither executedQuery() nor lastQuery() display
            // the values in bound queries against a MySQL5 database.
            // So, replace the named placeholders with their values.

            QMapIterator<QString, QVariant> b = boundValues();
            while (b.hasNext())
            {
                b.next();
                str.replace(b.key(), '\'' + b.value().toString() + '\'');
            }

            LOG(VB_DATABASE, LOG_DEBUG,
                QString("MSqlQuery::exec(%1) %2%3")
                        .arg(m_db->MSqlDatabase::GetConnectionName()).arg(str)
                        .arg(isSelect() ? QString(" <<<< Returns %1 row(s)")
                                              .arg(size()) : QString()));
        }
    }

    return result;
}
Esempio n. 14
0
bool KisBaseNode::check(const KoProperties & properties) const
{
    QMapIterator<QString, QVariant> iter = properties.propertyIterator();
    while (iter.hasNext()) {
        iter.next();
        if (m_d->properties.contains(iter.key())) {
            if (m_d->properties.value(iter.key()) != iter.value())
                return false;
        }
    }
    return true;
}
Esempio n. 15
0
void ClientPrivate::tuiLaunched () {
    qDebug () << "ClientPrivate::tuiLaunched";
    QMapIterator<QString, Transfer *> iter (transfers);

    if (transfers.count() == 0) {
        // There are no transfers
        return;
    }

    while (iter.hasNext()) {
        iter.next();
        Transfer *transfer = iter.value ();

        if (iter.key() != transfer->transferId ()) {
            qCritical () <<
                "Client::tuiLaunched -> Key does not match transfer id";
        }

        QDBusReply<bool> exists =
            interface->transferExists (transfer->transferId ());
        if (exists.isValid ()) {
            if (exists.value () == true) {
                qDebug() << transfer->transferId () << "exists in TUI"
                    << "- not registering this. Moving to next";

                // Transfer exists in TUI - go to next transfer
                continue;
            }
        } else {
            qCritical() << "Got invalid reply when checking if transfer "
                << transfer->transferId () << " exists in TUI";
            continue;
        }

        QDBusReply<QString> reply =
            interface->registerTransientTransfer (transfer->transferId ());

        if (reply.isValid()) {
            if (reply.value () == transfer->transferId ()) {
                transfer->tuiLaunched ();
            } else {
                qCritical() << "Got " << reply.value () <<
                    " as reply from registerPersistentTransfer instead of "
                    << "expected value of " << transfer->transferId ();
            }
        } else {
            qWarning() << "Transfer with tracker uri" << transfer->transferId ()
                << "not found.";
        }
    }
}
Esempio n. 16
0
/**
 * @brief reads the commands that are available form the stored settings
 * @param commandMap the map that is to store
 * @return
 *	void
 */
void DLDConfigureOB::writeCommandMap (QMap<QString, QString> commandMap)
{
	QMapIterator<QString, QString> iter (commandMap);
	int i;
	QString nameBase = "%1-commandName";
	QString descBase = "%1-commandDescription";
	for (i = 0; iter.hasNext (); i++)
	{
		iter.next();
		settings->setValue(nameBase.arg(i), iter.key());
		settings->setValue(descBase.arg(i), iter.value());
	}
	settings->setValue("numberOfCommands", i);
	emit commandListChanged ();
}
void QtPropertyDataIntrospection::ChildNeedUpdate()
{
	QMapIterator<QtPropertyDataDavaVariant*, const DAVA::IntrospectionMember *> i = QMapIterator<QtPropertyDataDavaVariant*, const DAVA::IntrospectionMember *>(childVariantMembers);

	while(i.hasNext())
	{
		i.next();

		QtPropertyDataDavaVariant *childData = i.key();
		DAVA::VariantType childCurValue = i.value()->Value(object);

		if(childCurValue != childData->GetVariantValue())
		{
			childData->SetVariantValue(childCurValue);
		}

	}
}
Esempio n. 18
0
QHash<QString, QVariant> RefactoringApplier::properties(Id const &id) const
{
	QHash<QString, QVariant> result;

	QMapIterator<QString, QVariant> properties =
			(mLogicalModelApi.isLogicalId(id))
			? mLogicalModelApi.logicalRepoApi().propertiesIterator(id)
			: mLogicalModelApi.logicalRepoApi().propertiesIterator(
					mGraphicalModelApi.logicalId(id));

	while (properties.hasNext()) {
		properties.next();

		if (!defaultProperties.contains(properties.key())) {
			result.insert(properties.key(), properties.value());
		}
	}

	return result;
}
Esempio n. 19
0
void ViewManager::ViewManagerPrivate::slotLockedChanged(bool locked)
{
    if(locked) {
        // When the view is locked, all draggers should be destroyed
        QMapIterator<WidgetProperties *, QDeclarativeItem *> iterator =
                QMapIterator<WidgetProperties *, QDeclarativeItem *>(registeredDraggers);
        while (iterator.hasNext()) {
            iterator.next();
            QDeclarativeItem *item = iterator.value();
            registeredDraggers.remove(iterator.key());
            item->deleteLater();
        }

        q->setCurrentDraggedWidget("");
    } else {
        // For each item in the current page, a dragger should
        // be created
        DisplayedPageWidgetsModel * pageModel = displayedPagesModel->pageModel(currentPageIndex);
        for (int i = 0; i < pageModel->rowCount(); i++) {
            emit q->requestCreateDragger(pageModel->widget(i));
        }
    }
}
Esempio n. 20
0
void Material::setFilterAnisotropy( float anisotropy )
{
	if( anisotropy > filterAnisotropyMaximum() )
		anisotropy = filterAnisotropyMaximum();
	else if( anisotropy < 1.0f )
		anisotropy = 1.0f;

	QHashIterator< QString, QWeakPointer<MaterialData> > mi( Material::cache() );
	while( mi.hasNext() )
	{
		mi.next();
		QSharedPointer<MaterialData> d = mi.value().toStrongRef();
		if( d.isNull() )
			continue;
		QMapIterator<QString,GLuint> ti (d->textures());
		while( ti.hasNext() )
		{
			ti.next();
			glBindTexture( GL_TEXTURE_2D, ti.value() );
			glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy );
		}
	}
	sFilterAnisotropy = anisotropy;
}
Esempio n. 21
0
bool MSqlQuery::exec()
{
    if (!m_db)
    {
        // Database structure's been deleted
        return false;
    }

    if (m_last_prepared_query.isEmpty())
    {
        LOG(VB_GENERAL, LOG_ERR,
            "MSqlQuery::exec(void) called without a prepared query.");
        return false;
    }

#if DEBUG_RECONNECT
    if (random() < RAND_MAX / 50)
    {
        LOG(VB_GENERAL, LOG_INFO,
            "MSqlQuery disconnecting DB to test reconnection logic");
        m_db->m_db.close();
    }
#endif

    // Database connection down.  Try to restart it, give up if it's still
    // down
    if (!m_db->isOpen() && !Reconnect())
    {
        LOG(VB_GENERAL, LOG_INFO, "MySQL server disconnected");
        return false;
    }

    QElapsedTimer timer;
    timer.start();

    bool result = QSqlQuery::exec();
    qint64 elapsed = timer.elapsed();

    // if the query failed with "MySQL server has gone away"
    // Close and reopen the database connection and retry the query if it
    // connects again
    if (!result && QSqlQuery::lastError().number() == 2006 && Reconnect())
        result = QSqlQuery::exec();

    if (!result)
    {
        QString err = MythDB::GetError("MSqlQuery", *this);
        MSqlBindings tmp = QSqlQuery::boundValues();
        bool has_null_strings = false;
        for (MSqlBindings::iterator it = tmp.begin(); it != tmp.end(); ++it)
        {
            if (it->type() != QVariant::String)
                continue;
            if (it->isNull() || it->toString().isNull())
            {
                has_null_strings = true;
                *it = QVariant(QString(""));
            }
        }
        if (has_null_strings)
        {
            bindValues(tmp);
            timer.restart();
            result = QSqlQuery::exec();
            elapsed = timer.elapsed();
        }
        if (result)
        {
            LOG(VB_GENERAL, LOG_ERR,
                QString("Original query failed, but resend with empty "
                        "strings in place of NULL strings worked. ") +
                "\n" + err);
        }
    }

    if (VERBOSE_LEVEL_CHECK(VB_DATABASE, LOG_INFO))
    {
        QString str = lastQuery();

        // Database logging will cause an infinite loop here if not filtered
        // out
        if (!str.startsWith("INSERT INTO logging "))
        {
            // Sadly, neither executedQuery() nor lastQuery() display
            // the values in bound queries against a MySQL5 database.
            // So, replace the named placeholders with their values.

            QMapIterator<QString, QVariant> b = boundValues();
            while (b.hasNext())
            {
                b.next();
                str.replace(b.key(), '\'' + b.value().toString() + '\'');
            }

            LOG(VB_DATABASE, LOG_INFO,
                QString("MSqlQuery::exec(%1) %2%3%4")
                        .arg(m_db->MSqlDatabase::GetConnectionName()).arg(str)
                        .arg(QString(" <<<< Took %1ms").arg(QString::number(elapsed)))
                        .arg(isSelect() ? QString(", Returned %1 row(s)")
                                              .arg(size()) : QString()));
        }
    }

    return result;
}
Esempio n. 22
0
// Reconstruct the area exit data in a format that actually makes sense - only
// needed until the TRoom & TArea classes can be restructured to store exits
// using the exit direction as a key and the to room as a value instead of vice-versa
const QMultiMap<int, QPair<QString, int>> TArea::getAreaExitRoomData() const
{
    QMultiMap<int, QPair<QString, int>> results;
    QSet<int> roomsWithOtherAreaSpecialExits;

    QMapIterator<int, QPair<int, int>> itAreaExit = exits;
    // First parse the normal exits and also find the rooms where there is at
    // least one special area exit
    while (itAreaExit.hasNext()) {
        itAreaExit.next();
        QPair<QString, int> exitData;
        exitData.second = itAreaExit.value().first;
        switch (itAreaExit.value().second) {
        case DIR_NORTH:     exitData.first = QString("north");                         break;
        case DIR_NORTHEAST: exitData.first = QString("northeast");                     break;
        case DIR_NORTHWEST: exitData.first = QString("northwest");                     break;
        case DIR_SOUTH:     exitData.first = QString("south");                         break;
        case DIR_WEST:      exitData.first = QString("west");                          break;
        case DIR_EAST:      exitData.first = QString("east");                          break;
        case DIR_SOUTHEAST: exitData.first = QString("southeast");                     break;
        case DIR_SOUTHWEST: exitData.first = QString("southwest");                     break;
        case DIR_UP:        exitData.first = QString("up");                            break;
        case DIR_DOWN:      exitData.first = QString("down");                          break;
        case DIR_IN:        exitData.first = QString("in");                            break;
        case DIR_OUT:       exitData.first = QString("out");                           break;
        case DIR_OTHER:     roomsWithOtherAreaSpecialExits.insert(itAreaExit.key());   break;
        default:
            qWarning("TArea::getAreaExitRoomData() Warning: unrecognised exit code %i found for exit from room %i to room %i.",
                     itAreaExit.value().second, itAreaExit.key(), itAreaExit.value().first);
        }
        if (!exitData.first.isEmpty()) {
            results.insert(itAreaExit.key(), exitData);
        }
    }
    // Now have to find the special area exits in the rooms where we know there
    // IS one
    QSetIterator<int> itRoomWithOtherAreaSpecialExit = roomsWithOtherAreaSpecialExits;
    while (itRoomWithOtherAreaSpecialExit.hasNext()) {
        int fromRoomId = itRoomWithOtherAreaSpecialExit.next();
        TRoom* pFromRoom = mpRoomDB->getRoom(fromRoomId);
        if (pFromRoom) {
            QMapIterator<int, QString> itOtherExit = pFromRoom->getOtherMap();
            while (itOtherExit.hasNext()) {
                itOtherExit.next();
                QPair<QString, int> exitData;
                exitData.second = itOtherExit.key();
                TRoom* pToRoom = mpRoomDB->getRoom(exitData.second);
                if (pToRoom && mpRoomDB->getArea(pToRoom->getArea()) != this) {
                    // Note that pToRoom->getArea() is misnamed, should be getAreaId() !
                    if (itOtherExit.value().mid(0, 1) == QStringLiteral("0") || itOtherExit.value().mid(0, 1) == QStringLiteral("1")) {
                        exitData.first = itOtherExit.value().mid(1);
                    } else {
                        exitData.first = itOtherExit.value();
                    }
                    if (!exitData.first.isEmpty()) {
                        results.insert(fromRoomId, exitData);
                    }
                }
            }
        }
    }
    return results;
}
Esempio n. 23
0
//---------------------------------------------------------------------------
//  refreshClicked
//
//! Called when the Refresh button is clicked.
//---------------------------------------------------------------------------
void
CardboxForm::refreshClicked()
{
    QString lexicon = lexiconWidget->getCurrentLexicon();
    QString quizType = quizTypeCombo->currentText();
    QuizDatabase db (lexicon, quizType);
    if (!db.isValid()) {
        // FIXME: pop up a warning
        return;
    }

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

    cardboxCountTree->clear();
    QMap<int, int> cardboxCounts = db.getCardboxCounts();
    QMapIterator<int, int> it (cardboxCounts);
    while (it.hasNext()) {
        it.next();
        QStringList strings;
        strings.append(QString::number(it.key()));
        strings.append(QString::number(it.value()));
        cardboxCountTree->addTopLevelItem(new QTreeWidgetItem(strings));
    }

    cardboxDaysTree->clear();
    QMap<int, int> dayCounts = db.getScheduleDayCounts();
    QMapIterator<int, int> jt (dayCounts);
    while (jt.hasNext()) {
        jt.next();
        QStringList strings;
        strings.append(QString::number(jt.key()));
        strings.append(QString::number(jt.value()));
        cardboxDaysTree->addTopLevelItem(new QTreeWidgetItem(strings));
    }

    // Refresh cardbox contents

    // Attempt using QSqlTableModel:
    // XXX: This would be lovely except that SQLite locks the database and
    // doesn't let go, thus preventing quiz responses from being counted
    //if (!cardboxContentsModel) {
    //    cardboxContentsModel = new QSqlTableModel(this, *sqlDb);
    //    cardboxContentsView->setModel(cardboxContentsModel);
    //    cardboxContentsView->setSortingEnabled(true);
    //    cardboxContentsModel->setTable("questions");
    //    cardboxContentsModel->select();
    //    while (cardboxContentsModel->canFetchMore()) {
    //        qDebug("Fetching more for cardbox contents model");
    //        cardboxContentsModel->fetchMore();
    //    }
    //}

    // Attempt using QSqlQueryModel:
    //if (!cardboxContentsModel) {
    //    cardboxContentsModel = new QSqlQueryModel;
    //    cardboxContentsView->setModel(cardboxContentsModel);
    //}
    //queryStr =
    //    "SELECT question, cardbox, correct, incorrect, streak, "
    //    "next_scheduled FROM questions WHERE cardbox NOT NULL "
    //    "ORDER BY next_scheduled";
    //
    //cardboxContentsModel->setQuery(queryStr, *sqlDb);
    //while (cardboxContentsModel->canFetchMore()) {
    //    qDebug("Fetching more for cardbox contents model");
    //    cardboxContentsModel->fetchMore();
    //}
    //
    //cardboxContentsModel->setHeaderData(0, Qt::Horizontal, "Question");
    //cardboxContentsModel->setHeaderData(1, Qt::Horizontal, "Cardbox");
    //cardboxContentsModel->setHeaderData(2, Qt::Horizontal, "Correct");
    //cardboxContentsModel->setHeaderData(3, Qt::Horizontal, "Incorrect");
    //cardboxContentsModel->setHeaderData(4, Qt::Horizontal, "Streak");
    //cardboxContentsModel->setHeaderData(5, Qt::Horizontal, "Next Scheduled");

    QApplication::restoreOverrideCursor();
}
Esempio n. 24
0
/**
 * @brief slot: show preference dialog
 * @return
 *      void
 */
void DLDConfigureOB::showPreferences ()
{
	QDialog * preferenceDialog = new QDialog;
	preferences.setupUi (preferenceDialog);

	// fill with defaults: (from settings)
	QString logFile = settings->value("logFile", "").toString ();
	preferences.flashBasepathEdit->setText (settings->value("FlashBasepath", "ttyUSB").toString ());
	preferences.openBeaconBasepathEdit->setText (settings->value("OpenBeaconBasepath", "ttyACM").toString ());
	preferences.refreshSpin->setValue (settings->value("DeviceRefreshRate", 5).toInt ());
	preferences.logFileEdit->setText (logFile);
	preferences.sam7PathEdit->setText (settings->value("sam7Path", "/usr/local/bin/sam7").toString ());
	preferences.showTagPacketsCheck->setChecked (showRX);

	// fill command table
	QStringList		tableHeader;
	tableHeader << tr ("Command") << tr ("Command description");
	preferences.commandTable->setColumnCount(2);
	preferences.commandTable->setHorizontalHeaderLabels (tableHeader);
	preferences.commandTable->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
	preferences.commandTable->setShowGrid(true);

	QMap<QString, QString> cmdMap = getCommandMap ();
	QMapIterator<QString, QString> i (cmdMap);
	while (i.hasNext())
	{
		i.next();
		QTableWidgetItem * cmdNameItem = new QTableWidgetItem(i.key());
		QTableWidgetItem * cmdDescItem = new QTableWidgetItem(i.value());
		preferences.commandTable->insertRow(0);
		preferences.commandTable->setItem(0, 0, cmdNameItem);
		preferences.commandTable->setItem(0, 1, cmdDescItem);
	}

	// connect buttons:
	connect(preferences.addButton,		SIGNAL(clicked ()), this, SLOT(insertCommandTableRow ()));
	connect(preferences.deleteButton,	SIGNAL(clicked ()), this, SLOT(deleteCommandTableRow ()));
	connect(preferences.logFileButton,	SIGNAL(clicked ()), this, SLOT(selectLogFile ()));
	connect(preferences.sam7PathButton,	SIGNAL(clicked ()), this, SLOT(selectSam7File ()));
	connect(preferences.defaultCommandsButton,SIGNAL(clicked ()), this, SLOT(fillDefaultCommands ()));

	// connect entry checks
	connect(preferences.flashBasepathEdit,	SIGNAL(editingFinished ()), this, SLOT(checkFilled ()));
	connect(preferences.openBeaconBasepathEdit,SIGNAL(editingFinished ()), this, SLOT(checkFilled ()));

	if (preferenceDialog->exec () == QDialog::Accepted)
	{
		int refreshRate = preferences.refreshSpin->value ();
		settings->setValue("FlashBasepath", preferences.flashBasepathEdit->text ());
		settings->setValue("OpenBeaconBasepath", preferences.openBeaconBasepathEdit->text ());
		settings->setValue("DeviceRefreshRate", refreshRate);
		settings->setValue("showRX", showRX);
		showRX = preferences.showTagPacketsCheck->isChecked();
		settings->setValue("sam7Path", preferences.sam7PathEdit->text ());

		QString newLogFile = preferences.logFileEdit->text();
		if (logFile != newLogFile)
		{
			emit logFileChanged (newLogFile);
			settings->setValue("logFile", newLogFile);
			log->infoLog (QString("Logpath changed to: %1").arg(newLogFile));
		}

		QMap<QString, QString> newCmdMap;
		log->debugLog ("Current command list:");
		for (int row = 0; row < preferences.commandTable->rowCount(); row++)
		{
			QTableWidgetItem *cmdNameItem = preferences.commandTable->item(row, 0);
			QTableWidgetItem *cmdDescItem = preferences.commandTable->item(row, 1);
			if (cmdNameItem && cmdDescItem)
			{
				newCmdMap.insert (cmdNameItem->text(), cmdDescItem->text());
				log->debugLog (QString ("Name: %1\tDesc: %2").arg(cmdNameItem->text()).arg(cmdDescItem->text()));
			}
		}
		writeCommandMap (newCmdMap);
		refreshDevices ();
		refreshTimer->setInterval (refreshRate * 1000);
	}
}
// creates options page widget (uses the UI file)
QWidget *PfdQmlGadgetOptionsPage::createPage(QWidget *parent)
{
    options_page = new Ui::PfdQmlGadgetOptionsPage();
    // main widget
    QWidget *optionsPageWidget = new QWidget(parent);
    // main layout
    options_page->setupUi(optionsPageWidget);

    // QML file chooser
    options_page->qmlSourceFile->setExpectedKind(Utils::PathChooser::File);
    options_page->qmlSourceFile->setPromptDialogFilter(tr("QML file (*.qml)"));
    options_page->qmlSourceFile->setPromptDialogTitle(tr("Choose QML File"));
    options_page->qmlSourceFile->setPath(m_config->qmlFile());

    // Speed Unit combo
    QMapIterator<double, QString> iter = m_config->speedMapIterator();
    while (iter.hasNext()) {
        iter.next();
        options_page->speedUnitCombo->addItem(iter.value(), iter.key());
    }
    options_page->speedUnitCombo->setCurrentIndex(options_page->speedUnitCombo->findData(m_config->speedFactor()));

    // Altitude Unit combo
    iter = m_config->altitudeMapIterator();
    while (iter.hasNext()) {
        iter.next();
        options_page->altUnitCombo->addItem(iter.value(), iter.key());
    }
    options_page->altUnitCombo->setCurrentIndex(options_page->altUnitCombo->findData(m_config->altitudeFactor()));

    // Terrain check boxes
    options_page->showTerrain->setChecked(m_config->terrainEnabled());

    // Terrain file chooser
    options_page->earthFile->setExpectedKind(Utils::PathChooser::File);
    options_page->earthFile->setPromptDialogFilter(tr("OsgEarth (*.earth)"));
    options_page->earthFile->setPromptDialogTitle(tr("Choose Terrain File"));
    options_page->earthFile->setPath(m_config->terrainFile());

    // Terrain position
    options_page->latitude->setText(QString::number(m_config->latitude()));
    options_page->longitude->setText(QString::number(m_config->longitude()));
    options_page->altitude->setText(QString::number(m_config->altitude()));

    options_page->useOnlyCache->setChecked(m_config->cacheOnly());

    // Sky options
    options_page->useLocalTime->setChecked(m_config->timeMode() == TimeMode::Local);
    options_page->usePredefinedTime->setChecked(m_config->timeMode() == TimeMode::Predefined);
    options_page->dateEdit->setDate(m_config->dateTime().date());
    options_page->timeEdit->setTime(m_config->dateTime().time());
    options_page->minAmbientLightSpinBox->setValue(m_config->minAmbientLight());

    // Model check boxes
    options_page->showModel->setChecked(m_config->modelEnabled());
    options_page->useAutomaticModel->setChecked(m_config->modelSelectionMode() == ModelSelectionMode::Auto);
    options_page->usePredefinedModel->setChecked(m_config->modelSelectionMode() == ModelSelectionMode::Predefined);

    // Model file chooser
    options_page->modelFile->setExpectedKind(Utils::PathChooser::File);
    options_page->modelFile->setPromptDialogFilter(tr("Model file (*.3ds)"));
    options_page->modelFile->setPromptDialogTitle(tr("Choose Model File"));
    options_page->modelFile->setPath(m_config->modelFile());

    // Background image chooser
    options_page->backgroundImageFile->setExpectedKind(Utils::PathChooser::File);
    // options_page->backgroundImageFile->setPromptDialogFilter(tr("Image file"));
    options_page->backgroundImageFile->setPromptDialogTitle(tr("Choose Background Image File"));
    options_page->backgroundImageFile->setPath(m_config->backgroundImageFile());

#ifndef USE_OSG
    options_page->showTerrain->setChecked(false);
    options_page->showTerrain->setVisible(false);
#endif

    QObject::connect(options_page->actualizeDateTimeButton, SIGNAL(clicked()),
                     this, SLOT(actualizeDateTime()));

    return optionsPageWidget;
}