Commit 4979147f authored by cyrush's avatar cyrush

added right click context menu to the File Panel, added option to replace selected plots

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@6873 18c085ea-50e0-402c-830e-de6fd14e8384
parent e3dca9e0
......@@ -39,7 +39,10 @@
#include <visitstream.h>
#include <QComboBox>
#include <QDebug>
#include <QContextMenuEvent>
#include <QLabel>
#include <QMenu>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QLayout>
......@@ -238,6 +241,9 @@ const int FileTree::FileTreeNode::DATABASE_NODE = 3;
// Cyrus Harrison, Tue Jul 1 14:28:23 PDT 2008
// Initial Qt4 Port.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Added creation & setup of filePopupMenu.
//
// ****************************************************************************
QvisFilePanel::QvisFilePanel(QWidget *parent) :
......@@ -263,6 +269,12 @@ QvisFilePanel::QvisFilePanel(QWidget *parent) :
connect(fileTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)),
this, SLOT(openFileDblClick(QTreeWidgetItem *)));
/*
connect(fileListView,
SIGNAL(rightButtonClicked(QListViewItem *,const QPoint &,int)),
this,
SLOT(showFilePopup(QListViewItem *, const QPoint &, int)));
*/
connect(fileTree, SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),
this, SLOT(highlightFile(QTreeWidgetItem *)));
connect(fileTree, SIGNAL(itemExpanded(QTreeWidgetItem *)),
......@@ -338,6 +350,13 @@ QvisFilePanel::QvisFilePanel(QWidget *parent) :
connect(vcrControls, SIGNAL(nextFrame()), this, SLOT(forwardStep()));
topLayout->addWidget(vcrControls);
filePopupMenu = new QMenu(this);
openAct = filePopupMenu->addAction(tr("&Open"));
replaceAct = filePopupMenu->addAction(tr("&Replace"));
replaceSelectedAct = filePopupMenu->addAction(tr("Replace &Selected"));
overlayAct = filePopupMenu->addAction(tr("&Overlay"));
closeAct = filePopupMenu->addAction(tr("&Close"));
// Create the computer pixmap.
computerPixmap = new QPixmap(computer_xpm);
// Create the database pixmap.
......@@ -2005,10 +2024,41 @@ QvisFilePanel::HighlightedItemIsInvalid() const
// Cyrus Harrison, Tue Jul 1 16:04:25 PDT 2008
// Initial Qt4 Port.
//
// Cyrus Harrison, Tue Apr 14 14:24:08 PDT 2009
// Refactored to use common CheckIfReplaceIsValid() method.
//
// ****************************************************************************
bool
QvisFilePanel::UpdateReplaceButtonEnabledState()
{
bool enabled = CheckIfReplaceIsValid();
replaceButton->setEnabled(enabled);
return enabled;
}
// ****************************************************************************
// Method: QvisFilePanel::CheckIfReplaceIsValid
//
// Purpose:
// This method tells us if replace/replace selected are valid operations.
//
//
// Note: Refactored from UpdateReplaceButtonEnabledState(), so the core
// logic could be used both in UpdateReplaceButtonEnabledState() and
// for the filePopupMenu.
//
// Returns: True if replace is a valid operation given the selected item.
//
// Programmer: Cyrus Harrison
// Creation: Tue Apr 14 14:23:11 PDT 2009
//
// Modifications:
//
// ****************************************************************************
bool
QvisFilePanel::CheckIfReplaceIsValid()
{
bool enabled = false;
if(!fileServer->GetOpenFile().Empty())
......@@ -2016,7 +2066,7 @@ QvisFilePanel::UpdateReplaceButtonEnabledState()
QTreeWidgetItem *item = fileTree->currentItem();
if(item != 0)
{
QvisFilePanelItem *ci = (QvisFilePanelItem *)item;
QvisFilePanelItem *ci = (QvisFilePanelItem*)item;
bool differentFiles = fileServer->GetOpenFile() != ci->file;
stringVector defs(fileServer->GetVirtualFileDefinition(ci->file));
......@@ -2064,7 +2114,6 @@ QvisFilePanel::UpdateReplaceButtonEnabledState()
}
}
replaceButton->setEnabled(enabled);
return enabled;
}
......@@ -2227,16 +2276,21 @@ QvisFilePanel::OpenFile(const QualifiedFilename &qf, int timeState, bool reOpen)
// Brad Whitlock, Mon Dec 20 16:21:30 PST 2004
// Changed how the Replace button's enabled state is set.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Added argument to allow replace of only active plots.
//
// ****************************************************************************
void
QvisFilePanel::ReplaceFile(const QualifiedFilename &filename, int timeState)
QvisFilePanel::ReplaceFile(const QualifiedFilename &filename, int timeState,
bool onlyReplaceActive)
{
// Try and set the open the data file.
SetOpenDataFile(filename, timeState, this, false);
// Tell the viewer to replace the database.
GetViewerMethods()->ReplaceDatabase(filename.FullName().c_str(), timeState);
GetViewerMethods()->ReplaceDatabase(filename.FullName().c_str(),
timeState,onlyReplaceActive);
// Update the Replace and Overlay buttons.
UpdateReplaceButtonEnabledState();
......@@ -2511,6 +2565,65 @@ QvisFilePanel::SetTimeSliderState(int state)
}
}
// ****************************************************************************
// Method: QvisFilePanel::contextMenuEvent
//
// Purpose:
// Shows file popup menu.
//
//
// Programmer: Cyrus Harrison
// Creation: Tue Apr 14 16:27:57 PDT 2009
//
// Modifications:
//
// ****************************************************************************
void
QvisFilePanel::contextMenuEvent(QContextMenuEvent *e)
{
QvisFilePanelItem *file_item=(QvisFilePanelItem*)fileTree->currentItem();
if(file_item == NULL || !file_item->isFile())
return;
// update popup menu with proper commands
bool file_opened_before = fileServer->HaveOpenedFile(file_item->file);
if(file_opened_before)
{
if(fileServer->GetOpenFile() != file_item->file)
openAct->setText(tr("&Activate"));
else
openAct->setText(tr("Re&Open"));
// enable close menu item
closeAct->setEnabled(true);
}
else
{
openAct->setText(tr("&Open"));
// if the file is not opened, disable the "Close" menu item
closeAct->setEnabled(false);
}
bool replace_valid = CheckIfReplaceIsValid();
replaceAct->setEnabled(replace_valid);
replaceSelectedAct->setEnabled(replace_valid);
overlayAct->setEnabled(replace_valid);
QAction *result = filePopupMenu->exec(e->globalPos());
if(result == openAct)
openFile();
else if(result == replaceAct)
replaceFile();
else if(result == replaceSelectedAct)
replaceSelected();
else if(result == overlayAct)
overlayFile();
else if(result == closeAct)
closeFile();
}
// ****************************************************************************
// Method: QvisFilePanel::SetShowSelectedFiles
//
......@@ -3264,10 +3377,43 @@ QvisFilePanel::replaceFile()
int timeState = (fileItem->timeState < 0) ? 0 : fileItem->timeState;
// Try and replace the file.
ReplaceFile(fileItem->file.FullName(), timeState);
ReplaceFile(fileItem->file.FullName(), timeState,false);
}
}
// ****************************************************************************
// Method: QvisFilePanel::replaceSelected
//
// Purpose:
// This is a Qt slot function that replaces active when the Replace
// Selected menu option from the file popup menu is clicked.
//
// Programmer: Cyrus Harrison
// Creation: Tue Apr 14 16:43:13 PDT 2009
//
// Modifications:
//
// ****************************************************************************
void
QvisFilePanel::replaceSelected()
{
QvisFilePanelItem *file_item= (QvisFilePanelItem *)fileTree->currentItem();
if((file_item != 0) && file_item->isFile() && (!file_item->file.Empty()))
{
// Make sure that we use a valid time state. Some file items
// have a time state of -1 if they are the parent item of several
// time step items.
int timeState = (file_item->timeState < 0) ? 0 : file_item->timeState;
// Try and replace the file.
ReplaceFile(file_item->file.FullName(), timeState, true);
}
}
// ****************************************************************************
// Method: QvisFilePanel::overlayFile
//
......@@ -3307,6 +3453,33 @@ QvisFilePanel::overlayFile()
}
}
// ****************************************************************************
// Method: QvisFilePanel::closeFile
//
// Purpose:
// This is a Qt slot function that overlays a file when the Overlay
// button is clicked. TODO
//
// Programmer: Cyrus Harrison
// Creation: Tue Apr 14 16:43:13 PDT 2009
//
// Modifications:
//
//
// ****************************************************************************
void
QvisFilePanel::closeFile()
{
QvisFilePanelItem *fileItem = (QvisFilePanelItem *) fileTree->currentItem();
if((fileItem != 0) && fileItem ->isFile() && (!fileItem->file.Empty()))
{
fileServer->ClearFile(fileItem->file.FullName());
GetViewerMethods()->CloseDatabase(fileItem->file.FullName());
UpdateOpenButtonState();
}
}
// ****************************************************************************
// Method: QvisFilePanel::sliderStart
//
......
......@@ -48,12 +48,14 @@
// Forward declarations.
class QComboBox;
class QContextMenuEvent;
class QLabel;
class QTreeWidget;
class QTreeWidgetItem;
class QPushButton;
class QLineEdit;
class QPixmap;
class QMenu;
class QvisAnimationSlider;
class QvisFilePanelItem;
class QvisVCRControl;
......@@ -156,6 +158,10 @@ class ViewerProxy;
// Added SetTimeFieldText() helper to make sure long time values remain
// visible.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Added right click popup menu w/ file options including new
// "Replace Selected" option, which only replaces active plots.
//
// ****************************************************************************
class GUI_API QvisFilePanel : public QWidget, public SimpleObserver, public GUIBase
......@@ -216,12 +222,14 @@ private:
void UpdateTimeFieldText(int timeState);
void SetTimeFieldText(const QString &text);
void UpdateAnimationControlsEnabledState();
bool CheckIfReplaceIsValid();
bool UpdateReplaceButtonEnabledState();
void UpdateOpenButtonState(QvisFilePanelItem *fileItem);
bool OpenFile(const QualifiedFilename &filename, int timeState,
bool reOpen);
void ReplaceFile(const QualifiedFilename &filename, int timeState=0);
void ReplaceFile(const QualifiedFilename &filename, int timeState=0,
bool onlyReplaceActive = false);
void OverlayFile(const QualifiedFilename &filename, int timeState=0);
void ExpandDatabases();
......@@ -241,6 +249,8 @@ private:
bool DisplayVirtualDBInformation(const QualifiedFilename &file) const;
void SetTimeSliderState(int);
protected:
void contextMenuEvent(QContextMenuEvent *e);
private slots:
void changeActiveTimeSlider(int);
void backwardStep();
......@@ -260,8 +270,11 @@ private slots:
void openFile();
void openFileDblClick(QTreeWidgetItem *);
void replaceFile();
void replaceSelected();
void overlayFile();
void closeFile();
void internalUpdateFileList();
private:
bool showSelectedFiles;
......@@ -277,7 +290,14 @@ private:
QPixmap *computerPixmap;
QPixmap *databasePixmap;
QPixmap *folderPixmap;
QMenu *filePopupMenu;
QAction *openAct;
QAction *replaceAct;
QAction *replaceSelectedAct;
QAction *overlayAct;
QAction *closeAct;
WindowInformation *windowInfo;
bool allowFileSelectionChange;
......
......@@ -669,6 +669,9 @@ LineoutListItem::DisableTool()
// Added call to SetActiveTimeSlider to ensure the correct plots in the
// window are updated.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ViewerPlotList::ReplaceDatabase.
//
// ****************************************************************************
void
......@@ -682,7 +685,7 @@ LineoutListItem::Update(Subject *TheChangedSubject)
{
case PlotQueryInfo::Database:
vpl->ReplaceDatabase(origPlot->GetEngineKey(),
origPlot->GetDatabaseName(), 0, false, false);
origPlot->GetDatabaseName(), 0, false, false,false);
break;
case PlotQueryInfo::VarName:
vpl->SetPlotVar(origPlot->GetVariableName());
......
......@@ -4485,12 +4485,15 @@ ViewerPlotList::CloseDatabase(const std::string &dbName)
// Brad Whitlock, Tue Apr 29 16:03:00 PDT 2008
// Support for internationalization.
//
// Cyrus Harrison, Tue Apr 14 13:32:18 PDT 2009
// Added ability to only replace active plots.
//
// ****************************************************************************
void
ViewerPlotList::ReplaceDatabase(const EngineKey &key,
const std::string &database, int timeState, bool setTimeState,
bool onlyReplaceSame)
bool onlyReplaceSame, bool onlyReplaceActive)
{
//
// Loop through the list replacing the plot's database.
......@@ -4500,6 +4503,8 @@ ViewerPlotList::ReplaceDatabase(const EngineKey &key,
const std::string &host = key.OriginalHostName();
for (int i = 0; i < nPlots; i++)
{
if(onlyReplaceActive && !plots[i].active)
continue;
//
// Decide which files to replace.
//
......
......@@ -302,6 +302,9 @@ typedef std::map<std::string, int> StringIntMap;
// Kathleen Bonnell, Tue Mar 3 15:03:19 PST 2009
// Renamed CanDoLogViewScaling to PermitsLogViewScaling.
//
// Cyrus Harrison, Tue Apr 14 13:34:15 PDT 2009
// Modified ReplaceDatabase to add option for replacing only active plots.
//
// ****************************************************************************
......@@ -399,7 +402,8 @@ public:
void SetPlotAtts(const int plotType);
void SetPlotOperatorAtts(const int operatorType, bool applyToAll = false);
void ReplaceDatabase(const EngineKey &ek, const std::string &database,
int timeState, bool setTimeState, bool onlyReplaceSame);
int timeState, bool setTimeState, bool onlyReplaceSame,
bool onlyReplaceActive);
void OverlayDatabase(const EngineKey &ek,
const std::string &database, int timeState);
......
......@@ -4400,6 +4400,10 @@ ViewerSubject::CheckForNewStates()
// Made it use the generic integer argument for forceClose so as to not be
// misleading.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ReplaceDatabase to support option for only
// replacing active plots.
//
// ****************************************************************************
void
......@@ -4520,7 +4524,7 @@ ViewerSubject::ReOpenDatabase()
// specified database.
//
ViewerWindowManager::Instance()->ReplaceDatabase(key, db, reOpenState,
false, true);
false, true, false);
}
// ****************************************************************************
......@@ -4583,13 +4587,20 @@ ViewerSubject::ReOpenDatabase()
// I added code to make sure that the active window is still compatible
// with other time-locked windows after the database was replaced.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ReplaceDatabase to support option for only
// replacing active plots.
//
// ****************************************************************************
void
ViewerSubject::ReplaceDatabase()
{
debug4 << "ReplaceDatabase: db=" << GetViewerState()->GetViewerRPC()->GetDatabase().c_str()
<< ", time=" << GetViewerState()->GetViewerRPC()->GetIntArg1() << endl;
debug4 << "ReplaceDatabase: db="
<< GetViewerState()->GetViewerRPC()->GetDatabase().c_str()
<< ", time=" << GetViewerState()->GetViewerRPC()->GetIntArg1()
<< ", onlyReplaceActive="
<< GetViewerState()->GetViewerRPC()->GetIntArg2() << endl;
//
// If the replace is merely changing the timestate, then turn on
......@@ -4607,9 +4618,11 @@ ViewerSubject::ReplaceDatabase()
// First open the database.
//
int timeState = GetViewerState()->GetViewerRPC()->GetIntArg1();
timeState = OpenDatabaseHelper(GetViewerState()->GetViewerRPC()->GetDatabase(), timeState,
false, false);
bool onlyReplaceActive = (bool) GetViewerState()->GetViewerRPC()->GetIntArg2();
//
// Now perform the database replacement.
//
......@@ -4618,7 +4631,8 @@ ViewerSubject::ReplaceDatabase()
plotList->GetDatabaseName(),
timeState,
true,
false);
false,
onlyReplaceActive);
//
// If the current window is time-locked then we have to make sure that
......@@ -9270,6 +9284,10 @@ ViewerSubject::DeferCommandFromSimulation(const EngineKey &key,
// Brad Whitlock, Fri Mar 27 11:27:40 PDT 2009
// I added INTERNALSYNC so we can sync with the simulation.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ReplaceDatabase to support option for only
// replacing active plots.
//
// ****************************************************************************
void
......@@ -9284,7 +9302,8 @@ ViewerSubject::HandleCommandFromSimulation(const EngineKey &key,
{
// The simulation told us that it wants us to update all of the plots
// that use it as a source.
ViewerWindowManager::Instance()->ReplaceDatabase(key, db, 0, false, true);
ViewerWindowManager::Instance()->ReplaceDatabase(key, db, 0, false, true,
false);
}
else if(command.substr(0,8) == "Message:")
{
......
......@@ -6762,12 +6762,16 @@ ViewerWindowManager::CloseDatabase(const std::string &dbName)
// Mark C. Miller, Mon Dec 6 20:18:43 PST 2004
// Added code to push final SIL controls to client
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ReplaceDatabase, adding option to replace
// only active plots.
//
// ****************************************************************************
void
ViewerWindowManager::ReplaceDatabase(const EngineKey &key,
const std::string &database, int timeState, bool setTimeState,
bool onlyReplaceSame)
bool onlyReplaceSame,bool onlyReplaceActive)
{
for(int i = 0; i < maxWindows; ++i)
{
......@@ -6775,7 +6779,8 @@ ViewerWindowManager::ReplaceDatabase(const EngineKey &key,
{
windows[i]->GetPlotList()->
ReplaceDatabase(key, database, timeState, setTimeState,
onlyReplaceSame);
onlyReplaceSame,
onlyReplaceActive);
}
}
......
......@@ -405,6 +405,10 @@ typedef struct {
// Kathleen Bonnell, Thu Mar 6 09:21:02 PST 2008
// Made return type of SetPlotFollowsTime be 'void'.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Changed the interface to ReplaceDatabase, adding option to replace
// only active plots.
//
// ****************************************************************************
class VIEWER_API ViewerWindowManager : public ViewerBase
......@@ -557,7 +561,8 @@ class VIEWER_API ViewerWindowManager : public ViewerBase
const std::string &database,
int timeState,
bool setTimeState,
bool onlyReplaceSame);
bool onlyReplaceSame,
bool onlyReplaceActive);
void CheckForNewStates(const std::string &hostDatabase);
void CreateDatabaseCorrelation(const std::string &name,
const stringVector &dbs,
......
......@@ -669,10 +669,14 @@ ViewerMethods::ReOpenDatabase(const std::string &database, bool forceClose)
// I added an optional timeState argument so we can replace databases
// at later time states.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Added argument to allow replace of only active plots.
//
// ****************************************************************************
void
ViewerMethods::ReplaceDatabase(const std::string &database, int timeState)
ViewerMethods::ReplaceDatabase(const std::string &database, int timeState,
bool onlyReplaceActive)
{
//
// Set the rpc type and arguments.
......@@ -680,6 +684,7 @@ ViewerMethods::ReplaceDatabase(const std::string &database, int timeState)
state->GetViewerRPC()->SetRPCType(ViewerRPC::ReplaceDatabaseRPC);
state->GetViewerRPC()->SetDatabase(database);
state->GetViewerRPC()->SetIntArg1(timeState);
state->GetViewerRPC()->SetIntArg2((int)onlyReplaceActive);
//
// Issue the RPC.
......
......@@ -116,6 +116,10 @@ class ViewerState;
// Added arguments for host name and simulation name to methods for loading
// and saving named selections.
//
// Cyrus Harrison, Tue Apr 14 13:35:54 PDT 2009
// Added argument to ReplaceDatabase to allow replace of only active
// plots.
//
// ****************************************************************************
class VIEWER_RPC_API ViewerMethods
......@@ -158,7 +162,8 @@ public:
void ActivateDatabase(const std::string &database);
void CheckForNewStates(const std::string &database);
void ReOpenDatabase(const std::string &database, bool forceClose = true);
void ReplaceDatabase(const std::string &database, int timeState = 0);
void ReplaceDatabase(const std::string &database, int timeState = 0,
bool onlyReplaceActive = false);
void OverlayDatabase(const std::string &database, int timeState = 0);
void RequestMetaData(const std::string &database, int ts = -1);
void ClearCache(const std::string &hostName, const std::string &simName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment