Closure Compiler warning - HTMLCanvasElement and Element types mismatch - google-closure-compiler

I am not sure how to clear this warning:
WARNING - actual parameter 1 of
CanvasRenderingContext2D.prototype.drawImage does not match formal parameter
found : Element
required: (HTMLCanvasElement|HTMLImageElement|HTMLVideoElement|null)
ctx.drawImage( poolCanvas, rect.x, rect.y );
Here is the relevant code:
var /** #type {HTMLCanvasElement|Element} */ poolCanvas = document.createElement('canvas');
var /** #type {CanvasRenderingContext2D} */ ctx;
...
ctx.drawImage( poolCanvas, rect.x, rect.y );
I have tried a various combination of type declarations and I can't get rid of this warning.
What am I doing wrong here?

You need to type cast the call to document.createElement:
var poolCanvas =
/** #type {!HTMLCanvasElement} */ (document.createElement('canvas'));
Note the extra parens - they are required for a type cast

Related

How to use MDX constants/functions in icCube Reporting?

I have several functions/constants defined in the schema. An example is:
_latestPeriodWithData() which returns a date.
Goal: I want to use this value in the Reporting to set a Guide in a chart, using the demo example 'On Widget Options':
This is what I tried so far:
I have assigned this function as 'MDX / Value' for a Report Constant _lastDate and obtained the value for this constant using the java script function: context.eventValue('_lastDate'); but that just gives me the caption. The function context.eventObject("_lastDate").options.asMdx gives me _latestPeriodWithData(), but not its value.
On Widget Options
/**
* Result will be used while rendering.
*/
function(context, options, $box) {
// for debugging purpose
console.log(context.eventObject("_lastDate").options.asMdx);
options.guides[0].value = context.eventObject("_lastDate").options.asMdx; // <-- gives me _latestPeriodeWith data
// but not its value
options.guides[0].toValue = context.eventObject("_lastDate").options.asMdx;
options.guides[0].lineAlpha = 1;
options.guides[0].lineColor = "#c44";
return options;
}

Convert QT Resource to ::std::istream&

I am trying to convert a QResource XML to istream. The thirdparty signature to which the XML goes into is shown below.
::std::unique_ptr< ::NO::Peoplefile >
peoplefile (::std::istream& is,
::xml_schema::Flags f = 0,
const ::xml_schema::Properties& p = ::xml_schema::Properties ());
But how do I convert a QResource to istream?
tried using the below, but not been able to convert it to ::std::istream&. Any idea?
ifstream& QFileToifstream(QFile & file) {
Q_ASSERT(file.isReadable());
return ifstream(::_fdopen(file.handle(), "r")); //error: non-const lvalue reference to type 'basic_ifstream<...>' cannot bind to a temporary of type 'basic_ifstream<...>'
}
Since the resource in question is XML I'm assuming it's not huge and can easily be read into memory in its entirety. That being the case you could simply use an std::istringstream...
/*
* Attempt to open the bound resource `:/some-resource.xml'.
*/
if (QFile f(":/some-resource.xml"); f.open(QIODevice::ReadOnly)) {
/*
* Read its contents into an std::string which is used to
* initialize an std::istringstream.
*/
std::istringstream is(f.readAll().toStdString());
/*
* Pass the istringstream as the first parameter to peoplefile.
*/
auto result = peoplefile(is, 0/* flags */, ::xml_schema::Properties());
}

Doctrine - querybuilder - how to make to results from "join" query were not alternately?

