Skip to content

Commit

Permalink
Another improvement for AstroCalc/WUT: Let's use filters for list of …
Browse files Browse the repository at this point in the history
…matching objects
  • Loading branch information
alex-w committed Jul 2, 2018
1 parent bae304b commit d7d00d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
50 changes: 25 additions & 25 deletions src/gui/AstroCalcDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include <QFileDialog>
#include <QDir>
#include <QSortFilterProxyModel>
#include <QStringListModel>

QVector<Vec3d> AstroCalcDialog::EphemerisListCoords;
QVector<QString> AstroCalcDialog::EphemerisListDates;
Expand All @@ -66,6 +68,8 @@ QString AstroCalcDialog::yAxis2Legend = "";

AstroCalcDialog::AstroCalcDialog(QObject* parent)
: StelDialog("AstroCalc", parent)
, wutModel(Q_NULLPTR)
, proxyModel(Q_NULLPTR)
, currentTimeLine(Q_NULLPTR)
, plotAltVsTime(false)
, plotAltVsTimeSun(false)
Expand Down Expand Up @@ -265,13 +269,20 @@ void AstroCalcDialog::createDialogContent()
connect(ui->graphsSecondComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveGraphsSecondId(int)));
connect(ui->drawGraphsPushButton, SIGNAL(clicked()), this, SLOT(drawXVsTimeGraphs()));

wutModel = new QStringListModel(this);
proxyModel = new QSortFilterProxyModel(ui->wutMatchingObjectsListView);
proxyModel->setSourceModel(wutModel);
proxyModel->sort(0, Qt::AscendingOrder);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->wutMatchingObjectsListView->setModel(proxyModel);

ui->wutMagnitudeDoubleSpinBox->setValue(conf->value("astrocalc/wut_magnitude_limit", 10.0).toDouble());
connect(ui->wutMagnitudeDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(saveWutMagnitudeLimit(double)));
connect(ui->wutComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveWutTimeInterval(int)));
connect(ui->wutCategoryListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(calculateWutObjects()));
connect(ui->wutMatchingObjectsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(selectWutObject()));
connect(ui->wutMatchingObjectsListView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(selectWutObject(const QModelIndex&)));
connect(ui->saveObjectsButton, SIGNAL(clicked()), this, SLOT(saveWutObjects()));
connect(ui->wutMatchingObjectsLineEdit, SIGNAL(textChanged(QString)), this, SLOT(searchWutObjects(QString)));
connect(ui->wutMatchingObjectsLineEdit, SIGNAL(textChanged(const QString&)), proxyModel, SLOT(setFilterWildcard(const QString&)));
connect(dsoMgr, SIGNAL(catalogFiltersChanged(Nebula::CatalogGroup)), this, SLOT(calculateWutObjects()));
connect(dsoMgr, SIGNAL(typeFiltersChanged(Nebula::TypeGroup)), this, SLOT(calculateWutObjects()));
connect(dsoMgr, SIGNAL(flagSizeLimitsUsageChanged(bool)), this, SLOT(calculateWutObjects()));
Expand Down Expand Up @@ -323,7 +334,9 @@ void AstroCalcDialog::createDialogContent()
void AstroCalcDialog::searchWutClear()
{
ui->wutMatchingObjectsLineEdit->clear();
ui->wutMatchingObjectsListWidget->reset();
proxyModel->setSourceModel(wutModel);
proxyModel->sort(0, Qt::AscendingOrder);
//ui->wutMatchingObjectsListWidget->reset();
}

void AstroCalcDialog::updateAstroCalcData()
Expand Down Expand Up @@ -3686,7 +3699,6 @@ void AstroCalcDialog::saveWutTimeInterval(int index)

void AstroCalcDialog::calculateWutObjects()
{
ui->wutMatchingObjectsListWidget->clear();
if (ui->wutCategoryListWidget->currentItem())
{
ui->labelRiseValue->setText("");
Expand Down Expand Up @@ -4118,19 +4130,18 @@ void AstroCalcDialog::calculateWutObjects()
}

core->setJD(JD);
ui->wutMatchingObjectsListWidget->blockSignals(true);
ui->wutMatchingObjectsListWidget->clear();
ui->wutMatchingObjectsListWidget->addItems(wutObjects.keys());
ui->wutMatchingObjectsListWidget->sortItems(Qt::AscendingOrder);
ui->wutMatchingObjectsListWidget->blockSignals(false);
ui->wutMatchingObjectsListView->blockSignals(true);
ui->wutMatchingObjectsListView->reset();
wutModel->setStringList(wutObjects.keys());
ui->wutMatchingObjectsListView->blockSignals(false);
}
}

void AstroCalcDialog::selectWutObject()
void AstroCalcDialog::selectWutObject(const QModelIndex &index)
{
if (ui->wutMatchingObjectsListWidget->currentItem())
if (index.isValid())
{
QString wutObjectEnglisName = wutObjects.value(ui->wutMatchingObjectsListWidget->currentItem()->text());
QString wutObjectEnglisName = wutObjects.value(index.data().toString());
if (objectMgr->findAndSelectI18n(wutObjectEnglisName) || objectMgr->findAndSelect(wutObjectEnglisName))
{
const QList<StelObjectP> newSelected = objectMgr->getSelectedObject();
Expand Down Expand Up @@ -4184,25 +4195,14 @@ void AstroCalcDialog::saveWutObjects()
QTextStream wutObjList(&objlist);
wutObjList.setCodec("UTF-8");

for (int row = 0; row < ui->wutMatchingObjectsListWidget->count(); ++row)
for (int row = 0; row < proxyModel->rowCount(); ++row)
{
wutObjList << ui->wutMatchingObjectsListWidget->item(row)->text() << acEndl;
wutObjList << proxyModel->index(row, 0).data(Qt::DisplayRole).toString() << acEndl;
}

objlist.close();
}

void AstroCalcDialog::searchWutObjects(const QString &newText)
{
QList<QListWidgetItem*> items = ui->wutMatchingObjectsListWidget->findItems(newText, Qt::MatchStartsWith);
ui->wutMatchingObjectsListWidget->clearSelection();
if (!items.isEmpty())
{
items.at(0)->setSelected(true);
ui->wutMatchingObjectsListWidget->scrollToItem(items.at(0));
}
}

void AstroCalcDialog::saveFirstCelestialBody(int index)
{
Q_ASSERT(ui->firstCelestialBodyComboBox);
Expand Down
7 changes: 5 additions & 2 deletions src/gui/AstroCalcDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

class Ui_astroCalcDialogForm;
class QListWidgetItem;
class QSortFilterProxyModel;
class QStringListModel;

class AstroCalcDialog : public StelDialog
{
Expand Down Expand Up @@ -177,9 +179,8 @@ private slots:
void saveWutMagnitudeLimit(double mag);
void saveWutTimeInterval(int index);
void calculateWutObjects();
void selectWutObject();
void selectWutObject(const QModelIndex& index);
void saveWutObjects();
void searchWutObjects(const QString& newText);
void searchWutClear();

void updateAstroCalcData();
Expand All @@ -196,6 +197,8 @@ private slots:
class StelObjectMgr* objectMgr;
class StelLocaleMgr* localeMgr;
class StelMovementMgr* mvMgr;
QStringListModel* wutModel;
QSortFilterProxyModel *proxyModel;
QSettings* conf;
QTimer *currentTimeLine;
QHash<QString,QString> wutObjects;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/astroCalcDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="wutMatchingObjectsListWidget"/>
<widget class="QListView" name="wutMatchingObjectsListView"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayoutRTSData">
Expand Down

0 comments on commit d7d00d2

Please sign in to comment.