Skip to content

Commit

Permalink
Added possibility to create new player, places and drinks
Browse files Browse the repository at this point in the history
  • Loading branch information
Niclas Raabe committed Aug 7, 2014
1 parent 5303146 commit cd31450
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 3 deletions.
69 changes: 69 additions & 0 deletions src/ui/dialogs/placeinformationdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "placeinformationdialog.h"
#include "ui_placeinformationdialog.h"

#include <data/place.h>
#include <QPushButton>

PlaceInformationDialog::PlaceInformationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PlaceInformationDialog)
{
ui->setupUi(this);

ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

connect(ui->lineEditNumber, SIGNAL(editingFinished()), this, SLOT(checkData()));
connect(ui->lineEditPLZ, SIGNAL(editingFinished()), this, SLOT(checkData()));
connect(ui->lineEditStreet, SIGNAL(editingFinished()), this, SLOT(checkData()));
connect(ui->lineEditTown, SIGNAL(editingFinished()), this, SLOT(checkData()));
}

PlaceInformationDialog::~PlaceInformationDialog()
{
delete ui;
}

void PlaceInformationDialog::setPlace(QSharedPointer<Place> place)
{
m_place = place;
}

void PlaceInformationDialog::checkData()
{
if(ui->lineEditNumber->text() == "" || ui->lineEditPLZ->text() == "" || ui->lineEditStreet->text() == "" || ui->lineEditTown->text() == "") {
return;
}

bool ok = false;
ui->lineEditPLZ->text().toInt(&ok);
if(!ok)
return;

ok = false;
ui->lineEditNumber->text().toInt(&ok);
if(!ok)
return;

ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}

void PlaceInformationDialog::accept()
{
bool create = false;

if(!m_place) {
m_place = Qp::create<Place>();
create = true;
}

m_place->setCity(ui->lineEditTown->text());
m_place->setPostalCode(ui->lineEditPLZ->text().toInt());
m_place->setStreet(ui->lineEditStreet->text());
m_place->setHouseNumber(ui->lineEditNumber->text().toInt());


if(create)
emit placeAdded(m_place);

QDialog::accept();
}
35 changes: 35 additions & 0 deletions src/ui/dialogs/placeinformationdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef PLACEINFORMATIONDIALOG_H
#define PLACEINFORMATIONDIALOG_H

#include <QDialog>

class Place;

namespace Ui {
class PlaceInformationDialog;
}

class PlaceInformationDialog : public QDialog
{
Q_OBJECT

public:
explicit PlaceInformationDialog(QWidget *parent = 0);
~PlaceInformationDialog();

void setPlace(QSharedPointer<Place> place);

public slots:
void accept() Q_DECL_OVERRIDE;
void checkData();

signals:
void placeAdded(QSharedPointer<Place> place);

private:
Ui::PlaceInformationDialog *ui;

QSharedPointer<Place> m_place;
};

#endif // PLACEINFORMATIONDIALOG_H
106 changes: 106 additions & 0 deletions src/ui/dialogs/placeinformationdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PlaceInformationDialog</class>
<widget class="QDialog" name="PlaceInformationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>452</width>
<height>133</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Street:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditStreet">
<property name="placeholderText">
<string>Street</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="lineEditNumber">
<property name="placeholderText">
<string>Number</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Town:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditPLZ">
<property name="placeholderText">
<string>PLZ</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="lineEditTown">
<property name="placeholderText">
<string>Town</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PlaceInformationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PlaceInformationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
8 changes: 8 additions & 0 deletions src/ui/dialogs/playerinformationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,13 @@ void PlayerInformationDialog::saveCurrentPlayer()

void PlayerInformationDialog::on_actionClose_triggered()
{
if(!m_model) { // new player was created
Qp::remove(m_player);
}
close();
}

void PlayerInformationDialog::on_buttonBox_rejected()
{
on_actionClose_triggered();
}
5 changes: 3 additions & 2 deletions src/ui/dialogs/playerinformationdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PlayerInformationDialog : public QDialog

QSharedPointer<Player> player() const;
void setPlayerFromModel(QpSortFilterProxyObjectModel<Player> *model, int index);
void setPlayer(const QSharedPointer<Player> &player);

