Пример #1
0
StartPageModel::StartPageModel(QObject *parent) : QStandardItemModel(parent),
	m_bookmark(nullptr)
{
	optionChanged(SettingsManager::Backends_WebOption);
	reloadModel();

	connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));
	connect(SettingsManager::getInstance(), SIGNAL(valueChanged(int,QVariant)), this, SLOT(optionChanged(int)));
}
Пример #2
0
void MainWindow::on_actionRandomGraph_triggered() {
  graph_ = make_unique<Graph>();
  connectionVertex_ = -1;

  Vertex* prev = &graph_->add_vertex();

  std::queue<Vertex*> queue;
  queue.push(prev);

  // Randomized edge count, between 10-15
  int count = rand() % 6 + 10;

  while (count--) {
    Vertex& next = graph_->add_vertex();
    queue.push(&next);

    graph_->connect(*prev, next);
    prev = &next;
  }

  while (!queue.empty()) {
    Vertex* top = queue.front();
    queue.pop();

    int index = (rand() % (graph_->size() - 1)) + 1;
    int dice = rand() % 6;

    if (top->value != index && dice > 2) {
      graph_->connect(top->value, index);
    }
  }

  reloadModel();
}
Пример #3
0
        void Variable::onClickRemoveTerm() {
            std::ostringstream message;
            message << "Do you want to delete the following terms?\n\n";

            for (int i = 0; i < ui->lvw_terms->count(); ++i) {
                if (ui->lvw_terms->item(i)->isSelected()) {
                    message << "- " << variable->getTerm(i)->toString();
                    if (i + 1 < ui->lvw_terms->selectedItems().size()) message << "\n\n";
                }
            }

            QMessageBox::StandardButton clicked = QMessageBox::warning(this, "Delete term",
                    QString::fromStdString(message.str()),
                    QMessageBox::Yes | QMessageBox::No,
                    QMessageBox::Yes);
            if (clicked == QMessageBox::Yes) {
                for (int i = ui->lvw_terms->count() - 1; i >= 0; --i) {
                    if (ui->lvw_terms->item(i)->isSelected()) {
                        delete (variable->removeTerm(i));
                    }
                }
                reloadModel();
            }

        }
Пример #4
0
        void Variable::edit(const OutputVariable* outputVariable) {
            variable->setMinimum(outputVariable->getMinimum());
            variable->setMaximum(outputVariable->getMaximum());
            for (int i = 0; i < outputVariable->numberOfTerms(); ++i) {
                this->variable->addTerm(outputVariable->getTerm(i)->copy());
            }

            scalar singleStep = (variable->getMaximum() - variable->getMinimum()) / 100;
            ui->sbx_min->setSingleStep(std::max(scalar(0.01), singleStep));
            ui->sbx_max->setSingleStep(std::max(scalar(0.01), singleStep));

            setWindowTitle("Edit variable");
            ui->led_name->setText(QString::fromStdString(outputVariable->getName()));
            ui->cbx_enabled->setChecked(outputVariable->isEnabled());

            OutputVariable* editable = dynamic_cast<OutputVariable*> (this->variable);
            editable->setDefaultValue(outputVariable->getDefaultValue());
            editable->setLastValidOutput(fl::nan);
            editable->setLockValidOutput(outputVariable->isLockingValidOutput());
            editable->setLockOutputRange(outputVariable->isLockingOutputRange());

            editable->fuzzyOutput()->setAccumulation(outputVariable->fuzzyOutput()->getAccumulation());
            Defuzzifier* defuzzifier = outputVariable->getDefuzzifier();
            //            if (not defuzzifier) {
            //                defuzzifier = Factory::instance()->defuzzifier()->
            //                        create(Centroid().className(), fl::fuzzylite::defaultDivisions());
            //            }
            editable->setDefuzzifier(defuzzifier);

            reloadModel();
        }
