コード例 #1
0
void RecipeWidget::save(QString filepath)
{

    if(!filepath.isEmpty()) {
        setWindowFilePath(filepath);
    } else if(!isWindowModified()) {
        return;     // Don't do anything if the file would be the same
    }


    QDomDocument document("Recipe");
    document.appendChild(recipe()->toXml(document));

    if(windowFilePath().isEmpty()) {
        throw tr("File path is not valid");
    }
    QFile file(windowFilePath());

    if(!file.open(QIODevice::WriteOnly)) {
        throw tr("Failed to open ingredients file");
    }

    file.write(document.toString().toLatin1());
    file.flush();
    file.close();

    setWindowModified(false);
    refreshText();
    emit changed();
}
コード例 #2
0
ファイル: BtTreeModel.cpp プロジェクト: kscottj/brewtarget
void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied)
{
   while ( ! toBeCopied.isEmpty() ) 
   {
      QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst();
      QModelIndex ndx = thisPair.first;
      QString name = thisPair.second;

      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Equipment *copyKit,  *oldKit;
            oldKit = equipment(ndx);
            copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy.
            copyKit->setName(name);
            break;
         case BtTreeItem::FERMENTABLE:
            Fermentable *copyFerm, *oldFerm;
            oldFerm = fermentable(ndx);
            copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy.
            copyFerm->setName(name);
            break;
         case BtTreeItem::HOP:
            Hop *copyHop,  *oldHop;
            oldHop = hop(ndx);
            copyHop = Database::instance().newHop(oldHop); // Create a deep copy.
            copyHop->setName(name);
            break;
         case BtTreeItem::MISC:
            Misc *copyMisc, *oldMisc;
            oldMisc = misc(ndx);
            copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy.
            copyMisc->setName(name);
            break;
         case BtTreeItem::RECIPE:
            Recipe *copyRec,  *oldRec;
            oldRec = recipe(ndx);
            copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy.
            copyRec->setName(name);
            break;
         case BtTreeItem::STYLE:
            Style *copyStyle, *oldStyle;
            oldStyle = style(ndx);
            copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy.
            copyStyle->setName(name);
            break;
         case BtTreeItem::YEAST:
            Yeast *copyYeast, *oldYeast;
            oldYeast = yeast(ndx);
            copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy.
            copyYeast->setName(name);
            
            break;
         default:
            Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx)));
      }
   }
}
コード例 #3
0
ファイル: settingstest.cpp プロジェクト: giucam/ssu
void SettingsTest::testUpgrade_data(){
  // Read recipe
  QFile recipe(":/testdata/upgrade/recipe");
  QVERIFY(recipe.open(QIODevice::ReadOnly));
  QList<UpgradeTestHelper::TestCase> testCases = UpgradeTestHelper::readRecipe(&recipe);

  // Generate settings file according to recipe
  QTemporaryFile settingsFile;
  QVERIFY(settingsFile.open() == true);

  QSettings settings(settingsFile.fileName(), QSettings::IniFormat);

  UpgradeTestHelper::fillSettings(&settings, testCases);

  // Generate defaults file according to recipe
  QTemporaryFile defaultSettingsFile;
  QVERIFY(defaultSettingsFile.open() == true);

  QSettings defaultSettings(defaultSettingsFile.fileName(), QSettings::IniFormat);

  UpgradeTestHelper::fillDefaultSettings(&defaultSettings, testCases);

  // Parse settings -- do upgrade
#if 0
  settingsFile.seek(0);
  defaultSettingsFile.seek(0);
  qDebug() << "SETTINGS {{{\n" << settingsFile.readAll() << "\n}}}";
  qDebug() << "DEFAULT SETTINGS {{{\n" << defaultSettingsFile.readAll() << "\n}}}";
#endif

  SsuSettings ssuSettings(settingsFile.fileName(), QSettings::IniFormat,
      defaultSettingsFile.fileName());

#if 0
  settingsFile.seek(0);
  qDebug() << "SETTINGS UPGRADED {{{\n" << settingsFile.readAll() << "\n}}}";
#endif

  // Record data for verification phase
  QTest::addColumn<bool>("keyIsSet");
  QTest::addColumn<bool>("keyShouldBeSet");
  QTest::addColumn<QString>("actualValue");
  QTest::addColumn<QString>("expectedValue");

  foreach (const UpgradeTestHelper::TestCase &testCase, testCases){
    foreach (const QString &group, UpgradeTestHelper::groups()){
      const QString key = group.isEmpty() ? testCase.key() : group + '/' + testCase.key();
      QTest::newRow(qPrintable(QString("%1%2:%3:%4")
          .arg(group.isEmpty() ? "" : group + "/")
          .arg(testCase.history())
          .arg(testCase.current())
          .arg(testCase.expected())))
        << ssuSettings.contains(key)
        << testCase.keyShouldBeSet()
        << ssuSettings.value(key).toString()
        << testCase.expected();
    }
  }
コード例 #4
0
ファイル: inventory.cpp プロジェクト: madcad/mineserver
bool Inventory::addRecipe(int width, int height, std::vector<ItemPtr> inputrecipe, int outputCount, int16_t outputType, int16_t outputHealth)
{
  RecipePtr recipe(new Recipe);

  recipe->width  = width;
  recipe->height = height;
  recipe->output.setCount(outputCount);
  recipe->output.setType(outputType);
  recipe->output.setHealth(outputHealth);
  recipe->slots = inputrecipe;

  recipes.push_back(recipe);

  return true;
}
コード例 #5
0
void BtTreeModel::deleteSelected(QModelIndexList victims)
{
   QModelIndexList toBeDeleted = victims; // trust me

   while ( ! toBeDeleted.isEmpty() ) 
   {
      QModelIndex ndx = toBeDeleted.takeFirst();
      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Database::instance().remove( equipment(ndx) );
            break;
         case BtTreeItem::FERMENTABLE:
            Database::instance().remove( fermentable(ndx) );
            break;
         case BtTreeItem::HOP:
            Database::instance().remove( hop(ndx) );
            break;
         case BtTreeItem::MISC:
            Database::instance().remove( misc(ndx) );
            break;
         case BtTreeItem::RECIPE:
            Database::instance().remove( recipe(ndx) );
            break;
         case BtTreeItem::STYLE:
            Database::instance().remove( style(ndx) );
            break;
         case BtTreeItem::YEAST:
            Database::instance().remove( yeast(ndx) );
            break;
         case BtTreeItem::BREWNOTE:
            Database::instance().remove( brewNote(ndx) );
            break;
         case BtTreeItem::FOLDER:
            // This one is weird.
            toBeDeleted += allChildren(ndx);
            removeFolder(ndx);
            break;
         default:
            Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx)));
      }
   }
}
コード例 #6
0
void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied)
{
   bool failed = false;
   while ( ! toBeCopied.isEmpty() ) 
   {
      QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst();
      QModelIndex ndx = thisPair.first;
      QString name = thisPair.second;

      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Equipment *copyKit,  *oldKit;
            oldKit = equipment(ndx);
            copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy.
            if ( copyKit) 
               copyKit->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::FERMENTABLE:
            Fermentable *copyFerm, *oldFerm;
            oldFerm = fermentable(ndx);
            copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy.
            if ( copyFerm )
               copyFerm->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::HOP:
            Hop *copyHop,  *oldHop;
            oldHop = hop(ndx);
            copyHop = Database::instance().newHop(oldHop); // Create a deep copy.
            if ( copyHop )
               copyHop->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::MISC:
            Misc *copyMisc, *oldMisc;
            oldMisc = misc(ndx);
            copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy.
            if ( copyMisc )
               copyMisc->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::RECIPE:
            Recipe *copyRec,  *oldRec;
            oldRec = recipe(ndx);
            copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy.
            if ( copyRec )
               copyRec->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::STYLE:
            Style *copyStyle, *oldStyle;
            oldStyle = style(ndx);
            copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy.
            if ( copyStyle )
               copyStyle->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::YEAST:
            Yeast *copyYeast, *oldYeast;
            oldYeast = yeast(ndx);
            copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy.
            if ( copyYeast )
               copyYeast->setName(name);
            else 
               failed = true;
            break;
         default:
            Brewtarget::logW(QString("copySelected:: unknown type %1").arg(type(ndx)));
      }
      if ( failed ) {
         QMessageBox::warning(0,
                              tr("Could not copy"), 
                              tr("There was an unexpected error creating %1").arg(name));
         return;
      }
   }
}
コード例 #7
0
void RecipeWidget::print(QPrinter *printer)
{
    //FIXME: This is obviously clunky code. Clean this up and modularize it.  A stylesheet would also be nice.

    QTextDocument document(this);
    QDomDocument xhtml("PrintRecipe");
    xhtml.appendChild(xhtml.createElement("html"));
    xhtml.firstChild().appendChild(xhtml.createElement("head"));

    QDomElement bodyElement = xhtml.createElement("body");
    xhtml.firstChild().appendChild(bodyElement);

    QDomElement element = xhtml.createElement("h1");
    element.appendChild(xhtml.createTextNode(recipe()->name()));
    bodyElement.appendChild(element);

    /* BEGIN Properties */
    element = xhtml.createElement("h3");
    element.appendChild(xhtml.createTextNode("Properties"));
    bodyElement.appendChild(element);

    element = xhtml.createElement("p");
    element.appendChild(xhtml.createTextNode(QString("Style: %1").arg(recipe()->style())));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Volume: %1").arg(recipe()->volume().toString())));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Boil time: %1 minutes").arg(recipe()->boilTime())));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Efficiency: %1%").arg(recipe()->efficiency() * 100)));
    element.appendChild(xhtml.createElement("br"));
    bodyElement.appendChild(element);
    /* END Properties */

    /* BEGIN Calculated */
    element = xhtml.createElement("h3");
    element.appendChild(xhtml.createTextNode("Calculated"));
    bodyElement.appendChild(element);

    element = xhtml.createElement("p");
    element.appendChild(xhtml.createTextNode(QString("Original gravity: %1").arg(recipe()->originalGravity(), 0, 'f', 3)));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Final Gravity: %1").arg(recipe()->finalGravity(), 0, 'f', 3)));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Bitterness: %1 IBU").arg(recipe()->bitterness(), 0, 'f', 0)));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("Color: %1 SRM").arg(recipe()->color(), 0, 'f', 1)));
    element.appendChild(xhtml.createElement("br"));
    element.appendChild(xhtml.createTextNode(QString("ABV: %1%").arg(recipe()->alcoholByVolume() * 100, 0, 'f', 1)));
    element.appendChild(xhtml.createElement("br"));
    bodyElement.appendChild(element);
    /* END Calculated */

    /* BEGIN Ingredients */
    element = xhtml.createElement("h3");
    element.appendChild(xhtml.createTextNode("Ingredients"));
    bodyElement.appendChild(element);

    element = xhtml.createElement("p");
    foreach(RecipeIngredient *recipeIngredient, recipe()->ingredients()) {

        QString ingredientText = QString("%1 - %2").arg(recipeIngredient->name()).arg(recipeIngredient->quantity().toString());
        if(recipeIngredient->minutes() > 0)
            ingredientText += QString(" @ %1 minutes").arg(recipeIngredient->minutes(), 0, 'f', 0);

        element.appendChild(xhtml.createTextNode(ingredientText));
        element.appendChild(xhtml.createElement("br"));
    }
