From 2ca7f247317ea2270df6f816c1a209ac1360efef Mon Sep 17 00:00:00 2001 From: graffy76 Date: Thu, 24 Oct 2013 17:33:28 -0500 Subject: [PATCH] Fixed filedialog new / edit content path issue --- apps/opencs/editor.cpp | 11 +++--- apps/opencs/view/doc/filedialog.cpp | 2 +- .../contentselector/model/contentmodel.cpp | 1 - .../contentselector/view/contentselector.cpp | 34 ++++++++++++------- .../contentselector/view/contentselector.hpp | 2 ++ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 1099226d2..6396563f2 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -126,12 +126,9 @@ void CS::Editor::openFiles() files.push_back(path.toStdString()); } - foreach (const boost::filesystem::path fp, files) - qDebug() << "loading files: " << fp.c_str(); + boost::filesystem::path savePath = mFileDialog.filename().toStdString(); - /// \todo Get the save path from the file dialogue - - CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), false); + CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false); mViewManager.addView (document); mFileDialog.hide(); @@ -147,9 +144,9 @@ void CS::Editor::createNewFile() files.push_back(mFileDialog.filename().toStdString()); - /// \todo Get the save path from the file dialogue. + boost::filesystem::path savePath = mFileDialog.filename().toStdString(); - CSMDoc::Document *document = mDocumentManager.addDocument (files, *files.rbegin(), true); + CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, true); mViewManager.addView (document); mFileDialog.hide(); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 1ac476cb2..e82cc30cb 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -120,7 +120,7 @@ QString CSVDoc::FileDialog::filename() const if (mDialogType == DialogType_New) return mFileWidget->getName(); - return QString (""); + return mSelector->currentFile(); } void CSVDoc::FileDialog::slotRejected() diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index accc149cb..0674642ee 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -503,7 +503,6 @@ bool ContentSelectorModel::ContentModel::isChecked(const QString& name) const void ContentSelectorModel::ContentModel::setCheckState(const QString &name, bool checkState) { - if (name.isEmpty()) return; diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 3d615906d..33b31b00c 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -9,10 +9,9 @@ #include #include +#include #include -#include - ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) : QObject(parent) { @@ -26,7 +25,6 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent) : void ContentSelectorView::ContentSelector::buildContentModel() { mContentModel = new ContentSelectorModel::ContentModel(); - //connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); } void ContentSelectorView::ContentSelector::buildGameFileView() @@ -41,7 +39,7 @@ void ContentSelectorView::ContentSelector::buildGameFileView() ui.gameFileView->setPlaceholderText(QString("Select a game file...")); ui.gameFileView->setModel(mGameFileProxyModel); - connect (ui.gameFileView, SIGNAL(currentIndexChanged(int)), + connect (ui.gameFileView, SIGNAL (currentIndexChanged(int)), this, SLOT (slotCurrentGameFileIndexChanged(int))); connect (ui.gameFileView, SIGNAL (currentIndexChanged (int)), @@ -64,9 +62,6 @@ void ContentSelectorView::ContentSelector::buildAddonView() ui.addonView->setModel(mAddonProxyModel); connect(ui.addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &))); - - for (int i = 0; i < mAddonProxyModel->rowCount(); ++i) - qDebug() << mAddonProxyModel->data(mAddonProxyModel->index(i,0,QModelIndex())); } void ContentSelectorView::ContentSelector::setGameFile(const QString &filename) @@ -113,6 +108,19 @@ void ContentSelectorView::ContentSelector::addFiles(const QString &path) if (ui.gameFileView->currentIndex() != -1) ui.gameFileView->setCurrentIndex(-1); + + mContentModel->uncheckAll(); +} + +QString ContentSelectorView::ContentSelector::currentFile() const +{ + QModelIndex currentIdx = ui.addonView->currentIndex(); + + if (!currentIdx.isValid()) + return ui.gameFileView->currentText(); + + QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex()); + return mContentModel->data(idx, Qt::DisplayRole).toString(); } void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index) @@ -125,12 +133,15 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i if (proxy) proxy->setDynamicSortFilter(false); - if (oldIndex > -1) - model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); + if (index != oldIndex) + { + if (oldIndex > -1) + model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1); - oldIndex = index; + oldIndex = index; - model->setData(model->index(index, 0), true, Qt::UserRole + 1); + model->setData(model->index(index, 0), true, Qt::UserRole + 1); + } if (proxy) proxy->setDynamicSortFilter(true); @@ -139,7 +150,6 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index) { QAbstractItemModel *const model = ui.addonView->model(); - //QSortFilterProxyModel *proxy = dynamic_cast(model); if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked) model->setData(index, Qt::Checked, Qt::CheckStateRole); diff --git a/components/contentselector/view/contentselector.hpp b/components/contentselector/view/contentselector.hpp index 163b19855..1e24a5523 100644 --- a/components/contentselector/view/contentselector.hpp +++ b/components/contentselector/view/contentselector.hpp @@ -26,6 +26,8 @@ namespace ContentSelectorView explicit ContentSelector(QWidget *parent = 0); + QString currentFile() const; + void addFiles(const QString &path); void clearCheckStates();