Пример #5
0
void MainWindow::on_actionRestartAlgorithm_triggered() {
  if (graph_->search_ready()) {
    auto text = ui->algList->currentText();
    if (text == "BFS") {
      graph_->clear_metadata(false);
      search_ = new BFS(*graph_, graph_->start_, graph_->end_);
    } else if (text == "DFS") {
      graph_->clear_metadata(false);
      search_ = new DFS(*graph_, graph_->start_, graph_->end_);
    } else if (text == "Dijkstra") {
      graph_->clear_metadata(true);
      search_ = new Dijkstra(*graph_, graph_->start_);
    } else if (text == "Euler") {
      graph_->clear_metadata(false);
      search_ = new Euler(*graph_, graph_->start_);
    } else if (text == "Jarnik") {
      graph_->clear_metadata(false);
      search_ = new Jarnik(*graph_, *graph_->start_);
    } else {
      QMessageBox box;
      box.setText("No algorithm was selected.");
      box.exec();
    }

    search_->start();
    reloadModel();
  }
}
Пример #6
0
void MainWindow::on_actionRandomEulerianGraph_triggered() {
  graph_ = make_unique<Graph>();
  connectionVertex_ = -1;
  graph_->add_vertex();

  int cycle_count = 5 + rand() % 3;

  for (int i = 0; i < cycle_count; i++) {
    // Pick a random vertex
    int index = rand() % graph_->size();
    auto it = graph_->begin();
    std::advance(it, index);

    Vertex* v = &*it;
    Vertex* prev = v;

    int cycle_length = 2 + rand() % 2;
    for (int j = 0; j < cycle_length; j++) {
      Vertex& v0 = graph_->add_vertex();
      graph_->connect(*prev, v0);
      prev = &v0;
    }

    graph_->connect(prev->value, v->value);
  }

  reloadModel();
}
Пример #7
0
void MainWindow::on_actionNextStep_triggered() {
  if (graph_->search_ready() && search_) {
    search_->step();
    reloadModel();
  } else {
    qDebug() << "Search isn't ready yet.";
  }
}
Пример #8
0
void MainWindow::on_actionRandomEdgeWeights_triggered() {
  for (auto& v : *graph_) {
    for (auto& e : v.edges) {
      e.weight = 1 + rand() % 9;
    }
  }

  reloadModel();
  event_log << "Edge weights randomized";
}
Пример #9
0
void StartPageModel::optionChanged(int identifier)
{
	if (identifier == SettingsManager::Backends_WebOption)
	{
		connect(AddonsManager::getWebBackend(), SIGNAL(thumbnailAvailable(QUrl,QPixmap,QString)), this, SLOT(thumbnailCreated(QUrl,QPixmap,QString)));
	}
	else if (identifier == SettingsManager::StartPage_BookmarksFolderOption || identifier == SettingsManager::StartPage_ShowAddTileOption)
	{
		reloadModel();
	}
}
Пример #10
0
/*
copy brush
*/
editorBrush::editorBrush(const editorBrush& brush) {
    isBox = brush.isBox;
    mins = brush.mins;
    maxs = brush.maxs;
    entType = 0;
    strncpy(steamid, brush.steamid, 32);
    if(brush.entType == 0) {
        faces = brush.faces;

        reloadModel();
    }
}
Пример #11
0
        void Variable::edit(const InputVariable* inputVariable) {
            variable->setMinimum(inputVariable->getMinimum());
            variable->setMaximum(inputVariable->getMaximum());
            for (int i = 0; i < inputVariable->numberOfTerms(); ++i) {
                this->variable->addTerm(inputVariable->getTerm(i)->copy());
            }
            scalar singleStep = (variable->getMaximum() - variable->getMinimum()) / 100;
            ui->sbx_min->setSingleStep(std::max(scalar(0.01), singleStep));
            ui->sbx_max->setSingleStep(std::max(scalar(0.01), singleStep));

            setWindowTitle("Edit variable");
            ui->led_name->setText(QString::fromStdString(inputVariable->getName()));
            ui->cbx_enabled->setChecked(inputVariable->isEnabled());
            reloadModel();
        }
