Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void NumismatistHandbook::openFileSlot()
- {
- //сохранение текущего файла, если нужно
- if (fileChanged())
- {
- if (askToSafe(/*includeCancelButton = */false) == SafeAccepted)
- saveFileSlot();
- }
- //открываем новый файл
- QString newFilename = QFileDialog::getOpenFileName(this, "Открыть файл", "/", "Файлы монет (*.coins)");
- if (!newFilename.isEmpty())
- {
- currentFilename = newFilename;
- model.load(currentFilename);
- updateForm();
- ui->currentFileLabel->setText(currentFilename);
- }
- }
- void NumismatistHandbook::createFileSlot()
- {
- if (fileChanged())
- {
- if (askToSafe(/*includeCancelButton = */false) == SafeAccepted)
- saveFileSlot();
- }
- currentFilename = "";
- model.clear();
- updateForm();
- ui->currentFileLabel->setText(currentFilename);
- }
- void NumismatistHandbook::saveFileSlot()
- {
- if (!currentFilename.isEmpty())
- model.save(currentFilename);
- else
- saveAsFileSlot();
- ui->currentFileLabel->setText(currentFilename);
- }
- void NumismatistHandbook::saveAsFileSlot()
- {
- QString newFilename = QFileDialog::getSaveFileName(this, "Сохранить как", "/", "Файлы монет (*.coins)");
- if (!newFilename.isEmpty())
- {
- currentFilename = newFilename;
- model.save(currentFilename);
- }
- ui->currentFileLabel->setText(currentFilename);
- }
- bool NumismatistHandbook::fileChanged()
- {
- //файл был изменен и не является только что созданным не сохраннёным файлом без записей
- return model.isModified() && not(currentFilename.isEmpty() && model.count() == 0);
- }
- NumismatistHandbook::SafeState NumismatistHandbook::askToSafe(bool includeCancelButton)
- {
- //NumismatistHandbook::SafeState это синоним типа QMessageBox::StandartButton
- QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No;
- if (includeCancelButton)
- buttons |= QMessageBox::Cancel;
- QMessageBox::StandardButton selectedButton =
- QMessageBox::question(this, "База данных", "Сохранить изменения в текущем файле?", buttons);
- return selectedButton;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement