mirror of https://github.com/KLayout/klayout.git
[consider merging] Qt4 compatibility
This commit is contained in:
parent
dc927717c2
commit
c6e457d3d6
|
|
@ -27,8 +27,6 @@
|
|||
#include "layQtTools.h"
|
||||
#include "tlException.h"
|
||||
|
||||
#include <QSignalBlocker>
|
||||
|
||||
namespace ant
|
||||
{
|
||||
|
||||
|
|
@ -483,7 +481,7 @@ PropertiesPage::update_with (const ant::Object &obj)
|
|||
text += "\n";
|
||||
}
|
||||
|
||||
QSignalBlocker blocker (points_edit);
|
||||
lay::SignalBlocker blocker (points_edit);
|
||||
points_edit->setPlainText (tl::to_qstring (text));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,23 @@ const std::string cfg_macro_editor_watch_expressions ("macro-editor-watch-expres
|
|||
const std::string cfg_macro_editor_debugging_enabled ("macro-editor-debugging-enabled");
|
||||
const std::string cfg_macro_editor_ignore_exception_list ("macro-editor-ignore-exception-list");
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Finds the tab bar widget for a QTabWidget
|
||||
*/
|
||||
static QTabBar *tab_bar_of (QTabWidget *tab)
|
||||
{
|
||||
#if QT_VERSION >= 0x50000
|
||||
return tab->tabBar ();
|
||||
#else
|
||||
// Qt 4 does not have a public method for getting the QTabBar
|
||||
QTabBar *tb = tab->findChild<QTabBar *> ();
|
||||
tl_assert (tb != 0);
|
||||
return tb;
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// Implementation of the macro template selection dialog
|
||||
|
||||
|
|
@ -324,7 +341,11 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection
|
|||
macro_tree->header ()->hide ();
|
||||
// TODO: that is supposed to enable the horizontal scroll bar, but it doesn't:
|
||||
macro_tree->header ()->setStretchLastSection (false);
|
||||
#if QT_VERSION >= 0x50000
|
||||
macro_tree->header ()->setSectionResizeMode (QHeaderView::ResizeToContents);
|
||||
#else
|
||||
macro_tree->header ()->setResizeMode (QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
|
||||
macro_tree->setItemDelegate (new EditRoleDelegate (macro_tree));
|
||||
|
||||
|
|
@ -1546,7 +1567,7 @@ MacroEditorDialog::eventFilter (QObject *obj, QEvent *event)
|
|||
|
||||
}
|
||||
|
||||
} else if (obj == tabWidget->tabBar () && dynamic_cast<QMouseEvent *> (event) != 0) {
|
||||
} else if (obj == tab_bar_of (tabWidget) && dynamic_cast<QMouseEvent *> (event) != 0) {
|
||||
|
||||
// just spy on the events, don't eat them
|
||||
QMouseEvent *mouse_event = dynamic_cast<QMouseEvent *> (event);
|
||||
|
|
@ -2306,7 +2327,7 @@ MacroEditorDialog::close_many (int r2c)
|
|||
|
||||
BEGIN_PROTECTED
|
||||
|
||||
int ci = tabWidget->tabBar ()->tabAt (m_mouse_pos);
|
||||
int ci = tab_bar_of (tabWidget)->tabAt (m_mouse_pos);
|
||||
if (ci < 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,10 +33,17 @@
|
|||
|
||||
#include <QStackedLayout>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QModelIndex>
|
||||
|
||||
namespace lay
|
||||
{
|
||||
|
||||
#if QT_VERSION >= 0x50000
|
||||
typedef qint64 tree_id_type;
|
||||
#else
|
||||
typedef qint32 tree_id_type;
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// PropertiesTreeModel definition and implementation
|
||||
|
||||
|
|
@ -56,14 +63,14 @@ public:
|
|||
QVariant data (const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.internalId () < mp_dialog->properties_pages ().size ()) {
|
||||
if (tree_id_type (index.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) {
|
||||
return tl::to_qstring (mp_dialog->properties_pages () [index.internalId ()]->description (index.row ()));
|
||||
} else if (index.row () < int (mp_dialog->properties_pages ().size ())) {
|
||||
return tl::to_qstring (mp_dialog->properties_pages () [index.row ()]->description ());
|
||||
}
|
||||
} else if (role == Qt::DecorationRole) {
|
||||
QIcon icon;
|
||||
if (index.internalId () < mp_dialog->properties_pages ().size ()) {
|
||||
if (tree_id_type (index.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) {
|
||||
icon = mp_dialog->properties_pages () [index.internalId ()]->icon (index.row (), m_icon_width, m_icon_height);
|
||||
} else if (index.row () < int (mp_dialog->properties_pages ().size ())) {
|
||||
icon = mp_dialog->properties_pages () [index.row ()]->icon (m_icon_width, m_icon_height);
|
||||
|
|
@ -78,7 +85,7 @@ public:
|
|||
Qt::ItemFlags flags (const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags f = QAbstractItemModel::flags (index);
|
||||
if (index.internalId () >= mp_dialog->properties_pages ().size () && ! mp_dialog->properties_pages () [index.row ()]->can_apply_to_all ()) {
|
||||
if (tree_id_type (index.internalId ()) >= tree_id_type (mp_dialog->properties_pages ().size ()) && ! mp_dialog->properties_pages () [index.row ()]->can_apply_to_all ()) {
|
||||
f &= ~Qt::ItemIsSelectable;
|
||||
}
|
||||
return f;
|
||||
|
|
@ -86,22 +93,22 @@ public:
|
|||
|
||||
bool hasChildren (const QModelIndex &parent) const
|
||||
{
|
||||
return (! parent.isValid () || parent.internalId () >= mp_dialog->properties_pages ().size ());
|
||||
return (! parent.isValid () || tree_id_type (parent.internalId ()) >= tree_id_type (mp_dialog->properties_pages ().size ()));
|
||||
}
|
||||
|
||||
QModelIndex index (int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (! parent.isValid ()) {
|
||||
return createIndex (row, column, qint64 (mp_dialog->properties_pages ().size ()));
|
||||
return createIndex (row, column, tree_id_type (mp_dialog->properties_pages ().size ()));
|
||||
} else {
|
||||
return createIndex (row, column, qint64 (parent.row ()));
|
||||
return createIndex (row, column, tree_id_type (parent.row ()));
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex parent (const QModelIndex &child) const
|
||||
{
|
||||
if (child.internalId () < mp_dialog->properties_pages ().size ()) {
|
||||
return createIndex (int (child.internalId ()), child.column (), qint64 (mp_dialog->properties_pages ().size ()));
|
||||
if (tree_id_type (child.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) {
|
||||
return createIndex (int (child.internalId ()), child.column (), tree_id_type (mp_dialog->properties_pages ().size ()));
|
||||
} else {
|
||||
return QModelIndex ();
|
||||
}
|
||||
|
|
@ -133,7 +140,7 @@ public:
|
|||
if (page_index < 0) {
|
||||
return QModelIndex ();
|
||||
} else {
|
||||
return createIndex (object_index, 0, qint64 (page_index));
|
||||
return createIndex (object_index, 0, tree_id_type (page_index));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +149,7 @@ public:
|
|||
if (page_index < 0) {
|
||||
return QModelIndex ();
|
||||
} else {
|
||||
return createIndex (page_index, 0, qint64 (mp_dialog->properties_pages ().size ()));
|
||||
return createIndex (page_index, 0, tree_id_type (mp_dialog->properties_pages ().size ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +221,11 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager,
|
|||
// if at end disable the "Next" button and return (this may only happen at the first call)
|
||||
mp_tree_model = new PropertiesTreeModel (this, mp_ui->tree->iconSize ().width (), mp_ui->tree->iconSize ().height ());
|
||||
mp_ui->tree->setModel (mp_tree_model);
|
||||
#if QT_VERSION >= 0x50000
|
||||
mp_ui->tree->header()->setSectionResizeMode (QHeaderView::ResizeToContents);
|
||||
#else
|
||||
mp_ui->tree->header()->setResizeMode (QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
mp_ui->tree->expandAll ();
|
||||
|
||||
if (mp_properties_pages.empty ()) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include <memory>
|
||||
|
||||
class QStackedLayout;
|
||||
class QModelIndex;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue