RemovePlayer::RemovePlayer(Score &score, int index)
    : QUndoCommand(QObject::tr("Remove Player")),
      myScore(score),
      myPlayer(score.getPlayers()[index]),
      myPlayerIndex(index)
{
}
AddPlayer::AddPlayer(Score &score, const Player &player)
    : QUndoCommand(QObject::tr("Add Player")),
      myScore(score),
      myPlayer(player),
      myPlayerIndex(score.getPlayers().size())
{
}
PlayerChangeDialog::PlayerChangeDialog(QWidget *parent, const Score &score,
                                       const System &system,
                                       const PlayerChange *currentPlayers)
    : QDialog(parent),
      ui(new Ui::PlayerChangeDialog)
{
    ui->setupUi(this);

    const int spacing = 12;

    // Set up title row.
    auto titleLayout = new QHBoxLayout();
    titleLayout->addWidget(new QLabel(tr("Staff")));
    titleLayout->addWidget(new QLabel(tr("Instrument")));
    titleLayout->setSpacing(spacing * 4);
    ui->formLayout->addRow(tr("Player"), titleLayout);

    for (const Player &player : score.getPlayers())
    {
        const int numStrings = player.getTuning().getStringCount();

        auto layout = new QHBoxLayout();
        layout->setSpacing(spacing);
        layout->addWidget(getStaffComboBox(numStrings, system));
        layout->addWidget(getInstrumentComboBox(score));

        ui->formLayout->addRow(
                    QString::fromStdString(player.getDescription() + ":"),
                    layout);
    }

    // Initialize the dialog with the current staff/instrument for each player.
    if (currentPlayers)
    {
        for (int staff = 0; staff < system.getStaves().size(); ++staff)
        {
            std::vector<ActivePlayer> players =
                    currentPlayers->getActivePlayers(staff);

            for (const ActivePlayer &player : players)
            {
                const int i = player.getPlayerNumber();
                myStaffComboBoxes.at(i)->setCurrentIndex(
                            myStaffComboBoxes.at(i)->findData(staff));
                myInstrumentComboBoxes.at(i)->setCurrentIndex(
                            player.getInstrumentNumber());
            }
        }
    }

    ui->formLayout->setFieldGrowthPolicy(QFormLayout::FieldsStayAtSizeHint);
}
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
  
#include <catch.hpp>

#include <actions/addplayer.h>
#include <score/score.h>

TEST_CASE("Actions/AddPlayer", "")
{
    Score score;
    Player player;
    player.setDescription("Test Player");

    AddPlayer action(score, player);

    action.redo();
    REQUIRE(score.getPlayers().size() == 1);
    REQUIRE(score.getPlayers()[0] == player);

    action.undo();
    REQUIRE(score.getPlayers().size() == 0);
}