Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ben Boeckel
QtTesting
Commits
e872b4b1
Commit
e872b4b1
authored
Dec 05, 2006
by
Clinton Stimpson
Browse files
ENH: Modify naming scheme slightly to allow better compatibility between
Qt 4.1 and Qt 4.2.
parent
87a36ba1
Changes
1
Hide whitespace changes
Inline
Side-by-side
pqObjectNaming.cxx
View file @
e872b4b1
...
...
@@ -55,79 +55,93 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QToolButton>
#include <QtDebug>
/** Returns the name of an object. If the object doesn't have an explicit name,
assigns a name as a convenience. Also replaces problematic characters such as '/'.
/** Returns the name of an object as if it was unnamed.
*/
static
const
QString
InternalGetName
(
QObject
&
Object
)
static
const
QString
InternalGetName
AsUnnamed
(
QObject
&
Object
)
{
QString
result
=
Object
.
objectName
()
;
QString
result
;
if
(
result
.
isEmpty
())
QObjectList
siblings
;
if
(
Object
.
parent
())
{
QObjectList
siblings
;
if
(
Object
.
parent
())
{
siblings
=
Object
.
parent
()
->
children
();
}
else
siblings
=
Object
.
parent
()
->
children
()
;
}
else
{
QWidgetList
widgets
=
QApplication
::
topLevelWidgets
();
for
(
int
i
=
0
;
i
!=
widgets
.
size
();
++
i
)
{
QWidgetList
widgets
=
QApplication
::
topLevelWidgets
();
for
(
int
i
=
0
;
i
!=
widgets
.
size
();
++
i
)
{
siblings
.
push_back
(
widgets
[
i
]);
}
siblings
.
push_back
(
widgets
[
i
]);
}
}
const
QString
type
=
Object
.
metaObject
()
->
className
();
// order of top level widgets is not guarenteed
// we can someone counter that by checking visibility,
// as we usually only test visible widgets, we would get the right one
int
invisible_index
=
0
;
int
visible_index
=
0
;
for
(
int
i
=
0
;
i
!=
siblings
.
size
();
++
i
)
const
QString
type
=
Object
.
metaObject
()
->
className
();
// order of top level widgets is not guarenteed
// we can someone counter that by checking visibility,
// as we usually only test visible widgets, we would get the right one
int
invisible_index
=
0
;
int
visible_index
=
0
;
for
(
int
i
=
0
;
i
!=
siblings
.
size
();
++
i
)
{
QObject
*
test
=
siblings
[
i
];
if
(
test
==
&
Object
)
{
QObject
*
test
=
siblings
[
i
];
if
(
test
==
&
Object
)
{
break
;
}
else
if
(
type
==
test
->
metaObject
()
->
className
()
&&
test
->
objectName
().
isEmpty
())
{
QWidget
*
widget
=
qobject_cast
<
QWidget
*>
(
test
);
if
(
widget
&&
widget
->
isVisible
())
{
++
visible_index
;
}
else
{
++
invisible_index
;
}
}
break
;
}
int
index
=
invisible_index
;
if
(
QWidget
*
const
widget
=
qobject_cast
<
QWidget
*>
(
&
Object
))
else
if
(
type
==
test
->
metaObject
()
->
className
()
&&
test
->
objectName
().
isEmpty
(
))
{
if
(
widget
->
isVisible
())
QWidget
*
widget
=
qobject_cast
<
QWidget
*>
(
test
);
if
(
widget
&&
widget
->
isVisible
())
{
result
+=
QString
::
number
(
1
);
index
=
visible_index
;
++
visible_index
;
}
else
{
result
+=
QString
::
number
(
0
)
;
++
invisible_index
;
}
}
result
+=
type
+
QString
::
number
(
index
);
}
int
index
=
invisible_index
;
if
(
QWidget
*
const
widget
=
qobject_cast
<
QWidget
*>
(
&
Object
))
{
if
(
widget
->
isVisible
())
{
result
+=
QString
::
number
(
1
);
index
=
visible_index
;
}
else
{
result
+=
QString
::
number
(
0
);
}
}
result
+=
type
+
QString
::
number
(
index
);
result
.
replace
(
"/"
,
"|"
);
return
result
;
}
/** Returns the name of an object. If the object doesn't have an explicit name,
assigns a name as a convenience. Also replaces problematic characters such as '/'.
*/
static
const
QString
InternalGetName
(
QObject
&
Object
)
{
QString
result
=
Object
.
objectName
();
if
(
result
.
isEmpty
())
{
result
=
InternalGetNameAsUnnamed
(
Object
);
}
result
.
replace
(
"/"
,
"|"
);
return
result
;
}
const
QString
pqObjectNaming
::
GetName
(
QObject
&
Object
)
{
QString
name
=
InternalGetName
(
Object
);
...
...
@@ -172,8 +186,9 @@ QObject* pqObjectNaming::GetObject(const QString& Name)
{
QObject
*
object
=
top_level_widgets
[
i
];
const
QString
name
=
InternalGetName
(
*
object
);
const
QString
alt_name
=
InternalGetNameAsUnnamed
(
*
object
);
if
(
name
==
names
[
0
])
if
(
name
==
names
[
0
]
||
alt_name
==
names
[
0
])
{
result
=
object
;
lastObject
=
object
;
...
...
@@ -190,14 +205,25 @@ QObject* pqObjectNaming::GetObject(const QString& Name)
{
QObject
*
child
=
children
[
k
];
const
QString
name
=
InternalGetName
(
*
child
);
const
QString
alt_name
=
InternalGetNameAsUnnamed
(
*
child
);
if
(
name
==
names
[
j
])
if
(
name
==
names
[
j
]
||
alt_name
==
names
[
j
])
{
result
=
child
;
lastObject
=
child
;
break
;
}
}
// if there is a real name, also allow skipping generations
// in the hierarchy to find a child
if
(
result
==
0
)
{
if
(
!
names
[
j
].
isEmpty
()
&&
names
[
j
].
at
(
0
).
isDigit
())
{
result
=
result
->
findChild
<
QObject
*>
(
names
[
j
]);
}
}
}
if
(
result
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment