StillImageCamera: fix multiple prompt

This commit is contained in:
zhupengfei 2018-06-07 14:48:52 +08:00
parent a15e4e80c6
commit 3c554153c7
No known key found for this signature in database
GPG Key ID: 85B82A3E62174206
2 changed files with 19 additions and 2 deletions

View File

@ -13,6 +13,10 @@ namespace Camera {
StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip) StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip)
: QtCameraInterface(flip), image(std::move(image_)) {} : QtCameraInterface(flip), image(std::move(image_)) {}
StillImageCamera::~StillImageCamera() {
StillImageCameraFactory::last_path.clear();
}
void StillImageCamera::StartCapture() {} void StillImageCamera::StartCapture() {}
void StillImageCamera::StopCapture() {} void StillImageCamera::StopCapture() {}
@ -25,7 +29,12 @@ bool StillImageCamera::IsPreviewAvailable() {
return !image.isNull(); return !image.isNull();
} }
std::string StillImageCameraFactory::last_path;
const std::string StillImageCameraFactory::GetFilePath() const { const std::string StillImageCameraFactory::GetFilePath() const {
if (!last_path.empty()) {
return last_path;
}
QList<QByteArray> types = QImageReader::supportedImageFormats(); QList<QByteArray> types = QImageReader::supportedImageFormats();
QList<QString> temp_filters; QList<QString> temp_filters;
for (QByteArray type : types) { for (QByteArray type : types) {
@ -33,8 +42,9 @@ const std::string StillImageCameraFactory::GetFilePath() const {
} }
QString filter = QObject::tr("Supported image files (%1)").arg(temp_filters.join(" ")); QString filter = QObject::tr("Supported image files (%1)").arg(temp_filters.join(" "));
return QFileDialog::getOpenFileName(nullptr, QObject::tr("Open File"), ".", filter) last_path =
.toStdString(); QFileDialog::getOpenFileName(nullptr, QObject::tr("Open File"), ".", filter).toStdString();
return last_path;
} }
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(const std::string& config, std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(const std::string& config,

View File

@ -15,6 +15,7 @@ namespace Camera {
class StillImageCamera final : public QtCameraInterface { class StillImageCamera final : public QtCameraInterface {
public: public:
StillImageCamera(QImage image, const Service::CAM::Flip& flip); StillImageCamera(QImage image, const Service::CAM::Flip& flip);
~StillImageCamera();
void StartCapture() override; void StartCapture() override;
void StopCapture() override; void StopCapture() override;
void SetFrameRate(Service::CAM::FrameRate frame_rate) override {} void SetFrameRate(Service::CAM::FrameRate frame_rate) override {}
@ -33,6 +34,12 @@ public:
const Service::CAM::Flip& flip) override; const Service::CAM::Flip& flip) override;
Q_INVOKABLE const std::string GetFilePath() const; Q_INVOKABLE const std::string GetFilePath() const;
private:
/// Record the path chosen to avoid multiple prompt problem
static std::string last_path;
friend class StillImageCamera;
}; };
} // namespace Camera } // namespace Camera