~sachinr/xpad/xpad-qt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "padgroup.h"
#include<pad.h>
#include <QDir>
#include <QFile>
#include <QTextStream>

PadGroup::PadGroup()
{
    newPadIndex = 0;
}

void PadGroup::CreateNewPad()
{
    auto filename = QString("%1/%2").arg(directory).arg(newPadIndex);

    newPadWithInfo(filename);

    ++newPadIndex;
}

Pad* PadGroup::newPadWithInfo(QString filename)
{
    auto pad = new Pad();
    pad->setFilename(filename);
    padToFilenameMap[pad] = filename;
    pads.push_back(pad);
    return pad;
}

void PadGroup::SetDirectory(QString dir)
{
    directory = dir;
}

const list<Pad*>& PadGroup::GetPads()
{
    return pads;
}

void PadGroup::LoadPads()
{
    QDir dir(directory);
    dir.setFilter(QDir::Files);
    for (auto file : dir.entryInfoList())
    {
        auto absFilepath = file.absoluteFilePath();
        // update new pad index
        auto fileno = file.fileName().toInt();
        if (fileno > newPadIndex)
            newPadIndex = fileno;
        auto pad = newPadWithInfo(absFilepath);
        pad->loadFromFile();
    }
    ++newPadIndex;
}

PadGroup::~PadGroup()
{
    for(auto pad : pads)
    {
        delete pad;
    }
}