Пример #12
0
        void Variable::onClickAddTerm() {
            Term* window = new Term(this);
            window->setup(*variable);
            if (window->exec()) {
                for (int i = variable->numberOfTerms() - 1; i >= 0; --i) {
                    delete variable->removeTerm(i);
                }

                for (int i = 0; i < window->dummyVariable->numberOfTerms(); ++i) {
                    variable->addTerm(window->dummyVariable->getTerm(i)->copy());
                }
                reloadModel();
            }
            delete window;
        }
Пример #13
0
MainWindow::MainWindow(Graph* graph, QWidget* parent)
    : QMainWindow(parent), ui(new Ui::MainWindow), graph_(graph) {
  ui->setupUi(this);

  scene = new QGraphicsScene(this);
  scene->setSceneRect(-1500, -1500, 3000, 3000);
  ui->graphicsView->setScene(scene);
  ui->graphicsView->setRenderHints(QPainter::Antialiasing);
  ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
  ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

  event_log.enable(*ui->txtLogView);

  reloadModel();
}
Пример #14
0
void MainWindow::on_actionOpen_triggered() {
  auto file = QFileDialog::getOpenFileName();

  if (!file.isNull()) {
    std::ifstream fs(file.toStdString());
    auto g = make_unique<Graph>();
    fs >> *g;

    if (fs) {
      graph_ = std::move(g);
      connectionVertex_ = -1;
      reloadModel();

      event_log << "Graph loaded";
    } else {
      event_log << "Error loading from file";
    }

  } else {
Пример #15
0
void MainWindow::on_actionRandomDirectedEdges_triggered() {
  // We can use pairs since they already handle comparisons properly.
  std::set<std::pair<int, int> > edges;

  for (auto& v : *graph_) {
    for (Edge& e : v.edges) {
      edges.insert(std::make_pair(e.from->value, e.to->value));
    }
  }

  for (auto& pair : edges) {
    if (rand() % 2 == 0) {
      graph_->toggle_edge(pair.first, pair.second);
    }
  }

  reloadModel();
  event_log << "Randomized edges";
}
Пример #16
0
/// isStart - true for start vertex, false for end vertex
void MainWindow::searchToggle(bool isStart) {
  VertexGraphicsItem* current = selectedVertex();

  if (current) {
    auto msg = QString("searchToggle(%1) on vertex %2")
                   .arg(isStart)
                   .arg(current->vertex->value);
    event_log << msg.toStdString();
    if (isStart) {
      graph_->set_start(current->vertex);
    } else {
      graph_->set_end(current->vertex);
    }

    reloadModel();
  } else {
    QMessageBox box;
    box.setText("Select a vertex to begin search.");
    box.exec();
  }
}
Пример #17
0
void MainWindow::on_actionMakeUndirected_triggered() {
  // We can use pairs since they already handle comparisons properly.
  std::set<std::pair<Vertex*, Vertex*> > edges;

  for (auto& v : *graph_) {
    for (Edge& e : v.edges) {
      edges.insert(std::make_pair(e.from, e.to));
    }
  }

  for (auto& pair : edges) {
    graph_->disconnect(pair.first->value, pair.second->value);
    auto& edge = graph_->connect(*pair.first, *pair.second);

    edge.oriented = false;
    edge.reverseEdge()->oriented = false;
  }

  reloadModel();
  event_log << "Removed orientation";
}
Пример #18
0
 void Variable::onClickMoveDown() {
     std::vector<int> newPositions;
     bool rotate = false;
     for (int i = ui->lvw_terms->count() - 1; i >= 0; --i) {
         if (ui->lvw_terms->item(i)->isSelected()) {
             int newPosition = i + 1 - rotate;
             if (newPosition >= ui->lvw_terms->count()) {
                 newPosition = 0;
                 newPositions.push_back(newPosition);
                 rotate = true;
             } else {
                 newPositions.push_back(newPosition + rotate);
             }
             fl::Term* term = variable->removeTerm(i);
             variable->insertTerm(term, newPosition);
         }
     }
     reloadModel();
     for (std::size_t i = 0; i < newPositions.size(); ++i) {
         ui->lvw_terms->item(newPositions[i])->setSelected(true);
     }
 }
Пример #19
0
void MainWindow::keyReleaseEvent(QKeyEvent* e) {
  switch (e->key()) {
    case Qt::Key_0:
      setEdgeWeight(0);
      break;
    case Qt::Key_1:
      setEdgeWeight(1);
      break;
    case Qt::Key_2:
      setEdgeWeight(2);
      break;
    case Qt::Key_3:
      setEdgeWeight(3);
      break;
    case Qt::Key_4:
      setEdgeWeight(4);
      break;
    case Qt::Key_5:
      setEdgeWeight(5);
      break;
    case Qt::Key_6:
      setEdgeWeight(6);
      break;
    case Qt::Key_7:
      setEdgeWeight(7);
      break;
    case Qt::Key_8:
      setEdgeWeight(8);
      break;
    case Qt::Key_9:
      setEdgeWeight(9);
      break;
    case Qt::Key_B:
      graph_->update_bridges();
      reloadModel();
    default:
      QMainWindow::keyReleaseEvent(e);
  }
}
Пример #20
0
        void Variable::onClickEditTerm() {
            if (ui->lvw_terms->selectedItems().size() > 1) {
                std::ostringstream message;
                message << "Do you want to edit the following terms?\n\n";
                for (int i = 0; i < ui->lvw_terms->count(); ++i) {
                    if (ui->lvw_terms->item(i)->isSelected()) {
                        message << "- " << variable->getTerm(i)->toString();
                        if (i + 1 < ui->lvw_terms->selectedItems().size()) message << "\n\n";
                    }
                }
                QMessageBox::StandardButton clicked = QMessageBox::information(this,
                        "Edit multiple terms",
                        QString::fromStdString(message.str()),
                        QMessageBox::Yes | QMessageBox::No,
                        QMessageBox::Yes);
                if (clicked == QMessageBox::No) {
                    return;
                }
            }

            bool reload = false;
            for (int i = 0; i < ui->lvw_terms->count(); ++i) {
                if (ui->lvw_terms->item(i)->isSelected()) {
                    Term* window = new Term(this);
                    window->setup(*variable, variable->getTerm(i));
                    if (window->exec()) {
                        reload |= true;
                        for (int t = variable->numberOfTerms() - 1; t >= 0; --t) {
                            delete variable->removeTerm(t);
                        }
                        for (int t = 0; t < window->dummyVariable->numberOfTerms(); ++t) {
                            variable->addTerm(window->dummyVariable->getTerm(t)->copy());
                        }
                    }
                    delete window;
                }
            }
            if (reload) reloadModel();
        }
Пример #21
0
void MainWindow::on_actionDelete_triggered() {
  if (scene->selectedItems().size() == 1) {
    QGraphicsItem* selectedItem = scene->selectedItems().at(0);

    if (VertexGraphicsItem* vgi =
            dynamic_cast<VertexGraphicsItem*>(selectedItem)) {
      if (connectionVertex_ == vgi->value()) {
        connectionVertex_ = -1;
      }

      graph_->remove_vertex(*vgi->vertex);
    } else if (EdgeGraphicsItem* egi =
                   dynamic_cast<EdgeGraphicsItem*>(selectedItem)) {
      auto from = egi->from;
      auto to = egi->to;

      graph_->disconnect(from->vertex->value, to->vertex->value);
    } else {
      qDebug() << "Trying to delete something unknown";
    }
  }

  reloadModel();
}
Пример #22
0
void MainWindow::on_actionNew_triggered() {
  graph_ = make_unique<Graph>();
  connectionVertex_ = -1;
  reloadModel();
  event_log << "New graph";
}
    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
    {
        osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
        if (!viewer) return false;

        switch(ea.getEventType())
        {
            case(osgGA::GUIEventAdapter::KEYUP):
            {
                bool handled = 0;
                if (ea.getKey()=='1')
                {
                    handled = decimateModel(1);
                }                
                else if (ea.getKey()=='2')
                {
                    handled = decimateModel(2);
                }                
                else if (ea.getKey()=='5')
                {
                    handled = decimateModel(5);
                }                
                else if (ea.getKey()=='d')
                {
                    handled = decimateModel(10);
                }                
                else if (ea.getKey()=='c')
                {
                    handled = decimateModel(100);
                }                
                else if (ea.getKey()=='k')
                {
                    handled = decimateModel(1000);
                }                
                else if (ea.getKey()=='y')
                {
                    handled = swapModels();
                }
                else if (ea.getKey()=='u')
                {
                    handled = stepbackModels();
                }
                else if (ea.getKey()=='r')
                {
                    osg::notify(osg::NOTICE)<<"Reloading original model"<<std::endl;
                    handled = reloadModel();
                }
                if (handled)
                {
                    if (_displayGroup == DISPLAY_LIVE)
                        setSceneData(viewer, _liveNode.get());
                    else if (_displayGroup == DISPLAY_STEPBACK)
                        setSceneData(viewer, _stepbackNode.get());
                    else
                        setSceneData(viewer, _copyNode.get());
               }
                return false;
            }

            default:
                return false;
        }
    }
Пример #24
0
void StartPageModel::reloadModel()
{
	const QString path(SettingsManager::getValue(SettingsManager::StartPage_BookmarksFolderOption).toString());

	m_bookmark = BookmarksManager::getModel()->getItem(path);

	if (!m_bookmark)
	{
		const QStringList directories(path.split(QLatin1Char('/'), QString::SkipEmptyParts));

		m_bookmark = BookmarksManager::getModel()->getRootItem();

		for (int i = 0; i < directories.count(); ++i)
		{
			bool hasFound(false);

			for (int j = 0; j < m_bookmark->rowCount(); ++j)
			{
				if (m_bookmark->child(j) && m_bookmark->child(j)->data(Qt::DisplayRole) == directories.at(i))
				{
					m_bookmark = dynamic_cast<BookmarksItem*>(m_bookmark->child(j));

					hasFound = true;

					break;
				}
			}

			if (!hasFound)
			{
				disconnect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));

				m_bookmark = BookmarksManager::getModel()->addBookmark(BookmarksModel::FolderBookmark, 0, QUrl(), directories.at(i), m_bookmark);

				connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));
			}
		}
	}

	clear();

	if (m_bookmark)
	{
		for (int i = 0; i < m_bookmark->rowCount(); ++i)
		{
			if (m_bookmark->child(i))
			{
				const BookmarksModel::BookmarkType type(static_cast<BookmarksModel::BookmarkType>(m_bookmark->child(i)->data(BookmarksModel::TypeRole).toInt()));

				if (type != BookmarksModel::UrlBookmark && type != BookmarksModel::FolderBookmark)
				{
					continue;
				}

				const quint64 identifier(m_bookmark->child(i)->data(BookmarksModel::IdentifierRole).toULongLong());
				const QUrl url(m_bookmark->child(i)->data(BookmarksModel::UrlRole).toUrl());
				QStandardItem *item(m_bookmark->child(i)->clone());
				item->setData(identifier, BookmarksModel::IdentifierRole);

				if (url.isValid() && SettingsManager::getValue(SettingsManager::StartPage_TileBackgroundModeOption) == QLatin1String("thumbnail") && !QFile::exists(SessionsManager::getWritableDataPath(QLatin1String("thumbnails/")) + QString::number(identifier) + QLatin1String(".png")))
				{
					m_reloads[url] = qMakePair(identifier, false);

					AddonsManager::getWebBackend()->requestThumbnail(url, QSize(SettingsManager::getValue(SettingsManager::StartPage_TileWidthOption).toInt(), SettingsManager::getValue(SettingsManager::StartPage_TileHeightOption).toInt()));
				}

				appendRow(item);
			}
		}
	}

	if (SettingsManager::getValue(SettingsManager::StartPage_ShowAddTileOption).toBool())
	{
		QStandardItem *item(new QStandardItem());
		item->setData(tr("Add Tile…"), Qt::ToolTipRole);
		item->setData(tr("Add Tile…"), Qt::StatusTipRole);
		item->setData(QLatin1String("add"), Qt::AccessibleDescriptionRole);
		item->setDragEnabled(false);
		item->setDropEnabled(false);

		appendRow(item);
	}

	emit modelModified();
}