mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Initial commit of ResInsight version 0.4.8
This commit is contained in:
27
cafUserInterface/CMakeLists.txt
Normal file
27
cafUserInterface/CMakeLists.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
project (cafUserInterface)
|
||||
|
||||
include_directories(
|
||||
${cafProjectDataModel_SOURCE_DIR}
|
||||
${QtPropertyBrowser_SOURCE_DIR}
|
||||
)
|
||||
|
||||
# These headers need to go through Qt's MOC compiler
|
||||
set( QOBJECT_HEADERS
|
||||
cafBasicAboutDialog.h
|
||||
cafUiTreeModelPdm.h
|
||||
cafUiPropertyCreatorPdm.h
|
||||
cafUiProcess.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( MOC_FILES_CPP ${QOBJECT_HEADERS} )
|
||||
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
cafBasicAboutDialog.cpp
|
||||
cafUiTreeModelPdm.cpp
|
||||
cafUiPropertyCreatorPdm.cpp
|
||||
cafUiProcess.cpp
|
||||
${MOC_FILES_CPP}
|
||||
)
|
||||
324
cafUserInterface/cafBasicAboutDialog.cpp
Normal file
324
cafUserInterface/cafBasicAboutDialog.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafBasicAboutDialog.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <assert.h>
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
/// \class cvfqt::BasicAboutDialog
|
||||
/// \ingroup GuiQt
|
||||
///
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
BasicAboutDialog::BasicAboutDialog(QWidget* parent)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
|
||||
{
|
||||
m_isCreated = false;
|
||||
|
||||
//m_appName;
|
||||
//m_appVersion;
|
||||
//m_appCopyright;
|
||||
|
||||
m_showCeeVizVersion = true;
|
||||
m_showQtVersion = true;
|
||||
|
||||
m_isDebugBuild = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set application name to show in the dialog. Must be specified if any other app info is to be displayed
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::setApplicationName(const QString& appName)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_appName = appName;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set application version info to display
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::setApplicationVersion(const QString& ver)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_appVersion = ver;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set copyright info to display
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::setCopyright(const QString& copyright)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_appCopyright = copyright;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Enable display of CeeViz version
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::showCeeVizVersion(bool show)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_showCeeVizVersion = show;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Enable display of Qt version
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::showQtVersion(bool show)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_showQtVersion = show;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::addVersionEntry(const QString& verLabel, const QString& verText)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
|
||||
m_verLabels.push_back(verLabel);
|
||||
m_verTexts.push_back(verText);
|
||||
|
||||
assert(m_verLabels.size() == m_verTexts.size());
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Set to true to show text in dialog to indicate that we're running a debug build of our app
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::setIsDebugBuild(bool isDebugBuild)
|
||||
{
|
||||
assert(!m_isCreated);
|
||||
m_isDebugBuild = isDebugBuild;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::create()
|
||||
{
|
||||
// Only allowed to call once
|
||||
assert(!m_isCreated);
|
||||
|
||||
// Only show app info if app name is non-empty
|
||||
bool showAppInfo = !m_appName.isEmpty();
|
||||
|
||||
// Do an initial resize, dialog will resize itself later based on the widgets we have added
|
||||
resize(10, 10);
|
||||
|
||||
|
||||
// Set caption, different text depending on whether we're showing app info or not
|
||||
QString dlgCaption = "Version Information Details";
|
||||
if (showAppInfo)
|
||||
{
|
||||
dlgCaption = "About " + m_appName;
|
||||
if (m_isDebugBuild) dlgCaption += " (DEBUG)";
|
||||
}
|
||||
|
||||
setWindowTitle(dlgCaption);
|
||||
|
||||
|
||||
// Create the dialog's main layout
|
||||
QVBoxLayout* dlgMainLayout = new QVBoxLayout(this);
|
||||
|
||||
// The the top layout
|
||||
QVBoxLayout* topLayout = new QVBoxLayout;
|
||||
topLayout->setSpacing(3);
|
||||
|
||||
|
||||
// Possibly create and set text for widgets with app info
|
||||
if (showAppInfo)
|
||||
{
|
||||
QVBoxLayout* appInfoLayout = new QVBoxLayout;
|
||||
appInfoLayout->setSpacing(3);
|
||||
|
||||
// Always do app name
|
||||
assert(!m_appName.isEmpty());
|
||||
QLabel* appNameLabel = new QLabel(this);
|
||||
|
||||
QFont appNameFont(appNameLabel->font());
|
||||
appNameFont.setPointSize(14);
|
||||
appNameFont.setBold(true);
|
||||
appNameLabel->setFont(appNameFont);
|
||||
appNameLabel->setText(m_appName);
|
||||
appInfoLayout->addWidget(appNameLabel);
|
||||
|
||||
// Application version if specified
|
||||
if (!m_appVersion.isEmpty())
|
||||
{
|
||||
QString appVer = m_appVersion;
|
||||
// appVer += cvf::System::is64Bit() ? " (64-bit)" : " (32-bit)";
|
||||
|
||||
QLabel* appVersionLabel = new QLabel(this);
|
||||
QFont appVersionFont(appVersionLabel->font());
|
||||
appVersionFont.setPointSize(8);
|
||||
appVersionFont.setBold(TRUE);
|
||||
appVersionLabel->setFont(appVersionFont);
|
||||
appVersionLabel->setText(appVer);
|
||||
appInfoLayout->addWidget(appVersionLabel);
|
||||
}
|
||||
|
||||
// Application copyright if specified
|
||||
if (!m_appCopyright.isEmpty())
|
||||
{
|
||||
QLabel* appCopyrightLabel = new QLabel(this);
|
||||
QFont appCopyrightFont(appCopyrightLabel->font());
|
||||
appCopyrightFont.setPointSize(8);
|
||||
appCopyrightFont.setBold(TRUE);
|
||||
appCopyrightLabel->setFont(appCopyrightFont);
|
||||
appCopyrightLabel->setText(m_appCopyright);
|
||||
appInfoLayout->addWidget(appCopyrightLabel);
|
||||
}
|
||||
|
||||
QFrame* line = new QFrame(this);
|
||||
line->setProperty("frameShape", (int)QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
appInfoLayout->addWidget(line);
|
||||
|
||||
topLayout->addLayout(appInfoLayout);
|
||||
}
|
||||
|
||||
|
||||
// Possibly show extend version info
|
||||
if (m_showCeeVizVersion ||
|
||||
m_showQtVersion ||
|
||||
m_verLabels.size() > 0)
|
||||
{
|
||||
QGridLayout* verInfoLayout = new QGridLayout;
|
||||
verInfoLayout->setSpacing(0);
|
||||
|
||||
int insertRow = 0;
|
||||
|
||||
// CeeViz version
|
||||
if (m_showCeeVizVersion)
|
||||
{
|
||||
// QString ver;
|
||||
// ver.sprintf("%s.%s%s-%s", CVF_MAJOR_VERSION, CVF_MINOR_VERSION, CVF_SPECIAL_BUILD, CVF_BUILD_NUMBER);
|
||||
//
|
||||
// addStringPairToVerInfoLayout("CeeViz ver.: ", ver, verInfoLayout, insertRow++);
|
||||
}
|
||||
|
||||
// Qt version
|
||||
if (m_showQtVersion)
|
||||
{
|
||||
addStringPairToVerInfoLayout("Qt ver.: ", qVersion(), verInfoLayout, insertRow++);
|
||||
}
|
||||
|
||||
// Custom specified labels
|
||||
if (m_verLabels.size() > 0)
|
||||
{
|
||||
assert(m_verLabels.size() == m_verTexts.size());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < m_verLabels.size(); i++)
|
||||
{
|
||||
addStringPairToVerInfoLayout(m_verLabels[i], m_verTexts[i], verInfoLayout, insertRow++);
|
||||
}
|
||||
}
|
||||
|
||||
topLayout->addLayout(verInfoLayout);
|
||||
}
|
||||
|
||||
|
||||
dlgMainLayout->addLayout(topLayout);
|
||||
|
||||
QSpacerItem* spacer1 = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
dlgMainLayout->addItem(spacer1);
|
||||
|
||||
|
||||
// The bottom part with the OK button and
|
||||
// possibly text label indicating that we're running a debug build
|
||||
QHBoxLayout* bottomLayout = new QHBoxLayout;
|
||||
|
||||
// Indicate that this is a debug build
|
||||
if (m_isDebugBuild)
|
||||
{
|
||||
QLabel* debugLabel = new QLabel(this);
|
||||
debugLabel->setText("<font color='brown'><b>This is a DEBUG build...</b></font>");
|
||||
bottomLayout->addWidget(debugLabel);
|
||||
}
|
||||
|
||||
|
||||
// Add OK button
|
||||
QSpacerItem* spacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
bottomLayout->addItem(spacer2);
|
||||
|
||||
QPushButton* buttonOk = new QPushButton("&OK", this);
|
||||
buttonOk->setAutoDefault(TRUE);
|
||||
buttonOk->setDefault(TRUE);
|
||||
buttonOk->setFocus();
|
||||
connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()) );
|
||||
bottomLayout->addWidget(buttonOk);
|
||||
|
||||
dlgMainLayout->addLayout(bottomLayout);
|
||||
|
||||
m_isCreated = true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BasicAboutDialog::addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow)
|
||||
{
|
||||
QLabel* label = new QLabel(this);
|
||||
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
label->setText(labelStr);
|
||||
verInfoLayout->addWidget(label, insertRow, 0);
|
||||
|
||||
QLabel* info = new QLabel(this);
|
||||
info->setText(infoStr);
|
||||
verInfoLayout->addWidget(info, insertRow, 1 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace cvfqt
|
||||
|
||||
|
||||
|
||||
//########################################################
|
||||
//#include "GeneratedFiles/moc_cvfqtBasicAboutDialog.cpp"
|
||||
//########################################################
|
||||
|
||||
70
cafUserInterface/cafBasicAboutDialog.h
Normal file
70
cafUserInterface/cafBasicAboutDialog.h
Normal file
@@ -0,0 +1,70 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
namespace caf {
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class BasicAboutDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BasicAboutDialog(QWidget* parent);
|
||||
|
||||
void setApplicationName(const QString& appName);
|
||||
void setApplicationVersion(const QString& ver);
|
||||
void setCopyright(const QString& copyright);
|
||||
|
||||
void showCeeVizVersion(bool show);
|
||||
void showQtVersion(bool show);
|
||||
void addVersionEntry(const QString& verLabel, const QString& verText);
|
||||
void setIsDebugBuild(bool isDebugBuild);
|
||||
|
||||
void create();
|
||||
|
||||
private:
|
||||
void addStringPairToVerInfoLayout(const QString& labelStr, const QString& infoStr, QGridLayout* verInfoLayout, int insertRow);
|
||||
|
||||
private:
|
||||
bool m_isCreated; // Indicates if the create() function has been called
|
||||
|
||||
QString m_appName; // Application name, appears in bold at the top of the dialog.
|
||||
QString m_appVersion; // Application version info. Can be empty
|
||||
QString m_appCopyright; // Application copyright string. Can be empty
|
||||
|
||||
bool m_showCeeVizVersion; // Flags whether CeeViz version info should be shown
|
||||
bool m_showQtVersion; // Flags whether Qt version info should be shown
|
||||
QStringList m_verLabels; // Labels for user specified version entries
|
||||
QStringList m_verTexts; // The actual version text for user specified version entries
|
||||
|
||||
bool m_isDebugBuild; // If set to true, will show info in dlg to indicate that this is a debug build
|
||||
};
|
||||
|
||||
}
|
||||
157
cafUserInterface/cafUiProcess.cpp
Normal file
157
cafUserInterface/cafUiProcess.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafUiProcess.h"
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
UiProcess::UiProcess(QObject* parent)
|
||||
: QProcess(parent)
|
||||
{
|
||||
connect(this, SIGNAL(started()), SLOT(slotProcStarted()));
|
||||
connect(this, SIGNAL(error(QProcess::ProcessError)), SLOT(slotProcError(QProcess::ProcessError)));
|
||||
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(slotProcFinished(int, QProcess::ExitStatus)));
|
||||
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)), SLOT(slotProcStateChanged(QProcess::ProcessState)));
|
||||
connect(this, SIGNAL(readyReadStandardError()), SLOT(slotUpdateStatusMessage()));
|
||||
connect(this, SIGNAL(readyReadStandardOutput()), SLOT(slotUpdateStatusMessage()));
|
||||
|
||||
// Use a one sec timer to make sure the status message is updated at least every second
|
||||
QTimer* timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(slotUpdateStatusMessage()));
|
||||
timer->start(1000);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::doEmitStatusMsg(const QString& msg, int statusMsgType)
|
||||
{
|
||||
QString simpleMsg = msg;
|
||||
QString formattedMsg = simpleMsg;
|
||||
|
||||
if (statusMsgType == PROCESS_STATE_RUNNING) formattedMsg = QString("<font color='green'>%1</font>").arg(simpleMsg);
|
||||
else if (statusMsgType == PROCESS_STATE_ERROR) formattedMsg = QString("<font color='red'>%1</font>").arg(simpleMsg);
|
||||
|
||||
emit signalStatusMsg(simpleMsg, statusMsgType);
|
||||
emit signalFormattedStatusMsg(formattedMsg);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::slotProcStarted()
|
||||
{
|
||||
m_timer.start();
|
||||
|
||||
doEmitStatusMsg("Started", PROCESS_STATE_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::slotProcError(QProcess::ProcessError error)
|
||||
{
|
||||
QString msg = "UNKNOWN";
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case QProcess::FailedToStart: msg = "Failed to start"; break;
|
||||
case QProcess::Crashed: msg = "Crashed"; break;
|
||||
case QProcess::Timedout: msg = "Timed out"; break;
|
||||
case QProcess::WriteError: msg = "Write error"; break;
|
||||
case QProcess::ReadError: msg = "Read error"; break;
|
||||
case QProcess::UnknownError: msg = "Unknown error"; break;
|
||||
}
|
||||
|
||||
doEmitStatusMsg(msg, PROCESS_STATE_ERROR);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::slotProcFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
if (exitStatus == QProcess::CrashExit)
|
||||
{
|
||||
doEmitStatusMsg("Crashed or aborted", PROCESS_STATE_ERROR);
|
||||
}
|
||||
|
||||
else if (exitStatus == QProcess::NormalExit)
|
||||
{
|
||||
if (exitCode == 0)
|
||||
{
|
||||
doEmitStatusMsg("Finished OK", PROCESS_STATE_NORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString msg = QString("Error exit (code %1)").arg(exitCode);
|
||||
doEmitStatusMsg(msg, PROCESS_STATE_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::slotProcStateChanged(QProcess::ProcessState newState)
|
||||
{
|
||||
int statusMsgType = PROCESS_STATE_ERROR;
|
||||
QString msg = "UNKNOWN";
|
||||
|
||||
switch (newState)
|
||||
{
|
||||
case QProcess::NotRunning: msg = "Not running"; statusMsgType = PROCESS_STATE_NORMAL; break;
|
||||
case QProcess::Starting: msg = "Starting..."; statusMsgType = PROCESS_STATE_NORMAL; break;
|
||||
case QProcess::Running: msg = "Running"; statusMsgType = PROCESS_STATE_RUNNING; break;
|
||||
}
|
||||
|
||||
doEmitStatusMsg(msg, statusMsgType);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiProcess::slotUpdateStatusMessage()
|
||||
{
|
||||
if (state() == QProcess::Running)
|
||||
{
|
||||
// Use this as a sign that the process is alive and kicking
|
||||
// Emit a message with the current run time to signify progress
|
||||
double timeRunning = m_timer.elapsed() / 1000.0;
|
||||
|
||||
QString msg = QString("Running (%1 s)").arg(timeRunning, 0, 'f', 1);
|
||||
|
||||
doEmitStatusMsg(msg, PROCESS_STATE_RUNNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace caf
|
||||
63
cafUserInterface/cafUiProcess.h
Normal file
63
cafUserInterface/cafUiProcess.h
Normal file
@@ -0,0 +1,63 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QProcess>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
const int PROCESS_STATE_NORMAL = 0; // Normal messages
|
||||
const int PROCESS_STATE_RUNNING = 1; // Messages sent as long as the process is running
|
||||
const int PROCESS_STATE_ERROR = 2; // Message sent for error messages
|
||||
|
||||
|
||||
//=================================================================================================================================
|
||||
//
|
||||
//
|
||||
//=================================================================================================================================
|
||||
class UiProcess : public QProcess
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QTime m_timer;
|
||||
|
||||
public:
|
||||
UiProcess(QObject* pParent = 0);
|
||||
|
||||
private:
|
||||
void doEmitStatusMsg(const QString& msg, int statusMsgType);
|
||||
|
||||
private slots:
|
||||
void slotProcStarted();
|
||||
void slotProcError(QProcess::ProcessError error);
|
||||
void slotProcFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
void slotProcStateChanged(QProcess::ProcessState newState);
|
||||
void slotUpdateStatusMessage();
|
||||
|
||||
signals:
|
||||
void signalStatusMsg(const QString& msg, int statusMsgType);
|
||||
void signalFormattedStatusMsg(const QString& msg);
|
||||
};
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
364
cafUserInterface/cafUiPropertyCreatorPdm.cpp
Normal file
364
cafUserInterface/cafUiPropertyCreatorPdm.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafUiPropertyCreatorPdm.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QItemSelectionModel>
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafUiTreeModelPdm.h"
|
||||
|
||||
#include "qtvariantproperty.h"
|
||||
#include "qtpropertymanager.h"
|
||||
#include "qteditorfactory.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
UiPropertyCreatorPdm::UiPropertyCreatorPdm(QObject * parent)
|
||||
: QObject(parent),
|
||||
m_treeModel(NULL),
|
||||
m_selectionModel(NULL),
|
||||
m_propertyBrowser(NULL)
|
||||
{
|
||||
m_variantPropertyManager = new QtVariantPropertyManager();
|
||||
m_variantEditorFactory = new QtVariantEditorFactory();
|
||||
|
||||
m_doublePropertyManager = new QtStringPropertyManager();
|
||||
m_doubleEditorFactory = new QtLineEditFactory();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
UiPropertyCreatorPdm::~UiPropertyCreatorPdm()
|
||||
{
|
||||
delete m_variantPropertyManager;
|
||||
delete m_variantEditorFactory;
|
||||
|
||||
|
||||
delete m_doublePropertyManager;
|
||||
delete m_doubleEditorFactory;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::setPropertyBrowser(QtAbstractPropertyBrowser* propertyBrowser)
|
||||
{
|
||||
m_propertyBrowser = propertyBrowser;
|
||||
|
||||
if (m_propertyBrowser)
|
||||
{
|
||||
m_propertyBrowser->setFactoryForManager(m_variantPropertyManager, m_variantEditorFactory);
|
||||
m_propertyBrowser->setFactoryForManager(m_doublePropertyManager, m_doubleEditorFactory);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::setModel(UiTreeModelPdm* treeModel, QItemSelectionModel* selectionModel)
|
||||
{
|
||||
clearWidgetsAndProperties();
|
||||
|
||||
m_treeModel = treeModel;
|
||||
if (m_treeModel)
|
||||
{
|
||||
connect(m_treeModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &)));
|
||||
}
|
||||
|
||||
m_selectionModel = selectionModel;
|
||||
if (m_selectionModel)
|
||||
{
|
||||
connect(m_selectionModel, SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), SLOT(slotCurrentChanged(const QModelIndex&, const QModelIndex&)));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::createAndShowPropertiesForIndex(const QModelIndex& index)
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
caf::PdmUiTreeItem* treeItem = caf::UiTreeModelPdm::getTreeItemFromIndex(index);
|
||||
assert(treeItem);
|
||||
|
||||
createAndShowPropertiesForObject(treeItem->dataObject());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::createAndShowPropertiesForObject(caf::PdmObject* object)
|
||||
{
|
||||
assert(m_propertyBrowser);
|
||||
|
||||
if (!object) return;
|
||||
|
||||
// Disconnect listening on property manager during building of property browser content
|
||||
m_variantPropertyManager->disconnect(this);
|
||||
m_doublePropertyManager->disconnect(this);
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
uiFields(object, fields);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < fields.size(); i++)
|
||||
{
|
||||
caf::PdmFieldHandle* field = fields[i];
|
||||
assert(field);
|
||||
|
||||
|
||||
QString uiName = field->uiName();
|
||||
|
||||
QtProperty* qtProperty = NULL;
|
||||
bool fromMenuOnly = false;
|
||||
QList<PdmOptionItemInfo> enumNames = field->valueOptions(&fromMenuOnly);
|
||||
|
||||
// Check if we have an option menu to only show
|
||||
if (!enumNames.isEmpty() && fromMenuOnly == true)
|
||||
{
|
||||
QtVariantProperty* variantProperty = m_variantPropertyManager->addProperty(QtVariantPropertyManager::enumTypeId(), uiName);
|
||||
if (variantProperty)
|
||||
{
|
||||
variantProperty->setAttribute("enumNames", PdmOptionItemInfo::extractUiTexts(enumNames));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
qtProperty = variantProperty;
|
||||
}
|
||||
else if (!enumNames.isEmpty() )
|
||||
{
|
||||
assert(false); // This is not yet supprted
|
||||
}
|
||||
else
|
||||
{
|
||||
QVariant uiValue = field->uiValue();
|
||||
|
||||
if (uiValue.type() == QVariant::Double)
|
||||
{
|
||||
qtProperty = m_doublePropertyManager->addProperty(uiName);
|
||||
}
|
||||
else
|
||||
{
|
||||
qtProperty = m_variantPropertyManager->addProperty(uiValue.type(), uiName);
|
||||
|
||||
if (uiValue.type() == QVariant::Color)
|
||||
{
|
||||
QList<QtProperty *> subProperties = qtProperty->subProperties();
|
||||
int i;
|
||||
for (i = 0; i < subProperties.size(); i++)
|
||||
{
|
||||
qtProperty->removeSubProperty(subProperties[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qtProperty)
|
||||
{
|
||||
qtProperty->setToolTip(field->uiToolTip());
|
||||
qtProperty->setWhatsThis(field->uiWhatsThis());
|
||||
|
||||
m_properties[qtProperty] = field;
|
||||
if (!field->isHidden())
|
||||
{
|
||||
m_propertyBrowser->addProperty(qtProperty);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error
|
||||
}
|
||||
}
|
||||
|
||||
setAllPropertyValuesFromDataSource();
|
||||
}
|
||||
|
||||
// Establish listening on property manager when all properties are updated from data source
|
||||
connect(m_variantPropertyManager, SIGNAL(valueChanged(QtProperty*, const QVariant&)), SLOT(slotWriteValueToDataSource(QtProperty*, const QVariant&)));
|
||||
connect(m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*, const QString&)), SLOT(slotWriteDoubleValueToDataSource(QtProperty*, const QString&)));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::clearWidgetsAndProperties()
|
||||
{
|
||||
assert(m_propertyBrowser);
|
||||
|
||||
m_propertyBrowser->clear();
|
||||
m_properties.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::setAllPropertyValuesFromDataSource()
|
||||
{
|
||||
std::map<QtProperty*, caf::PdmFieldHandle*>::iterator it;
|
||||
for (it = m_properties.begin(); it != m_properties.end(); it++)
|
||||
{
|
||||
#if 1
|
||||
if (it->second->isHidden())
|
||||
{
|
||||
QtProperty* prop = it->first;
|
||||
#if 0
|
||||
it++;
|
||||
m_properties.erase(prop);
|
||||
delete prop;
|
||||
#endif
|
||||
m_propertyBrowser->removeProperty(prop);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_propertyBrowser->addProperty(it->first);
|
||||
QVariant uiValue = it->second->uiValue();
|
||||
|
||||
if (uiValue.type() == QVariant::Double)
|
||||
{
|
||||
QString text = uiValue.toString();
|
||||
m_doublePropertyManager->setValue(it->first, text);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_variantPropertyManager->setValue(it->first, uiValue);
|
||||
}
|
||||
|
||||
QString uiName = it->second->uiName();
|
||||
it->first->setPropertyName(uiName);
|
||||
|
||||
bool fromMenuOnly = false;
|
||||
QList<PdmOptionItemInfo> enumNames = it->second->valueOptions(&fromMenuOnly);
|
||||
if (!enumNames.isEmpty() && fromMenuOnly == true)
|
||||
{
|
||||
QtVariantProperty* variantProperty = dynamic_cast<QtVariantProperty*>(it->first);
|
||||
if (variantProperty)
|
||||
{
|
||||
variantProperty->setAttribute("enumNames", PdmOptionItemInfo::extractUiTexts(enumNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::slotWriteValueToDataSource(QtProperty* uiProperty, const QVariant& newValue)
|
||||
{
|
||||
assert(uiProperty);
|
||||
|
||||
caf::PdmFieldHandle* field = NULL;
|
||||
|
||||
std::map<QtProperty*, caf::PdmFieldHandle*>::iterator it;
|
||||
for (it = m_properties.begin(); it != m_properties.end(); it++)
|
||||
{
|
||||
if (it->first == uiProperty)
|
||||
{
|
||||
field = it->second;
|
||||
}
|
||||
}
|
||||
if (!field) return;
|
||||
|
||||
// Make sure we return a QVariant of unsigned int to tell pdm that we are using an option
|
||||
// index, and not an int value.
|
||||
QtVariantProperty* variantProperty = dynamic_cast<QtVariantProperty*> (uiProperty);
|
||||
if (variantProperty && variantProperty->propertyType() == QtVariantPropertyManager::enumTypeId())
|
||||
{
|
||||
QVariant uintValue(newValue.toUInt());
|
||||
field->setValueFromUi(uintValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
field->setValueFromUi(newValue);
|
||||
}
|
||||
|
||||
if (m_selectionModel)
|
||||
{
|
||||
m_treeModel->emitDataChanged(m_selectionModel->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::slotWriteDoubleValueToDataSource(QtProperty* uiProperty, const QString& newValue)
|
||||
{
|
||||
double doubleValue = newValue.toDouble();
|
||||
|
||||
slotWriteValueToDataSource(uiProperty, doubleValue);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
if (m_selectionModel)
|
||||
{
|
||||
if (topLeft == m_selectionModel->currentIndex())
|
||||
{
|
||||
// We must delay update of widgets to after the signal has returned
|
||||
QTimer::singleShot(0, this, SLOT(slotUpdateProperties()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::slotCurrentChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||
{
|
||||
clearWidgetsAndProperties();
|
||||
|
||||
createAndShowPropertiesForIndex(current);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiPropertyCreatorPdm::slotUpdateProperties()
|
||||
{
|
||||
setAllPropertyValuesFromDataSource();
|
||||
}
|
||||
|
||||
|
||||
void UiPropertyCreatorPdm::uiFields(const caf::PdmObject* object, std::vector<caf::PdmFieldHandle*>& fields) const
|
||||
{
|
||||
assert(object);
|
||||
object->fields(fields);
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
90
cafUserInterface/cafUiPropertyCreatorPdm.h
Normal file
90
cafUserInterface/cafUiPropertyCreatorPdm.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <map>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class QDockWidget;
|
||||
class QLabel;
|
||||
class QtAbstractPropertyBrowser;
|
||||
class QItemSelectionModel;
|
||||
|
||||
// Property browser
|
||||
class QtVariantEditorFactory;
|
||||
class QtVariantPropertyManager;
|
||||
class QtProperty;
|
||||
class QtStringPropertyManager;
|
||||
class QtLineEditFactory;
|
||||
|
||||
namespace caf {
|
||||
class PdmObject;
|
||||
class PdmFieldHandle;
|
||||
class UiTreeModelPdm;
|
||||
|
||||
|
||||
class UiPropertyCreatorPdm : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UiPropertyCreatorPdm(QObject* parent);
|
||||
~UiPropertyCreatorPdm();
|
||||
void setPropertyBrowser(QtAbstractPropertyBrowser* propertyBrowser);
|
||||
void setModel(UiTreeModelPdm* treeModel, QItemSelectionModel* selectionModel);
|
||||
|
||||
virtual void uiFields(const caf::PdmObject* object, std::vector<caf::PdmFieldHandle*>& fields) const;
|
||||
|
||||
void createAndShowPropertiesForObject(caf::PdmObject* dataSource);
|
||||
|
||||
private:
|
||||
void createAndShowPropertiesForIndex(const QModelIndex& index);
|
||||
|
||||
void setAllPropertyValuesFromDataSource();
|
||||
void clearWidgetsAndProperties();
|
||||
|
||||
|
||||
private slots:
|
||||
|
||||
void slotWriteValueToDataSource(QtProperty* uiProperty, const QVariant& newValue);
|
||||
void slotWriteDoubleValueToDataSource(QtProperty* uiProperty, const QString& newValue);
|
||||
void slotDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
void slotCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
|
||||
void slotUpdateProperties();
|
||||
|
||||
private:
|
||||
UiTreeModelPdm* m_treeModel;
|
||||
QItemSelectionModel* m_selectionModel;
|
||||
QtAbstractPropertyBrowser* m_propertyBrowser;
|
||||
|
||||
QtVariantPropertyManager* m_variantPropertyManager;
|
||||
QtVariantEditorFactory* m_variantEditorFactory;
|
||||
|
||||
QtStringPropertyManager* m_doublePropertyManager;
|
||||
QtLineEditFactory* m_doubleEditorFactory;
|
||||
|
||||
std::map<QtProperty*, caf::PdmFieldHandle*> m_properties;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
160
cafUserInterface/cafUiTreeItem.h
Normal file
160
cafUserInterface/cafUiTreeItem.h
Normal file
@@ -0,0 +1,160 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
/// Class used to build a tree item holding a data object
|
||||
/// Todo: Needs destructor !!!
|
||||
//==================================================================================================
|
||||
template <typename T>
|
||||
class UiTreeItem
|
||||
{
|
||||
public:
|
||||
// Create a new item at a specified position in parent child list. "-1" is understood as append.
|
||||
UiTreeItem(UiTreeItem* parent, int position, T dataObject)
|
||||
{
|
||||
m_parentItem = parent;
|
||||
|
||||
if (m_parentItem)
|
||||
{
|
||||
if (position < 0) m_parentItem->m_childItems.push_back( this);
|
||||
else m_parentItem->m_childItems.insert(position, this);
|
||||
}
|
||||
|
||||
setDataObject(dataObject);
|
||||
}
|
||||
|
||||
~UiTreeItem()
|
||||
{
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
UiTreeItem* child(int row)
|
||||
{
|
||||
assert(row < m_childItems.size());
|
||||
return m_childItems.value(row);
|
||||
}
|
||||
|
||||
int childCount() const
|
||||
{
|
||||
return m_childItems.count();
|
||||
}
|
||||
|
||||
int columnCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int row() const
|
||||
{
|
||||
if (m_parentItem)
|
||||
return m_parentItem->m_childItems.indexOf(const_cast<UiTreeItem*>(this));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UiTreeItem* parent()
|
||||
{
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
T dataObject()
|
||||
{
|
||||
return m_dataObject;
|
||||
}
|
||||
|
||||
void setDataObject(const T& dataObject)
|
||||
{
|
||||
m_dataObject = dataObject;
|
||||
}
|
||||
|
||||
void appendChild( UiTreeItem* child)
|
||||
{
|
||||
m_childItems.append(child);
|
||||
child->m_parentItem = this;
|
||||
}
|
||||
|
||||
bool insertChildren(int position, int count)
|
||||
{
|
||||
if (position < 0 || position > m_childItems.size())
|
||||
return false;
|
||||
|
||||
for (int row = 0; row < count; ++row)
|
||||
{
|
||||
createChild(this, position + row);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a new Ui tree item at given position pointing to a NULL data object
|
||||
virtual UiTreeItem* createChild(UiTreeItem* parent, int position)
|
||||
{
|
||||
return new UiTreeItem(this, position, NULL);
|
||||
}
|
||||
|
||||
bool removeChildren(int position, int count)
|
||||
{
|
||||
if (position < 0 || position + count > m_childItems.size())
|
||||
return false;
|
||||
|
||||
for (int row = 0; row < count; ++row)
|
||||
{
|
||||
UiTreeItem* uiItem = m_childItems.takeAt(position);
|
||||
|
||||
delete uiItem;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeAllChildrenNoDelete()
|
||||
{
|
||||
m_childItems.clear();
|
||||
}
|
||||
|
||||
UiTreeItem* findUiItem(const T& dataObject)
|
||||
{
|
||||
if (m_dataObject == dataObject) return this;
|
||||
int i;
|
||||
for (i = 0; i < m_childItems.size(); ++i)
|
||||
{
|
||||
UiTreeItem* itemFound = m_childItems[i]->findUiItem(dataObject);
|
||||
if (itemFound != NULL) return itemFound;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<UiTreeItem*> m_childItems;
|
||||
UiTreeItem* m_parentItem;
|
||||
T m_dataObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
432
cafUserInterface/cafUiTreeModelPdm.cpp
Normal file
432
cafUserInterface/cafUiTreeModelPdm.cpp
Normal file
@@ -0,0 +1,432 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafUiTreeModelPdm.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
UiTreeModelPdm::UiTreeModelPdm(QObject* parent)
|
||||
{
|
||||
m_root = NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiTreeModelPdm::setRoot(PdmUiTreeItem* root)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
if (m_root)
|
||||
{
|
||||
delete m_root;
|
||||
}
|
||||
|
||||
m_root = root;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QModelIndex UiTreeModelPdm::index(int row, int column, const QModelIndex &parentIndex /*= QModelIndex( ) */) const
|
||||
{
|
||||
if (!m_root)
|
||||
return QModelIndex();
|
||||
|
||||
if (!hasIndex(row, column, parentIndex))
|
||||
return QModelIndex();
|
||||
|
||||
PdmUiTreeItem* parentItem = NULL;
|
||||
|
||||
if (!parentIndex.isValid())
|
||||
parentItem = m_root;
|
||||
else
|
||||
parentItem = UiTreeModelPdm::getTreeItemFromIndex(parentIndex);
|
||||
|
||||
|
||||
PdmUiTreeItem* childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QModelIndex UiTreeModelPdm::parent(const QModelIndex &childIndex) const
|
||||
{
|
||||
if (!m_root) return QModelIndex();
|
||||
|
||||
if (!childIndex.isValid()) return QModelIndex();
|
||||
|
||||
PdmUiTreeItem* childItem = UiTreeModelPdm::getTreeItemFromIndex(childIndex);
|
||||
if (!childItem) return QModelIndex();
|
||||
|
||||
PdmUiTreeItem* parentItem = childItem->parent();
|
||||
if (!parentItem) return QModelIndex();
|
||||
|
||||
if (parentItem == m_root) return QModelIndex();
|
||||
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int UiTreeModelPdm::rowCount(const QModelIndex &parentIndex /*= QModelIndex( ) */) const
|
||||
{
|
||||
if (!m_root)
|
||||
return 0;
|
||||
|
||||
if (parentIndex.column() > 0)
|
||||
return 0;
|
||||
|
||||
PdmUiTreeItem* parentItem;
|
||||
if (!parentIndex.isValid())
|
||||
parentItem = m_root;
|
||||
else
|
||||
parentItem = UiTreeModelPdm::getTreeItemFromIndex(parentIndex);
|
||||
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int UiTreeModelPdm::columnCount(const QModelIndex &parentIndex /*= QModelIndex( ) */) const
|
||||
{
|
||||
if (!m_root)
|
||||
return 0;
|
||||
|
||||
if (parentIndex.isValid())
|
||||
{
|
||||
PdmUiTreeItem* parentItem = UiTreeModelPdm::getTreeItemFromIndex(parentIndex);
|
||||
if (parentItem)
|
||||
{
|
||||
return parentItem->columnCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return m_root->columnCount();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QVariant UiTreeModelPdm::data(const QModelIndex &index, int role /*= Qt::DisplayRole */) const
|
||||
{
|
||||
if (!m_root)
|
||||
return QVariant();
|
||||
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
PdmUiTreeItem* treeItem = UiTreeModelPdm::getTreeItemFromIndex(index);
|
||||
assert(treeItem);
|
||||
|
||||
PdmObject* obj = treeItem->dataObject();
|
||||
|
||||
// We try to find the context of the object first: The parent field
|
||||
// If found, use its data to describe the thing
|
||||
// Note: This code will only find first field pointing at the current object. Its valid for now,
|
||||
// but will not generally be valid if references is introduced in the pdm system
|
||||
|
||||
PdmFieldHandle* parentField = 0;
|
||||
|
||||
PdmUiTreeItem* parentTreeItem = treeItem->parent();
|
||||
if (parentTreeItem)
|
||||
{
|
||||
PdmObject* parentObj = parentTreeItem->dataObject();
|
||||
if (parentObj)
|
||||
{
|
||||
std::vector<PdmFieldHandle*> fields;
|
||||
parentObj->fields(fields);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < fields.size(); ++i)
|
||||
{
|
||||
std::vector<PdmObject*> children;
|
||||
if (fields[i]) fields[i]->childObjects(&children);
|
||||
size_t cIdx;
|
||||
for (cIdx = 0; cIdx < children.size(); ++ cIdx)
|
||||
{
|
||||
if (children[cIdx] == obj)
|
||||
{
|
||||
parentField = fields[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parentField) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(obj);
|
||||
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||
{
|
||||
if (obj->userDescriptionField())
|
||||
{
|
||||
return obj->userDescriptionField()->uiValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parentField && !parentField->uiName().isEmpty())
|
||||
return parentField->uiName();
|
||||
else
|
||||
return obj->uiName();
|
||||
}
|
||||
}
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
if (parentField && !parentField->uiIcon().isNull())
|
||||
return parentField->uiIcon();
|
||||
else
|
||||
return obj->uiIcon();
|
||||
}
|
||||
else if (role == Qt::ToolTipRole)
|
||||
{
|
||||
if (parentField && !parentField->uiToolTip().isEmpty())
|
||||
return parentField->uiToolTip();
|
||||
else
|
||||
return obj->uiToolTip();
|
||||
}
|
||||
else if (role == Qt::WhatsThisRole)
|
||||
{
|
||||
if (parentField && !parentField->uiWhatsThis().isEmpty())
|
||||
return parentField->uiWhatsThis();
|
||||
else
|
||||
return obj->uiWhatsThis();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiTreeModelPdm::emitDataChanged(const QModelIndex& index)
|
||||
{
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool UiTreeModelPdm::setData(const QModelIndex &index, const QVariant &value, int role /*= Qt::EditRole*/)
|
||||
{
|
||||
if (index.isValid() && role == Qt::EditRole)
|
||||
{
|
||||
PdmUiTreeItem* treeItem = UiTreeModelPdm::getTreeItemFromIndex(index);
|
||||
assert(treeItem);
|
||||
|
||||
PdmObject* obj = treeItem->dataObject();
|
||||
|
||||
if (obj->userDescriptionField())
|
||||
{
|
||||
obj->userDescriptionField()->setValueFromUi(value);
|
||||
}
|
||||
|
||||
emitDataChanged(index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Qt::ItemFlags UiTreeModelPdm::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::ItemIsEnabled;
|
||||
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool UiTreeModelPdm::insertRows(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
|
||||
{
|
||||
PdmUiTreeItem* parentItem = getTreeItemFromIndex(parent);
|
||||
|
||||
bool success;
|
||||
|
||||
beginInsertRows(parent, position, position + rows - 1);
|
||||
success = parentItem->insertChildren(position, rows);
|
||||
endInsertRows();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool UiTreeModelPdm::removeRows(int position, int rows, const QModelIndex &parent /*= QModelIndex()*/)
|
||||
{
|
||||
if (rows <= 0) return true;
|
||||
|
||||
PdmUiTreeItem* parentItem = getTreeItemFromIndex(parent);
|
||||
|
||||
bool success = true;
|
||||
|
||||
beginRemoveRows(parent, position, position + rows - 1);
|
||||
success = parentItem->removeChildren(position, rows);
|
||||
endRemoveRows();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiTreeModelPdm::rebuildUiSubTree(PdmObject* root)
|
||||
{
|
||||
QModelIndex item = getModelIndexFromPdmObject(root);
|
||||
if (item.isValid())
|
||||
{
|
||||
this->removeRows(0, rowCount(item), item);
|
||||
PdmUiTreeItem* treeItem = getTreeItemFromIndex(item);
|
||||
|
||||
|
||||
PdmUiTreeItem* fakeRoot = UiTreeItemBuilderPdm::buildViewItems(NULL, -1, root);
|
||||
|
||||
this->beginInsertRows(item, 0, fakeRoot->childCount());
|
||||
for(int i = 0; i < fakeRoot->childCount(); ++i)
|
||||
{
|
||||
treeItem->appendChild(fakeRoot->child(i));
|
||||
}
|
||||
this->endInsertRows();
|
||||
fakeRoot->removeAllChildrenNoDelete();
|
||||
delete fakeRoot;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeItem* caf::UiTreeModelPdm::getTreeItemFromIndex(const QModelIndex& index)
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
assert(index.internalPointer());
|
||||
|
||||
PdmUiTreeItem* treeItem = static_cast<PdmUiTreeItem*>(index.internalPointer());
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QModelIndex caf::UiTreeModelPdm::getModelIndexFromPdmObjectRecursive(const QModelIndex& root, const PdmObject * object) const
|
||||
{
|
||||
if (root.internalPointer())
|
||||
{
|
||||
PdmUiTreeItem* treeItem = static_cast<PdmUiTreeItem*>(root.internalPointer());
|
||||
if (treeItem->dataObject() == object) return root;
|
||||
}
|
||||
|
||||
int row;
|
||||
for (row = 0; row < rowCount(root); ++row)
|
||||
{
|
||||
QModelIndex foundIndex = getModelIndexFromPdmObjectRecursive(index(row, 0, root), object);
|
||||
if (foundIndex.isValid()) return foundIndex;
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QModelIndex caf::UiTreeModelPdm::getModelIndexFromPdmObject( const PdmObject * object) const
|
||||
{
|
||||
QModelIndex foundIndex;
|
||||
int numRows = rowCount(QModelIndex());
|
||||
int r = 0;
|
||||
while (r < numRows && !foundIndex.isValid())
|
||||
{
|
||||
foundIndex = getModelIndexFromPdmObjectRecursive(index(r, 0, QModelIndex()), object);
|
||||
++r;
|
||||
}
|
||||
return foundIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeItem* UiTreeItemBuilderPdm::buildViewItems(PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* object)
|
||||
{
|
||||
if (object == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PdmUiTreeItem* objectTreeItem = new PdmUiTreeItem(parentTreeItem, position, object);
|
||||
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
object->fields(fields);
|
||||
|
||||
std::vector<caf::PdmFieldHandle*>::iterator it;
|
||||
for (it = fields.begin(); it != fields.end(); it++)
|
||||
{
|
||||
caf::PdmFieldHandle* field = *it;
|
||||
if (field->isHidden()) continue;
|
||||
|
||||
std::vector<caf::PdmObject*> children;
|
||||
field->childObjects(&children);
|
||||
size_t i;
|
||||
for (i = 0; i < children.size(); i++)
|
||||
{
|
||||
caf::PdmObject* childObj = children[i];
|
||||
assert(childObj);
|
||||
|
||||
UiTreeItemBuilderPdm::buildViewItems(objectTreeItem, position, childObj);
|
||||
}
|
||||
}
|
||||
|
||||
return objectTreeItem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
86
cafUserInterface/cafUiTreeModelPdm.h
Normal file
86
cafUserInterface/cafUiTreeModelPdm.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafUiTreeItem.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <assert.h>
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmObject;
|
||||
|
||||
typedef UiTreeItem<PdmPointer<PdmObject> > PdmUiTreeItem;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class UiTreeModelPdm : public QAbstractItemModel
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UiTreeModelPdm(QObject* parent);
|
||||
|
||||
void setRoot(PdmUiTreeItem* root);
|
||||
void emitDataChanged(const QModelIndex& index);
|
||||
|
||||
static PdmUiTreeItem* getTreeItemFromIndex(const QModelIndex& index);
|
||||
QModelIndex getModelIndexFromPdmObject( const PdmObject * object) const;
|
||||
void rebuildUiSubTree(PdmObject* root);
|
||||
|
||||
public:
|
||||
// Overrides from QAbstractItemModel
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parentIndex = QModelIndex( )) const;
|
||||
virtual QModelIndex parent(const QModelIndex &index) const;
|
||||
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex( ) ) const;
|
||||
virtual int columnCount(const QModelIndex &parentIndex = QModelIndex( ) ) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
||||
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
virtual bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||
virtual bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||
|
||||
private:
|
||||
QModelIndex getModelIndexFromPdmObjectRecursive(const QModelIndex& root, const PdmObject * object) const;
|
||||
|
||||
private:
|
||||
PdmUiTreeItem* m_root;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class UiTreeItemBuilderPdm
|
||||
{
|
||||
public:
|
||||
static PdmUiTreeItem* buildViewItems(PdmUiTreeItem* parentTreeItem, int position, caf::PdmObject* object);
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
Reference in New Issue
Block a user