void ObservingList::slotRemoveObject( SkyObject *o, bool session, bool update ) {
    if( ! update ) { 
        if ( ! o )
            o = ks->map()->clickedObject(); 
        else if( sessionView ) //else if is needed as clickedObject should not be removed from the session list.
            session = true;
    }

    QStandardItemModel *currentModel;

    int k;
    if (! session) {
        currentModel = m_Model;
        k = obsList().indexOf( o );
    }
    else {
        currentModel = m_Session;
        k = sessionList().indexOf( o );
    }

    if ( o == LogObject ) saveCurrentUserLog();
    //Remove row from the TableView model
    if ( o->name() == "star" ) {
        //Find object in table by RA and Dec
        for ( int irow = 0; irow < currentModel->rowCount(); ++irow ) {
            QString ra = currentModel->item(irow, 1)->text();
            QString dc = currentModel->item(irow, 2)->text();
            if ( o->ra0().toHMSString() == ra && o->dec0().toDMSString() == dc ) {
                currentModel->removeRow(irow);
                break;
            }
        }
    } else { // name is not "star"
        //Find object in table by name
        for ( int irow = 0; irow < currentModel->rowCount(); ++irow ) {
            QString name = currentModel->item(irow, 0)->text();
            if ( o->translatedName() == name ) {
                currentModel->removeRow(irow);
                break;
            }
        }
    }

    if( ! session ) {
        obsList().removeAt(k);
        ui->View->removeAllPlotObjects();
        ui->TableView->resizeColumnsToContents();
        if( ! update )
            slotSaveList();
    } else {
        if( ! update )
            TimeHash.remove( o->name() );
        sessionList().removeAt(k); //Remove from the session list
        isModified = true;         //Removing an object should trigger the modified flag
        ui->View->removeAllPlotObjects();
        ui->SessionView->resizeColumnsToContents();
    }
}
Exemple #2
0
SessionDlg::SessionDlg(QWidget* parent) : QDialog(parent), result_(0) {
	ui.setupUi(this);

	ui.sessionTree->header()->hide();

	QStringList sList = sessionList();
	foreach (QString session, sList) {
		if (session.compare("_empty_session_") != 0) {
			QStringList items;
			items << session;
			QTreeWidgetItem* it = new QTreeWidgetItem(items);
			ui.sessionTree->addTopLevelItem(it);
		}
	}
	if (sList.count() > 0) {
		ui.sessionTree->setCurrentItem(ui.sessionTree->topLevelItem(0));
	}
	else {
		ui.openSessionBtn->setEnabled(false);
		ui.removeSessionBtn->setEnabled(false);
	}

	connect(ui.openSessionBtn,   SIGNAL(clicked()), SLOT(openSession()));
	connect(ui.newSessionBtn,    SIGNAL(clicked()), SLOT(newSession()));
	connect(ui.removeSessionBtn, SIGNAL(clicked()), SLOT(removeSession()));
	connect(ui.sessionTree, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(activated(QTreeWidgetItem*, int)));
}
void MainWindow::initActions()
{
    m_sessionNew = new QAction(this);
    m_sessionNew->setShortcut( tr( "Ctrl+N" ) );
    connect ( m_sessionNew , SIGNAL ( triggered() ), this , SLOT ( newSession() ) );

    m_sessionList = new QAction(this);
    m_sessionList->setShortcut( tr( "Ctrl+L" ) );
    connect ( m_sessionList , SIGNAL ( triggered() ), this , SLOT ( sessionList() ) );

    m_closeFullScreenAction = new QAction(this);
    m_closeFullScreenAction -> setIcon( QIcon( ":/shellicons/Restore") );
    connect ( m_closeFullScreenAction , SIGNAL ( triggered() ), this , SLOT ( showNormal() ) );

    //TODO: Fix fullscreen action behaviour
    m_fullScreenAction = new QAction(this);
    m_fullScreenAction -> setIcon( QIcon( ":/icons/FullScreen") );
    m_fullScreenAction->setShortcut( tr( "F11" ) );
    connect ( m_fullScreenAction, SIGNAL ( triggered() ), this , SLOT ( fullScreen() ) );
  
    m_quitAction = new QAction(this);
    m_quitAction->setShortcut(tr("Ctrl+Q"));
    m_quitAction -> setIcon( QIcon( ":/icons/Quit") );

    connect ( m_quitAction, SIGNAL ( triggered() ), this , SLOT ( close() ) );

    m_updateAllMonitorsActions = new QAction(this);
    m_updateAllMonitorsActions->setShortcut( tr("F5") );
    connect ( m_updateAllMonitorsActions, SIGNAL ( triggered() ),this, SLOT ( update() ) );

    m_selectStyleAction = new QAction(this);
    connect ( m_selectStyleAction , SIGNAL (triggered()), this , SLOT ( selectStyle() ) );

    m_preferencesAction = new QAction( this );
    connect ( m_preferencesAction, SIGNAL ( triggered() ),this, SLOT ( showPreferences() ) );

    aboutAction = new QAction(this);
    aboutQtAction = new QAction(this);
    connect ( aboutAction, SIGNAL ( triggered () ), this, SLOT ( aboutDialog() ) );
    connect ( aboutQtAction, SIGNAL ( triggered () ), qApp, SLOT ( aboutQt() ) );
}
void ObservingList::slotNewSelection() {
    bool found = false;
    singleSelection = false;
    noSelection = false;
    showScope = false;
    ui->ImagePreview->clearPreview();
    ui->ImagePreview->setCursor( Qt::ArrowCursor );
    QModelIndexList selectedItems;
    QString newName;
    SkyObject *o;
    ui->SaveImage->setEnabled( false );
    ui->DeleteImage->setEnabled( false );

    QStandardItemModel *currentModel;
    QList<SkyObject*> currList;

    if ( sessionView ) {
        selectedItems = m_SortModelSession->mapSelectionToSource( ui->SessionView->selectionModel()->selection() ).indexes();
        currentModel = m_Session;
        currList = sessionList();
    } else {
        selectedItems = m_SortModel->mapSelectionToSource( ui->TableView->selectionModel()->selection() ).indexes();
        currentModel = m_Model;
        currList = obsList();
    }

    if ( selectedItems.size() == currentModel->columnCount() ) {
        newName = selectedItems[0].data().toString();
        singleSelection = true;
        //Find the selected object in the SessionList,
        //then break the loop.  Now SessionList.current()
        //points to the new selected object (until now it was the previous object)
        foreach ( o, currList ) {
            if ( o->translatedName() == newName ) {
                found = true;
                break;
            }
        }
    }
void ObservingList::slotRemoveSelectedObjects() {
    QStandardItemModel *currentModel;
//    ObservingListUI local_ui;
    if ( sessionView )    
        currentModel = m_Session;
    else
        currentModel = m_Model;

    //Find each object by name in the session list, and remove it
    //Go backwards so item alignment doesn't get screwed up as rows are removed.
    for ( int irow = currentModel->rowCount()-1; irow >= 0; --irow ) {
        bool rowSelected;
        if ( sessionView )
            rowSelected = ui->SessionView->selectionModel()->isRowSelected( irow, QModelIndex() );
        else
            rowSelected = ui->TableView->selectionModel()->isRowSelected( irow, QModelIndex() );

        if ( rowSelected ) {
            QList<SkyObject*> currList;
            QModelIndex mSortIndex, mIndex;
             if ( sessionView ) {
                mSortIndex = m_SortModelSession->index( irow, 0 );
                mIndex = m_SortModelSession->mapToSource( mSortIndex );
                currList = sessionList();
            } else {
                mSortIndex = m_SortModel->index( irow, 0 );
                mIndex = m_SortModel->mapToSource( mSortIndex );
                currList = obsList();
            }

            int irow = mIndex.row();
            QString ra = currentModel->item(irow, 1)->text();
            QString dc = currentModel->item(irow, 2)->text();

            foreach ( SkyObject *o, currList ) {
                //Stars named "star" must be matched by coordinates
                if ( o->name() == "star" ) {
                    if ( o->ra0().toHMSString() == ra && o->dec0().toDMSString() == dc ) {
                        slotRemoveObject(o, sessionView);
                        break;
                    }
                } else {
                    if ( o->translatedName() == mIndex.data().toString() ) {
                        slotRemoveObject(o, sessionView);
                        break;
                    }
                }
            }
        }
    }

    if (sessionView) {
        //we've removed all selected objects, so clear the selection
        ui->SessionView->selectionModel()->clear();
        //Update the lists in the Execute window as well
        ks->getExecute()->init();
    }

    setSaveImagesButton();
    ui->ImagePreview->setCursor( Qt::ArrowCursor );
}
void ObservingList::slotAddObject( SkyObject *obj, bool session, bool update ) {
    bool addToWishList=true;
    if( ! obj )
        obj = ks->map()->clickedObject();

    if( obj->name() == "star" ) {
        KMessageBox::sorry(0, i18n( "Unnamed stars are not supported in the observing lists"));
        return;
    }
        
    //First, make sure object is not already in the list
    if ( obsList().contains( obj ) ) {
        addToWishList = false;
        if( ! session ) {
            ks->statusBar()->changeItem( i18n( "%1 is already in your wishlist.", obj->name() ), 0 );
            return;
        }
    }

    if ( session && sessionList().contains( obj ) ) { 
        ks->statusBar()->changeItem( i18n( "%1 is already in the session plan.", obj->name() ), 0 );
        return;
    }
    
    QString smag = "--";
    if (  - 30.0 < obj->mag() && obj->mag() < 90.0 )
        smag = QString::number( obj->mag(), 'g', 2 ); // The lower limit to avoid display of unrealistic comet magnitudes

    SkyPoint p = obj->recomputeCoords( dt, geo );

    //Insert object in the Wish List
    if( addToWishList  ) {
        m_ObservingList.append( obj );
        m_CurrentObject = obj;
        QList<QStandardItem*> itemList;

        QString ra, dec;

        if(obj->name() == "star" ) {
            ra = obj->ra0().toHMSString();
            dec = obj->dec0().toDMSString();
        }
        else {
            ra = p.ra().toHMSString();
            dec = p.dec().toDMSString();
        }

        itemList << new QStandardItem( obj->translatedName() )
                << new QStandardItem( ra )
                << new QStandardItem( dec )
                << new QStandardItem( smag )
                << new QStandardItem( obj->typeName() );

        m_Model->appendRow( itemList );
        //Note addition in statusbar
        ks->statusBar()->changeItem( i18n( "Added %1 to observing list.", obj->name() ), 0 );
        ui->TableView->resizeColumnsToContents(); 
        if( ! update ) slotSaveList();
    }
    //Insert object in the Session List
    if( session ){
        m_SessionList.append(obj);
        dt.setTime( TimeHash.value( obj->name(), obj->transitTime( dt, geo ) ) );
        dms lst(geo->GSTtoLST( dt.gst() ));
        p.EquatorialToHorizontal( &lst, geo->lat() );
        QList<QStandardItem*> itemList;

        QString ra, dec, time = "--", alt = "--", az = "--";

        QStandardItem *BestTime = new QStandardItem();
        if(obj->name() == "star" ) {
            ra = obj->ra0().toHMSString();
            dec = obj->dec0().toDMSString();
            BestTime->setData( QString( "--" ), Qt::DisplayRole );
        }
        else {
            ra = p.ra().toHMSString();
            dec = p.dec().toDMSString();
            BestTime->setData( TimeHash.value( obj->name(), obj->transitTime( dt, geo ) ), Qt::DisplayRole );
            alt = p.alt().toDMSString();
            az = p.az().toDMSString();
        }
        // TODO: Change the rest of the parameters to their appropriate datatypes.
        itemList << new QStandardItem( obj->translatedName() )
                << new QStandardItem( ra )
                << new QStandardItem( dec )
                << new QStandardItem( smag )
                << new QStandardItem( obj->typeName() )
                << BestTime
                << new QStandardItem( alt )
                << new QStandardItem( az );

        m_Session->appendRow( itemList );
        //Adding an object should trigger the modified flag
        isModified = true;
        ui->SessionView->resizeColumnsToContents();
        //Note addition in statusbar
        ks->statusBar()->changeItem( i18n( "Added %1 to session list.", obj->name() ), 0 );
    }
    setSaveImagesButton();
}