Контейнер вместо массива

Можете подсказать: как изменить код, чтобы ипользовать для хранения данных контейнер вместо массива - при любом обходе контейнера использовать итераторы ( итератор java ); И, если можно, то как провести разделение классов модели и вида?

Код:

#include "QtGuiApplication2.h"
#include <QMessageBox>
#include <QHeaderView>
#include "QDate"
#include "TABL.h"
TABL tmp;

QtGuiApplication2::QtGuiApplication2(QWidget* parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    connect(ui.pb_save, SIGNAL(clicked()), this, SLOT(btn_save()));                     //Save button
    connect(ui.pb_back, SIGNAL(clicked()), this, SLOT(btn_back()));                     //Back button
    connect(ui.pb_create, SIGNAL(clicked()), this, SLOT(btn_create()));
    connect(ui.pb_change, SIGNAL(clicked()), this, SLOT(btn_change()));
    connect(ui.pb_delete, SIGNAL(clicked()), this, SLOT(btn_delete()));

    connect(ui.le_FIO, SIGNAL(editingFinished()), this, SLOT(FIO_change()));            // reaction on changes
    connect(ui.de_birth,SIGNAL(dateChanged(const QDate)), this, SLOT(date_change()));
    connect(ui.cb_pol, SIGNAL(currentIndexChanged(const int)), this, SLOT(pol_change()));
    connect(ui.cb_study, SIGNAL(currentIndexChanged(const int)), this, SLOT(study_change()));
    connect(ui.cb_prof, SIGNAL(currentIndexChanged(const int)), this, SLOT(prof_change()));
    connect(ui.chb_in_inv, SIGNAL(toggled(bool)), this, SLOT(ininv_change()));
    connect(ui.cb_inv, SIGNAL(currentIndexChanged(const int)), this, SLOT(inv_change()));
    connect(ui.spb_price, SIGNAL(valueChanged(int)), this, SLOT(price_change()));
    connect(ui.spb_stah, SIGNAL(valueChanged(int)), this, SLOT(stah_change()));
    connect(ui.le_adress, SIGNAL(editingFinished()), this, SLOT(adress_change()));

    connect(ui.tabWidget_data, SIGNAL(itemSelectionChanged()), this, SLOT(datarow_change()));
    connect(ui.Redact_group, SIGNAL(toggled(bool)), this, SLOT(groupbox_enabled()));

    connect(ui.action_10, SIGNAL(triggered(bool)), this, SLOT(addten_records()));
    //Добавить триггер для красоты когда меняю ячейку справа все меняется 

    QDate dateToday = QDate::currentDate();
    ui.de_birth->setMinimumDate(dateToday.addYears(-60));
    ui.de_birth->setMaximumDate(dateToday.addYears(-16));

    count = 0;

    // Запрет на редактирование ячеек хехех 
    ui.tabWidget_data->setEditTriggers(QAbstractItemView::NoEditTriggers);


    tmp.get_fio(ui.le_FIO->text());
    tmp.get_age(ui.de_birth->date());
    tmp.get_pol(ui.cb_pol->currentIndex());
    tmp.get_study(ui.cb_study->currentIndex());
    tmp.get_prof(ui.cb_prof->currentIndex());
    tmp.get_in_inv(ui.chb_in_inv->isChecked());
    tmp.get_inv(ui.cb_inv->currentIndex());
    tmp.get_price(ui.spb_price->text());
    tmp.get_stah(ui.spb_stah->text());
    tmp.get_adress(ui.le_adress->text());

}


void QtGuiApplication2::btn_save() {            //Pressed button save
    if (ui.le_FIO->text().isEmpty()) return;

    if (ui.le_FIO->text().split(" ").size() < 2 || ui.le_FIO->text().split(" ")[1].size() == 0)
        return;
    if (ui.le_FIO->text().split(" ").size() == 3) {
        if (ui.le_FIO->text().split(" ")[2].size() == 0)
            return;
    }

    database[current_count].set_param(tmp);

    Form_Activity(false);

    sorting();

    datarow_change();

}