public slots:
void accept();
Expand All @@ -33,9 +34,9 @@ public slots:
private slots:
void on_actionClose_triggered();

private:
void setPlayer(const QSharedPointer<Player> &player);
void on_buttonBox_rejected();

private:
Ui::PlayerInformationDialog *ui;

int m_currentIndex;
Expand Down
7 changes: 7 additions & 0 deletions src/ui/game/gamewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ui/widgets/playerslistwidget.h>
#include <ui/widgets/menubar.h>
#include <ui/widgets/popupwidget.h>
#include <ui/dialogs/drinkinformationdialog.h>
#include <data/game.h>
#include <data/place.h>
#include <ui/model/gameoverviewmodel.h>
Expand Down Expand Up @@ -589,3 +590,9 @@ void GameWindow::on_actionZoom_out_triggered()
m_informationModel->setFontSize(m_informationModel->fontSize() - 1);
updateSizes();
}

void GameWindow::on_actionNew_Drink_triggered()
{
DrinkInformationDialog dlg;
dlg.exec();
}
2 changes: 2 additions & 0 deletions src/ui/game/gamewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private slots:

void on_actionZoom_out_triggered();

void on_actionNew_Drink_triggered();

private:
Ui::GameWindow *ui;

Expand Down
6 changes: 6 additions & 0 deletions src/ui/game/gamewindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ QWidget#widgetCreateGame {
<property name="title">
<string>File</string>
</property>
<addaction name="actionNew_Drink"/>
<addaction name="actionStats"/>
<addaction name="actionSettings"/>
<addaction name="actionCheck_for_updates"/>
Expand Down Expand Up @@ -635,6 +636,11 @@ QWidget#widgetCreateGame {
<string>Ctrl+-</string>
</property>
</action>
<action name="actionNew_Drink">
<property name="text">
<string>New Drink</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
23 changes: 23 additions & 0 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "dialogs/playerinformationdialog.h"
#include "dialogs/drinkinformationdialog.h"
#include "dialogs/placeinformationdialog.h"
#include "game/gamewindow.h"
#include "chooselibrarywidget.h"
#include "ui/league/addleaguedialog.h"
Expand Down Expand Up @@ -335,3 +336,25 @@ void MainWindow::on_actionCheck_for_updates_triggered()
{
Updater::instanceForPlatform()->checkForUpdatesInBackground();
}

void MainWindow::on_actionNew_Player_triggered()
{
QSharedPointer<Player> newPlayer = Qp::create<Player>();
newPlayer->setName("NewPlayer");

PlayerInformationDialog dialog;
dialog.setPlayer(newPlayer);
dialog.exec();
}

void MainWindow::on_actionNew_Place_triggered()
{
PlaceInformationDialog dialog;
dialog.exec();
}

void MainWindow::on_actionNew_Drink_triggered()
{
DrinkInformationDialog dialog;
dialog.exec();
}
8 changes: 7 additions & 1 deletion src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ private slots:

void on_actionCheck_for_updates_triggered();

signals:
void on_actionNew_Player_triggered();

void on_actionNew_Place_triggered();

void on_actionNew_Drink_triggered();

signals:
void photosAdded();

private:
Expand Down
18 changes: 18 additions & 0 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ border-bottom: 1px solid rgb(77,77,77);
</property>
<addaction name="actionNew_Game"/>
<addaction name="actionNew_League"/>
<addaction name="actionNew_Player"/>
<addaction name="actionNew_Place"/>
<addaction name="actionNew_Drink"/>
<addaction name="actionAdd_Photos"/>
<addaction name="actionInformation"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -695,6 +698,21 @@ border-bottom: 1px solid rgb(77,77,77);
<string>Check for updates...</string>
</property>
</action>
<action name="actionNew_Player">
<property name="text">
<string>New Player</string>
</property>
</action>
<action name="actionNew_Place">
<property name="text">
<string>New Place</string>
</property>
</action>
<action name="actionNew_Drink">
<property name="text">
<string>New Drink</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down

0 comments on commit cd31450

Please sign in to comment.