[sword-svn] r2921 - in trunk: . bindings examples examples/qt include src/modules src/utilfuns src/utilfuns/qt utilities
scribe at crosswire.org
scribe at crosswire.org
Sun Jul 28 10:21:45 MST 2013
Author: scribe
Date: 2013-07-28 10:21:44 -0700 (Sun, 28 Jul 2013)
New Revision: 2921
Added:
trunk/examples/qt/
trunk/examples/qt/qtLookup.cpp
trunk/examples/qt/qtLookup.pro
trunk/src/utilfuns/qt/
trunk/src/utilfuns/qt/qtsupport.cpp
Modified:
trunk/bindings/flatapi.cpp
trunk/configure.ac
trunk/include/swbuf.h
trunk/include/swkey.h
trunk/include/swmgr.h
trunk/include/swmodule.h
trunk/src/modules/swmodule.cpp
trunk/src/utilfuns/Makefile.am
trunk/utilities/mod2imp.cpp
trunk/utilities/vpl2mod.cpp
Log:
Added conditional Qt support to help Qt frontends add less code for integration with SWORD
Modified: trunk/bindings/flatapi.cpp
===================================================================
--- trunk/bindings/flatapi.cpp 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/bindings/flatapi.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -264,7 +264,7 @@
const char *SWModule_getRenderText(SWHANDLE hmodule) {
SWModule *module = (SWModule *)hmodule;
- return (const char *)((module) ? module->renderText() : 0);
+ return (const char *)((module) ? module->renderText().c_str() : 0);
}
const char *SWModule_getEntryAttributes(SWHANDLE hmodule, const char *level1, const char *level2, const char *level3) {
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/configure.ac 2013-07-28 17:21:44 UTC (rev 2921)
@@ -47,6 +47,8 @@
# ---------------------------------------------------------------------
# With options
# ---------------------------------------------------------------------
+AC_ARG_WITH(qt,
+ AC_HELP_STRING([--with-qt],[allow easier integration with Qt (default=yes)]),,with_qt=yes)
AC_ARG_WITH(zlib,
AC_HELP_STRING([--with-zlib],[allow zlib compressed modules (default=yes)]),,with_zlib=yes)
AC_ARG_WITH(icu,
@@ -285,6 +287,21 @@
AC_CHECK_FUNCS(vsnprintf, [have_vsnprintf="yes"])
+
+if test x$with_qt = xyes; then
+PKG_CHECK_MODULES([QT4], [QtCore QtGui >= 4.4.0], [
+ AC_PATH_PROGS(MOC, [moc-qt4 moc], moc,`eval $PKG_CONFIG --variable=exec_prefix QtCore`/bin)
+ AC_PATH_PROG(RCC, rcc, rcc,`eval $PKG_CONFIG --variable=exec_prefix QtCore`/bin)
+ AC_PATH_PROGS(UIC, [uic-qt4 uic], uic,`eval $PKG_CONFIG --variable=exec_prefix QtCore`/bin)
+], with_qt="no")
+else
+ with_qt="no"
+fi
+if test x$with_qt = xyes; then
+ACX_QT4
+fi
+
+
# ---------------------------------------------------------------------
# Alter global conf directory only if not /etc
# ---------------------------------------------------------------------
@@ -330,6 +347,7 @@
# ---------------------------------------------------------------------
# don't #ifdef in .cpp files HAVE_ stuff because non-ac compiles won't be able to switch them since we include config.h
+AM_CONDITIONAL(HAVE_QT, test x$with_qt = xyes)
AM_CONDITIONAL(HAVE_LIBZ, test x$with_zlib = xyes)
AM_CONDITIONAL(HAVE_ICU, test x$with_icu = xyes)
AM_CONDITIONAL(HAVE_ICUSWORD, test x$with_icusword = xyes)
@@ -371,6 +389,7 @@
echo " INTERNAL FTPLIB: $with_internalftplib"
echo " INTERNAL REGEX: $with_internalregex"
echo " CLUCENE: $with_clucene"
+echo " QT SUPPORT: $with_qt"
echo
echo
Added: trunk/examples/qt/qtLookup.cpp
===================================================================
--- trunk/examples/qt/qtLookup.cpp (rev 0)
+++ trunk/examples/qt/qtLookup.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -0,0 +1,36 @@
+#include <QApplication>
+#include <QTextEdit>
+#include <QString>
+#include <swmgr.h>
+#include <swmodule.h>
+#include <stdio.h>
+
+using namespace sword;
+
+int main(int argc, char **argv) {
+
+ if (argc != 3) {
+ fprintf(stderr, "\nusage: %s <modname> <\"lookup key\">\n"
+ "\tExample: %s KJV \"James 1:19\"\n\n", argv[0], argv[0]);
+ exit(-1);
+ }
+
+ QApplication app(argc, argv);
+
+ QString modName = argv[1];
+ QString key = argv[2];
+
+ SWMgr library;
+ SWModule *mod = library.getModule(modName);
+
+ QTextEdit textEdit;
+ if (mod) {
+ mod->setKey(key);
+ textEdit.setText(mod->renderText());
+ }
+ else textEdit.setText("module not found");
+
+ textEdit.show();
+
+ return app.exec();
+}
Added: trunk/examples/qt/qtLookup.pro
===================================================================
--- trunk/examples/qt/qtLookup.pro (rev 0)
+++ trunk/examples/qt/qtLookup.pro 2013-07-28 17:21:44 UTC (rev 2921)
@@ -0,0 +1,13 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Thu Jul 4 22:01:07 2013
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG += link_pkgconfig
+PKGCONFIG += sword
+
+# Input
+SOURCES += qtLookup.cpp
Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/include/swbuf.h 2013-07-28 17:21:44 UTC (rev 2921)
@@ -29,7 +29,10 @@
#ifdef __BORLANDC__
#include <mem.h>
#endif
+#include <string>
+class QString;
+
SWORD_NAMESPACE_START
@@ -96,6 +99,8 @@
*
*/
SWBuf(const char *initVal, unsigned long initSize = 0);
+ SWBuf(const std::string &initVal);
+ SWBuf(const QString &initVal);
// SWBuf(unsigned long initSize);
/**
@@ -325,6 +330,8 @@
inline char *getRawData() { return buf; }
inline operator const char *() const { return c_str(); }
+ inline operator std::string() const { return c_str(); }
+ operator QString () const;
inline char &operator[](unsigned long pos) { return charAt(pos); }
inline char &operator[](long pos) { return charAt((unsigned long)pos); }
inline char &operator[](unsigned int pos) { return charAt((unsigned long)pos); }
Modified: trunk/include/swkey.h
===================================================================
--- trunk/include/swkey.h 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/include/swkey.h 2013-07-28 17:21:44 UTC (rev 2921)
@@ -30,7 +30,10 @@
#include <defs.h>
#include <sysdata.h>
#include <utilstr.h>
+#include <string>
+class QString;
+
SWORD_NAMESPACE_START
#define KEYERR_OUTOFBOUNDS 1
@@ -40,6 +43,7 @@
SWKey &operator =(const SWKey &ikey) { positionFrom(ikey); return *this; } \
SWKey &operator =(SW_POSITION pos) { setPosition(pos); return *this; } \
operator const char *() const { return getText(); } \
+ operator const std::string() const { return getText(); } \
bool operator ==(const SWKey &ikey) { return equals(ikey); } \
bool operator !=(const SWKey &ikey) { return !equals(ikey); } \
virtual bool operator >(const SWKey &ikey) { return (compare(ikey) > 0); } \
@@ -122,11 +126,13 @@
* @param ikey string to use for initializing this new key
*/
SWKey(const char *ikey = 0);
+ SWKey(const std::string &);
/** Copy Constructor
* @param k The SWKey object to copy.
*/
- SWKey(SWKey const &k);
+ SWKey(const SWKey &k);
+ SWKey(const QString &k);
/** Destructor, cleans up this instance of SWKey
*/
Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/include/swmgr.h 2013-07-28 17:21:44 UTC (rev 2921)
@@ -214,6 +214,7 @@
* @return the module, if found, otherwise 0
*/
SWModule *getModule(const char *modName) { ModMap::iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
+ SWModule *getModule(const SWBuf &modName) { return getModule(modName.c_str()); }
const SWModule *getModule(const char *modName) const { ModMap::const_iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
Modified: trunk/include/swmodule.h
===================================================================
--- trunk/include/swmodule.h 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/include/swmodule.h 2013-07-28 17:21:44 UTC (rev 2921)
@@ -88,6 +88,7 @@
// Just leave for now. This lets us always able to call module->flush()
// to manually flush a cache, and doesn't hurt if there is no work done.
+
class SWDLLEXPORT SWModule : public SWCacher, public SWSearchable {
class StdOutDisplay : public SWDisplay {
@@ -213,6 +214,7 @@
* @return Error status
*/
char setKey(const SWKey &ikey) { return setKey(&ikey); }
+ char setKey(const char *keyText) { return setKey(keyText); }
/**
* @deprecated Use setKey() instead.
*/
@@ -642,7 +644,7 @@
* @param render for internal use
* @return result buffer
*/
- virtual const char *renderText(const char *buf = 0, int len = -1, bool render = true);
+ SWBuf renderText(const char *buf = 0, int len = -1, bool render = true);
SWDEPRECATED const char *RenderText(const char *buf = 0, int len = -1, bool render = true) { return renderText(buf, len, render); }
/** Produces any header data which might be useful which is associated with the
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/src/modules/swmodule.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -817,7 +817,7 @@
* RET: this module's text at current key location massaged by renderText filters
*/
- const char *SWModule::renderText(const char *buf, int len, bool render) {
+ SWBuf SWModule::renderText(const char *buf, int len, bool render) {
bool savePEA = isProcessEntryAttributes();
if (!buf) {
entryAttributes.clear();
Modified: trunk/src/utilfuns/Makefile.am
===================================================================
--- trunk/src/utilfuns/Makefile.am 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/src/utilfuns/Makefile.am 2013-07-28 17:21:44 UTC (rev 2921)
@@ -26,8 +26,14 @@
UNTGZ =
endif
+if HAVE_QT
+QTSUPPORT=$(utilfunsdir)/qt/qtsupport.cpp
+AM_CPPFLAGS += $(QT4_CFLAGS)
+endif
+
libsword_la_SOURCES += $(UNTGZ)
libsword_la_SOURCES += $(ftpsrc)
+libsword_la_SOURCES += $(QTSUPPORT)
if USE_INTERNAL_REGEX
SWREGEX = $(utilfunsdir)/regex.c
Added: trunk/src/utilfuns/qt/qtsupport.cpp
===================================================================
--- trunk/src/utilfuns/qt/qtsupport.cpp (rev 0)
+++ trunk/src/utilfuns/qt/qtsupport.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -0,0 +1,29 @@
+#include <swbuf.h>
+#include <swkey.h>
+#include <QString>
+
+SWORD_NAMESPACE_START
+
+
+SWBuf::SWBuf(const QString &str) {
+ init(0);
+ set(str.toUtf8().constData());
+}
+
+SWBuf::operator QString () const {
+ return QString::fromUtf8(c_str());
+}
+
+SWKey::SWKey(const QString &str) {
+ init();
+ index = 0;
+ persist = 0;
+ keytext = 0;
+ rangeText = 0;
+ error = 0;
+ userData = 0;
+ stdstr(&keytext, str.toUtf8().constData());
+}
+
+
+SWORD_NAMESPACE_END
Modified: trunk/utilities/mod2imp.cpp
===================================================================
--- trunk/utilities/mod2imp.cpp 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/utilities/mod2imp.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -116,7 +116,7 @@
for ((*module) = TOP; !module->popError(); (*module)++) {
std::cout << "$$$" << module->getKeyText() << std::endl;
- std::cout << ((render) ? module->renderText() : (strip) ? module->stripText() : module->getRawEntry()) << "\n";
+ std::cout << ((render) ? module->renderText().c_str() : (strip) ? module->stripText() : module->getRawEntry()) << "\n";
}
cout << endl;
Modified: trunk/utilities/vpl2mod.cpp
===================================================================
--- trunk/utilities/vpl2mod.cpp 2013-07-26 15:10:45 UTC (rev 2920)
+++ trunk/utilities/vpl2mod.cpp 2013-07-28 17:21:44 UTC (rev 2921)
@@ -41,8 +41,7 @@
#include <filemgr.h>
#include <swmgr.h>
#include <rawtext.h>
-#include <iostream>
-#include <string>
+#include <swbuf.h>
#include <versekey.h>
#ifndef NO_SWORD_NAMESPACE
@@ -50,10 +49,10 @@
using sword::SWMgr;
using sword::RawText;
using sword::VerseKey;
+using sword::SWBuf;
using sword::SW_POSITION;
#endif
-using std::string;
char readline(int fd, char **buf) {
char ch;
@@ -245,7 +244,7 @@
std::cerr << "Error parsing key: " << buffer << "\n";
exit(-5);
}
- string orig = mod.getRawEntry();
+ SWBuf orig = mod.getRawEntry();
if (!isKJVRef(buffer)) {
VerseKey origVK = vk;
@@ -266,7 +265,7 @@
orig += ") ";
orig += verseText;
orig += " ] ";
- verseText = orig.c_str();
+ verseText = orig;
}
else {
successive = 0;
More information about the sword-cvs
mailing list