void QtGuiApplication2::btn_back() {                //Pressed button back
    if (ui.tabWidget_data->currentRow() == count - 1 && database[count - 1].FIO.isEmpty())
    {
        ui.tabWidget_data->removeRow(count - 1);
        count--;
    }

    ui.le_FIO->setText(database[current_count].FIO);
    ui.de_birth->setDate(database[current_count].Date);
    ui.cb_pol->setCurrentIndex(database[current_count].Pol);
    ui.cb_study->setCurrentIndex(database[current_count].Study);
    ui.cb_prof->setCurrentIndex(database[current_count].Prof);
    ui.cb_inv->setCurrentIndex(database[current_count].Inv);
    ui.spb_price->setValue(database[current_count].Price.toInt());
    ui.chb_in_inv->setChecked(database[current_count].InInv);
    ui.spb_stah->setValue(database[current_count].Stah.toInt());
    ui.le_adress->setText(database[current_count].Adress);

    Form_Activity(false);
}

void QtGuiApplication2::btn_create() {  //Pressed button create 

    if (count >= 100) { ui.pb_create->setEnabled(false); return; }

    count++;
    current_count = count - 1;

    ui.tabWidget_data->setRowCount(count);

    QTableWidgetItem* item;

    ui.spb_stah->setEnabled(true);
    ui.tabWidget_data->setCurrentCell(current_count, 0);
    Form_Activity(true);
    Standart_view();
}

void QtGuiApplication2::btn_change()
{
    if (count < 1) return;
    current_count = ui.tabWidget_data->currentRow();

    tmp.get_fio(ui.le_FIO->text());
    tmp.get_age(ui.de_birth->date());
    tmp.get_pol(ui.cb_pol->currentIndex());
    tmp.get_study(ui.cb_study->currentIndex());
    tmp.get_prof(ui.cb_prof->currentIndex());
    tmp.get_in_inv(ui.chb_in_inv->isChecked());
    tmp.get_inv(ui.cb_inv->currentIndex());
    tmp.get_price(ui.spb_price->text());
    tmp.get_stah(ui.spb_stah->text());
    tmp.get_adress(ui.le_adress->text());

    Form_Activity(true);
}

void QtGuiApplication2::btn_delete()
{
    if (count + 10 < 100) {
        ui.action_10->setEnabled(true);
        ui.pb_create->setEnabled(true);
    }
    else if (count < 100) ui.pb_create->setEnabled(true);
    if (count < 1) return;

    current_count = ui.tabWidget_data->currentRow();


    if (count > 1) {

        for (int ix = current_count; ix < count; ix++) {
            database[ix] = database[ix + 1];
        }

        int some = current_count;
        ui.tabWidget_data->removeRow(current_count);

        if (some == count - 1)
            ui.tabWidget_data->selectRow(current_count);
        else if (some == 0)
            ui.tabWidget_data->selectRow(current_count - 1);
        else
            ui.tabWidget_data->selectRow(current_count + 1);
    }
    else {
        ui.tabWidget_data->removeRow(current_count);
        Standart_view();
    }
    count--;
    if (count < 1) {
        ui.pb_delete->setEnabled(false);
        ui.pb_change->setEnabled(false);
    }

}


void QtGuiApplication2::FIO_change() {
    tmp.get_fio(ui.le_FIO->text());
}
void QtGuiApplication2::date_change() {
    tmp.get_age(ui.de_birth->date());
}
void QtGuiApplication2::pol_change() {
    tmp.get_pol(ui.cb_pol->currentIndex());
}
void QtGuiApplication2::study_change()
{
    tmp.get_study(ui.cb_study->currentIndex());
}
void QtGuiApplication2::stah_change() {
    tmp.get_stah(ui.spb_stah->text());
}
void QtGuiApplication2::prof_change()
{
    tmp.get_prof(ui.cb_prof->currentIndex());
}
void QtGuiApplication2::ininv_change() {
    tmp.get_in_inv(ui.chb_in_inv->isChecked());
}
void QtGuiApplication2::inv_change()
{
    tmp.get_inv(ui.cb_inv->currentIndex());
}
void QtGuiApplication2::price_change() {
    tmp.get_price(ui.spb_price->text());
}
void QtGuiApplication2::adress_change() {
    tmp.get_adress(ui.le_adress->text());
}

void QtGuiApplication2::datarow_change()
{
    if (count == 1 || count == 0) return;
    current_count = ui.tabWidget_data->currentRow();
    ui.le_FIO->setText(database[current_count].FIO);
    ui.de_birth->setDate(database[current_count].Date);
    ui.cb_pol->setCurrentIndex(database[current_count].Pol);
    ui.cb_study->setCurrentIndex(database[current_count].Study);
    ui.cb_prof->setCurrentIndex(database[current_count].Prof);
    ui.cb_inv->setCurrentIndex(database[current_count].Inv);
    ui.spb_price->setValue(database[current_count].Price.toInt());
    ui.chb_in_inv->setChecked(database[current_count].InInv);
    ui.spb_stah->setValue(database[current_count].Stah.toInt());
    ui.le_adress->setText(database[current_count].Adress);
}