コード例 #8
0
        QString ingredientText = QString("%1 - %2").arg(recipeIngredient->name()).arg(recipeIngredient->quantity().toString());
        if(recipeIngredient->minutes() > 0)
            ingredientText += QString(" @ %1 minutes").arg(recipeIngredient->minutes(), 0, 'f', 0);

        element.appendChild(xhtml.createTextNode(ingredientText));
        element.appendChild(xhtml.createElement("br"));
    }
    bodyElement.appendChild(element);
    /* END Ingredients */

    /* BEGIN Notes */
    element = xhtml.createElement("h3");
    element.appendChild(xhtml.createTextNode("Notes"));
    bodyElement.appendChild(element);
    element = xhtml.createElement("p");
    foreach(QString note, recipe()->notes().split('\n')) {
        element.appendChild(xhtml.createTextNode(note));
        element.appendChild(xhtml.createElement("br"));
    }
    bodyElement.appendChild(element);
    /* END Notes */


    /*** BEGIN Process ***/
    element = xhtml.createElement("h2");
    element.appendChild(xhtml.createTextNode("Process"));
    element.setAttribute("style", "page-break-before: always;");
    bodyElement.appendChild(element);

    /* BEGIN Process - Mash */
    element = xhtml.createElement("h3");
コード例 #9
0
ファイル: main.cpp プロジェクト: BourgondAries/MLB-FiM
int main() {
	sf::RectangleShape backGround;
	sf::Event event;
	sf::Font font;
	sf::RenderWindow window;
	sf::Sprite screenS;

	Comchan communicator;
	initComchanMolars(communicator);

	char selection = (char)0;
	usize menu_item_count = 7;
	sf::Text menu[menu_item_count];
	sf::Texture backy, banny;
	sf::Sprite backys, bannys;
	font.loadFromFile("visitor1.ttf");

	About about(window, font);
	Economy economy(window, font, communicator);
	Recipe recipe(window, font, communicator, backGround);
	Product product(window, font, communicator, backGround);
	Save save(window, font, communicator);
	std::cout << "Before loop: " << communicator.sucroseEoC << std::endl;
	Load load(window, font, communicator);

	backy.loadFromFile("data/menu0.png"); banny.loadFromFile("data/menu1.png");
	backys.setTexture(backy); bannys.setTexture(banny);
	bannys.setPosition(200,0);
	menu[0].setString("Recipe"); menu[1].setString("Product"); menu[2].setString("Economy"); menu[3].setString("Load"); menu[4].setString("Save"); menu[5].setString("About"); menu[6].setString("Exit");
	menu[0].setCharacterSize(20);
	menu[0].setFont(font);
	menu[0].setColor(sf::Color(127,127,127));
	menu[0].setPosition(sf::Vector2f(800 / 2 - (int)menu[0].getGlobalBounds().width / 2, 400));
	for (int i = 1; i < menu_item_count; i++)
	{
		menu[i].setCharacterSize(20);
		menu[i].setFont(font);
		menu[i].setColor(sf::Color(127,127,127));
		menu[i].setPosition(sf::Vector2f(800 / 2. - (int)menu[i].getGlobalBounds().width / 2, menu[i-1].getPosition().y + 20));
	}
	menu[0].setColor(sf::Color(255,255,255));
	window.setFramerateLimit(30);
	window.create(sf::VideoMode(800,600,32), "My Little Brew : Fermentation is Magic", sf::Style::Default);
	window.clear();
	window.draw(backys);
	window.draw(backGround);
	for (int i = 0; i < menu_item_count; i++)
		window.draw(menu[i]);
	window.draw(bannys);
	window.display();
	window.setIcon(beer.width, beer.height, beer.pixel_data);
	while (window.isOpen())
	{
		invalid:
		if (window.waitEvent(event))
		{
			switch (event.type)
			{
				case sf::Event::KeyPressed:
					switch (event.key.code)
					{
						case sf::Keyboard::Up: case sf::Keyboard::I:
							menu[(int)selection].setColor(sf::Color(127,127,127));
							if (selection == (char) 0)
								selection = (char) 6;
							else
								selection--;
							menu[(int)selection].setColor(sf::Color(255,255,255));
							break;
						case sf::Keyboard::Down: case sf::Keyboard::K:
							menu[(int)selection].setColor(sf::Color(127,127,127));
							if (selection == (char) 6)
								selection = (char) 0;
							else
								selection++;
							menu[(int)selection].setColor(sf::Color(255,255,255));
							break;
						case sf::Keyboard::Return:
							switch ((int)selection)
							{
								case 0:
									if (recipe.enter() == 1)
										return 0;
									break;
								case 1:
									if (product.enter() == 1)
										return 0;
									break;
								case 2:
									if (economy.enter(backGround) == 1)
										return 0;
									break;
								case 3:
									{
										window.clear();
										window.draw(backys);
										window.draw(backGround);
										for (int i = 0; i < menu_item_count; i++)
											window.draw(menu[i]);
										window.draw(bannys);
										window.display();

										sf::Image screen = window.capture();
										sf::Texture screenT; screenT.loadFromImage(screen);
										screenS.setTexture(screenT);
										if (load.enter(screenS) == 1)
											return 0;
									}
									break;
								case 4:
									{
										window.clear();
										window.draw(backys);
										window.draw(backGround);
										for (int i = 0; i < menu_item_count; i++)
											window.draw(menu[i]);
										window.draw(bannys);
										window.display();

										sf::Image screen = window.capture();
										sf::Texture screenT; screenT.loadFromImage(screen);
										screenS.setTexture(screenT);
										if (save.enter(screenS) == 1)
											return 0;
									}
									break;
								case 6:
									window.close();
									return 0;
									break;
								default:
								{
									window.clear();
									window.draw(backys);
									window.draw(backGround);
									for (int i = 0; i < menu_item_count; i++)
										window.draw(menu[i]);
									window.draw(bannys);
									window.display();

									sf::Image screen = window.capture();
									sf::Texture screenT; screenT.loadFromImage(screen);
									screenS.setTexture(screenT);
									if (about.enter(screenS) == 1)
										return 0;
								}
									break;
							}
							break;
						case sf::Keyboard::Escape:
							window.close();
							return 0;
						case sf::Keyboard::L:
						{
							window.clear();
							window.draw(backys);
							window.draw(backGround);
							for (int i = 0; i < menu_item_count; i++)
								window.draw(menu[i]);
							window.draw(bannys);
							window.display();

							sf::Image screen = window.capture();
							sf::Texture screenT; screenT.loadFromImage(screen);
							screenS.setTexture(screenT);
							load.enter(screenS);
						}
							break;
						case sf::Keyboard::S:
						{
							window.clear();
							window.draw(backys);
							window.draw(backGround);
							for (int i = 0; i < menu_item_count; i++)
								window.draw(menu[i]);
							window.draw(bannys);
							window.display();

							sf::Image screen = window.capture();
							sf::Texture screenT; screenT.loadFromImage(screen);
							screenS.setTexture(screenT);
							save.enter(screenS);
						}
							break;
						default: ;
					}
					break;
				case sf::Event::Closed:
					window.close();
					return 0;
				default: goto invalid;
			}
		}
		window.clear();
		window.draw(backys);
		window.draw(backGround);
		for (int i = 0; i < menu_item_count; i++)
			window.draw(menu[i]);
		window.draw(bannys);
		window.display();
	}
	return 0;
}