I have to table Stats and Stat_values. These tables are in relatioship many to one (A stat can have a lot of stat_value)
I created query via querybuilder:
return $this->getEntityManager()
->createQueryBuilder()
->select(array('s', 'v'))
->from("CMailingDefaultBundle:Stat", "s")
->leftJoin("CMailingDefaultBundle:StatValue", "v")
->where("s.project = :project")
->andWhere("v.isCurrent = 1")
->setParameter("project", $project )
->getQuery()
->getResult();
It works good, but I don't have result in this way (I make it simpler, because all structure of array is so big):
[0] => Stats.field1, Stats.field2, ..., Stat_values.field1, Stat_values, ...
[1] => Stats.field1, Stats.field2, ..., Stat_values.field1, Stat_values, ...
etc...
but I have:
[0] => Stats.field1, Stats.field2, ...
[1] => Stat_values.field1, Stat_values ...
etc...
It is "litle bit" annoying. I tried change select arguments to "s, v" - the results are the same.
Do you have any ideas how to make to datas was ordered in first way?
Could it be because you're not requesting the relation, just a seperate entity?
Instead of:
->from("CMailingDefaultBundle:Stat", "s")
->leftJoin("CMailingDefaultBundle:StatValue", "v")
Try:
->from("CMailingDefaultBundle:Stat", "s")
->leftJoin("s.StatValue", "v")
Assuming the Stat entity has a relation called StatValue...
You can use another hydration method.
Doctrine provides 5 hydration methods, as listed below:
/**
* Hydrates an object graph. This is the default behavior.
*/
const HYDRATE_OBJECT = 1;
/**
* Hydrates an array graph.
*/
const HYDRATE_ARRAY = 2;
/**
* Hydrates a flat, rectangular result set with scalar values.
*/
const HYDRATE_SCALAR = 3;
/**
* Hydrates a single scalar value.
*/
const HYDRATE_SINGLE_SCALAR = 4;
/**
* Very simple object hydrator (optimized for performance).
*/
const HYDRATE_SIMPLEOBJECT = 5;
HYDRATE_SCALAR gives you what you are looking for.
So change the call of: getResult(); to getResult(3); or a little nicer by using the actual constant name: getResult(AbstractQuery::HYDRATE_SCALAR)

Closure Compiler issues warning with namespaced enum

The following sample code generates a compiler warning on advanced optimization: "JSC_UNSAFE_NAMESPACE: incomplete alias created for namespace NS". If I remove the #enum comment, it doesn't give the warning.
var NS = {};
/**
* #enum {string}
*/
NS.type = {
FOO : 'bar'
};
NS.foobar = function(){ alert(NS.type.FOO); };
window['NS'] = NS;
window['NS']['foobar'] = NS.foobar;
Exporting only the function and not the namespace also seems to work:
window['NS_foobar'] = NS.foobar;
What am I doing wrong? Is there a way around this? I'd rather not include the Closure library if possible.
The compiler expects to collapse the enum value into single variables:
NS.type.FOO becomes NS$type$FOO. The "NS" that you exported would not contain what you expect.
I suspect you want something like this:
window['NS'] = {}; // an external namespace object.
window['NS']['foobar'] = NS.foobar; // add 'foobar' to the external namespace.

Flex 3: Using array item value as an objects name

If I have a list of items in an array that represent the names of modules:
var phaseNames:Array = new Array("directorsPrep", "checkIO", "pickupPhoto", "pickupPhoto", "syncing", "dailies", "pictureEdit", "soundEdit", "soundMix", "colorCorrection", "finishing");
and I want to go through each one of these and call a function within each instance of each module, how would I go about doing so. So far, I have the following:
private function changeStartViewDate(numDays:Number):void
{
startViewDate = rightDate(startViewDate.getMonth(), startViewDate.getDate() + numDays, startViewDate.getFullYear());
getDateInfo();
determineCalendarWeek();
var phaseNames:Array = new Array("directorsPrep", "checkIO", "pickupPhoto", "pickupPhoto", "syncing", "dailies", "pictureEdit", "soundEdit", "soundMix", "colorCorrection", "finishing");
for (var i:int = 0; i < wholeProject.length; i++)
{
wholeProject[i].moveProject(Number((1-2) * numDays));
}
for (i = 0; i < phaseNames.length; i++)
{
for (var j:int = 0; j < [phaseNames[i]].length; j++)
{
[phaseNames[i]].movePhase(Number((-1) * numDays));
}
}
}
But when I try to save it, I get the following error:
1084: Syntax Error: expecting identifier before dot.
It's telling me the error is on the following line:
[phaseNames[i]].movePhase(Number((-1) * numDays));
I tried doing something like the following, but it didn't work:
[phaseNames[i].movePhase(Number((-1) * numDays))];
The above attempt of trying to figure this out gave me the following error
1064: Invalid metadata.
Any help would be appreciated.
I am going to assume that:
Each value of your phaseNames array references an actual instance of some other class [and not the name of the class]
The instance defined in the phaseNames array is a child of the current class.
You should be able to do something like this:
var childName = phaseNames[0];
var myChild : myObjectType = this[childName];
// then call function
myChild.doStuff();
This approach is not dissimilar to what you have; I'm just doing it in more lines. I'm also adding the this keyword to access the child.
I bet if you tried this, directly, it would work:
this[phaseNames[i]].movePhase(Number((-1) * numDays));
I have to wonder why you haven't created an array of all the instances instead of an array of all the variables names that point to the instances.

Resources