void QtGuiApplication2::groupbox_enabled()
{
    tmp.get_fio(ui.le_FIO->text());
    tmp.get_age(ui.de_birth->date());
    tmp.get_pol(ui.cb_pol->currentIndex());
    tmp.get_study(ui.cb_study->currentIndex());
    tmp.get_prof(ui.cb_prof->currentIndex());
    tmp.get_in_inv(ui.chb_in_inv->isChecked());
    tmp.get_inv(ui.cb_inv->currentIndex());
    tmp.get_price(ui.spb_price->text());
    tmp.get_stah(ui.spb_stah->text());
    tmp.get_adress(ui.le_adress->text());
}

void QtGuiApplication2::addten_records()
{
    add_ten_Records();
}

void QtGuiApplication2::Standart_view() {
    ui.le_FIO->setText("");
    ui.de_birth->setDate(QDate(2000, 01, 01));
    ui.cb_pol->setCurrentIndex(0);
    ui.cb_study->setCurrentIndex(0);
    ui.cb_prof->setCurrentIndex(0);
    ui.spb_stah->setValue(1);
    ui.chb_in_inv->setChecked(false);
    ui.cb_inv->setCurrentIndex(0);
    ui.le_adress->setText("");
    ui.spb_price->setValue(1000);
}

void QtGuiApplication2::Form_Activity(bool form)
{
    ui.Redact_group->setEnabled(form);
    ui.tabWidget_data->setEnabled(!form);

    ui.pb_create->setEnabled(!form);
    ui.pb_delete->setEnabled(!form);
    ui.pb_change->setEnabled(!form);
    ui.action_10->setEnabled(!form);
}

void QtGuiApplication2::sorting()
{
    //Быстрая сортировка
    int j = 0;
    TABL temp;
    // Проходимся по всему массиву
    for (int i = 1; i < count; i++)
    {
        j = i;
        // Пока наш элемент > 0 и < левого элемента, меняем их местами
        while (j > 0 && database[j - 1] > database[j])
        {
            temp = database[j - 1];
            database[j - 1] = database[j];
            database[j] = temp;
            j = j - 1;

        }
    }
    update(0);
}

void QtGuiApplication2::update(int counter) {
    ui.tabWidget_data->setRowCount(count);
    QTableWidgetItem* item;
    for (int ix = counter; ix <= count - 1; ix++) {
        item = new QTableWidgetItem(database[ix].FIO);
        ui.tabWidget_data->setItem(ix, 0, item);

        item = new QTableWidgetItem(ui.cb_prof->itemText(database[ix].Prof));
        ui.tabWidget_data->setItem(ix, 1, item);

        item = new QTableWidgetItem(database[ix].Stah);
        ui.tabWidget_data->setItem(ix, 2, item);
    }
}

void QtGuiApplication2::add_ten_Records()
{


    if (count + 10 >= 100) {
        ui.action_10->setEnabled(false);
        ui.pb_create->setEnabled(false);
        return;
    }
    QString name[10] = { "Максим Максимович", "Иван Дурак","Серый Пень" ,"Запись Чудак" ,"Чингачгук Российский" ,"Владимир Владимирович" ,"Пень Стрелковый" ,"Лол Ага", "Всем Привет", "Последний Человек" };
    count += 10;
    for (int i = count - 10; i < count; i++) {
        database[i].FIO = name[rand() % 10];
        database[i].Date = QDate(1975 + rand() % 25, 1 + rand() % 11, 1 + rand() % 25);
        database[i].Prof = rand() % 5;
        database[i].Study = rand() % 4;
        database[i].Stah = QString::number(0 + rand() % 60);
        database[i].Pol = rand() % 2;
        database[i].Price = QString::number(1000 + rand() % 100000);
        if (rand() % 2 < 1) {
            database[i].InInv = false;

            database[i].Inv = 0;
        }
        else
        {
            database[i].InInv = true;

            database[i].Inv = rand() % 3;
        }
    }

    sorting();
    ui.pb_change->setEnabled(true);`
    ui.pb_delete->setEnabled(true);
    current_count = count - 1;
    ui.tabWidget_data->setCurrentCell(current_count, 0);
}

Ответы (0 шт):